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
@@ -65,15 +66,7 @@ That's it! Your auto-generated MCP server is now available at `https://app.base.
65
66
66
67
## Documentation, Examples and Advanced Usage
67
68
68
-
FastAPI-MCP provides comprehensive documentation in the `docs` folder:
69
-
-[Best Practices](docs/00_BEST_PRACTICES.md) - Essential guidelines for converting APIs to MCP tools safely and effectively
70
-
-[FAQ](docs/00_FAQ.md) - Frequently asked questions about usage, development and support
71
-
-[Tool Naming](docs/01_tool_naming.md) - Best practices for naming your MCP tools using operation IDs
72
-
-[Connecting to MCP Server](docs/02_connecting_to_the_mcp_server.md) - How to connect various MCP clients like Cursor and Claude Desktop
73
-
-[Authentication and Authorization](docs/03_authentication_and_authorization.md) - How to authenticate and authorize your MCP tools
74
-
-[Advanced Usage](docs/04_advanced_usage.md) - Advanced features like custom schemas, endpoint filtering, and separate deployment
75
-
76
-
Check out the [examples directory](examples) for code samples demonstrating these features in action.
69
+
FastAPI-MCP provides [comprehensive documentation](https://fastapi-mcp.tadata.com/). Additionaly, check out the [examples directory](examples) for code samples demonstrating these features in action.
77
70
78
71
## FastAPI-first Approach
79
72
@@ -83,7 +76,7 @@ FastAPI-MCP is designed as a native extension of FastAPI, not just a converter t
83
76
84
77
-**ASGI transport**: Communicates directly with your FastAPI app using its ASGI interface, eliminating the need for HTTP calls from the MCP to your API
85
78
86
-
-**Unified infrastructure**: Your FastAPI app doesn't need to run separately from the MCP server (though [separate deployment](docs/04_advanced_usage.md#deploying-separately-from-original-fastapi-app) is also supported)
79
+
-**Unified infrastructure**: Your FastAPI app doesn't need to run separately from the MCP server (though [separate deployment](https://fastapi-mcp.tadata.com/advanced/deploy#deploying-separately-from-original-fastapi-app) is also supported)
87
80
88
81
This design philosophy ensures minimum friction when adding MCP capabilities to your existing FastAPI services.
Copy file name to clipboardExpand all lines: docs/advanced/auth.mdx
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,7 @@
1
-
# Authentication and Authorization
1
+
---
2
+
title: Authentication & Authorization
3
+
icon: key
4
+
---
2
5
3
6
FastAPI-MCP supports authentication and authorization using your existing FastAPI dependencies.
4
7
@@ -12,7 +15,7 @@ If you just want to be able to pass a valid authorization header, without suppor
12
15
13
16
You just need to make sure your MCP client is sending it:
14
17
15
-
```json
18
+
```json {8-9, 13}
16
19
{
17
20
"mcpServers": {
18
21
"remote-example": {
@@ -35,7 +38,7 @@ This is enough to pass the authorization header to your FastAPI endpoints.
35
38
36
39
Optionally, if you want your MCP server to reject requests without an authorization header, you can add a dependency:
37
40
38
-
```python
41
+
```python {1-2, 7-9}
39
42
from fastapi import Depends
40
43
from fastapi_mcp import FastApiMCP, AuthConfig
41
44
@@ -49,15 +52,15 @@ mcp = FastApiMCP(
49
52
mcp.mount()
50
53
```
51
54
52
-
For a complete working example of authorization header, check out the [auth_example_token_passthrough.py](/examples/08_auth_example_token_passthrough.py) in the examples folder.
55
+
For a complete working example of authorization header, check out the [Token Passthrough Example](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py) in the examples folder.
53
56
54
57
## OAuth Flow
55
58
56
59
FastAPI-MCP supports the full OAuth 2 flow, compliant with [MCP Spec 2025-03-26](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization).
57
60
58
61
It would look something like this:
59
62
60
-
```python
63
+
```python {7-16}
61
64
from fastapi import Depends
62
65
from fastapi_mcp import FastApiMCP, AuthConfig
63
66
@@ -102,7 +105,7 @@ You can use it with any OAuth provider that supports the OAuth 2 spec. See expla
102
105
103
106
If you already have a properly configured OAuth server that works with MCP clients, or if you want full control over the metadata, you can provide your own OAuth metadata directly:
104
107
105
-
```python
108
+
```python {9, 22}
106
109
from fastapi import Depends
107
110
from fastapi_mcp import FastApiMCP, AuthConfig
108
111
@@ -140,7 +143,7 @@ For this to work, you have to make sure mcp-remote is running [on a fixed port](
140
143
141
144
## Working Example with Auth0
142
145
143
-
For a complete working example of OAuth integration with Auth0, check out the [auth_example_auth0.py](/examples/09_auth_example_auth0.py) in the examples folder. This example demonstrates the simple case of using Auth0 as an OAuth provider, with a working example of the OAuth flow.
146
+
For a complete working example of OAuth integration with Auth0, check out the [Auth0 Example](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/09_auth_example_auth0.py) in the examples folder. This example demonstrates the simple case of using Auth0 as an OAuth provider, with a working example of the OAuth flow.
144
147
145
148
For it to work, you need an .env file in the root of the project with the following variables:
146
149
@@ -221,5 +224,4 @@ Proxies solve several problems:
221
224
222
225
Normally, mcp-remote will start on a random port, making it impossible to configure the OAuth provider's callback URL properly.
223
226
224
-
225
-
You have to make sure mcp-remote is running on a fixed port, for example `8080`, and then configure the callback URL to `http://127.0.0.1:8080/oauth/callback` in your OAuth provider.
227
+
You have to make sure mcp-remote is running on a fixed port, for example `8080`, and then configure the callback URL to `http://127.0.0.1:8080/oauth/callback` in your OAuth provider.
description: How to communicate with the FastAPI app
4
+
icon: car
5
+
---
6
+
7
+
FastAPI-MCP uses ASGI transport by default, which means it communicates directly with your FastAPI app without making HTTP requests. This is more efficient and doesn't require a base URL.
8
+
9
+
It's not even necessary that the FastAPI server will run.
10
+
11
+
If you need to specify a custom base URL or use a different transport method, you can provide your own `httpx.AsyncClient`:
0 commit comments