Skip to content

Commit 5edf379

Browse files
committed
Add documentation on ProxyOAuthServerProvider
1 parent 1899d5c commit 5edf379

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- [Low-Level Server](#low-level-server)
2222
- [Writing MCP Clients](#writing-mcp-clients)
2323
- [Server Capabilities](#server-capabilities)
24+
- [Proxy OAuth Server](#proxy-authorization-requests-upstream)
2425

2526
## Overview
2627

@@ -489,6 +490,52 @@ const result = await client.callTool({
489490
});
490491
```
491492

493+
### Proxy Authorization Requests Upstream
494+
495+
You can proxy OAuth requests to an external OAuth provider while adding custom validation and client management:
496+
497+
```typescript
498+
import express from 'express';
499+
import { ProxyOAuthServerProvider, mcpAuthRouter } from '@modelcontextprotocol/sdk';
500+
501+
const app = express();
502+
503+
const proxyProvider = new ProxyOAuthServerProvider({
504+
endpoints: {
505+
authorizationUrl: "https://auth.external.com/oauth2/v1/authorize",
506+
tokenUrl: "https://auth.external.com/oauth2/v1/token",
507+
revocationUrl: "https://auth.external.com/oauth2/v1/revoke",
508+
},
509+
verifyAccessToken: async (token) => {
510+
return {
511+
token,
512+
clientId: "123",
513+
scopes: ["openid", "email", "profile"],
514+
}
515+
},
516+
getClient: async (client_id) => {
517+
return {
518+
client_id,
519+
redirect_uris: ["http://localhost:3000/callback"],
520+
}
521+
}
522+
})
523+
524+
app.use(mcpAuthRouter({
525+
provider: proxyProvider,
526+
issuerUrl: new URL("http://auth.external.com"),
527+
baseUrl: new URL("http://mcp.example.com"),
528+
serviceDocumentationUrl: new URL("https://docs.example.com/"),
529+
}))
530+
```
531+
532+
This setup allows you to:
533+
- Forward OAuth requests to an external provider
534+
- Add custom token validation logic
535+
- Manage client registrations
536+
- Provide custom documentation URLs
537+
- Maintain control over the OAuth flow while delegating to an external provider
538+
492539
## Documentation
493540

494541
- [Model Context Protocol documentation](https://modelcontextprotocol.io)

0 commit comments

Comments
 (0)