fastmcp 1.0__py3-none-any.whl → 2.0.0__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/__init__.py +15 -4
- fastmcp/cli/__init__.py +0 -1
- fastmcp/cli/claude.py +13 -11
- fastmcp/cli/cli.py +61 -41
- fastmcp/client/__init__.py +25 -0
- fastmcp/client/base.py +1 -0
- fastmcp/client/client.py +181 -0
- fastmcp/client/roots.py +75 -0
- fastmcp/client/sampling.py +50 -0
- fastmcp/client/transports.py +411 -0
- fastmcp/prompts/__init__.py +1 -1
- fastmcp/prompts/base.py +27 -26
- fastmcp/prompts/prompt_manager.py +50 -12
- fastmcp/resources/__init__.py +5 -5
- fastmcp/resources/base.py +2 -2
- fastmcp/resources/resource_manager.py +66 -9
- fastmcp/resources/templates.py +15 -10
- fastmcp/resources/types.py +16 -11
- fastmcp/server/__init__.py +5 -0
- fastmcp/server/context.py +222 -0
- fastmcp/server/openapi.py +625 -0
- fastmcp/server/proxy.py +219 -0
- fastmcp/{server.py → server/server.py} +251 -262
- fastmcp/settings.py +73 -0
- fastmcp/tools/base.py +28 -18
- fastmcp/tools/tool_manager.py +45 -10
- fastmcp/utilities/func_metadata.py +33 -19
- fastmcp/utilities/openapi.py +797 -0
- fastmcp/utilities/types.py +3 -4
- fastmcp-2.0.0.dist-info/METADATA +770 -0
- fastmcp-2.0.0.dist-info/RECORD +39 -0
- fastmcp-2.0.0.dist-info/licenses/LICENSE +201 -0
- fastmcp/prompts/manager.py +0 -50
- fastmcp-1.0.dist-info/METADATA +0 -604
- fastmcp-1.0.dist-info/RECORD +0 -28
- fastmcp-1.0.dist-info/licenses/LICENSE +0 -21
- {fastmcp-1.0.dist-info → fastmcp-2.0.0.dist-info}/WHEEL +0 -0
- {fastmcp-1.0.dist-info → fastmcp-2.0.0.dist-info}/entry_points.txt +0 -0
fastmcp-1.0.dist-info/METADATA
DELETED
|
@@ -1,604 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: fastmcp
|
|
3
|
-
Version: 1.0
|
|
4
|
-
Summary: A more ergonomic interface for MCP servers
|
|
5
|
-
Author: Jeremiah Lowin
|
|
6
|
-
License: MIT
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Requires-Python: >=3.10
|
|
9
|
-
Requires-Dist: httpx>=0.26.0
|
|
10
|
-
Requires-Dist: mcp<2.0.0,>=1.0.0
|
|
11
|
-
Requires-Dist: pydantic-settings>=2.6.1
|
|
12
|
-
Requires-Dist: pydantic<3.0.0,>=2.5.3
|
|
13
|
-
Requires-Dist: python-dotenv>=1.0.1
|
|
14
|
-
Requires-Dist: typer>=0.9.0
|
|
15
|
-
Provides-Extra: dev
|
|
16
|
-
Requires-Dist: copychat>=0.5.2; extra == 'dev'
|
|
17
|
-
Requires-Dist: ipython>=8.12.3; extra == 'dev'
|
|
18
|
-
Requires-Dist: pdbpp>=0.10.3; extra == 'dev'
|
|
19
|
-
Requires-Dist: pre-commit; extra == 'dev'
|
|
20
|
-
Requires-Dist: pyright>=1.1.389; extra == 'dev'
|
|
21
|
-
Requires-Dist: pytest-asyncio>=0.23.5; extra == 'dev'
|
|
22
|
-
Requires-Dist: pytest-flakefinder; extra == 'dev'
|
|
23
|
-
Requires-Dist: pytest-xdist>=3.6.1; extra == 'dev'
|
|
24
|
-
Requires-Dist: pytest>=8.3.3; extra == 'dev'
|
|
25
|
-
Requires-Dist: ruff; extra == 'dev'
|
|
26
|
-
Provides-Extra: tests
|
|
27
|
-
Requires-Dist: pre-commit; extra == 'tests'
|
|
28
|
-
Requires-Dist: pyright>=1.1.389; extra == 'tests'
|
|
29
|
-
Requires-Dist: pytest-asyncio>=0.23.5; extra == 'tests'
|
|
30
|
-
Requires-Dist: pytest-flakefinder; extra == 'tests'
|
|
31
|
-
Requires-Dist: pytest-xdist>=3.6.1; extra == 'tests'
|
|
32
|
-
Requires-Dist: pytest>=8.3.3; extra == 'tests'
|
|
33
|
-
Requires-Dist: ruff; extra == 'tests'
|
|
34
|
-
Description-Content-Type: text/markdown
|
|
35
|
-
|
|
36
|
-
<div align="center">
|
|
37
|
-
|
|
38
|
-
### 🎉 FastMCP has been added to the official MCP SDK! 🎉
|
|
39
|
-
|
|
40
|
-
You can now find FastMCP as part of the official Model Context Protocol Python SDK:
|
|
41
|
-
|
|
42
|
-
👉 [github.com/modelcontextprotocol/python-sdk](https://github.com/modelcontextprotocol/python-sdk)
|
|
43
|
-
|
|
44
|
-
*Please note: this repository is no longer maintained.*
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</br></br></br>
|
|
50
|
-
|
|
51
|
-
</div>
|
|
52
|
-
|
|
53
|
-
<div align="center">
|
|
54
|
-
|
|
55
|
-
<!-- omit in toc -->
|
|
56
|
-
# FastMCP 🚀
|
|
57
|
-
<strong>The fast, Pythonic way to build MCP servers.</strong>
|
|
58
|
-
|
|
59
|
-
[](https://pypi.org/project/fastmcp)
|
|
60
|
-
[](https://github.com/jlowin/fastmcp/actions/workflows/run-tests.yml)
|
|
61
|
-
[](https://github.com/jlowin/fastmcp/blob/main/LICENSE)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
</div>
|
|
65
|
-
|
|
66
|
-
[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:
|
|
67
|
-
|
|
68
|
-
```python
|
|
69
|
-
# demo.py
|
|
70
|
-
|
|
71
|
-
from fastmcp import FastMCP
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
mcp = FastMCP("Demo 🚀")
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
@mcp.tool()
|
|
78
|
-
def add(a: int, b: int) -> int:
|
|
79
|
-
"""Add two numbers"""
|
|
80
|
-
return a + b
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
That's it! Give Claude access to the server by running:
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
fastmcp install demo.py
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
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.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
### Key features:
|
|
93
|
-
* **Fast**: High-level interface means less code and faster development
|
|
94
|
-
* **Simple**: Build MCP servers with minimal boilerplate
|
|
95
|
-
* **Pythonic**: Feels natural to Python developers
|
|
96
|
-
* **Complete***: FastMCP aims to provide a full implementation of the core MCP specification
|
|
97
|
-
|
|
98
|
-
(\*emphasis on *aims*)
|
|
99
|
-
|
|
100
|
-
🚨 🚧 🏗️ *FastMCP is under active development, as is the MCP specification itself. Core features are working but some advanced capabilities are still in progress.*
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
<!-- omit in toc -->
|
|
104
|
-
## Table of Contents
|
|
105
|
-
|
|
106
|
-
- [Installation](#installation)
|
|
107
|
-
- [Quickstart](#quickstart)
|
|
108
|
-
- [What is MCP?](#what-is-mcp)
|
|
109
|
-
- [Core Concepts](#core-concepts)
|
|
110
|
-
- [Server](#server)
|
|
111
|
-
- [Resources](#resources)
|
|
112
|
-
- [Tools](#tools)
|
|
113
|
-
- [Prompts](#prompts)
|
|
114
|
-
- [Images](#images)
|
|
115
|
-
- [Context](#context)
|
|
116
|
-
- [Running Your Server](#running-your-server)
|
|
117
|
-
- [Development Mode (Recommended for Building \& Testing)](#development-mode-recommended-for-building--testing)
|
|
118
|
-
- [Claude Desktop Integration (For Regular Use)](#claude-desktop-integration-for-regular-use)
|
|
119
|
-
- [Direct Execution (For Advanced Use Cases)](#direct-execution-for-advanced-use-cases)
|
|
120
|
-
- [Server Object Names](#server-object-names)
|
|
121
|
-
- [Examples](#examples)
|
|
122
|
-
- [Echo Server](#echo-server)
|
|
123
|
-
- [SQLite Explorer](#sqlite-explorer)
|
|
124
|
-
- [Contributing](#contributing)
|
|
125
|
-
- [Prerequisites](#prerequisites)
|
|
126
|
-
- [Installation](#installation-1)
|
|
127
|
-
- [Testing](#testing)
|
|
128
|
-
- [Formatting](#formatting)
|
|
129
|
-
- [Opening a Pull Request](#opening-a-pull-request)
|
|
130
|
-
|
|
131
|
-
## Installation
|
|
132
|
-
|
|
133
|
-
We strongly recommend installing FastMCP with [uv](https://docs.astral.sh/uv/), as it is required for deploying servers:
|
|
134
|
-
|
|
135
|
-
```bash
|
|
136
|
-
uv pip install fastmcp
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
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.
|
|
140
|
-
|
|
141
|
-
Alternatively, to use the SDK without deploying, you may use pip:
|
|
142
|
-
|
|
143
|
-
```bash
|
|
144
|
-
pip install fastmcp
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## Quickstart
|
|
148
|
-
|
|
149
|
-
Let's create a simple MCP server that exposes a calculator tool and some data:
|
|
150
|
-
|
|
151
|
-
```python
|
|
152
|
-
# server.py
|
|
153
|
-
|
|
154
|
-
from fastmcp import FastMCP
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
# Create an MCP server
|
|
158
|
-
mcp = FastMCP("Demo")
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
# Add an addition tool
|
|
162
|
-
@mcp.tool()
|
|
163
|
-
def add(a: int, b: int) -> int:
|
|
164
|
-
"""Add two numbers"""
|
|
165
|
-
return a + b
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
# Add a dynamic greeting resource
|
|
169
|
-
@mcp.resource("greeting://{name}")
|
|
170
|
-
def get_greeting(name: str) -> str:
|
|
171
|
-
"""Get a personalized greeting"""
|
|
172
|
-
return f"Hello, {name}!"
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
You can install this server in [Claude Desktop](https://claude.ai/download) and interact with it right away by running:
|
|
176
|
-
```bash
|
|
177
|
-
fastmcp install server.py
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
Alternatively, you can test it with the MCP Inspector:
|
|
181
|
-
```bash
|
|
182
|
-
fastmcp dev server.py
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-

|
|
186
|
-
|
|
187
|
-
## What is MCP?
|
|
188
|
-
|
|
189
|
-
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. Think of it like a web API, but specifically designed for LLM interactions. MCP servers can:
|
|
190
|
-
|
|
191
|
-
- Expose data through **Resources** (think of these sort of like GET endpoints; they are used to load information into the LLM's context)
|
|
192
|
-
- Provide functionality through **Tools** (sort of like POST endpoints; they are used to execute code or otherwise produce a side effect)
|
|
193
|
-
- Define interaction patterns through **Prompts** (reusable templates for LLM interactions)
|
|
194
|
-
- And more!
|
|
195
|
-
|
|
196
|
-
There is a low-level [Python SDK](https://github.com/modelcontextprotocol/python-sdk) available for implementing the protocol directly, but FastMCP aims to make that easier by providing a high-level, Pythonic interface.
|
|
197
|
-
|
|
198
|
-
## Core Concepts
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
### Server
|
|
202
|
-
|
|
203
|
-
The FastMCP server is your core interface to the MCP protocol. It handles connection management, protocol compliance, and message routing:
|
|
204
|
-
|
|
205
|
-
```python
|
|
206
|
-
from fastmcp import FastMCP
|
|
207
|
-
|
|
208
|
-
# Create a named server
|
|
209
|
-
mcp = FastMCP("My App")
|
|
210
|
-
|
|
211
|
-
# Specify dependencies for deployment and development
|
|
212
|
-
mcp = FastMCP("My App", dependencies=["pandas", "numpy"])
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Resources
|
|
216
|
-
|
|
217
|
-
Resources are how you expose data to LLMs. They're similar to GET endpoints in a REST API - they provide data but shouldn't perform significant computation or have side effects. Some examples:
|
|
218
|
-
|
|
219
|
-
- File contents
|
|
220
|
-
- Database schemas
|
|
221
|
-
- API responses
|
|
222
|
-
- System information
|
|
223
|
-
|
|
224
|
-
Resources can be static:
|
|
225
|
-
```python
|
|
226
|
-
@mcp.resource("config://app")
|
|
227
|
-
def get_config() -> str:
|
|
228
|
-
"""Static configuration data"""
|
|
229
|
-
return "App configuration here"
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
Or dynamic with parameters (FastMCP automatically handles these as MCP templates):
|
|
233
|
-
```python
|
|
234
|
-
@mcp.resource("users://{user_id}/profile")
|
|
235
|
-
def get_user_profile(user_id: str) -> str:
|
|
236
|
-
"""Dynamic user data"""
|
|
237
|
-
return f"Profile data for user {user_id}"
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### Tools
|
|
241
|
-
|
|
242
|
-
Tools let LLMs take actions through your server. Unlike resources, tools are expected to perform computation and have side effects. They're similar to POST endpoints in a REST API.
|
|
243
|
-
|
|
244
|
-
Simple calculation example:
|
|
245
|
-
```python
|
|
246
|
-
@mcp.tool()
|
|
247
|
-
def calculate_bmi(weight_kg: float, height_m: float) -> float:
|
|
248
|
-
"""Calculate BMI given weight in kg and height in meters"""
|
|
249
|
-
return weight_kg / (height_m ** 2)
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
HTTP request example:
|
|
253
|
-
```python
|
|
254
|
-
import httpx
|
|
255
|
-
|
|
256
|
-
@mcp.tool()
|
|
257
|
-
async def fetch_weather(city: str) -> str:
|
|
258
|
-
"""Fetch current weather for a city"""
|
|
259
|
-
async with httpx.AsyncClient() as client:
|
|
260
|
-
response = await client.get(
|
|
261
|
-
f"https://api.weather.com/{city}"
|
|
262
|
-
)
|
|
263
|
-
return response.text
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
Complex input handling example:
|
|
267
|
-
```python
|
|
268
|
-
from pydantic import BaseModel, Field
|
|
269
|
-
from typing import Annotated
|
|
270
|
-
|
|
271
|
-
class ShrimpTank(BaseModel):
|
|
272
|
-
class Shrimp(BaseModel):
|
|
273
|
-
name: Annotated[str, Field(max_length=10)]
|
|
274
|
-
|
|
275
|
-
shrimp: list[Shrimp]
|
|
276
|
-
|
|
277
|
-
@mcp.tool()
|
|
278
|
-
def name_shrimp(
|
|
279
|
-
tank: ShrimpTank,
|
|
280
|
-
# You can use pydantic Field in function signatures for validation.
|
|
281
|
-
extra_names: Annotated[list[str], Field(max_length=10)],
|
|
282
|
-
) -> list[str]:
|
|
283
|
-
"""List all shrimp names in the tank"""
|
|
284
|
-
return [shrimp.name for shrimp in tank.shrimp] + extra_names
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
### Prompts
|
|
288
|
-
|
|
289
|
-
Prompts are reusable templates that help LLMs interact with your server effectively. They're like "best practices" encoded into your server. A prompt can be as simple as a string:
|
|
290
|
-
|
|
291
|
-
```python
|
|
292
|
-
@mcp.prompt()
|
|
293
|
-
def review_code(code: str) -> str:
|
|
294
|
-
return f"Please review this code:\n\n{code}"
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
Or a more structured sequence of messages:
|
|
298
|
-
```python
|
|
299
|
-
from fastmcp.prompts.base import UserMessage, AssistantMessage
|
|
300
|
-
|
|
301
|
-
@mcp.prompt()
|
|
302
|
-
def debug_error(error: str) -> list[Message]:
|
|
303
|
-
return [
|
|
304
|
-
UserMessage("I'm seeing this error:"),
|
|
305
|
-
UserMessage(error),
|
|
306
|
-
AssistantMessage("I'll help debug that. What have you tried so far?")
|
|
307
|
-
]
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
### Images
|
|
312
|
-
|
|
313
|
-
FastMCP provides an `Image` class that automatically handles image data in your server:
|
|
314
|
-
|
|
315
|
-
```python
|
|
316
|
-
from fastmcp import FastMCP, Image
|
|
317
|
-
from PIL import Image as PILImage
|
|
318
|
-
|
|
319
|
-
@mcp.tool()
|
|
320
|
-
def create_thumbnail(image_path: str) -> Image:
|
|
321
|
-
"""Create a thumbnail from an image"""
|
|
322
|
-
img = PILImage.open(image_path)
|
|
323
|
-
img.thumbnail((100, 100))
|
|
324
|
-
|
|
325
|
-
# FastMCP automatically handles conversion and MIME types
|
|
326
|
-
return Image(data=img.tobytes(), format="png")
|
|
327
|
-
|
|
328
|
-
@mcp.tool()
|
|
329
|
-
def load_image(path: str) -> Image:
|
|
330
|
-
"""Load an image from disk"""
|
|
331
|
-
# FastMCP handles reading and format detection
|
|
332
|
-
return Image(path=path)
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
Images can be used as the result of both tools and resources.
|
|
336
|
-
|
|
337
|
-
### Context
|
|
338
|
-
|
|
339
|
-
The Context object gives your tools and resources access to MCP capabilities. To use it, add a parameter annotated with `fastmcp.Context`:
|
|
340
|
-
|
|
341
|
-
```python
|
|
342
|
-
from fastmcp import FastMCP, Context
|
|
343
|
-
|
|
344
|
-
@mcp.tool()
|
|
345
|
-
async def long_task(files: list[str], ctx: Context) -> str:
|
|
346
|
-
"""Process multiple files with progress tracking"""
|
|
347
|
-
for i, file in enumerate(files):
|
|
348
|
-
ctx.info(f"Processing {file}")
|
|
349
|
-
await ctx.report_progress(i, len(files))
|
|
350
|
-
|
|
351
|
-
# Read another resource if needed
|
|
352
|
-
data = await ctx.read_resource(f"file://{file}")
|
|
353
|
-
|
|
354
|
-
return "Processing complete"
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
The Context object provides:
|
|
358
|
-
- Progress reporting through `report_progress()`
|
|
359
|
-
- Logging via `debug()`, `info()`, `warning()`, and `error()`
|
|
360
|
-
- Resource access through `read_resource()`
|
|
361
|
-
- Request metadata via `request_id` and `client_id`
|
|
362
|
-
|
|
363
|
-
## Running Your Server
|
|
364
|
-
|
|
365
|
-
There are three main ways to use your FastMCP server, each suited for different stages of development:
|
|
366
|
-
|
|
367
|
-
### Development Mode (Recommended for Building & Testing)
|
|
368
|
-
|
|
369
|
-
The fastest way to test and debug your server is with the MCP Inspector:
|
|
370
|
-
|
|
371
|
-
```bash
|
|
372
|
-
fastmcp dev server.py
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
This launches a web interface where you can:
|
|
376
|
-
- Test your tools and resources interactively
|
|
377
|
-
- See detailed logs and error messages
|
|
378
|
-
- Monitor server performance
|
|
379
|
-
- Set environment variables for testing
|
|
380
|
-
|
|
381
|
-
During development, you can:
|
|
382
|
-
- Add dependencies with `--with`:
|
|
383
|
-
```bash
|
|
384
|
-
fastmcp dev server.py --with pandas --with numpy
|
|
385
|
-
```
|
|
386
|
-
- Mount your local code for live updates:
|
|
387
|
-
```bash
|
|
388
|
-
fastmcp dev server.py --with-editable .
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
### Claude Desktop Integration (For Regular Use)
|
|
392
|
-
|
|
393
|
-
Once your server is ready, install it in Claude Desktop to use it with Claude:
|
|
394
|
-
|
|
395
|
-
```bash
|
|
396
|
-
fastmcp install server.py
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
Your server will run in an isolated environment with:
|
|
400
|
-
- Automatic installation of dependencies specified in your FastMCP instance:
|
|
401
|
-
```python
|
|
402
|
-
mcp = FastMCP("My App", dependencies=["pandas", "numpy"])
|
|
403
|
-
```
|
|
404
|
-
- Custom naming via `--name`:
|
|
405
|
-
```bash
|
|
406
|
-
fastmcp install server.py --name "My Analytics Server"
|
|
407
|
-
```
|
|
408
|
-
- Environment variable management:
|
|
409
|
-
```bash
|
|
410
|
-
# Set variables individually
|
|
411
|
-
fastmcp install server.py -e API_KEY=abc123 -e DB_URL=postgres://...
|
|
412
|
-
|
|
413
|
-
# Or load from a .env file
|
|
414
|
-
fastmcp install server.py -f .env
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
### Direct Execution (For Advanced Use Cases)
|
|
418
|
-
|
|
419
|
-
For advanced scenarios like custom deployments or running without Claude, you can execute your server directly:
|
|
420
|
-
|
|
421
|
-
```python
|
|
422
|
-
from fastmcp import FastMCP
|
|
423
|
-
|
|
424
|
-
mcp = FastMCP("My App")
|
|
425
|
-
|
|
426
|
-
if __name__ == "__main__":
|
|
427
|
-
mcp.run()
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
Run it with:
|
|
431
|
-
```bash
|
|
432
|
-
# Using the FastMCP CLI
|
|
433
|
-
fastmcp run server.py
|
|
434
|
-
|
|
435
|
-
# Or with Python/uv directly
|
|
436
|
-
python server.py
|
|
437
|
-
uv run python server.py
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
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.
|
|
442
|
-
|
|
443
|
-
Choose this method when you need:
|
|
444
|
-
- Custom deployment configurations
|
|
445
|
-
- Integration with other services
|
|
446
|
-
- Direct control over the server lifecycle
|
|
447
|
-
|
|
448
|
-
### Server Object Names
|
|
449
|
-
|
|
450
|
-
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`:
|
|
451
|
-
|
|
452
|
-
```bash
|
|
453
|
-
# Using a standard name
|
|
454
|
-
fastmcp run server.py
|
|
455
|
-
|
|
456
|
-
# Using a custom name
|
|
457
|
-
fastmcp run server.py:my_custom_server
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
## Examples
|
|
461
|
-
|
|
462
|
-
Here are a few examples of FastMCP servers. For more, see the `examples/` directory.
|
|
463
|
-
|
|
464
|
-
### Echo Server
|
|
465
|
-
A simple server demonstrating resources, tools, and prompts:
|
|
466
|
-
|
|
467
|
-
```python
|
|
468
|
-
from fastmcp import FastMCP
|
|
469
|
-
|
|
470
|
-
mcp = FastMCP("Echo")
|
|
471
|
-
|
|
472
|
-
@mcp.resource("echo://{message}")
|
|
473
|
-
def echo_resource(message: str) -> str:
|
|
474
|
-
"""Echo a message as a resource"""
|
|
475
|
-
return f"Resource echo: {message}"
|
|
476
|
-
|
|
477
|
-
@mcp.tool()
|
|
478
|
-
def echo_tool(message: str) -> str:
|
|
479
|
-
"""Echo a message as a tool"""
|
|
480
|
-
return f"Tool echo: {message}"
|
|
481
|
-
|
|
482
|
-
@mcp.prompt()
|
|
483
|
-
def echo_prompt(message: str) -> str:
|
|
484
|
-
"""Create an echo prompt"""
|
|
485
|
-
return f"Please process this message: {message}"
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
### SQLite Explorer
|
|
489
|
-
A more complex example showing database integration:
|
|
490
|
-
|
|
491
|
-
```python
|
|
492
|
-
from fastmcp import FastMCP
|
|
493
|
-
import sqlite3
|
|
494
|
-
|
|
495
|
-
mcp = FastMCP("SQLite Explorer")
|
|
496
|
-
|
|
497
|
-
@mcp.resource("schema://main")
|
|
498
|
-
def get_schema() -> str:
|
|
499
|
-
"""Provide the database schema as a resource"""
|
|
500
|
-
conn = sqlite3.connect("database.db")
|
|
501
|
-
schema = conn.execute(
|
|
502
|
-
"SELECT sql FROM sqlite_master WHERE type='table'"
|
|
503
|
-
).fetchall()
|
|
504
|
-
return "\n".join(sql[0] for sql in schema if sql[0])
|
|
505
|
-
|
|
506
|
-
@mcp.tool()
|
|
507
|
-
def query_data(sql: str) -> str:
|
|
508
|
-
"""Execute SQL queries safely"""
|
|
509
|
-
conn = sqlite3.connect("database.db")
|
|
510
|
-
try:
|
|
511
|
-
result = conn.execute(sql).fetchall()
|
|
512
|
-
return "\n".join(str(row) for row in result)
|
|
513
|
-
except Exception as e:
|
|
514
|
-
return f"Error: {str(e)}"
|
|
515
|
-
|
|
516
|
-
@mcp.prompt()
|
|
517
|
-
def analyze_table(table: str) -> str:
|
|
518
|
-
"""Create a prompt template for analyzing tables"""
|
|
519
|
-
return f"""Please analyze this database table:
|
|
520
|
-
Table: {table}
|
|
521
|
-
Schema:
|
|
522
|
-
{get_schema()}
|
|
523
|
-
|
|
524
|
-
What insights can you provide about the structure and relationships?"""
|
|
525
|
-
```
|
|
526
|
-
|
|
527
|
-
## Contributing
|
|
528
|
-
|
|
529
|
-
<details>
|
|
530
|
-
|
|
531
|
-
<summary><h3>Open Developer Guide</h3></summary>
|
|
532
|
-
|
|
533
|
-
### Prerequisites
|
|
534
|
-
|
|
535
|
-
FastMCP requires Python 3.10+ and [uv](https://docs.astral.sh/uv/).
|
|
536
|
-
|
|
537
|
-
### Installation
|
|
538
|
-
|
|
539
|
-
For development, we recommend installing FastMCP with development dependencies, which includes various utilities the maintainers find useful.
|
|
540
|
-
|
|
541
|
-
```bash
|
|
542
|
-
git clone https://github.com/jlowin/fastmcp.git
|
|
543
|
-
cd fastmcp
|
|
544
|
-
uv sync --frozen --extra dev
|
|
545
|
-
```
|
|
546
|
-
|
|
547
|
-
For running tests only (e.g., in CI), you only need the testing dependencies:
|
|
548
|
-
|
|
549
|
-
```bash
|
|
550
|
-
uv sync --frozen --extra tests
|
|
551
|
-
```
|
|
552
|
-
|
|
553
|
-
### Testing
|
|
554
|
-
|
|
555
|
-
Please make sure to test any new functionality. Your tests should be simple and atomic and anticipate change rather than cement complex patterns.
|
|
556
|
-
|
|
557
|
-
Run tests from the root directory:
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
```bash
|
|
561
|
-
pytest -vv
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
### Formatting
|
|
565
|
-
|
|
566
|
-
FastMCP enforces a variety of required formats, which you can automatically enforce with pre-commit.
|
|
567
|
-
|
|
568
|
-
Install the pre-commit hooks:
|
|
569
|
-
|
|
570
|
-
```bash
|
|
571
|
-
pre-commit install
|
|
572
|
-
```
|
|
573
|
-
|
|
574
|
-
The hooks will now run on every commit (as well as on every PR). To run them manually:
|
|
575
|
-
|
|
576
|
-
```bash
|
|
577
|
-
pre-commit run --all-files
|
|
578
|
-
```
|
|
579
|
-
|
|
580
|
-
### Opening a Pull Request
|
|
581
|
-
|
|
582
|
-
Fork the repository and create a new branch:
|
|
583
|
-
|
|
584
|
-
```bash
|
|
585
|
-
git checkout -b my-branch
|
|
586
|
-
```
|
|
587
|
-
|
|
588
|
-
Make your changes and commit them:
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
```bash
|
|
592
|
-
git add . && git commit -m "My changes"
|
|
593
|
-
```
|
|
594
|
-
|
|
595
|
-
Push your changes to your fork:
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
```bash
|
|
599
|
-
git push origin my-branch
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
Feel free to reach out in a GitHub issue or discussion if you have any questions!
|
|
603
|
-
|
|
604
|
-
</details>
|
fastmcp-1.0.dist-info/RECORD
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
fastmcp/__init__.py,sha256=Y5dHGBwyQPgNP5gzOyNIItefvMZ3vJLdom1oV8A1u_k,248
|
|
2
|
-
fastmcp/exceptions.py,sha256=q9djUDmpwmGEWcHI8q4UzJBtf7s7UtgL--OB7OaGzyQ,435
|
|
3
|
-
fastmcp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
fastmcp/server.py,sha256=iM8tIqA258sK_-8xfsPlC2QJRnoMo5s1a5qPLaRDnZg,22538
|
|
5
|
-
fastmcp/cli/__init__.py,sha256=7hrwtCHX9nMd9qcz7R_JFSoqbL71fC35cBLXBS430mg,88
|
|
6
|
-
fastmcp/cli/claude.py,sha256=5SoVEsA_PnOyOe2bcItvfcCwuhfX6W99TP1nXahLIJE,4442
|
|
7
|
-
fastmcp/cli/cli.py,sha256=sWNhq0ryeWcT_ANCW-Ss4ldHfptVDm8d6GjNtJe-8x8,13510
|
|
8
|
-
fastmcp/prompts/__init__.py,sha256=4BsMxoYolpoxg74xkkkzCFL8vvdkLVJ5cIPNs1ND1Jo,99
|
|
9
|
-
fastmcp/prompts/base.py,sha256=8zAIvO3MyiBKs-c-fURMbTBi4CW-UuCizQ0Mv5t2Wnc,5530
|
|
10
|
-
fastmcp/prompts/manager.py,sha256=EkexOB_N4QNtC-UlZmIcWcau91ceO2O1K4_kD75pA_A,1485
|
|
11
|
-
fastmcp/prompts/prompt_manager.py,sha256=5uR14gsi7l0YHwbxFH7N5b_ACHHRWyTtBAH3R0-G5rk,1129
|
|
12
|
-
fastmcp/resources/__init__.py,sha256=9QShop6ckX3Khh3BQLZNkB6R2ZhwskAcnh7-sIuX-W8,464
|
|
13
|
-
fastmcp/resources/base.py,sha256=mKJUiOQaGJAc0qEim0R3Xzd_COtW3anOghAwGOmZ0v0,1368
|
|
14
|
-
fastmcp/resources/resource_manager.py,sha256=b0PKpG-pKi7x2Yx-qaeknjv0mqL17zixSIYOz2V5G6o,3271
|
|
15
|
-
fastmcp/resources/templates.py,sha256=_JHJ8sZqHsQM9p81Bcc_0-OBkYnYd1dFBoibFEMLwkw,2884
|
|
16
|
-
fastmcp/resources/types.py,sha256=VbMaQ1n-UfN1eSQjz0LcadrmOBtAx6TadXkO4nA3fgg,6048
|
|
17
|
-
fastmcp/tools/__init__.py,sha256=ZboxhyMJDl87Svjov8YwNYwNZi55P9VhmpTjBZLesnk,96
|
|
18
|
-
fastmcp/tools/base.py,sha256=aJEOnNUs5KiTC16Szr8AEZyozTtpp0vZXtF5wMIA2mM,2797
|
|
19
|
-
fastmcp/tools/tool_manager.py,sha256=PT6XHcQWzhdC6kfdsJaddRn7VLps4nAs5FMG8l1j8Zc,1617
|
|
20
|
-
fastmcp/utilities/__init__.py,sha256=-imJ8S-rXmbXMWeDamldP-dHDqAPg_wwmPVz-LNX14E,31
|
|
21
|
-
fastmcp/utilities/func_metadata.py,sha256=khB5bPMB9I8T7LfFDRwNzQSFqYVSME41KNZpIESmKY4,7266
|
|
22
|
-
fastmcp/utilities/logging.py,sha256=1ipiOXzgWUp3Vih_JtEiLX7aAFmrUDZNr4KrZbofZTM,818
|
|
23
|
-
fastmcp/utilities/types.py,sha256=kCjz2h3UlMAfHBB-HR5w6s9kauX0KLyQzRuHyhpaP4A,1810
|
|
24
|
-
fastmcp-1.0.dist-info/METADATA,sha256=iis0AaqqDhY6bdlI4WcUSCO54aMXUFWTLEqpHvfhw44,16747
|
|
25
|
-
fastmcp-1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
26
|
-
fastmcp-1.0.dist-info/entry_points.txt,sha256=ff8bMtKX1JvXyurMibAacMSKbJEPmac9ffAKU9mLnM8,44
|
|
27
|
-
fastmcp-1.0.dist-info/licenses/LICENSE,sha256=l3hc_411P__OCHoZlE2ZYWekMW-fmIZe9cYnGVyhu9I,1071
|
|
28
|
-
fastmcp-1.0.dist-info/RECORD,,
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Jeremiah Lowin
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
File without changes
|
|
File without changes
|