Skip to content

Commit ef8d546

Browse files
committed
add readme
1 parent fd353c5 commit ef8d546

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

README.md

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,43 +423,39 @@ The `elicit()` method returns an `ElicitationResult` with:
423423

424424
Authentication can be used by servers that want to expose tools accessing protected resources.
425425

426-
`mcp.server.auth` implements an OAuth 2.0 server interface, which servers can use by
427-
providing an implementation of the `OAuthAuthorizationServerProvider` protocol.
426+
`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-06-18/basic/authorization) and implements RFC 9728 (Protected Resource Metadata) for AS discovery.
427+
428+
MCP servers can use authentication by providing an implementation of the `TokenVerifier` protocol:
428429

429430
```python
430431
from mcp import FastMCP
431-
from mcp.server.auth.provider import OAuthAuthorizationServerProvider
432-
from mcp.server.auth.settings import (
433-
AuthSettings,
434-
ClientRegistrationOptions,
435-
RevocationOptions,
436-
)
437-
438-
439-
class MyOAuthServerProvider(OAuthAuthorizationServerProvider):
440-
# See an example on how to implement at `examples/servers/simple-auth`
441-
...
432+
from mcp.server.auth.verifier import TokenVerifier
433+
from mcp.server.auth.settings import AuthSettings
442434

435+
class MyTokenVerifier(TokenVerifier):
436+
# Implement token validation logic (typically via token introspection)
437+
async def verify_token(self, token: str) -> TokenInfo:
438+
# Verify with your authorization server
439+
...
443440

444441
mcp = FastMCP(
445442
"My App",
446-
auth_server_provider=MyOAuthServerProvider(),
443+
token_verifier=MyTokenVerifier(),
447444
auth=AuthSettings(
448-
issuer_url="https://myapp.com",
449-
revocation_options=RevocationOptions(
450-
enabled=True,
451-
),
452-
client_registration_options=ClientRegistrationOptions(
453-
enabled=True,
454-
valid_scopes=["myscope", "myotherscope"],
455-
default_scopes=["myscope"],
456-
),
457-
required_scopes=["myscope"],
445+
authorization_servers=["https://auth.example.com"],
446+
required_scopes=["mcp:read", "mcp:write"],
458447
),
459448
)
460449
```
461450

462-
See [OAuthAuthorizationServerProvider](src/mcp/server/auth/provider.py) for more details.
451+
For a complete example with separate Authorization Server and Resource Server implementations, see [`examples/servers/simple-auth/`](examples/servers/simple-auth/).
452+
453+
**Architecture:**
454+
- **Authorization Server (AS)**: Handles OAuth flows, user authentication, and token issuance
455+
- **Resource Server (RS)**: Your MCP server that validates tokens and serves protected resources
456+
- **Client**: Discovers AS through RFC 9728, obtains tokens, and uses them with the MCP server
457+
458+
See [TokenVerifier](src/mcp/server/auth/verifier.py) for more details on implementing token validation.
463459

464460
## Running Your Server
465461

examples/servers/simple-auth/mcp_simple_auth/token_verifier.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import logging
44

55
from mcp.server.auth.provider import AccessToken
6+
from mcp.server.auth.token_verifier import TokenVerifier
67

78
logger = logging.getLogger(__name__)
89

910

10-
class IntrospectionTokenVerifier:
11+
class IntrospectionTokenVerifier(TokenVerifier):
1112
"""Example token verifier that uses OAuth 2.0 Token Introspection (RFC 7662).
1213
1314
This is a simple example implementation for demonstration purposes.

src/mcp/server/auth/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pydantic import AnyUrl, BaseModel
66

7+
from mcp.server.auth.token_verifier import TokenVerifier
78
from mcp.shared.auth import OAuthClientInformationFull, OAuthToken
89

910

@@ -280,7 +281,7 @@ def construct_redirect_uri(redirect_uri_base: str, **params: str | None) -> str:
280281
return redirect_uri
281282

282283

283-
class ProviderTokenVerifier:
284+
class ProviderTokenVerifier(TokenVerifier):
284285
"""Token verifier that uses an OAuthAuthorizationServerProvider.
285286
286287
This is provided for backwards compatibility with existing auth_server_provider

0 commit comments

Comments
 (0)