You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/mcp/secure/add-oauth-functions.mdx
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,4 +42,6 @@ You can follow the steps in our [guide](/docs/mcp/secure/adding-oauth-servers) t
42
42
43
43
## Caveats
44
44
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.
Copy file name to clipboardExpand all lines: docs/mcp/secure/adding-oauth-servers.mdx
+62-4Lines changed: 62 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,10 @@ Before implementing OAuth, consider what kind of credentials you expect end user
63
63
64
64
**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.
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
+
66
70
## Access Token Based Authentication
67
71
68
72
**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
124
128
125
129
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!
126
130
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).
128
132
129
133
The artifact you are able to produce should look something like this:
130
134
@@ -154,17 +158,71 @@ Note: An MCP Client such as Claude will use the same client_id in perpetuity unl
154
158
155
159
See our [guide](/docs/mcp/build/examples/oauth-external-server) on integrating a DCR compliant OAuth setup into a Gram MCP Server.
156
160
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.
| 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
+
157
214
## Summary
158
215
159
216
When implementing authentication for your MCP server, remember:
160
217
161
218
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:
163
221
- Access tokens: Simple, works with existing systems
164
222
- Client credentials: Good for server-to-server auth
165
223
- Gram OAuth: Organization-based access control for private servers (no external OAuth needed)
166
224
- 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
169
227
170
228
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.
Copy file name to clipboardExpand all lines: docs/mcp/secure/public-private-servers.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Public servers are the easiest way to use Gram and are typically what you'd use
26
26
27
27

28
28
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.
0 commit comments