Spaces:
Sleeping
Sleeping
Jeremiah Lowin commited on
Commit ·
e2e6dea
1
Parent(s): 8a40e1f
Add claude desktop docs
Browse filesFiles changed (6)
29 unmodified lines30313233343536373839404142434445464748495051524 unmodified lines5758596061626364656667682 unmodified lines717273747576777879808129 unmodified linesIf you're using a string token, do not include the `Bearer` prefix. FastMCP will add it for you.</Tip>```python {4}from fastmcp import Clientasync with Client("https://fastmcp.cloud/mcp", auth="<your-token>") as client:await client.ping()```You can also supply a Bearer token to a transport instance, such as `StreamableHttpTransport` or `SSETransport`:```python {5}from fastmcp import Clientfrom fastmcp.client.transports import StreamableHttpTransporttransport = StreamableHttpTransport("http://fastmcp.cloud/mcp", auth="<your-token>")async with Client(transport) as client:4 unmodified linesIf you prefer to be more explicit and not rely on FastMCP to transform your string token, you can use the `BearerAuth` class yourself, which implements the `httpx.Auth` interface.```python {5}from fastmcp import Clientfrom fastmcp.client.auth import BearerAuthasync with Client("https://fastmcp.cloud/mcp", auth=BearerAuth(token="<your-token>")) as client:await client.ping()```2 unmodified linesIf the MCP server expects a custom header or token scheme, you can manually set the client's `headers` instead of using the `auth` parameter:```python {4}from fastmcp import Clientasync with Client("https://fastmcp.cloud/mcp", headers={"X-API-Key": "<your-token>"}) as client:await client.ping()```29 unmodified lines303132333435363738394041424344454647484950515253544 unmodified lines596061626364656667686970712 unmodified lines74757677787980818283848529 unmodified linesIf you're using a string token, do not include the `Bearer` prefix. FastMCP will add it for you.</Tip>```python {5}from fastmcp import Clientasync with Client("https://fastmcp.cloud/mcp",auth="<your-token>",) as client:await client.ping()```You can also supply a Bearer token to a transport instance, such as `StreamableHttpTransport` or `SSETransport`:```python {6}from fastmcp import Clientfrom fastmcp.client.transports import StreamableHttpTransporttransport = StreamableHttpTransport("http://fastmcp.cloud/mcp",auth="<your-token>",)async with Client(transport) as client:4 unmodified linesIf you prefer to be more explicit and not rely on FastMCP to transform your string token, you can use the `BearerAuth` class yourself, which implements the `httpx.Auth` interface.```python {6}from fastmcp import Clientfrom fastmcp.client.auth import BearerAuthasync with Client("https://fastmcp.cloud/mcp",auth=BearerAuth(token="<your-token>"),) as client:await client.ping()```2 unmodified linesIf the MCP server expects a custom header or token scheme, you can manually set the client's `headers` instead of using the `auth` parameter:```python {5}from fastmcp import Clientasync with Client("https://fastmcp.cloud/mcp",headers={"X-API-Key": "<your-token>"},) as client:await client.ping()```
70 unmodified lines717273747576777817 unmodified lines969798991001011021032 unmodified lines10610710810911011111270 unmodified lines"icon": "upload","pages": ["deployment/running-server","deployment/asgi","deployment/cli"]}]17 unmodified lines{"group": "Integrations","pages": ["integrations/openai","integrations/anthropic","integrations/contrib"]},2 unmodified lines"pages": ["patterns/decorating-methods","patterns/http-requests","patterns/testing"]}]70 unmodified lines7172737475767717 unmodified lines95969798991001011021032 unmodified lines10610710810911011111211370 unmodified lines"icon": "upload","pages": ["deployment/running-server","deployment/asgi"]}]17 unmodified lines{"group": "Integrations","pages": ["integrations/anthropic","integrations/claude-desktop","integrations/openai","integrations/contrib"]},2 unmodified lines"pages": ["patterns/decorating-methods","patterns/http-requests","patterns/testing","patterns/cli"]}]
12345678910111213141516171819202145 unmodified lines676869707172737475115 unmodified lines191192193194195196197---title: AnthropicsidebarTitle: Anthropicdescription: Integrate FastMCP servers with the Anthropic Messages APIicon: message-smile---import { VersionBadge } from "/snippets/version-badge.mdx"Anthropic's Claude supports MCP servers through the MCP connector feature in the Messages API, allowing you to extend AI capabilities with custom tools from remote MCP servers.## Messages APIAnthropic's [Messages API](https://docs.anthropic.com/en/api/messages) supports [MCP servers](https://docs.anthropic.com/en/docs/agents-and-tools/mcp-connector) as remote tool sources through the MCP connector feature.<Tip>Currently, the MCP connector only accesses **tools** from MCP servers—it queries the `list_tools` endpoint and exposes those functions to Claude. Other MCP features like resources and prompts are not currently supported.</Tip>### Create a Server45 unmodified linespip install anthropic```Here is an example of how to call your server from Python. Note that you'll need to replace `https://your-server-url.com` with the actual URL of your server. In addition, we use `/sse` as the endpoint because we deployed an SSE server with the default path; you may need to use a different endpoint if you customized your server's deployment.```python {4, 12-19}import anthropicfrom rich import print115 unmodified linesTo authenticate the client, you can pass the token using the `authorization_token` parameter in your MCP server configuration:```python {7, 17}import anthropicfrom rich import print123456789101112131415161718192045 unmodified lines666768697071727374115 unmodified lines190191192193194195196---title: AnthropicsidebarTitle: Anthropicdescription: Access FastMCP servers from the Anthropic Messages APIicon: message-smile---import { VersionBadge } from "/snippets/version-badge.mdx"Anthropic supports MCP servers through the [MCP connector](https://docs.anthropic.com/en/docs/agents-and-tools/mcp-connector) feature in the Messages API, allowing you to extend AI capabilities with custom tools from remote MCP servers.## Messages APIAnthropic's [Messages API](https://docs.anthropic.com/en/api/messages) supports MCP servers as remote tool sources. This tutorial will show you how to create a FastMCP server and deploy it to a public URL, then how to call it from the Messages API.<Tip>Currently, the MCP connector only accesses **tools** from MCP servers—it queries the `list_tools` endpoint and exposes those functions to Claude. Other MCP features like resources and prompts are not currently supported. You can read more about the MCP connector in the [Anthropic documentation](https://docs.anthropic.com/en/docs/agents-and-tools/mcp-connector).</Tip>### Create a Server45 unmodified linespip install anthropic```Here is an example of how to call your server from Python. Note that you'll need to replace `https://your-server-url.com` with the actual URL of your server. In addition, we use `/sse` as the endpoint because we deployed an SSE server with the default path; you may need to use a different endpoint if you customized your server's deployment. **At this time you must also include the `extra_headers` parameter with the `anthropic-beta` header.**```python {5, 13-22}import anthropicfrom rich import print115 unmodified linesTo authenticate the client, you can pass the token using the `authorization_token` parameter in your MCP server configuration:```python {8, 21}import anthropicfrom rich import print
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221---title: Claude DesktopsidebarTitle: Claude Desktopdescription: Integrate FastMCP servers with Claude Desktopicon: desktop---
Claude Desktop supports MCP servers through local STDIO connections, allowing you to extend Claude's capabilities with custom tools, resources, and prompts from your FastMCP servers.
<Note>This guide focuses specifically on using FastMCP servers with Claude Desktop. For general Claude Desktop MCP setup and official examples, see the [official Claude Desktop quickstart guide](https://modelcontextprotocol.io/quickstart/user).</Note>
## Requirements
Claude Desktop requires MCP servers to run locally using STDIO transport. This means your server will communicate with Claude through standard input/output rather than HTTP.
<Tip>If you need to connect to remote servers, you can create a **proxy server** that runs locally via STDIO and forwards requests to remote HTTP servers. See the [Proxy Servers](#proxy-servers) section below.</Tip>
## Create a Server
The examples in this guide will use the following simple dice-rolling server, saved as `server.py`.
```python server.pyimport randomfrom fastmcp import FastMCP
mcp = FastMCP(name="Dice Roller")
@mcp.tool()def roll_dice(n_dice: int) -> list[int]: """Roll `n_dice` 6-sided dice and return the results.""" return [random.randint(1, 6) for _ in range(n_dice)]
if __name__ == "__main__": mcp.run()```
## Install the Server
### FastMCP CLI
The easiest way to install a FastMCP server in Claude Desktop is using the `fastmcp install` command. This automatically handles the configuration and dependency management.
```bashfastmcp install server.py```
The install command supports the same `file.py:object` notation as the `run` command. If no object is specified, it will automatically look for a FastMCP server object named `mcp`, `server`, or `app` in your file:
```bash# These are equivalent if your server object is named 'mcp'fastmcp install server.pyfastmcp install server.py:mcp
# Use explicit object name if your server has a different namefastmcp install server.py:my_custom_server```
After installation, restart Claude Desktop completely. You should see a hammer icon (🔨) in the bottom left of the input box, indicating that MCP tools are available.
#### Dependencies
If your server has dependencies, include them with the `--with` flag:
```bashfastmcp install server.py --with pandas --with requests```
Alternatively, you can specify dependencies directly in your server code:
```python server.pyfrom fastmcp import FastMCP
mcp = FastMCP( name="Dice Roller", dependencies=["pandas", "requests"])```
#### Environment Variables
<Warning>Claude Desktop runs servers in a completely isolated environment with no access to your shell environment or locally installed applications. You must explicitly pass any environment variables your server needs.</Warning>
If your server needs environment variables (like API keys), you must include them:
```bashfastmcp install server.py --name "Weather Server" \ --env-var API_KEY=your-api-key \ --env-var DEBUG=true```
Or load them from a `.env` file:
```bashfastmcp install server.py --name "Weather Server" --env-file .env```<Warning>- **`uv` must be installed and available in your system PATH**. Claude Desktop runs in its own isolated environment and needs `uv` to manage dependencies.- **On macOS, it is recommended to install `uv` globally with Homebrew** so that Claude Desktop will detect it: `brew install uv`. Installing `uv` with other methods may not make it accessible to Claude Desktop.</Warning>
### Manual Configuration
For more control over the configuration, you can manually edit Claude Desktop's configuration file. You can open the configuration file from Claude's developer settings, or find it in the following locations:- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
The configuration file is a JSON object with a `mcpServers` key, which contains the configuration for each MCP server.
```json{ "mcpServers": { "dice-roller": { "command": "python", "args": ["path/to/your/server.py"] } }}```
After updating the configuration file, restart Claude Desktop completely. Look for the hammer icon (🔨) to confirm your server is loaded.
#### Dependencies
If your server has dependencies, you can use `uv` or another package manager to set up the environment.
```json{ "mcpServers": { "dice-roller": { "command": "uv", "args": [ "run", "--with", "pandas", "--with", "requests", "python", "path/to/your/server.py" ] } }}```
<Warning>- **`uv` must be installed and available in your system PATH**. Claude Desktop runs in its own isolated environment and needs `uv` to manage dependencies.- **On macOS, it is recommended to install `uv` globally with Homebrew** so that Claude Desktop will detect it: `brew install uv`. Installing `uv` with other methods may not make it accessible to Claude Desktop.</Warning>
#### Environment Variables
You can also specify environment variables in the configuration:
```json{ "mcpServers": { "weather-server": { "command": "python", "args": ["path/to/weather_server.py"], "env": { "API_KEY": "your-api-key", "DEBUG": "true" } } }}```<Warning>Claude Desktop runs servers in a completely isolated environment with no access to your shell environment or locally installed applications. You must explicitly pass any environment variables your server needs.</Warning>
## Remote Servers
Claude Desktop only supports local STDIO servers, but FastMCP can create a proxy server that forwards requests to a remote HTTP server. You can install the proxy server in Claude Desktop.
Create a proxy server that connects to a remote HTTP server:
```python proxy_server.pyfrom fastmcp import FastMCP
# Create a proxy to a remote serverproxy = FastMCP.as_proxy( "https://example.com/mcp/sse", name="Remote Server Proxy")
if __name__ == "__main__": proxy.run() # Runs via STDIO for Claude Desktop```
### Authentication
For authenticated remote servers, create an authenticated client following the guidance in the [client auth documentation](/clients/auth/bearer) and pass it to the proxy:
```python auth_proxy_server.py {7}from fastmcp import FastMCP, Clientfrom fastmcp.client.auth import BearerAuth
# Create authenticated clientclient = Client( "https://api.example.com/mcp/sse", auth=BearerAuth(token="your-access-token"))
# Create proxy using the authenticated clientproxy = FastMCP.as_proxy(client, name="Authenticated Proxy")
if __name__ == "__main__": proxy.run()```
1234567---title: OpenAIsidebarTitle: OpenAIdescription: Integrate FastMCP servers with the OpenAI APIicon: message-smile---1234567---title: OpenAIsidebarTitle: OpenAIdescription: Access FastMCP servers from the OpenAI APIicon: message-smile---
147 unmodified lines1481491501511521531541553 unmodified lines159160161162163164165166167168169170171172173174175176177178179147 unmodified linesfastmcp install server.py```Note that for security reasons, Claude runs every MCP server in a completely isolated environment. Therefore, all dependencies must be explicitly specified using the `--with` and/or `--with-editable` options (following `uv` conventions) or by attaching them to your server in code via the `dependencies` parameter.<Warning>- **`uv` must be installed and available in your system PATH**. Claude Desktop runs in its own isolated environment and needs `uv` to manage dependencies.- **On macOS, it is recommended to install `uv` globally with Homebrew** so that Claude Desktop will detect it: `brew install uv`. Installing `uv` with other methods may not make it accessible to Claude Desktop.3 unmodified linesThe `install` command currently only sets up servers for STDIO transport. When installed in the Claude desktop app, your server will be run using STDIO regardless of any transport configuration in your code.</Warning>#### Options| Option | Flag | Description || ------ | ---- | ----------- || Server Name | `--name`, `-n` | Custom name for the server || Editable Package | `--with-editable`, `-e` | Directory containing pyproject.toml to install in editable mode || Additional Packages | `--with` | Additional packages to install (can be used multiple times) || Environment Variables | `--env-var`, `-v` | Environment variables in KEY=VALUE format (can be used multiple times) || Environment File | `--env-file`, `-f` | Load environment variables from a .env file |**Example**```bash# Install server with custom name, dependencies, and environment variablesfastmcp install server.py -n "My Analysis Server" -e . --with pandas --env-var API_KEY=12345```### `version`147 unmodified lines1481491501511521531541553 unmodified lines159160161162163164165166167168169170171172173174175176177178179180181182147 unmodified linesfastmcp install server.py```Note that for security reasons, Claude runs every MCP server in a completely isolated environment. Therefore, all dependencies must be explicitly specified using the `--with` and/or `--with-editable` options (following `uv` conventions) or by attaching them to your server in code via the `dependencies` parameter.<Warning>- **`uv` must be installed and available in your system PATH**. Claude Desktop runs in its own isolated environment and needs `uv` to manage dependencies.- **On macOS, it is recommended to install `uv` globally with Homebrew** so that Claude Desktop will detect it: `brew install uv`. Installing `uv` with other methods may not make it accessible to Claude Desktop.3 unmodified linesThe `install` command currently only sets up servers for STDIO transport. When installed in the Claude desktop app, your server will be run using STDIO regardless of any transport configuration in your code.</Warning>#### Server SpecificationThe `install` command supports the same `file.py:object` notation as the `run` command:1. `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.2. `server.py:custom_name` - imports and uses the specified server object**Examples**```bash# Auto-detects server object (looks for 'mcp', 'server', or 'app')fastmcp install server.py# Uses specific server objectfastmcp install server.py:my_server# With custom name and dependenciesfastmcp install server.py:my_server -n "My Analysis Server" --with pandas```### `version`
docs/clients/auth/bearer.mdx+12-8
docs/docs.json+5-4
docs/integrations/anthropic.mdx+7-8
docs/integrations/claude-desktop.mdxAdded+221
docs/integrations/openai.mdx+1-1
docs/deployment/cli.mdx → docs/patterns/cli.mdxRenamed+15-12