mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-18 22:44:20 +01:00
Fix and update OAuthAuthorizationServerProvider snippet in README.md (#830)
This commit is contained in:
52
README.md
52
README.md
@@ -315,27 +315,42 @@ async def long_task(files: list[str], ctx: Context) -> str:
|
|||||||
Authentication can be used by servers that want to expose tools accessing protected resources.
|
Authentication can be used by servers that want to expose tools accessing protected resources.
|
||||||
|
|
||||||
`mcp.server.auth` implements an OAuth 2.0 server interface, which servers can use by
|
`mcp.server.auth` implements an OAuth 2.0 server interface, which servers can use by
|
||||||
providing an implementation of the `OAuthServerProvider` protocol.
|
providing an implementation of the `OAuthAuthorizationServerProvider` protocol.
|
||||||
|
|
||||||
```
|
```python
|
||||||
mcp = FastMCP("My App",
|
from mcp import FastMCP
|
||||||
auth_server_provider=MyOAuthServerProvider(),
|
from mcp.server.auth.provider import OAuthAuthorizationServerProvider
|
||||||
auth=AuthSettings(
|
from mcp.server.auth.settings import (
|
||||||
issuer_url="https://myapp.com",
|
AuthSettings,
|
||||||
revocation_options=RevocationOptions(
|
ClientRegistrationOptions,
|
||||||
enabled=True,
|
RevocationOptions,
|
||||||
),
|
)
|
||||||
client_registration_options=ClientRegistrationOptions(
|
|
||||||
enabled=True,
|
|
||||||
valid_scopes=["myscope", "myotherscope"],
|
class MyOAuthServerProvider(OAuthAuthorizationServerProvider):
|
||||||
default_scopes=["myscope"],
|
# See an example on how to implement at `examples/servers/simple-auth`
|
||||||
),
|
...
|
||||||
required_scopes=["myscope"],
|
|
||||||
|
|
||||||
|
mcp = FastMCP(
|
||||||
|
"My App",
|
||||||
|
auth_server_provider=MyOAuthServerProvider(),
|
||||||
|
auth=AuthSettings(
|
||||||
|
issuer_url="https://myapp.com",
|
||||||
|
revocation_options=RevocationOptions(
|
||||||
|
enabled=True,
|
||||||
),
|
),
|
||||||
|
client_registration_options=ClientRegistrationOptions(
|
||||||
|
enabled=True,
|
||||||
|
valid_scopes=["myscope", "myotherscope"],
|
||||||
|
default_scopes=["myscope"],
|
||||||
|
),
|
||||||
|
required_scopes=["myscope"],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
See [OAuthServerProvider](src/mcp/server/auth/provider.py) for more details.
|
See [OAuthAuthorizationServerProvider](src/mcp/server/auth/provider.py) for more details.
|
||||||
|
|
||||||
## Running Your Server
|
## Running Your Server
|
||||||
|
|
||||||
@@ -462,15 +477,12 @@ For low level server with Streamable HTTP implementations, see:
|
|||||||
- Stateful server: [`examples/servers/simple-streamablehttp/`](examples/servers/simple-streamablehttp/)
|
- Stateful server: [`examples/servers/simple-streamablehttp/`](examples/servers/simple-streamablehttp/)
|
||||||
- Stateless server: [`examples/servers/simple-streamablehttp-stateless/`](examples/servers/simple-streamablehttp-stateless/)
|
- Stateless server: [`examples/servers/simple-streamablehttp-stateless/`](examples/servers/simple-streamablehttp-stateless/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The streamable HTTP transport supports:
|
The streamable HTTP transport supports:
|
||||||
- Stateful and stateless operation modes
|
- Stateful and stateless operation modes
|
||||||
- Resumability with event stores
|
- Resumability with event stores
|
||||||
- JSON or SSE response formats
|
- JSON or SSE response formats
|
||||||
- Better scalability for multi-node deployments
|
- Better scalability for multi-node deployments
|
||||||
|
|
||||||
|
|
||||||
### Mounting to an Existing ASGI Server
|
### Mounting to an Existing ASGI Server
|
||||||
|
|
||||||
> **Note**: SSE transport is being superseded by [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http).
|
> **Note**: SSE transport is being superseded by [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http).
|
||||||
|
|||||||
Reference in New Issue
Block a user