Skip to content

Commit 75ca216

Browse files
authored
Merge pull request #17 from sacha-development-stuff/codex/add-client-credentials-grant-and-token-introspection-documen
Update auth docs
2 parents b1b34e5 + 4a8294c commit 75ca216

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- [Completions](#completions)
3434
- [Elicitation](#elicitation)
3535
- [Authentication](#authentication)
36+
- [Token Introspection](#token-introspection)
3637
- [Running Your Server](#running-your-server)
3738
- [Development Mode](#development-mode)
3839
- [Claude Desktop Integration](#claude-desktop-integration)
@@ -44,6 +45,8 @@
4445
- [Advanced Usage](#advanced-usage)
4546
- [Low-Level Server](#low-level-server)
4647
- [Writing MCP Clients](#writing-mcp-clients)
48+
- [OAuth Authentication for Clients](#oauth-authentication-for-clients)
49+
- [Client Credentials Grant](#client-credentials-grant)
4750
- [MCP Primitives](#mcp-primitives)
4851
- [Server Capabilities](#server-capabilities)
4952
- [Documentation](#documentation)
@@ -460,6 +463,39 @@ For a complete example with separate Authorization Server and Resource Server im
460463

461464
See [TokenVerifier](src/mcp/server/auth/provider.py) for more details on implementing token validation.
462465

466+
### Token Introspection
467+
468+
The SDK provides `IntrospectionTokenVerifier` for servers that validate
469+
tokens via an OAuth 2.0 introspection endpoint. This verifier performs
470+
an HTTP POST to the configured endpoint and checks the returned token
471+
metadata. When combined with the `--oauth-strict` flag in the example
472+
server, it also enforces RFC 8707 resource validation.
473+
474+
```python
475+
from examples.servers.simple_auth.token_verifier import IntrospectionTokenVerifier
476+
from mcp.server.fastmcp import FastMCP
477+
from mcp.server.auth.settings import AuthSettings
478+
479+
verifier = IntrospectionTokenVerifier(
480+
introspection_endpoint="http://localhost:9000/introspect",
481+
server_url="http://localhost:8001",
482+
validate_resource=True, # same as --oauth-strict
483+
)
484+
485+
app = FastMCP(
486+
"MCP Resource Server",
487+
token_verifier=verifier,
488+
auth=AuthSettings(
489+
issuer_url="http://localhost:9000",
490+
resource_server_url="http://localhost:8001",
491+
required_scopes=["mcp:read"],
492+
),
493+
)
494+
```
495+
496+
See [`examples/servers/simple-auth/`](examples/servers/simple-auth/) for a full
497+
demonstration.
498+
463499
## Running Your Server
464500

465501
### Development Mode
@@ -1089,6 +1125,29 @@ async def main():
10891125

10901126
For a complete working example, see [`examples/clients/simple-auth-client/`](examples/clients/simple-auth-client/).
10911127

1128+
### Client Credentials Grant
1129+
1130+
Machine clients that do not require a user interaction can authenticate using
1131+
the OAuth2 *client credentials* grant. Use `ClientCredentialsProvider` to
1132+
obtain and refresh access tokens automatically.
1133+
1134+
```python
1135+
from mcp.client.auth import ClientCredentialsProvider, OAuthClientMetadata
1136+
1137+
auth = ClientCredentialsProvider(
1138+
server_url="https://api.example.com",
1139+
client_metadata=OAuthClientMetadata(
1140+
client_name="My Machine Client",
1141+
grant_types=["client_credentials"],
1142+
),
1143+
storage=CustomTokenStorage(),
1144+
)
1145+
```
1146+
1147+
`TokenExchangeProvider` builds on this to implement the RFC 8693
1148+
`token_exchange` grant when you need to exchange an existing user token for an
1149+
MCP token.
1150+
10921151

10931152
### MCP Primitives
10941153

0 commit comments

Comments
 (0)