fastmcp 0.3.2__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 CHANGED
@@ -68,16 +68,20 @@ def update_claude_config(
68
68
  env_vars = existing_env
69
69
 
70
70
  # Build uv run command
71
- args = ["run", "--with", "fastmcp"]
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:
fastmcp/cli/cli.py CHANGED
@@ -193,6 +193,11 @@ def dev(
193
193
  )
194
194
 
195
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
+
196
201
  uv_cmd = _build_uv_command(file_spec, with_editable, with_packages)
197
202
  # Run the MCP Inspector command
198
203
  process = subprocess.run(
@@ -232,23 +237,16 @@ def run(
232
237
  help="Transport protocol to use (stdio or sse)",
233
238
  ),
234
239
  ] = None,
235
- with_editable: Annotated[
236
- Optional[Path],
237
- typer.Option(
238
- "--with-editable",
239
- "-e",
240
- help="Directory containing pyproject.toml to install in editable mode",
241
- exists=True,
242
- file_okay=False,
243
- resolve_path=True,
244
- ),
245
- ] = None,
246
240
  ) -> None:
247
241
  """Run a FastMCP server.
248
242
 
249
243
  The server can be specified in two ways:
250
244
  1. Module approach: server.py - runs the module directly, expecting a server.run() call
251
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.
252
250
  """
253
251
  file, server_object = _parse_file_path(file_spec)
254
252
 
@@ -258,7 +256,6 @@ def run(
258
256
  "file": str(file),
259
257
  "server_object": server_object,
260
258
  "transport": transport,
261
- "with_editable": str(with_editable) if with_editable else None,
262
259
  },
263
260
  )
264
261
 
