Jeremiah Lowin commited on
Commit
cefca54
·
unverified ·
2 Parent(s): f8f2037e54a129

Merge pull request #687 from jlowin/docs-clean-up

Browse files
README.md CHANGED
@@ -74,6 +74,7 @@ There are two ways to access the LLM-friendly documentation:
74
  - [Proxy Servers](#proxy-servers)
75
  - [Composing MCP Servers](#composing-mcp-servers)
76
  - [OpenAPI \& FastAPI Generation](#openapi--fastapi-generation)
 
77
  - [Running Your Server](#running-your-server)
78
  - [Contributing](#contributing)
79
  - [Prerequisites](#prerequisites)
@@ -127,7 +128,7 @@ These are the building blocks for creating MCP servers and clients with FastMCP.
127
 
128
  ### The `FastMCP` Server
129
 
130
- The central object representing your MCP application. It holds your tools, resources, and prompts, manages connections, and can be configured with settings like [authentication providers](https://gofastmcp.com/servers/fastmcp#authentication).
131
 
132
  ```python
133
  from fastmcp import FastMCP
@@ -300,6 +301,16 @@ Automatically generate FastMCP servers from existing OpenAPI specifications (`Fa
300
 
301
  Learn more: [**OpenAPI Integration**](https://gofastmcp.com/patterns/openapi) | [**FastAPI Integration**](https://gofastmcp.com/patterns/fastapi).
302
 
 
 
 
 
 
 
 
 
 
 
303
  ## Running Your Server
304
 
305
  The main way to run a FastMCP server is by calling the `run()` method on your server instance:
 
74
  - [Proxy Servers](#proxy-servers)
75
  - [Composing MCP Servers](#composing-mcp-servers)
76
  - [OpenAPI \& FastAPI Generation](#openapi--fastapi-generation)
77
+ - [Authentication \& Security](#authentication--security)
78
  - [Running Your Server](#running-your-server)
79
  - [Contributing](#contributing)
80
  - [Prerequisites](#prerequisites)
 
128
 
129
  ### The `FastMCP` Server
130
 
131
+ The central object representing your MCP application. It holds your tools, resources, and prompts, manages connections, and can be configured with settings like authentication.
132
 
133
  ```python
134
  from fastmcp import FastMCP
 
301
 
302
  Learn more: [**OpenAPI Integration**](https://gofastmcp.com/patterns/openapi) | [**FastAPI Integration**](https://gofastmcp.com/patterns/fastapi).
303
 
304
+ ### Authentication & Security
305
+
306
+ FastMCP provides built-in authentication support to secure both your MCP servers and clients in production environments. Protect your server endpoints from unauthorized access and authenticate your clients against secured MCP servers using industry-standard protocols.
307
+
308
+ - **Server Protection**: Secure your FastMCP server endpoints with configurable authentication providers
309
+ - **Client Authentication**: Connect to authenticated MCP servers with automatic credential management
310
+ - **Production Ready**: Support for common authentication patterns used in enterprise environments
311
+
312
+ Learn more in the **Authentication Documentation** for [servers](https://gofastmcp.com/servers/auth) and [clients](https://gofastmcp.com/clients/auth).
313
+
314
  ## Running Your Server
315
 
316
  The main way to run a FastMCP server is by calling the `run()` method on your server instance:
docs/clients/auth/bearer.mdx CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
  title: Bearer Token Authentication
3
  sidebarTitle: Bearer Auth
4
- description: Authenticate your FastMCP client using pre-existing OAuth 2.0 Bearer tokens.
5
  icon: key
6
  ---
7
 
 
1
  ---
2
  title: Bearer Token Authentication
3
  sidebarTitle: Bearer Auth
4
+ description: Authenticate your FastMCP client with a Bearer token.
5
  icon: key
6
  ---
7
 
docs/clients/auth/oauth.mdx CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
  title: OAuth Authentication
3
  sidebarTitle: OAuth
4
- description: Authenticate your FastMCP client with servers using the OAuth 2.0 Authorization Code Grant, including user interaction via a web browser.
5
  icon: window
6
  ---
7
 
@@ -13,7 +13,7 @@ import { VersionBadge } from "/snippets/version-badge.mdx"
13
  OAuth authentication is only relevant for HTTP-based transports and requires user interaction via a web browser.
14
  </Tip>
15
 
16
- When your FastMCP client needs to access an MCP server protected by OAuth 2.0, and the process requires user interaction (like logging in and granting consent), you should use the Authorization Code Flow. FastMCP provides the `fastmcp.client.auth.OAuth` helper to simplify this entire process.
17
 
18
  This flow is common for user-facing applications where the application acts on behalf of the user.
19
 
@@ -35,7 +35,7 @@ async with Client("https://fastmcp.cloud/mcp", auth="oauth") as client:
35
 
36
  ### `OAuth` Helper
37
 
38
- To fully configure the OAuth flow, use the `OAuth` helper and pass it to the `auth` parameter of the `Client` or transport instance. `OAuth` manages the complexities of the OAuth 2.0 Authorization Code Grant with PKCE (Proof Key for Code Exchange) for enhanced security, and implements the full `httpx.Auth` interface.
39
 
40
  ```python {2, 4, 6}
41
  from fastmcp import Client
 
1
  ---
2
  title: OAuth Authentication
3
  sidebarTitle: OAuth
4
+ description: Authenticate your FastMCP client via OAuth 2.1.
5
  icon: window
6
  ---
7
 
 
13
  OAuth authentication is only relevant for HTTP-based transports and requires user interaction via a web browser.
14
  </Tip>
15
 
16
+ When your FastMCP client needs to access an MCP server protected by OAuth 2.1, and the process requires user interaction (like logging in and granting consent), you should use the Authorization Code Flow. FastMCP provides the `fastmcp.client.auth.OAuth` helper to simplify this entire process.
17
 
18
  This flow is common for user-facing applications where the application acts on behalf of the user.
19
 
 
35
 
36
  ### `OAuth` Helper
37
 
38
+ To fully configure the OAuth flow, use the `OAuth` helper and pass it to the `auth` parameter of the `Client` or transport instance. `OAuth` manages the complexities of the OAuth 2.1 Authorization Code Grant with PKCE (Proof Key for Code Exchange) for enhanced security, and implements the full `httpx.Auth` interface.
39
 
40
  ```python {2, 4, 6}
41
  from fastmcp import Client
docs/docs.json CHANGED
@@ -93,8 +93,8 @@
93
  "group": "Authentication",
94
  "icon": "user-shield",
95
  "pages": [
96
- "clients/auth/bearer",
97
- "clients/auth/oauth"
98
  ]
99
  },
100
  "clients/advanced-features"
 
93
  "group": "Authentication",
94
  "icon": "user-shield",
95
  "pages": [
96
+ "clients/auth/oauth",
97
+ "clients/auth/bearer"
98
  ]
99
  },
100
  "clients/advanced-features"
docs/servers/auth/bearer.mdx CHANGED
@@ -12,6 +12,10 @@ import { VersionBadge } from "/snippets/version-badge.mdx"
12
  Authentication and authorization are only relevant for HTTP-based transports.
13
  </Tip>
14
 
 
 
 
 
15
  Bearer Token authentication is a common way to secure HTTP-based APIs. In this model, the client sends a token (usually a JSON Web Token or JWT) in the `Authorization` header with the "Bearer" scheme. The server then validates this token to grant or deny access.
16
 
17
  FastMCP supports Bearer Token authentication for its HTTP-based transports (`streamable-http` and `sse`), allowing you to protect your server from unauthorized access.
@@ -32,7 +36,7 @@ This design allows you to integrate FastMCP servers into existing authentication
32
  To enable Bearer Token validation on your FastMCP server, use the `BearerAuthProvider` class. This provider validates incoming JWTs by verifying signatures, checking expiration, and optionally validating claims.
33
 
34
  <Warning>
35
- The `BearerAuthProvider` validates tokens; it does **not** issue them (or implement any part of an OAuth flow). You'll need to generate tokens separately, either using FastMCP utilities or an external Identity Provider (IdP) or OAuth 2.0 Authorization Server.
36
  </Warning>
37
 
38
  ### Basic Setup
@@ -100,7 +104,7 @@ JWKS is recommended for production as it supports automatic key rotation and mul
100
  For development and testing, FastMCP provides the `RSAKeyPair` utility class to generate tokens without needing an external OAuth provider.
101
 
102
  <Warning>
103
- The `RSAKeyPair` utility is intended for development and testing only. For production, use a proper OAuth 2.0 Authorization Server or Identity Provider.
104
  </Warning>
105
  ### Basic Token Generation
106
 
 
12
  Authentication and authorization are only relevant for HTTP-based transports.
13
  </Tip>
14
 
15
+ <Note>
16
+ The [MCP specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization) requires servers to implement full OAuth 2.1 authorization flows with dynamic client registration, server metadata discovery, and complete token endpoints. FastMCP's Bearer Token authentication provides a simpler, more practical alternative by directly validating pre-issued JWT tokens—ideal for service-to-service communication and programmatic environments where full OAuth flows may be impractical, and in accordance with how the MCP ecosystem is pragmatically evolving. However, please note that since it doesn't implement the full OAuth 2.1 flow, this implementation does not strictly comply with the MCP specification.
17
+ </Note>
18
+
19
  Bearer Token authentication is a common way to secure HTTP-based APIs. In this model, the client sends a token (usually a JSON Web Token or JWT) in the `Authorization` header with the "Bearer" scheme. The server then validates this token to grant or deny access.
20
 
21
  FastMCP supports Bearer Token authentication for its HTTP-based transports (`streamable-http` and `sse`), allowing you to protect your server from unauthorized access.
 
36
  To enable Bearer Token validation on your FastMCP server, use the `BearerAuthProvider` class. This provider validates incoming JWTs by verifying signatures, checking expiration, and optionally validating claims.
37
 
38
  <Warning>
39
+ The `BearerAuthProvider` validates tokens; it does **not** issue them (or implement any part of an OAuth flow). You'll need to generate tokens separately, either using FastMCP utilities or an external Identity Provider (IdP) or OAuth 2.1 Authorization Server.
40
  </Warning>
41
 
42
  ### Basic Setup
 
104
  For development and testing, FastMCP provides the `RSAKeyPair` utility class to generate tokens without needing an external OAuth provider.
105
 
106
  <Warning>
107
+ The `RSAKeyPair` utility is intended for development and testing only. For production, use a proper OAuth 2.1 Authorization Server or Identity Provider.
108
  </Warning>
109
  ### Basic Token Generation
110
 
docs/servers/composition.mdx CHANGED
@@ -33,7 +33,7 @@ The choice of importing or mounting depends on your use case and requirements.
33
 
34
  ### Proxy Servers
35
 
36
- FastMCP supports [MCP proxying](/patterns/proxy), which allows you to mirror a local or remote server in a local FastMCP instance. Proxies are fully compatible with both importing and mounting.
37
 
38
  <VersionBadge version="2.4.0" />
39
 
 
33
 
34
  ### Proxy Servers
35
 
36
+ FastMCP supports [MCP proxying](/servers/proxy), which allows you to mirror a local or remote server in a local FastMCP instance. Proxies are fully compatible with both importing and mounting.
37
 
38
  <VersionBadge version="2.4.0" />
39
 
docs/servers/fastmcp.mdx CHANGED
@@ -135,7 +135,7 @@ For detailed information on each transport, how to configure them (host, port, p
135
 
136
  FastMCP supports composing multiple servers together using `import_server` (static copy) and `mount` (live link). This allows you to organize large applications into modular components or reuse existing servers.
137
 
138
- See the [Server Composition](/patterns/composition) guide for full details, best practices, and examples.
139
 
140
  ```python
141
  # Example: Importing a subserver
@@ -159,7 +159,7 @@ main.mount("sub", sub)
159
 
160
  FastMCP can act as a proxy for any MCP server (local or remote) using `FastMCP.as_proxy`, letting you bridge transports or add a frontend to existing servers. For example, you can expose a remote SSE server locally via stdio, or vice versa.
161
 
162
- See the [Proxying Servers](/patterns/proxy) guide for details and advanced usage.
163
 
164
  ```python
165
  from fastmcp import FastMCP, Client
@@ -232,29 +232,3 @@ This customization is useful when you want to:
232
  <Tip>
233
  If the serializer function raises an exception, the tool will fall back to the default JSON serialization to avoid breaking the server.
234
  </Tip>
235
-
236
- ## Authentication
237
-
238
- <VersionBadge version="2.2.7" />
239
-
240
- FastMCP supports OAuth 2.0 authentication, allowing servers to protect their tools and resources. This is configured by providing an `auth_server_provider` and `auth` settings during `FastMCP` initialization.
241
-
242
- ```python
243
- from fastmcp import FastMCP
244
- from mcp.server.auth.settings import AuthSettings #, ... other auth imports
245
- # from your_auth_implementation import MyOAuthServerProvider # Placeholder
246
-
247
- # Create a server with authentication (conceptual example)
248
- # mcp = FastMCP(
249
- # name="SecureApp",
250
- # auth_server_provider=MyOAuthServerProvider(),
251
- # auth=AuthSettings(
252
- # issuer_url="https://myapp.com",
253
- # # ... other OAuth settings ...
254
- # required_scopes=["myscope"],
255
- # ),
256
- # )
257
- ```
258
- Due to the low-level nature of the current MCP SDK's auth provider interface, detailed implementation is beyond a quick example. Refer to the [MCP SDK documentation](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization) for specifics on implementing an `OAuthAuthorizationServerProvider`. FastMCP integrates with this by passing the provider and settings to the underlying MCP server.
259
-
260
- A dedicated [Authentication guide](/deployment/authentication) will cover this in more detail once higher-level abstractions are available in FastMCP.
 
135
 
136
  FastMCP supports composing multiple servers together using `import_server` (static copy) and `mount` (live link). This allows you to organize large applications into modular components or reuse existing servers.
137
 
138
+ See the [Server Composition](/servers/composition) guide for full details, best practices, and examples.
139
 
140
  ```python
141
  # Example: Importing a subserver
 
159
 
160
  FastMCP can act as a proxy for any MCP server (local or remote) using `FastMCP.as_proxy`, letting you bridge transports or add a frontend to existing servers. For example, you can expose a remote SSE server locally via stdio, or vice versa.
161
 
162
+ See the [Proxying Servers](/servers/proxy) guide for details and advanced usage.
163
 
164
  ```python
165
  from fastmcp import FastMCP, Client
 
232
  <Tip>
233
  If the serializer function raises an exception, the tool will fall back to the default JSON serialization to avoid breaking the server.
234
  </Tip>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
docs/snippets/version-badge.mdx CHANGED
@@ -1,13 +1,12 @@
1
  export const VersionBadge = ({ version }) => {
2
  return (
3
  <code className="version-badge-container">
4
- <div className="version-badge">
5
  <span className="version-badge-label">New in version:</span>&nbsp;
6
- <span className="version-badge-version">{version}</span>
7
- </div>
8
  </code>
9
 
10
 
11
-
12
  );
13
  };
 
1
  export const VersionBadge = ({ version }) => {
2
  return (
3
  <code className="version-badge-container">
4
+ <p className="version-badge">
5
  <span className="version-badge-label">New in version:</span>&nbsp;
6
+ <code className="version-badge-version">{version}</code>
7
+ </p>
8
  </code>
9
 
10
 
 
11
  );
12
  };
docs/style.css CHANGED
@@ -17,16 +17,18 @@ h6 code:not(pre code) {
17
  display: inline-block;
18
  align-items: center;
19
  gap: 0.3em;
20
- padding: 0.2em 0.8em;
21
- font-size: 1.1em;
22
- font-weight: 400;
23
-
 
 
 
24
  font-family: "Inter", sans-serif;
25
- letter-spacing: 0.025em;
26
  color: #ff5400;
27
- background: #ffeee6;
28
- border: 1px solid rgb(255, 84, 0, 0.5);
29
- border-radius: 6px;
30
  box-shadow: none;
31
  vertical-align: middle;
32
  position: relative;
@@ -44,7 +46,7 @@ h6 code:not(pre code) {
44
  }
45
 
46
  .dark .version-badge {
47
- color: #fff;
48
- background: #312e81;
49
- border: 1.5px solid #a78bfa;
50
  }
 
17
  display: inline-block;
18
  align-items: center;
19
  gap: 0.3em;
20
+ font-size: 1em;
21
+ margin-top: 0px;
22
+ margin-bottom: 0px;
23
+ padding-top: 6px;
24
+ padding-bottom: 6px;
25
+ padding-left: 20px;
26
+ padding-right: 20px;
27
  font-family: "Inter", sans-serif;
 
28
  color: #ff5400;
29
+ background: #fef2f2;
30
+ border: 1px solid rgba(220, 38, 38, 0.3);
31
+ border-radius: 12px;
32
  box-shadow: none;
33
  vertical-align: middle;
34
  position: relative;
 
46
  }
47
 
48
  .dark .version-badge {
49
+ color: #f1f5f9;
50
+ background: #334155;
51
+ border: 1px solid #64748b;
52
  }
src/fastmcp/client/auth/oauth.py CHANGED
@@ -68,9 +68,6 @@ class ServerOAuthMetadata(_MCPServerOAuthMetadata):
68
  class OAuthClientProvider(_MCPOAuthClientProvider):
69
  """
70
  OAuth client provider with more flexible OAuth metadata discovery.
71
-
72
- This subclass handles real-world OAuth servers that may not conform
73
- strictly to the MCP OAuth specification but are still valid OAuth 2.0 servers.
74
  """
75
 
76
  async def _discover_oauth_metadata(
 
68
  class OAuthClientProvider(_MCPOAuthClientProvider):
69
  """
70
  OAuth client provider with more flexible OAuth metadata discovery.
 
 
 
71
  """
72
 
73
  async def _discover_oauth_metadata(
src/fastmcp/server/auth/providers/in_memory.py CHANGED
@@ -1,8 +1,3 @@
1
- """
2
- This is a simple in-memory OAuth provider for testing purposes.
3
- It simulates the OAuth 2.0 flow locally without external calls.
4
- """
5
-
6
  import secrets
7
  import time
8
 
@@ -36,7 +31,7 @@ DEFAULT_REFRESH_TOKEN_EXPIRY_SECONDS = None # No expiry
36
  class InMemoryOAuthProvider(OAuthProvider):
37
  """
38
  An in-memory OAuth provider for testing purposes.
39
- It simulates the OAuth 2.0 flow locally without external calls.
40
  """
41
 
42
  def __init__(
 
 
 
 
 
 
1
  import secrets
2
  import time
3
 
 
31
  class InMemoryOAuthProvider(OAuthProvider):
32
  """
33
  An in-memory OAuth provider for testing purposes.
34
+ It simulates the OAuth 2.1 flow locally without external calls.
35
  """
36
 
37
  def __init__(
tests/server/test_auth_integration.py CHANGED
@@ -342,7 +342,7 @@ async def tokens(test_client, registered_client, auth_code, pkce_challenge, requ
342
 
343
  class TestAuthEndpoints:
344
  async def test_metadata_endpoint(self, test_client: httpx.AsyncClient):
345
- """Test the OAuth 2.0 metadata endpoint."""
346
  print("Sending request to metadata endpoint")
347
  response = await test_client.get("/.well-known/oauth-authorization-server")
348
  print(f"Got response: {response.status_code}")
 
342
 
343
  class TestAuthEndpoints:
344
  async def test_metadata_endpoint(self, test_client: httpx.AsyncClient):
345
+ """Test the OAuth 2.1 metadata endpoint."""
346
  print("Sending request to metadata endpoint")
347
  response = await test_client.get("/.well-known/oauth-authorization-server")
348
  print(f"Got response: {response.status_code}")