Skip to content

Commit ce62718

Browse files
committed
Sync open source content 🐝 (from 18cd0c491fb882f67c119678ef1bd1af986b3948)
1 parent 55e2cfd commit ce62718

3 files changed

Lines changed: 66 additions & 6 deletions

File tree

docs/mcp/secure/add-oauth-functions.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ You can follow the steps in our [guide](/docs/mcp/secure/adding-oauth-servers) t
4242

4343
## Caveats
4444

45-
MCP servers can only have one authentication method. This means that toolsets cannot contain tools that require different forms of OAuth (though they can contain any number of tools that DO NOT require OAuth alongside tools of a single OAuth type).
45+
Only one managed OAuth provider can be attached to an MCP server. However, other security schemes defined in your OpenAPI spec (API keys, bearer tokens, etc.) are still accepted alongside OAuth — users can authenticate with whichever method they prefer. See [Multiple security schemes](/docs/mcp/secure/adding-oauth-servers#multiple-security-schemes) for details.
46+
47+
Toolsets can contain any number of tools that do not require OAuth alongside tools that use a single OAuth provider.

docs/mcp/secure/adding-oauth-servers.mdx

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ Before implementing OAuth, consider what kind of credentials you expect end user
6363

6464
**Gram can integrate OAuth into a server in any way that's currently possible within the MCP context.** The key is choosing the approach that best fits your existing authentication system and user experience goals.
6565

66+
<Callout title="Multiple security schemes" type="info">
67+
If your OpenAPI spec defines multiple security schemes (e.g., OAuth **and** an API key), Gram will accept any of them. Users are not locked into a single authentication method — see [Multiple security schemes](#multiple-security-schemes) below.
68+
</Callout>
69+
6670
## Access Token Based Authentication
6771

6872
**This is often the simplest and most practical approach for MCP servers.** Gram allows passing pre-obtained OAuth access tokens directly to an MCP server through headers. This is completely valid and doesn't require implementing complex OAuth flows.
@@ -124,7 +128,7 @@ Companies like [Stripe](https://docs.stripe.com/mcp), [Asana](https://developers
124128

125129
If your underlying API supports the necessary OAuth requirements, you can easily place any OAuth server in front of any Gram MCP Server with just a few clicks!
126130

127-
Only one OAuth flow can be placed in front of an MCP server, so it is very important that your MCP server only includes a single downstream API provider that takes in OAuth.
131+
Only one managed OAuth flow can be placed in front of an MCP server, so it is very important that your MCP server only includes a single downstream API provider that takes in OAuth. However, other security schemes (API keys, bearer tokens, etc.) defined in your OpenAPI spec will still be accepted alongside managed OAuth — see [Multiple security schemes](#multiple-security-schemes).
128132

129133
The artifact you are able to produce should look something like this:
130134

@@ -154,17 +158,71 @@ Note: An MCP Client such as Claude will use the same client_id in perpetuity unl
154158

155159
See our [guide](/docs/mcp/build/examples/oauth-external-server) on integrating a DCR compliant OAuth setup into a Gram MCP Server.
156160

161+
## Multiple security schemes
162+
163+
If your OpenAPI spec defines more than one security scheme, Gram evaluates **all** of them when a request arrives. Access is granted as long as **at least one** scheme is satisfied. This means you can offer users flexibility: some may authenticate with an OAuth token while others provide an API key or a bearer token.
164+
165+
### Supported scheme types
166+
167+
| Scheme | OpenAPI type | Credential source |
168+
|---|---|---|
169+
| API Key | `apiKey` | Header or query parameter |
170+
| HTTP Bearer | `http` (scheme `bearer`) | `Authorization` header |
171+
| HTTP Basic | `http` (scheme `basic`) | `Authorization` header (username + password) |
172+
| OAuth 2.0 Authorization Code | `oauth2` (authorizationCode flow) | Bearer token via managed OAuth or pass-through |
173+
| OAuth 2.0 Client Credentials | `oauth2` (clientCredentials flow) | `client_id` + `client_secret` environment variables |
174+
| OpenID Connect | `openIdConnect` | Bearer token via managed OAuth or pass-through |
175+
176+
### How it works
177+
178+
- Gram reads the `securitySchemes` from your OpenAPI spec and classifies each one.
179+
- On every `tools/list` or `tools/call` request, Gram merges credentials from the system environment, the user's Gram environment, and any headers included in the request.
180+
- If **any** scheme's required credentials are present, the request proceeds. If none are satisfied, the server returns a `401` with a `WWW-Authenticate` header pointing to the OAuth metadata endpoint (when OAuth is configured).
181+
182+
### Example: OAuth + API key
183+
184+
```yaml
185+
components:
186+
securitySchemes:
187+
oauth2:
188+
type: oauth2
189+
flows:
190+
authorizationCode:
191+
authorizationUrl: /oauth/authorize
192+
tokenUrl: /oauth/token
193+
scopes:
194+
read: Read access
195+
apiKey:
196+
type: apiKey
197+
in: header
198+
name: X-API-Key
199+
200+
security:
201+
- oauth2: [read]
202+
- apiKey: []
203+
```
204+
205+
With this configuration:
206+
- Users who complete the OAuth flow are authenticated via their bearer token.
207+
- Users who pass an `X-API-Key` header are authenticated via the API key — no OAuth flow required.
208+
- If neither credential is provided, the server returns `401` with OAuth discovery metadata so clients can initiate the OAuth flow.
209+
210+
<Callout title="Managed OAuth limit" type="info">
211+
Only one managed OAuth provider can be attached to a server. The multi-scheme support described here applies to credentials defined in your OpenAPI spec's `securitySchemes`, not to multiple managed OAuth providers.
212+
</Callout>
213+
157214
## Summary
158215

159216
When implementing authentication for your MCP server, remember:
160217

161218
1. **OAuth exchange is NOT required** - passing access tokens directly is completely valid
162-
2. **Choose the right approach** for your use case:
219+
2. **Multiple security schemes are supported** - if your OpenAPI spec defines OAuth, API key, and bearer auth, users can authenticate with any of them
220+
3. **Choose the right approach** for your use case:
163221
- Access tokens: Simple, works with existing systems
164222
- Client credentials: Good for server-to-server auth
165223
- Gram OAuth: Organization-based access control for private servers (no external OAuth needed)
166224
- User-facing OAuth: Best for public servers with external OAuth providers (requires DCR or proxy)
167-
3. **DCR is only needed** if you want MCP clients to handle OAuth flows with external providers directly, but it is a requirement for that scenario
168-
4. **We can help** with white-glove service for guiding towards DCR compliance
225+
4. **DCR is only needed** if you want MCP clients to handle OAuth flows with external providers directly, but it is a requirement for that scenario
226+
5. **We can help** with white-glove service for guiding towards DCR compliance
169227

170228
The goal is to choose the authentication method that works best with your existing infrastructure while providing the right user experience for your MCP server's intended use case.

docs/mcp/secure/public-private-servers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Public servers are the easiest way to use Gram and are typically what you'd use
2626

2727
![Example of a Gram-hosted MCP documentation page showing available tools and endpoints](/assets/docs/gram/img/guides/gram-example-public-docs.png)
2828

29-
Public servers also support [MCP Managed OAuth](/docs/mcp/secure/adding-oauth-servers) for simplified authentication.
29+
Public servers also support [MCP Managed OAuth](/docs/mcp/secure/adding-oauth-servers) for simplified authentication. When OAuth is configured, users can still authenticate with alternative security schemes defined in your OpenAPI spec (such as API keys or bearer tokens). Gram evaluates all available schemes and grants access when any one is satisfied — see [Multiple security schemes](/docs/mcp/secure/adding-oauth-servers#multiple-security-schemes) for details.
3030

3131
## Private Servers
3232

0 commit comments

Comments
 (0)