@@ -361,6 +358,7 @@ def install(
361
358
 
362
359
  # Try to import server to get its name, but fall back to file name if dependencies missing
363
360
  name = server_name
361
+ server = None
364
362
  if not name:
365
363
  try:
366
364
  server = _import_server(file, server_object)
@@ -372,6 +370,11 @@ def install(
372
370
  )
373
371
  name = file.stem
374
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
+
375
378
  # Process environment variables if provided
376
379
  env_dict: Optional[Dict[str, str]] = None
377
380
  if env_file or env_vars:
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.2
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
@@ -27,11 +27,12 @@ Description-Content-Type: text/markdown
27
27
 
28
28
  <div align="center">
29
29
 
30
+ <strong>The fast, Pythonic way to build MCP servers.</strong>
31
+
30
32
  [![PyPI - Version](https://img.shields.io/pypi/v/fastmcp.svg)](https://pypi.org/project/fastmcp)
31
33
  [![Tests](https://github.com/jlowin/fastmcp/actions/workflows/run-tests.yml/badge.svg)](https://github.com/jlowin/fastmcp/actions/workflows/run-tests.yml)
32
34
  [![License](https://img.shields.io/github/license/jlowin/fastmcp.svg)](https://github.com/jlowin/fastmcp/blob/main/LICENSE)
33
35
 
34
- The fast, Pythonic way to build MCP servers
35
36
 
36
37
  </div>
37
38
 
@@ -85,24 +86,33 @@ FastMCP handles all the complex protocol details and server management, so you c
85
86
  - [Prompts](#prompts)
86
87
  - [Images](#images)
87
88
  - [Context](#context)
88
- - [Deployment](#deployment)
89
- - [Development](#development)
90
- - [Environment Variables](#environment-variables)
91
- - [Claude Desktop](#claude-desktop)
92
- - [Environment Variables](#environment-variables-1)
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)
93
94
  - [Examples](#examples)
94
95
  - [Echo Server](#echo-server)
95
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)
96
103
 
97
104
  ## Installation
98
105
 
106
+ We strongly recommend installing FastMCP with [uv](https://docs.astral.sh/uv/), as it is required for deploying servers:
107
+
99
108
  ```bash
100
- # We strongly recommend installing with uv
101
- brew install uv # on macOS
102
109
  uv pip install fastmcp
103
110
  ```
104
111
 
105
- Or with pip:
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
+
106
116
  ```bash
107
117
  pip install fastmcp
108
118
  ```
@@ -173,8 +183,10 @@ mcp = FastMCP("My App")
173
183
 
174
184
  # Configure host/port for HTTP transport (optional)
175
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"])
176
189
  ```
177
- *Note: All of the following code examples assume you've created a FastMCP server instance called `mcp`, as shown above.*
178
190
 
179
191
  ### Resources
180
192
 
@@ -303,84 +315,101 @@ The Context object provides:
303
315
  - Resource access through `read_resource()`
304
316
  - Request metadata via `request_id` and `client_id`
305
317
 
306
- ## Deployment
318
+ ## Running Your Server
307
319
 
308
- The FastMCP CLI helps you develop and deploy MCP servers.
320
+ There are three main ways to use your FastMCP server, each suited for different stages of development:
309
321
 
310
- Note that for all deployment commands, you are expected to provide the fully qualified path to your server object. For example, if you have a file `server.py` that contains a FastMCP server named `my_server`, you would provide `path/to/server.py:my_server`.
322
+ ### Development Mode (Recommended for Building & Testing)
311
323
 
312
- If your server variable has one of the standard names (`mcp`, `server`, or `app`), you can omit the server name from the path and just provide the file: `path/to/server.py`.
324
+ The fastest way to test and debug your server is with the MCP Inspector:
313
325
 
314
- ### Development
315
-
316
- Test and debug your server with the MCP Inspector:
317
326
  ```bash
318
- # Provide the fully qualified path to your server
319
- fastmcp dev server.py:my_mcp_server
320
-
321
- # Or just the file if your server is named 'mcp', 'server', or 'app'
322
327
  fastmcp dev server.py
323
328
  ```
324
329
 
325
- Your server is run in an isolated environment, so you'll need to indicate any dependencies with the `--with` flag. FastMCP is automatically included. If you are working on a uv project, you can use the `--with-editable` flag to mount your current directory:
326
-
327
- ```bash
328
- # With additional packages
329
- fastmcp dev server.py --with pandas --with numpy
330
-
331
- # Using your project's dependencies and up-to-date code
332
- fastmcp dev server.py --with-editable .
333
- ```
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
334
335
 
335
- #### Environment Variables
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
+ ```
336
345
 
337
- The MCP Inspector runs servers in an isolated environment. Environment variables must be set through the Inspector UI and are not inherited from your system. The Inspector does not currently support setting environment variables via command line (see [Issue #94](https://github.com/modelcontextprotocol/inspector/issues/94)).
346
+ ### Claude Desktop Integration (For Regular Use)
338
347
 
339
- ### Claude Desktop
348
+ Once your server is ready, install it in Claude Desktop to use it with Claude:
340
349
 
341
- Install your server in Claude Desktop:
342
350
  ```bash
343
- # Basic usage (name is taken from your FastMCP instance)
344
351
  fastmcp install server.py
352
+ ```
345
353
 
346
- # With a custom name
347
- fastmcp install server.py --name "My Server"
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:
348
375
 
349
- # With dependencies
350
- fastmcp install server.py --with pandas --with numpy
376
+ ```python
377
+ from fastmcp import FastMCP
378
+
379
+ mcp = FastMCP("My App")
380
+
381
+ if __name__ == "__main__":
382
+ mcp.run()
351
383
  ```
352
384
 
353
- The server name in Claude will be:
354
- 1. The `--name` parameter if provided
355
- 2. The `name` from your FastMCP instance
356
- 3. The filename if the server can't be imported
385
+ Run it with:
386
+ ```bash
387
+ # Using the FastMCP CLI
388
+ fastmcp run server.py
357
389
 
358
- #### Environment Variables
390
+ # Or with Python/uv directly
391
+ python server.py
392
+ uv run python server.py
393
+ ```
359
394
 
360
- Claude Desktop runs servers in an isolated environment. Environment variables from your system are NOT automatically available to the server - you must explicitly provide them during installation:
361
395
 
362
- ```bash
363
- # Single env var
364
- fastmcp install server.py -e API_KEY=abc123
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.
365
397
 
366
- # Multiple env vars
367
- fastmcp install server.py -e API_KEY=abc123 -e OTHER_VAR=value
398
+ Choose this method when you need:
399
+ - Custom deployment configurations
400
+ - Integration with other services
401
+ - Direct control over the server lifecycle
368
402
 
369
- # Load from .env file
370
- fastmcp install server.py -f .env
371
- ```
403
+ ### Server Object Names
372
404
 
373
- Environment variables persist across reinstalls and are only updated when new values are provided:
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`:
374
406
 
375
407
  ```bash
376
- # First install
377
- fastmcp install server.py -e FOO=bar -e BAZ=123
408
+ # Using a standard name
409
+ fastmcp run server.py
378
410
 
379
- # Second install - FOO and BAZ are preserved
380
- fastmcp install server.py -e NEW=value
381
-
382
- # Third install - FOO gets new value, others preserved
383
- fastmcp install server.py -e FOO=newvalue
411
+ # Using a custom name
412
+ fastmcp run server.py:my_custom_server
384
413
  ```
385
414
 
386
415
  ## Examples
@@ -449,3 +478,85 @@ Schema:
449
478
 
450
479
  What insights can you provide about the structure and relationships?"""
451
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=JttRzt1bnJGBU8mL4Bo764WHFXQ09QqKc_CUT3390WM,21997
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=mepURIVhlwQQYgkjgmuJCS841QAs9Mu-xRxdLpfCO0o,3628
6
- fastmcp/cli/cli.py,sha256=gzpgUseCR5tkdyZumjjxyAIYJLMeAdyJ5zgRHC9EL_M,11407
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.2.dist-info/METADATA,sha256=R64QFKVKLfIVWjOFi-vmEL3At_Dx8rwHTBdjBOTLC30,13617
23
- fastmcp-0.3.2.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
24
- fastmcp-0.3.2.dist-info/entry_points.txt,sha256=ff8bMtKX1JvXyurMibAacMSKbJEPmac9ffAKU9mLnM8,44
25
- fastmcp-0.3.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
26
- fastmcp-0.3.2.dist-info/RECORD,,
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,,