Skip to content

Mintlify docs #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

</div>


<p align="center"><a href="https://github.com/tadata-org/fastapi_mcp"><img src="https://github.com/user-attachments/assets/b205adc6-28c0-4e3c-a68b-9c1a80eb7d0c" alt="fastapi-mcp-usage" height="400"/></a></p>


Expand Down Expand Up @@ -65,15 +66,7 @@ That's it! Your auto-generated MCP server is now available at `https://app.base.

## Documentation, Examples and Advanced Usage

FastAPI-MCP provides comprehensive documentation in the `docs` folder:
- [Best Practices](docs/00_BEST_PRACTICES.md) - Essential guidelines for converting APIs to MCP tools safely and effectively
- [FAQ](docs/00_FAQ.md) - Frequently asked questions about usage, development and support
- [Tool Naming](docs/01_tool_naming.md) - Best practices for naming your MCP tools using operation IDs
- [Connecting to MCP Server](docs/02_connecting_to_the_mcp_server.md) - How to connect various MCP clients like Cursor and Claude Desktop
- [Authentication and Authorization](docs/03_authentication_and_authorization.md) - How to authenticate and authorize your MCP tools
- [Advanced Usage](docs/04_advanced_usage.md) - Advanced features like custom schemas, endpoint filtering, and separate deployment

Check out the [examples directory](examples) for code samples demonstrating these features in action.
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.

## FastAPI-first Approach

Expand All @@ -83,7 +76,7 @@ FastAPI-MCP is designed as a native extension of FastAPI, not just a converter t

- **ASGI transport**: Communicates directly with your FastAPI app using its ASGI interface, eliminating the need for HTTP calls from the MCP to your API

- **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)
- **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)

This design philosophy ensures minimum friction when adding MCP capabilities to your existing FastAPI services.

Expand Down
36 changes: 0 additions & 36 deletions docs/02_connecting_to_the_mcp_server.md

This file was deleted.

152 changes: 0 additions & 152 deletions docs/04_advanced_usage.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Authentication and Authorization
---
title: Authentication & Authorization
icon: key
---

FastAPI-MCP supports authentication and authorization using your existing FastAPI dependencies.

Expand All @@ -12,7 +15,7 @@ If you just want to be able to pass a valid authorization header, without suppor

You just need to make sure your MCP client is sending it:

```json
```json {8-9, 13}
{
"mcpServers": {
"remote-example": {
Expand All @@ -35,7 +38,7 @@ This is enough to pass the authorization header to your FastAPI endpoints.

Optionally, if you want your MCP server to reject requests without an authorization header, you can add a dependency:

```python
```python {1-2, 7-9}
from fastapi import Depends
from fastapi_mcp import FastApiMCP, AuthConfig

Expand All @@ -49,15 +52,15 @@ mcp = FastApiMCP(
mcp.mount()
```

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.
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.

## OAuth Flow

FastAPI-MCP supports the full OAuth 2 flow, compliant with [MCP Spec 2025-03-26](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization).

It would look something like this:

```python
```python {7-16}
from fastapi import Depends
from fastapi_mcp import FastApiMCP, AuthConfig

Expand Down Expand Up @@ -102,7 +105,7 @@ You can use it with any OAuth provider that supports the OAuth 2 spec. See expla

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:

```python
```python {9, 22}
from fastapi import Depends
from fastapi_mcp import FastApiMCP, AuthConfig

Expand Down Expand Up @@ -140,7 +143,7 @@ For this to work, you have to make sure mcp-remote is running [on a fixed port](

## Working Example with Auth0

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.
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.

For it to work, you need an .env file in the root of the project with the following variables:

Expand Down Expand Up @@ -221,5 +224,4 @@ Proxies solve several problems:

Normally, mcp-remote will start on a random port, making it impossible to configure the OAuth provider's callback URL properly.


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.
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.
35 changes: 35 additions & 0 deletions docs/advanced/deploy.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Deploying the Server
icon: play
---

## Deploying separately from original FastAPI app

You are not limited to serving the MCP on the same FastAPI app from which it was created.

You can create an MCP server from one FastAPI app, and mount it to a different app:

```python {9, 15, }
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

# Your API app
api_app = FastAPI()
# ... define your API endpoints on api_app ...

# A separate app for the MCP server
mcp_app = FastAPI()

# Create MCP server from the API app
mcp = FastApiMCP(api_app)

# Mount the MCP server to the separate app
mcp.mount(mcp_app)
```

Then, you can run both apps separately:

```bash
uvicorn main:api_app --host api-host --port 8001
uvicorn main:mcp_app --host mcp-host --port 8000
```
25 changes: 25 additions & 0 deletions docs/advanced/refresh.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Refreshing the Server
description: Adding endpoints after MCP server creation
icon: arrows-rotate
---

If you add endpoints to your FastAPI app after creating the MCP server, you'll need to refresh the server to include them:

```python {9-12, 15}
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()

mcp = FastApiMCP(app)
mcp.mount()

# Add new endpoints after MCP server creation
@app.get("/new/endpoint/", operation_id="new_endpoint")
async def new_endpoint():
return {"message": "Hello, world!"}

# Refresh the MCP server to include the new endpoint
mcp.setup_server()
```
31 changes: 31 additions & 0 deletions docs/advanced/transport.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Transport
description: How to communicate with the FastAPI app
icon: car
---

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.

It's not even necessary that the FastAPI server will run.

If you need to specify a custom base URL or use a different transport method, you can provide your own `httpx.AsyncClient`:

```python {7-10, 14}
import httpx
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()

custom_client = httpx.AsyncClient(
base_url="https://api.example.com",
timeout=30.0
)

mcp = FastApiMCP(
app,
http_client=custom_client
)

mcp.mount()
```
Loading