fastmcp 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastmcp/cli/claude.py +33 -23
- fastmcp/cli/cli.py +68 -21
- fastmcp/server.py +7 -0
- {fastmcp-0.3.1.dist-info → fastmcp-0.3.3.dist-info}/METADATA +197 -42
- {fastmcp-0.3.1.dist-info → fastmcp-0.3.3.dist-info}/RECORD +8 -8
- {fastmcp-0.3.1.dist-info → fastmcp-0.3.3.dist-info}/WHEEL +0 -0
- {fastmcp-0.3.1.dist-info → fastmcp-0.3.3.dist-info}/entry_points.txt +0 -0
- {fastmcp-0.3.1.dist-info → fastmcp-0.3.3.dist-info}/licenses/LICENSE +0 -0
fastmcp/cli/claude.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import json
|
|
4
4
|
import sys
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Optional
|
|
6
|
+
from typing import Optional, Dict
|
|
7
7
|
|
|
8
8
|
from ..utilities.logging import get_logger
|
|
9
9
|
|
|
@@ -30,16 +30,17 @@ def update_claude_config(
|
|
|
30
30
|
*,
|
|
31
31
|
with_editable: Optional[Path] = None,
|
|
32
32
|
with_packages: Optional[list[str]] = None,
|
|
33
|
-
|
|
33
|
+
env_vars: Optional[Dict[str, str]] = None,
|
|
34
34
|
) -> bool:
|
|
35
|
-
"""Add
|
|
35
|
+
"""Add or update a FastMCP server in Claude's configuration.
|
|
36
36
|
|
|
37
37
|
Args:
|
|
38
38
|
file_spec: Path to the server file, optionally with :object suffix
|
|
39
39
|
server_name: Name for the server in Claude's config
|
|
40
40
|
with_editable: Optional directory to install in editable mode
|
|
41
41
|
with_packages: Optional list of additional packages to install
|
|
42
|
-
|
|
42
|
+
env_vars: Optional dictionary of environment variables. These are merged with
|
|
43
|
+
any existing variables, with new values taking precedence.
|
|
43
44
|
"""
|
|
44
45
|
config_dir = get_claude_config_path()
|
|
45
46
|
if not config_dir:
|
|
@@ -54,30 +55,33 @@ def update_claude_config(
|
|
|
54
55
|
if "mcpServers" not in config:
|
|
55
56
|
config["mcpServers"] = {}
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
)
|
|
58
|
+
# Always preserve existing env vars and merge with new ones
|
|
59
|
+
if (
|
|
60
|
+
server_name in config["mcpServers"]
|
|
61
|
+
and "env" in config["mcpServers"][server_name]
|
|
62
|
+
):
|
|
63
|
+
existing_env = config["mcpServers"][server_name]["env"]
|
|
64
|
+
if env_vars:
|
|
65
|
+
# New vars take precedence over existing ones
|
|
66
|
+
env_vars = {**existing_env, **env_vars}
|
|
67
|
+
else:
|
|
68
|
+
env_vars = existing_env
|
|
69
69
|
|
|
70
70
|
# Build uv run command
|
|
71
|
-
args = ["run"
|
|
71
|
+
args = ["run"]
|
|
72
|
+
|
|
73
|
+
# Collect all packages in a set to deduplicate
|
|
74
|
+
packages = {"fastmcp"}
|
|
75
|
+
if with_packages:
|
|
76
|
+
packages.update(pkg for pkg in with_packages if pkg)
|
|
77
|
+
|
|
78
|
+
# Add all packages with --with
|
|
79
|
+
for pkg in sorted(packages):
|
|
80
|
+
args.extend(["--with", pkg])
|
|
72
81
|
|
|
73
82
|
if with_editable:
|
|
74
83
|
args.extend(["--with-editable", str(with_editable)])
|
|
75
84
|
|
|
76
|
-
if with_packages:
|
|
77
|
-
for pkg in with_packages:
|
|
78
|
-
if pkg:
|
|
79
|
-
args.extend(["--with", pkg])
|
|
80
|
-
|
|
81
85
|
# Convert file path to absolute before adding to command
|
|
82
86
|
# Split off any :object suffix first
|
|
83
87
|
if ":" in file_spec:
|
|
@@ -89,11 +93,17 @@ def update_claude_config(
|
|
|
89
93
|
# Add fastmcp run command
|
|
90
94
|
args.extend(["fastmcp", "run", file_spec])
|
|
91
95
|
|
|
92
|
-
|
|
96
|
+
server_config = {
|
|
93
97
|
"command": "uv",
|
|
94
98
|
"args": args,
|
|
95
99
|
}
|
|
96
100
|
|
|
101
|
+
# Add environment variables if specified
|
|
102
|
+
if env_vars:
|
|
103
|
+
server_config["env"] = env_vars
|
|
104
|
+
|
|
105
|
+
config["mcpServers"][server_name] = server_config
|
|
106
|
+
|
|
97
107
|
config_file.write_text(json.dumps(config, indent=2))
|
|
98
108
|
logger.info(
|
|
99
109
|
f"Added server '{server_name}' to Claude config",
|
fastmcp/cli/cli.py
CHANGED
|
@@ -5,10 +5,11 @@ import importlib.util
|
|
|
5
5
|
import subprocess
|
|
6
6
|
import sys
|
|
7
7
|
from pathlib import Path
|
|
8
|
-
from typing import Optional, Tuple
|
|
8
|
+
from typing import Optional, Tuple, Dict
|
|
9
9
|
|
|
10
10
|
import typer
|
|
11
11
|
from typing_extensions import Annotated
|
|
12
|
+
import dotenv
|
|
12
13
|
|
|
13
14
|
from ..utilities.logging import get_logger
|
|
14
15
|
from . import claude
|
|
@@ -23,6 +24,17 @@ app = typer.Typer(
|
|
|
23
24
|
)
|
|
24
25
|
|
|
25
26
|
|
|
27
|
+
def _parse_env_var(env_var: str) -> Tuple[str, str]:
|
|
28
|
+
"""Parse environment variable string in format KEY=VALUE."""
|
|
29
|
+
if "=" not in env_var:
|
|
30
|
+
logger.error(
|
|
31
|
+
f"Invalid environment variable format: {env_var}. Must be KEY=VALUE"
|
|
32
|
+
)
|
|
33
|
+
sys.exit(1)
|
|
34
|
+
key, value = env_var.split("=", 1)
|
|
35
|
+
return key.strip(), value.strip()
|
|
36
|
+
|
|
37
|
+
|
|
26
38
|
def _build_uv_command(
|
|
27
39
|
file_spec: str,
|
|
28
40
|
with_editable: Optional[Path] = None,
|
|
@@ -181,6 +193,11 @@ def dev(
|
|
|
181
193
|
)
|
|
182
194
|
|
|
183
195
|
try:
|
|
196
|
+
# Import server to get dependencies
|
|
197
|
+
server = _import_server(file, server_object)
|
|
198
|
+
if hasattr(server, "dependencies"):
|
|
199
|
+
with_packages = list(set(with_packages + server.dependencies))
|
|
200
|
+
|
|
184
201
|
uv_cmd = _build_uv_command(file_spec, with_editable, with_packages)
|
|
185
202
|
# Run the MCP Inspector command
|
|
186
203
|
process = subprocess.run(
|
|
@@ -220,23 +237,16 @@ def run(
|
|
|
220
237
|
help="Transport protocol to use (stdio or sse)",
|
|
221
238
|
),
|
|
222
239
|
] = None,
|
|
223
|
-
with_editable: Annotated[
|
|
224
|
-
Optional[Path],
|
|
225
|
-
typer.Option(
|
|
226
|
-
"--with-editable",
|
|
227
|
-
"-e",
|
|
228
|
-
help="Directory containing pyproject.toml to install in editable mode",
|
|
229
|
-
exists=True,
|
|
230
|
-
file_okay=False,
|
|
231
|
-
resolve_path=True,
|
|
232
|
-
),
|
|
233
|
-
] = None,
|
|
234
240
|
) -> None:
|
|
235
241
|
"""Run a FastMCP server.
|
|
236
242
|
|
|
237
243
|
The server can be specified in two ways:
|
|
238
244
|
1. Module approach: server.py - runs the module directly, expecting a server.run() call
|
|
239
245
|
2. Import approach: server.py:app - imports and runs the specified server object
|
|
246
|
+
|
|
247
|
+
Note: This command runs the server directly. You are responsible for ensuring
|
|
248
|
+
all dependencies are available. For dependency management, use fastmcp install
|
|
249
|
+
or fastmcp dev instead.
|
|
240
250
|
"""
|
|
241
251
|
file, server_object = _parse_file_path(file_spec)
|
|
242
252
|
|
|
@@ -246,7 +256,6 @@ def run(
|
|
|
246
256
|
"file": str(file),
|
|
247
257
|
"server_object": server_object,
|
|
248
258
|
"transport": transport,
|
|
249
|
-
"with_editable": str(with_editable) if with_editable else None,
|
|
250
259
|
},
|
|
251
260
|
)
|
|
252
261
|
|
|
@@ -304,16 +313,32 @@ def install(
|
|
|
304
313
|
help="Additional packages to install",
|
|
305
314
|
),
|
|
306
315
|
] = [],
|
|
307
|
-
|
|
308
|
-
|
|
316
|
+
env_vars: Annotated[
|
|
317
|
+
list[str],
|
|
318
|
+
typer.Option(
|
|
319
|
+
"--env-var",
|
|
320
|
+
"-e",
|
|
321
|
+
help="Environment variables in KEY=VALUE format",
|
|
322
|
+
),
|
|
323
|
+
] = [],
|
|
324
|
+
env_file: Annotated[
|
|
325
|
+
Optional[Path],
|
|
309
326
|
typer.Option(
|
|
310
|
-
"--
|
|
327
|
+
"--env-file",
|
|
311
328
|
"-f",
|
|
312
|
-
help="
|
|
329
|
+
help="Load environment variables from a .env file",
|
|
330
|
+
exists=True,
|
|
331
|
+
file_okay=True,
|
|
332
|
+
dir_okay=False,
|
|
333
|
+
resolve_path=True,
|
|
313
334
|
),
|
|
314
|
-
] =
|
|
335
|
+
] = None,
|
|
315
336
|
) -> None:
|
|
316
|
-
"""Install a FastMCP server in the Claude desktop app.
|
|
337
|
+
"""Install a FastMCP server in the Claude desktop app.
|
|
338
|
+
|
|
339
|
+
Environment variables are preserved once added and only updated if new values
|
|
340
|
+
are explicitly provided.
|
|
341
|
+
"""
|
|
317
342
|
file, server_object = _parse_file_path(file_spec)
|
|
318
343
|
|
|
319
344
|
logger.debug(
|
|
@@ -324,7 +349,6 @@ def install(
|
|
|
324
349
|
"server_object": server_object,
|
|
325
350
|
"with_editable": str(with_editable) if with_editable else None,
|
|
326
351
|
"with_packages": with_packages,
|
|
327
|
-
"force": force,
|
|
328
352
|
},
|
|
329
353
|
)
|
|
330
354
|
|
|
@@ -334,6 +358,7 @@ def install(
|
|
|
334
358
|
|
|
335
359
|
# Try to import server to get its name, but fall back to file name if dependencies missing
|
|
336
360
|
name = server_name
|
|
361
|
+
server = None
|
|
337
362
|
if not name:
|
|
338
363
|
try:
|
|
339
364
|
server = _import_server(file, server_object)
|
|
@@ -345,12 +370,34 @@ def install(
|
|
|
345
370
|
)
|
|
346
371
|
name = file.stem
|
|
347
372
|
|
|
373
|
+
# Get server dependencies if available
|
|
374
|
+
server_dependencies = getattr(server, "dependencies", []) if server else []
|
|
375
|
+
if server_dependencies:
|
|
376
|
+
with_packages = list(set(with_packages + server_dependencies))
|
|
377
|
+
|
|
378
|
+
# Process environment variables if provided
|
|
379
|
+
env_dict: Optional[Dict[str, str]] = None
|
|
380
|
+
if env_file or env_vars:
|
|
381
|
+
env_dict = {}
|
|
382
|
+
# Load from .env file if specified
|
|
383
|
+
if env_file:
|
|
384
|
+
try:
|
|
385
|
+
env_dict.update(dotenv.dotenv_values(env_file))
|
|
386
|
+
except Exception as e:
|
|
387
|
+
logger.error(f"Failed to load .env file: {e}")
|
|
388
|
+
sys.exit(1)
|
|
389
|
+
|
|
390
|
+
# Add command line environment variables
|
|
391
|
+
for env_var in env_vars:
|
|
392
|
+
key, value = _parse_env_var(env_var)
|
|
393
|
+
env_dict[key] = value
|
|
394
|
+
|
|
348
395
|
if claude.update_claude_config(
|
|
349
396
|
file_spec,
|
|
350
397
|
name,
|
|
351
398
|
with_editable=with_editable,
|
|
352
399
|
with_packages=with_packages,
|
|
353
|
-
|
|
400
|
+
env_vars=env_dict,
|
|
354
401
|
):
|
|
355
402
|
logger.info(f"Successfully installed {name} in Claude app")
|
|
356
403
|
else:
|
fastmcp/server.py
CHANGED
|
@@ -9,6 +9,7 @@ from itertools import chain
|
|
|
9
9
|
from typing import Any, Callable, Dict, Literal, Sequence
|
|
10
10
|
|
|
11
11
|
import pydantic_core
|
|
12
|
+
from pydantic import Field
|
|
12
13
|
import uvicorn
|
|
13
14
|
from mcp.server import Server as MCPServer
|
|
14
15
|
from mcp.server.sse import SseServerTransport
|
|
@@ -76,6 +77,11 @@ class Settings(BaseSettings):
|
|
|
76
77
|
# prompt settings
|
|
77
78
|
warn_on_duplicate_prompts: bool = True
|
|
78
79
|
|
|
80
|
+
dependencies: list[str] = Field(
|
|
81
|
+
default_factory=list,
|
|
82
|
+
description="List of dependencies to install in the server environment",
|
|
83
|
+
)
|
|
84
|
+
|
|
79
85
|
|
|
80
86
|
class FastMCP:
|
|
81
87
|
def __init__(self, name: str | None = None, **settings: Any):
|
|
@@ -90,6 +96,7 @@ class FastMCP:
|
|
|
90
96
|
self._prompt_manager = PromptManager(
|
|
91
97
|
warn_on_duplicate_prompts=self.settings.warn_on_duplicate_prompts
|
|
92
98
|
)
|
|
99
|
+
self.dependencies = self.settings.dependencies
|
|
93
100
|
|
|
94
101
|
# Set up MCP protocol handlers
|
|
95
102
|
self._setup_handlers()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: fastmcp
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: A more ergonomic interface for MCP servers
|
|
5
5
|
Author: Jeremiah Lowin
|
|
6
6
|
License: Apache-2.0
|
|
@@ -9,6 +9,7 @@ Requires-Dist: httpx>=0.26.0
|
|
|
9
9
|
Requires-Dist: mcp<2.0.0,>=1.0.0
|
|
10
10
|
Requires-Dist: pydantic-settings>=2.6.1
|
|
11
11
|
Requires-Dist: pydantic<3.0.0,>=2.5.3
|
|
12
|
+
Requires-Dist: python-dotenv>=1.0.1
|
|
12
13
|
Requires-Dist: typer>=0.9.0
|
|
13
14
|
Provides-Extra: dev
|
|
14
15
|
Requires-Dist: copychat>=0.5.2; extra == 'dev'
|
|
@@ -26,28 +27,39 @@ Description-Content-Type: text/markdown
|
|
|
26
27
|
|
|
27
28
|
<div align="center">
|
|
28
29
|
|
|
30
|
+
<strong>The fast, Pythonic way to build MCP servers.</strong>
|
|
31
|
+
|
|
29
32
|
[](https://pypi.org/project/fastmcp)
|
|
30
33
|
[](https://github.com/jlowin/fastmcp/actions/workflows/run-tests.yml)
|
|
31
34
|
[](https://github.com/jlowin/fastmcp/blob/main/LICENSE)
|
|
32
35
|
|
|
33
|
-
A fast, Pythonic way to build [Model Context Protocol (MCP)](https://modelcontextprotocol.io) servers
|
|
34
36
|
|
|
35
37
|
</div>
|
|
36
38
|
|
|
37
|
-
FastMCP makes building MCP servers simple and intuitive. Create tools, expose resources, and define prompts with clean, Pythonic code:
|
|
39
|
+
[Model Context Protocol (MCP)](https://modelcontextprotocol.io) servers are a new, standardized way to provide context and tools to your LLMs, and FastMCP makes building MCP servers simple and intuitive. Create tools, expose resources, and define prompts with clean, Pythonic code:
|
|
38
40
|
|
|
39
41
|
```python
|
|
42
|
+
# demo.py
|
|
43
|
+
|
|
40
44
|
from fastmcp import FastMCP
|
|
41
45
|
|
|
46
|
+
|
|
42
47
|
mcp = FastMCP("Demo 🚀")
|
|
43
48
|
|
|
49
|
+
|
|
44
50
|
@mcp.tool()
|
|
45
51
|
def add(a: int, b: int) -> int:
|
|
46
52
|
"""Add two numbers"""
|
|
47
53
|
return a + b
|
|
48
54
|
```
|
|
49
55
|
|
|
50
|
-
That's it!
|
|
56
|
+
That's it! Give Claude access to the server by running:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
fastmcp install demo.py
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
FastMCP handles all the complex protocol details and server management, so you can focus on building great tools. It's designed to be high-level and Pythonic - in most cases, decorating a function is all you need.
|
|
51
63
|
|
|
52
64
|
|
|
53
65
|
### Key features:
|
|
@@ -74,22 +86,33 @@ That's it! FastMCP handles all the complex protocol details and server managemen
|
|
|
74
86
|
- [Prompts](#prompts)
|
|
75
87
|
- [Images](#images)
|
|
76
88
|
- [Context](#context)
|
|
77
|
-
- [
|
|
78
|
-
- [Development](#development)
|
|
79
|
-
- [Claude Desktop](#claude-desktop)
|
|
89
|
+
- [Running Your Server](#running-your-server)
|
|
90
|
+
- [Development Mode (Recommended for Building \& Testing)](#development-mode-recommended-for-building--testing)
|
|
91
|
+
- [Claude Desktop Integration (For Regular Use)](#claude-desktop-integration-for-regular-use)
|
|
92
|
+
- [Direct Execution (For Advanced Use Cases)](#direct-execution-for-advanced-use-cases)
|
|
93
|
+
- [Server Object Names](#server-object-names)
|
|
80
94
|
- [Examples](#examples)
|
|
81
95
|
- [Echo Server](#echo-server)
|
|
82
96
|
- [SQLite Explorer](#sqlite-explorer)
|
|
97
|
+
- [Contributing](#contributing)
|
|
98
|
+
- [Prerequisites](#prerequisites)
|
|
99
|
+
- [Installation](#installation-1)
|
|
100
|
+
- [Testing](#testing)
|
|
101
|
+
- [Formatting](#formatting)
|
|
102
|
+
- [Opening a Pull Request](#opening-a-pull-request)
|
|
83
103
|
|
|
84
104
|
## Installation
|
|
85
105
|
|
|
106
|
+
We strongly recommend installing FastMCP with [uv](https://docs.astral.sh/uv/), as it is required for deploying servers:
|
|
107
|
+
|
|
86
108
|
```bash
|
|
87
|
-
# We strongly recommend installing with uv
|
|
88
|
-
brew install uv # on macOS
|
|
89
109
|
uv pip install fastmcp
|
|
90
110
|
```
|
|
91
111
|
|
|
92
|
-
|
|
112
|
+
Note: on macOS, uv may need to be installed with Homebrew (`brew install uv`) in order to make it available to the Claude Desktop app.
|
|
113
|
+
|
|
114
|
+
Alternatively, to use the SDK without deploying, you may use pip:
|
|
115
|
+
|
|
93
116
|
```bash
|
|
94
117
|
pip install fastmcp
|
|
95
118
|
```
|
|
@@ -160,8 +183,10 @@ mcp = FastMCP("My App")
|
|
|
160
183
|
|
|
161
184
|
# Configure host/port for HTTP transport (optional)
|
|
162
185
|
mcp = FastMCP("My App", host="localhost", port=8000)
|
|
186
|
+
|
|
187
|
+
# Specify dependencies for deployment and development
|
|
188
|
+
mcp = FastMCP("My App", dependencies=["pandas", "numpy"])
|
|
163
189
|
```
|
|
164
|
-
*Note: All of the following code examples assume you've created a FastMCP server instance called `mcp`, as shown above.*
|
|
165
190
|
|
|
166
191
|
### Resources
|
|
167
192
|
|
|
@@ -290,59 +315,107 @@ The Context object provides:
|
|
|
290
315
|
- Resource access through `read_resource()`
|
|
291
316
|
- Request metadata via `request_id` and `client_id`
|
|
292
317
|
|
|
293
|
-
##
|
|
294
|
-
|
|
295
|
-
The FastMCP CLI helps you develop and deploy MCP servers.
|
|
318
|
+
## Running Your Server
|
|
296
319
|
|
|
297
|
-
|
|
320
|
+
There are three main ways to use your FastMCP server, each suited for different stages of development:
|
|
298
321
|
|
|
299
|
-
|
|
322
|
+
### Development Mode (Recommended for Building & Testing)
|
|
300
323
|
|
|
301
|
-
|
|
324
|
+
The fastest way to test and debug your server is with the MCP Inspector:
|
|
302
325
|
|
|
303
|
-
Test and debug your server with the MCP Inspector:
|
|
304
326
|
```bash
|
|
305
|
-
# Provide the fully qualified path to your server
|
|
306
|
-
fastmcp dev server.py:my_mcp_server
|
|
307
|
-
|
|
308
|
-
# Or just the file if your server is named 'mcp', 'server', or 'app'
|
|
309
327
|
fastmcp dev server.py
|
|
310
328
|
```
|
|
311
329
|
|
|
312
|
-
|
|
330
|
+
This launches a web interface where you can:
|
|
331
|
+
- Test your tools and resources interactively
|
|
332
|
+
- See detailed logs and error messages
|
|
333
|
+
- Monitor server performance
|
|
334
|
+
- Set environment variables for testing
|
|
313
335
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
336
|
+
During development, you can:
|
|
337
|
+
- Add dependencies with `--with`:
|
|
338
|
+
```bash
|
|
339
|
+
fastmcp dev server.py --with pandas --with numpy
|
|
340
|
+
```
|
|
341
|
+
- Mount your local code for live updates:
|
|
342
|
+
```bash
|
|
343
|
+
fastmcp dev server.py --with-editable .
|
|
344
|
+
```
|
|
317
345
|
|
|
318
|
-
|
|
319
|
-
fastmcp dev server.py --with-editable .
|
|
320
|
-
```
|
|
346
|
+
### Claude Desktop Integration (For Regular Use)
|
|
321
347
|
|
|
322
|
-
|
|
348
|
+
Once your server is ready, install it in Claude Desktop to use it with Claude:
|
|
323
349
|
|
|
324
|
-
Install your server in Claude Desktop:
|
|
325
350
|
```bash
|
|
326
|
-
# Basic usage (name is taken from your FastMCP instance)
|
|
327
351
|
fastmcp install server.py
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Your server will run in an isolated environment with:
|
|
355
|
+
- Automatic installation of dependencies specified in your FastMCP instance:
|
|
356
|
+
```python
|
|
357
|
+
mcp = FastMCP("My App", dependencies=["pandas", "numpy"])
|
|
358
|
+
```
|
|
359
|
+
- Custom naming via `--name`:
|
|
360
|
+
```bash
|
|
361
|
+
fastmcp install server.py --name "My Analytics Server"
|
|
362
|
+
```
|
|
363
|
+
- Environment variable management:
|
|
364
|
+
```bash
|
|
365
|
+
# Set variables individually
|
|
366
|
+
fastmcp install server.py -e API_KEY=abc123 -e DB_URL=postgres://...
|
|
367
|
+
|
|
368
|
+
# Or load from a .env file
|
|
369
|
+
fastmcp install server.py -f .env
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Direct Execution (For Advanced Use Cases)
|
|
373
|
+
|
|
374
|
+
For advanced scenarios like custom deployments or running without Claude, you can execute your server directly:
|
|
375
|
+
|
|
376
|
+
```python
|
|
377
|
+
from fastmcp import FastMCP
|
|
328
378
|
|
|
329
|
-
|
|
330
|
-
|
|
379
|
+
mcp = FastMCP("My App")
|
|
380
|
+
|
|
381
|
+
if __name__ == "__main__":
|
|
382
|
+
mcp.run()
|
|
383
|
+
```
|
|
331
384
|
|
|
332
|
-
|
|
333
|
-
|
|
385
|
+
Run it with:
|
|
386
|
+
```bash
|
|
387
|
+
# Using the FastMCP CLI
|
|
388
|
+
fastmcp run server.py
|
|
334
389
|
|
|
335
|
-
#
|
|
336
|
-
|
|
390
|
+
# Or with Python/uv directly
|
|
391
|
+
python server.py
|
|
392
|
+
uv run python server.py
|
|
337
393
|
```
|
|
338
394
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
395
|
+
|
|
396
|
+
Note: When running directly, you are responsible for ensuring all dependencies are available in your environment. Any dependencies specified on the FastMCP instance are ignored.
|
|
397
|
+
|
|
398
|
+
Choose this method when you need:
|
|
399
|
+
- Custom deployment configurations
|
|
400
|
+
- Integration with other services
|
|
401
|
+
- Direct control over the server lifecycle
|
|
402
|
+
|
|
403
|
+
### Server Object Names
|
|
404
|
+
|
|
405
|
+
All FastMCP commands will look for a server object called `mcp`, `app`, or `server` in your file. If you have a different object name or multiple servers in one file, use the syntax `server.py:my_server`:
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
# Using a standard name
|
|
409
|
+
fastmcp run server.py
|
|
410
|
+
|
|
411
|
+
# Using a custom name
|
|
412
|
+
fastmcp run server.py:my_custom_server
|
|
413
|
+
```
|
|
343
414
|
|
|
344
415
|
## Examples
|
|
345
416
|
|
|
417
|
+
Here are a few examples of FastMCP servers. For more, see the `examples/` directory.
|
|
418
|
+
|
|
346
419
|
### Echo Server
|
|
347
420
|
A simple server demonstrating resources, tools, and prompts:
|
|
348
421
|
|
|
@@ -405,3 +478,85 @@ Schema:
|
|
|
405
478
|
|
|
406
479
|
What insights can you provide about the structure and relationships?"""
|
|
407
480
|
```
|
|
481
|
+
|
|
482
|
+
## Contributing
|
|
483
|
+
|
|
484
|
+
<details>
|
|
485
|
+
|
|
486
|
+
<summary><h3>Open Developer Guide</h3></summary>
|
|
487
|
+
|
|
488
|
+
### Prerequisites
|
|
489
|
+
|
|
490
|
+
FastMCP requires Python 3.10+ and [uv](https://docs.astral.sh/uv/).
|
|
491
|
+
|
|
492
|
+
### Installation
|
|
493
|
+
|
|
494
|
+
Create a fork of this repository, then clone it:
|
|
495
|
+
|
|
496
|
+
```bash
|
|
497
|
+
git clone https://github.com/YouFancyUserYou/fastmcp.git
|
|
498
|
+
cd fastmcp
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
Next, create a virtual environment and install FastMCP:
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
uv venv
|
|
505
|
+
source .venv/bin/activate
|
|
506
|
+
uv sync --frozen --all-extras --dev
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
### Testing
|
|
512
|
+
|
|
513
|
+
Please make sure to test any new functionality. Your tests should be simple and atomic and anticipate change rather than cement complex patterns.
|
|
514
|
+
|
|
515
|
+
Run tests from the root directory:
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
```bash
|
|
519
|
+
pytest -vv
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### Formatting
|
|
523
|
+
|
|
524
|
+
FastMCP enforces a variety of required formats, which you can automatically enforce with pre-commit.
|
|
525
|
+
|
|
526
|
+
Install the pre-commit hooks:
|
|
527
|
+
|
|
528
|
+
```bash
|
|
529
|
+
pre-commit install
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
The hooks will now run on every commit (as well as on every PR). To run them manually:
|
|
533
|
+
|
|
534
|
+
```bash
|
|
535
|
+
pre-commit run --all-files
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### Opening a Pull Request
|
|
539
|
+
|
|
540
|
+
Fork the repository and create a new branch:
|
|
541
|
+
|
|
542
|
+
```bash
|
|
543
|
+
git checkout -b my-branch
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
Make your changes and commit them:
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
```bash
|
|
550
|
+
git add . && git commit -m "My changes"
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
Push your changes to your fork:
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
```bash
|
|
557
|
+
git push origin my-branch
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
Feel free to reach out in a GitHub issue or discussion if you have any questions!
|
|
561
|
+
|
|
562
|
+
</details>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
fastmcp/__init__.py,sha256=Y5dHGBwyQPgNP5gzOyNIItefvMZ3vJLdom1oV8A1u_k,248
|
|
2
2
|
fastmcp/exceptions.py,sha256=K0rCgXsUVlws39hz98Tb4BBf_BzIql_zXFZgqbkNTiE,348
|
|
3
|
-
fastmcp/server.py,sha256=
|
|
3
|
+
fastmcp/server.py,sha256=V6BaciC5u9g_XzbvPkafjGO8OtEBPGy_KlV535Au0do,22234
|
|
4
4
|
fastmcp/cli/__init__.py,sha256=7hrwtCHX9nMd9qcz7R_JFSoqbL71fC35cBLXBS430mg,88
|
|
5
|
-
fastmcp/cli/claude.py,sha256=
|
|
6
|
-
fastmcp/cli/cli.py,sha256=
|
|
5
|
+
fastmcp/cli/claude.py,sha256=APgTMQm7qa68Fz4EObZYmrgY-8-wjn6vCJZD7Se6XlU,3765
|
|
6
|
+
fastmcp/cli/cli.py,sha256=Ub2iNwnCVRO4TbC6Rr_1xOeTKnDN-9XE1z1O1yZatbg,11664
|
|
7
7
|
fastmcp/prompts/__init__.py,sha256=4BsMxoYolpoxg74xkkkzCFL8vvdkLVJ5cIPNs1ND1Jo,99
|
|
8
8
|
fastmcp/prompts/base.py,sha256=WaSsfyFSsUPUbcApkGy3Pm-Ne-Gk-5ZwU3efqRYn1mQ,4996
|
|
9
9
|
fastmcp/prompts/manager.py,sha256=EkexOB_N4QNtC-UlZmIcWcau91ceO2O1K4_kD75pA_A,1485
|
|
@@ -19,8 +19,8 @@ fastmcp/tools/tool_manager.py,sha256=PT6XHcQWzhdC6kfdsJaddRn7VLps4nAs5FMG8l1j8Zc
|
|
|
19
19
|
fastmcp/utilities/__init__.py,sha256=-imJ8S-rXmbXMWeDamldP-dHDqAPg_wwmPVz-LNX14E,31
|
|
20
20
|
fastmcp/utilities/logging.py,sha256=VLJdNc0tIYoQZmpobehLUnWrQz7NXnuwSqrDlFt2RF0,738
|
|
21
21
|
fastmcp/utilities/types.py,sha256=jFlZMZsKrJg4NWc1vTBIILLoHpTVwSd-vxO7ycoRuig,1718
|
|
22
|
-
fastmcp-0.3.
|
|
23
|
-
fastmcp-0.3.
|
|
24
|
-
fastmcp-0.3.
|
|
25
|
-
fastmcp-0.3.
|
|
26
|
-
fastmcp-0.3.
|
|
22
|
+
fastmcp-0.3.3.dist-info/METADATA,sha256=pDlwjd5p0ErFBvpK2D6u9jAWb4rsGzL9f3l95IWJToc,15319
|
|
23
|
+
fastmcp-0.3.3.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
24
|
+
fastmcp-0.3.3.dist-info/entry_points.txt,sha256=ff8bMtKX1JvXyurMibAacMSKbJEPmac9ffAKU9mLnM8,44
|
|
25
|
+
fastmcp-0.3.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
26
|
+
fastmcp-0.3.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|