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
This page covers OAuth 2.1 authentication for both MCP servers and clients.
4
4
5
-
This page is currently being written. Check back soon for complete documentation.
5
+
## Server-Side Authentication
6
+
7
+
Authentication can be used by servers that want to expose tools accessing protected resources.
8
+
9
+
`mcp.server.auth` implements OAuth 2.1 resource server functionality, where MCP servers act as Resource Servers (RS) that validate tokens issued by separate Authorization Servers (AS). This follows the [MCP authorization specification](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization) and implements RFC 9728 (Protected Resource Metadata) for AS discovery.
10
+
11
+
MCP servers can use authentication by providing an implementation of the `TokenVerifier` protocol:
For a complete example with separate Authorization Server and Resource Server implementations, see [`examples/servers/simple-auth/`](examples/servers/simple-auth/).
68
+
69
+
**Architecture:**
70
+
71
+
-**Authorization Server (AS)**: Handles OAuth flows, user authentication, and token issuance
72
+
-**Resource Server (RS)**: Your MCP server that validates tokens and serves protected resources
73
+
-**Client**: Discovers AS through RFC 9728, obtains tokens, and uses them with the MCP server
74
+
75
+
See [TokenVerifier](src/mcp/server/auth/provider.py) for more details on implementing token validation.
76
+
77
+
## Client-Side Authentication
78
+
79
+
The SDK includes [authorization support](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization) for connecting to protected MCP servers:
Copy file name to clipboardExpand all lines: docs/client.md
+7-107Lines changed: 7 additions & 107 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Writing MCP Clients
2
2
3
-
The SDK provides a high-level client interface for connecting to MCP servers using various [transports](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports):
3
+
The SDK provides a high-level client interface for connecting to MCP servers using various [transports](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports):
@@ -215,107 +215,9 @@ The `get_display_name()` function implements the proper precedence rules for dis
215
215
216
216
This ensures your client UI shows the most user-friendly names that servers provide.
217
217
218
-
## OAuth Authentication for Clients
218
+
## OAuth Authentication
219
219
220
-
The SDK includes [authorization support](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization) for connecting to protected MCP servers:
For a complete working example, see [`examples/clients/simple-auth-client/`](../examples/clients/simple-auth-client/).
220
+
For OAuth 2.1 client authentication, see [Authorization](authorization.md#client-side-authentication).
319
221
320
222
## Roots
321
223
@@ -324,14 +226,12 @@ For a complete working example, see [`examples/clients/simple-auth-client/`](../
324
226
Clients can provide a `list_roots_callback` so that servers can discover the client's workspace roots (directories, project folders, etc.):
325
227
326
228
```python
327
-
from typing import Any
328
-
329
229
from mcp import ClientSession, types
330
230
from mcp.shared.context import RequestContext
331
231
332
232
333
233
asyncdefhandle_list_roots(
334
-
context: RequestContext[ClientSession, Any],
234
+
context: RequestContext[ClientSession, None],
335
235
) -> types.ListRootsResult:
336
236
"""Return the client's workspace roots."""
337
237
return types.ListRootsResult(
@@ -384,7 +284,7 @@ async def main():
384
284
asyncio.run(main())
385
285
```
386
286
387
-
The `sse_client()` function accepts optional `headers`, `timeout`, `sse_read_timeout`, and `auth` parameters. The SSE transport is considered legacy; prefer [Streamable HTTP](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) for new servers.
287
+
The `sse_client()` function accepts optional `headers`, `timeout`, `sse_read_timeout`, and `auth` parameters. The SSE transport is considered legacy; prefer [Streamable HTTP](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#streamable-http) for new servers.
0 commit comments