|
33 | 33 | - [Completions](#completions)
|
34 | 34 | - [Elicitation](#elicitation)
|
35 | 35 | - [Authentication](#authentication)
|
| 36 | + - [Token Introspection](#token-introspection) |
36 | 37 | - [Running Your Server](#running-your-server)
|
37 | 38 | - [Development Mode](#development-mode)
|
38 | 39 | - [Claude Desktop Integration](#claude-desktop-integration)
|
|
44 | 45 | - [Advanced Usage](#advanced-usage)
|
45 | 46 | - [Low-Level Server](#low-level-server)
|
46 | 47 | - [Writing MCP Clients](#writing-mcp-clients)
|
| 48 | + - [OAuth Authentication for Clients](#oauth-authentication-for-clients) |
| 49 | + - [Client Credentials Grant](#client-credentials-grant) |
47 | 50 | - [MCP Primitives](#mcp-primitives)
|
48 | 51 | - [Server Capabilities](#server-capabilities)
|
49 | 52 | - [Documentation](#documentation)
|
@@ -460,6 +463,39 @@ For a complete example with separate Authorization Server and Resource Server im
|
460 | 463 |
|
461 | 464 | See [TokenVerifier](src/mcp/server/auth/provider.py) for more details on implementing token validation.
|
462 | 465 |
|
| 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 | + |
463 | 499 | ## Running Your Server
|
464 | 500 |
|
465 | 501 | ### Development Mode
|
@@ -1089,6 +1125,29 @@ async def main():
|
1089 | 1125 |
|
1090 | 1126 | For a complete working example, see [`examples/clients/simple-auth-client/`](examples/clients/simple-auth-client/).
|
1091 | 1127 |
|
| 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 | + |
1092 | 1151 |
|
1093 | 1152 | ### MCP Primitives
|
1094 | 1153 |
|
|
0 commit comments