Adding OAuth to an MCP Server
Configure authentication for MCP servers using different OAuth methods
Implementation Support
For assistance with OAuth implementation, including proxy setup and DCR compliance, reach out to Gram support
Starting March 2025, the MCP specification recommends OAuth-based authentication, but most existing OAuth implementations don’t meet MCP’s specific requirements. The specification calls for OAuth 2.1 and support for Dynamic Client Registration (DCR), which most major OAuth providers—including Google, GitHub, and Microsoft Azure AD—don’t support. This mismatch between MCP’s vision and existing OAuth infrastructure creates a common implementation barrier for enterprise adoption.
The requirements for OAuth 2.1 in MCP can be found [here].(https://modelcontextprotocol.io/specification/draft/basic/authorization#protocol-requirements
Gram bridges this gap by supporting multiple authentication approaches, from simple token-based methods to complex OAuth proxy solutions. How you set up authentication depends on the OAuth capabilities of the underlying API and the intended purpose of your MCP server. Understanding these different approaches and their trade-offs is essential for selecting the right authentication strategy.
Authorization Code Flow
Authorization code flow enables user-interactive OAuth with proper consent screens. However, it requires OAuth providers to support specific MCP requirements.
With DCR
When should you use it: If you want to host an MCP server for large-scale use by external developers, you should plan to built out support for DCR.
Examples: Stripe
Implementation in Gram
If the API is already configured to support DCR, enabling the authorization flow on Gram is simple:
- Create a manifest file for the OAuth server in Gram.
- Attach the manifest to your toolset.
Without DCR
When should you use it: Most APIs don’t support DCR, so Gram offers an OAuth proxy that translates between MCP requirements and standard OAuth implementations. The proxy will use a specific client id and secret to access the API on behalf of the users of the MCP server.
This is useful for MCP servers that won’t be exposed to the public, or in cases where a server acting as a single client_id is acceptable.
Examples: Cloudflare OAuth Proxy
How the OAuth proxy works
- Proxy Registration: Proxy exposes DCR-compliant endpoints to MCP clients
- Token Translation: Converts between proxy tokens and a set of real provider tokens
- Flow Management: Handles OAuth dance between client and actual provider
- State Storage: Maintains token mappings and authorization state
Implementation in Gram
If you want to implement OAuth proxy in Gram, please book in time with our team
Client Credentials Flow
Client credentials flow is a simpler authentication method. The server exchanges a client ID and secret for access tokens. Gram handles the token exchange process automatically.
Implementation in Gram
- Upload the OpenAPI specification to Gram
- Navigate to Environments tab
- Add environment variables:
CLIENT_ID
: Application client identifierCLIENT_SECRET
: Application client secret
- Attach environment to toolset
Access Token Authentication
Access token authentication allows passing pre-obtained tokens directly to the MCP server. This method works with any OAuth provider, regardless of DCR support.
Implementation in Gram
- Obtain access token from the OAuth provider
- Navigate to Environments tab
- Add
ACCESS_TOKEN
environment variable - Attach environment to toolset
Popular services like GitHub use this approach. While technically OAuth-based, no OAuth flow occurs through the MCP client.
Last updated on