Oura MCP Server for Sleep Data Retrieval
Retrieve Oura sleep data using an MCP server that connects to the Oura API for secure, automated sleep data access and sync.
npx -y @tomekkorbak/oura-mcp-serverOverview
This MCP (Model Context Protocol) server connects to the Oura API to fetch and surface sleep-related data for downstream applications and model contexts. It performs the OAuth2 handshake with Oura, stores access/refresh tokens securely, and exposes simple HTTP endpoints that return curated sleep metrics in a machine-friendly JSON format. The server is intended for developers who want automated, repeatable access to Oura sleep data for analytics, personal assistants, or model prompt augmentation.
Because the server acts as an intermediary, it centralizes authentication and token management and can be deployed behind standard infrastructure (containers, reverse proxies, secrets managers). Using an MCP-compatible endpoint pattern makes it straightforward to integrate sleep context into AI-driven workflows or pipelines while separating direct API credentials from consuming services.
Features
- OAuth2 integration with Oura Cloud API (authorization + token refresh)
- Endpoints that expose sleep summary and detailed sleep period data
- MCP-oriented endpoints for model context consumption
- Local or containerized deployment, configurable via environment variables
- Minimal dependencies to keep operational surface small
- Automated token refresh to maintain continuous access to user data
Installation / Configuration
Clone the repository and run with Docker or locally (example uses Docker but local builds follow the same env variables).
- Clone the repo:
- Build and run with Docker:
Common environment variables
OURA_CLIENT_ID # Oura OAuth client ID
OURA_CLIENT_SECRET # Oura OAuth client secret
REDIRECT_URI # Redirect URI configured for the Oura app
PORT # (optional) server listen port, default 8080
STORAGE_PATH # (optional) where persisted tokens or DB files are stored
If running locally without Docker, you can typically install dependencies and run a start script:
# example for a Node.js project
(Refer to the repository’s package/build files for exact commands if different.)
Available Resources
Below are the typical endpoints exposed by the server. Exact paths may vary — check the repo or the running service’s /openapi or README for precise routes.
| Endpoint | Method | Description |
|---|---|---|
| /authorize | GET | Starts Oura OAuth flow; redirect user to Oura consent screen |
| /callback | GET | OAuth callback to receive authorization code and save tokens |
| /sleep | GET | Returns recent sleep summaries (optionally accept date query params) |
| /sleep/:date | GET | Returns detailed sleep period for a specific date (YYYY-MM-DD) |
| /mcp/context | POST | MCP-style context endpoint that returns structured sleep context for models |
| /health | GET | Simple health check |
Example: request sleep for date
Example: request MCP context (POST body can include user id and date range)
Sample response (abbreviated):
Use Cases
- Enrich model prompts with recent sleep context: A personal assistant can include a user’s sleep quality summary when generating daily recommendations.
- Automated reporting pipeline: Periodically pull sleep metrics for cohort analysis and feed them into data warehouses or dashboards.
- Health-focused agents: Deliver personalized coaching by combining sleep trends with activity and readiness scores retrieved via the MCP server.
- Privacy-aware integrations: Keep Oura credentials and refresh tokens confined to the server; downstream services receive only the data they need via structured endpoints.
Concrete example flows
Personal assistant
- User authorizes the Oura account via /authorize.
- The assistant queries /mcp/context each morning to include sleep quality and duration in a greeting message like “You slept 7.1 hours last night with a sleep score of 82.”
Nightly ETL job
- A scheduler hits /sleep with a date range on a daily basis.
- The job stores aggregated nightly sleep metrics into a timeseries DB for trend analysis.
Notes and Next Steps
- Review the repository documentation for exact endpoint names and auth flow details.
- Secure deployment: run behind HTTPS, use a secrets manager for client credentials, and restrict access to MCP endpoints as needed.
- If you need additional fields, extend the server to map more Oura API fields into the MCP response schema.
Repository and source: https://github.com/tomekkorbak/oura-mcp-server
Common Issues & Solutions
A GitHub issue says my project is listed on Spark and asks me to sign in to claim the listing; I'm unsure if the message is legitimate, what permissions the claim flow needs, or what steps I should take.
I ran into this too! It looked like another repo notification, but it turned out to be legitimate: I visited the claim URL, signed in with GitHub, and the flow automatically checked my push access to the repo. It requested only minimal OAuth scopes (repo/org access) which I reviewed before approving. After claiming I updated the title, description, and tags on Spark and added the "Listed on Spark" badge to README.md. If you're unsure, verify the claim domain (spark.entire.vc), confirm the sender, and revoke app access afterward if desired.
Oura is deprecating Personal Access Tokens by the end of 2025, and our server currently uses PATs for API access. We need to migrate to OAuth2 so integrations keep working and avoid future outages.
I ran into this too! The fix was migrating off PATs to Oura's OAuth2 Authorization Code flow: I registered our app, added the redirect URI, and implemented the server-side token exchange to get access and refresh tokens. I updated all API requests to use the Bearer Authorization header, stored refresh tokens encrypted in our DB, and added an automated refresh job to get new access tokens before expiration. I replaced any CI secrets that held PATs with client_id/client_secret, tested the full flow in staging using Oura's auth docs, and then deployed the change — everything worked and no PATs are needed now.