fastmcp 2.1.2__tar.gz → 2.2.1__tar.gz
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-2.2.1/.github/ISSUE_TEMPLATE/bug.yml +63 -0
- fastmcp-2.2.1/.github/ISSUE_TEMPLATE/config.yml +8 -0
- fastmcp-2.2.1/.github/ISSUE_TEMPLATE/enhancement.yml +38 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/.github/workflows/run-tests.yml +0 -1
- {fastmcp-2.1.2 → fastmcp-2.2.1}/.pre-commit-config.yaml +0 -1
- {fastmcp-2.1.2 → fastmcp-2.2.1}/PKG-INFO +14 -6
- {fastmcp-2.1.2 → fastmcp-2.2.1}/README.md +10 -3
- fastmcp-2.1.2/docs/clients/overview.mdx → fastmcp-2.2.1/docs/clients/client.mdx +5 -1
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/clients/transports.mdx +1 -1
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/docs.json +2 -2
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/getting-started/quickstart.mdx +3 -3
- fastmcp-2.2.1/docs/patterns/composition.mdx +297 -0
- fastmcp-2.2.1/docs/patterns/fastapi.mdx +123 -0
- fastmcp-2.2.1/docs/patterns/openapi.mdx +156 -0
- fastmcp-2.1.2/docs/patterns/proxying.mdx → fastmcp-2.2.1/docs/patterns/proxy.mdx +15 -11
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/servers/context.mdx +4 -1
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/servers/fastmcp.mdx +66 -75
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/servers/prompts.mdx +7 -8
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/servers/resources.mdx +146 -34
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/servers/tools.mdx +7 -8
- fastmcp-2.2.1/docs/snippets/version-badge.mdx +8 -0
- fastmcp-2.2.1/docs/style.css +53 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/pyproject.toml +9 -7
- fastmcp-2.2.1/src/contrib/README.md +9 -0
- fastmcp-2.2.1/src/contrib/bulk_tool_caller/README.md +35 -0
- fastmcp-2.2.1/src/contrib/bulk_tool_caller/__init__.py +3 -0
- fastmcp-2.2.1/src/contrib/bulk_tool_caller/bulk_tool_caller.py +131 -0
- fastmcp-2.2.1/src/contrib/bulk_tool_caller/example.py +17 -0
- fastmcp-2.2.1/src/contrib/mcp_mixin/README.md +39 -0
- fastmcp-2.2.1/src/contrib/mcp_mixin/__init__.py +8 -0
- fastmcp-2.2.1/src/contrib/mcp_mixin/example.py +52 -0
- fastmcp-2.2.1/src/contrib/mcp_mixin/mcp_mixin.py +208 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/cli/cli.py +32 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/client/client.py +16 -15
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/client/transports.py +28 -7
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/exceptions.py +8 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/prompts/prompt.py +20 -1
- fastmcp-2.2.1/src/fastmcp/prompts/prompt_manager.py +83 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/resources/resource.py +20 -1
- fastmcp-2.2.1/src/fastmcp/resources/resource_manager.py +245 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/resources/template.py +81 -8
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/server/openapi.py +10 -16
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/server/proxy.py +102 -76
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/server/server.py +321 -256
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/settings.py +8 -11
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/tools/tool.py +67 -7
- fastmcp-2.2.1/src/fastmcp/tools/tool_manager.py +98 -0
- fastmcp-2.2.1/tests/cli/test_run.py +22 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/client/test_client.py +109 -0
- fastmcp-2.2.1/tests/contrib/__init__.py +1 -0
- fastmcp-2.2.1/tests/contrib/test_bulk_tool_caller.py +221 -0
- fastmcp-2.2.1/tests/contrib/test_mcp_mixin.py +255 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/prompts/test_base.py +0 -11
- fastmcp-2.2.1/tests/prompts/test_prompt_manager.py +261 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/resources/test_file_resources.py +0 -4
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/resources/test_function_resources.py +0 -7
- fastmcp-2.2.1/tests/resources/test_resource_manager.py +542 -0
- fastmcp-2.2.1/tests/resources/test_resource_template.py +378 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/resources/test_resources.py +0 -1
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/server/test_file_server.py +2 -7
- fastmcp-2.2.1/tests/server/test_import_server.py +391 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/server/test_lifespan.py +0 -2
- fastmcp-2.2.1/tests/server/test_mount.py +429 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/server/test_openapi.py +68 -30
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/server/test_proxy.py +64 -40
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/server/test_run_server.py +1 -1
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/server/test_server.py +398 -197
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/tools/test_tool_manager.py +203 -150
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/test_func_metadata.py +0 -3
- {fastmcp-2.1.2 → fastmcp-2.2.1}/uv.lock +11 -18
- fastmcp-2.1.2/docs/patterns/composition.mdx +0 -186
- fastmcp-2.1.2/docs/patterns/fastapi.mdx +0 -114
- fastmcp-2.1.2/docs/patterns/openapi.mdx +0 -174
- fastmcp-2.1.2/docs/servers/resources_backup.mdx +0 -270
- fastmcp-2.1.2/docs/style.css +0 -13
- fastmcp-2.1.2/src/fastmcp/prompts/prompt_manager.py +0 -93
- fastmcp-2.1.2/src/fastmcp/resources/resource_manager.py +0 -278
- fastmcp-2.1.2/src/fastmcp/tools/tool_manager.py +0 -99
- fastmcp-2.1.2/tests/prompts/test_prompt_manager.py +0 -344
- fastmcp-2.1.2/tests/resources/test_resource_manager.py +0 -558
- fastmcp-2.1.2/tests/resources/test_resource_template.py +0 -188
- fastmcp-2.1.2/tests/server/test_mount.py +0 -232
- {fastmcp-2.1.2 → fastmcp-2.2.1}/.cursor/rules/core-mcp-objects.mdc +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/.github/release.yml +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/.github/workflows/publish.yml +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/.github/workflows/run-static.yml +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/.gitignore +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/LICENSE +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/Windows_Notes.md +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/assets/demo-inspector.png +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/getting-started/installation.mdx +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/getting-started/welcome.mdx +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/docs/patterns/decorating-methods.mdx +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/complex_inputs.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/desktop.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/echo.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/memory.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/mount_example.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/readme-quickstart.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/sampling.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/screenshot.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/simple_echo.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/README.md +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/pyproject.toml +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/src/smart_home/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/src/smart_home/__main__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/src/smart_home/hub.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/src/smart_home/lights/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/src/smart_home/lights/hue_utils.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/src/smart_home/lights/server.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/src/smart_home/py.typed +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/src/smart_home/settings.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/smart_home/uv.lock +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/examples/text_me.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/justfile +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/cli/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/cli/claude.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/client/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/client/base.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/client/roots.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/client/sampling.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/prompts/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/py.typed +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/resources/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/resources/types.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/server/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/server/context.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/tools/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/utilities/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/utilities/decorators.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/utilities/func_metadata.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/utilities/logging.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/utilities/openapi.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/src/fastmcp/utilities/types.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/client/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/client/test_roots.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/client/test_sampling.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/conftest.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/prompts/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/resources/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/server/__init__.py +0 -0
- {fastmcp-2.1.2/tests/server → fastmcp-2.2.1/tests}/test_servers/fastmcp_server.py +0 -0
- {fastmcp-2.1.2/tests/server → fastmcp-2.2.1/tests}/test_servers/sse.py +0 -0
- {fastmcp-2.1.2/tests/server → fastmcp-2.2.1/tests}/test_servers/stdio.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/tools/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/openapi/__init__.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/openapi/conftest.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/openapi/test_openapi.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/openapi/test_openapi_advanced.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/openapi/test_openapi_fastapi.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/test_decorated_function.py +0 -0
- {fastmcp-2.1.2 → fastmcp-2.2.1}/tests/utilities/test_logging.py +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
name: 🐛 Bug Report
|
|
2
|
+
description: Report a bug or unexpected behavior in FastMCP
|
|
3
|
+
labels: [bug, pending]
|
|
4
|
+
|
|
5
|
+
body:
|
|
6
|
+
- type: markdown
|
|
7
|
+
attributes:
|
|
8
|
+
value: Thank you for contributing to FastMCP! 🙏
|
|
9
|
+
|
|
10
|
+
- type: textarea
|
|
11
|
+
id: description
|
|
12
|
+
attributes:
|
|
13
|
+
label: Description
|
|
14
|
+
description: |
|
|
15
|
+
Please explain what you're experiencing and what you would expect to happen instead.
|
|
16
|
+
|
|
17
|
+
Provide as much detail as possible to help us understand and solve your problem quickly.
|
|
18
|
+
validations:
|
|
19
|
+
required: true
|
|
20
|
+
|
|
21
|
+
- type: textarea
|
|
22
|
+
id: example
|
|
23
|
+
attributes:
|
|
24
|
+
label: Example Code
|
|
25
|
+
description: >
|
|
26
|
+
If applicable, please provide a self-contained,
|
|
27
|
+
[minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)
|
|
28
|
+
demonstrating the bug.
|
|
29
|
+
|
|
30
|
+
placeholder: |
|
|
31
|
+
from fastmcp import FastMCP
|
|
32
|
+
|
|
33
|
+
...
|
|
34
|
+
render: Python
|
|
35
|
+
|
|
36
|
+
- type: textarea
|
|
37
|
+
id: version
|
|
38
|
+
attributes:
|
|
39
|
+
label: Version Information
|
|
40
|
+
description: |
|
|
41
|
+
Please provide information about your FastMCP version, MCP version, Python version, and OS.
|
|
42
|
+
|
|
43
|
+
To get this information, run the following command in your terminal and paste the output below:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
fastmcp version
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If there is other information that would be helpful, please include it as well.
|
|
50
|
+
render: Text
|
|
51
|
+
validations:
|
|
52
|
+
required: true
|
|
53
|
+
|
|
54
|
+
- type: textarea
|
|
55
|
+
id: additional_context
|
|
56
|
+
attributes:
|
|
57
|
+
label: Additional Context
|
|
58
|
+
description: |
|
|
59
|
+
Add any other context about the problem here. This could include:
|
|
60
|
+
- The full error message and traceback (if applicable)
|
|
61
|
+
- Information about your environment (e.g., virtual environment, installed packages)
|
|
62
|
+
- Steps to reproduce the issue
|
|
63
|
+
- Any recent changes in your code or setup that might be relevant
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
blank_issues_enabled: false
|
|
2
|
+
contact_links:
|
|
3
|
+
- name: FastMCP Documentation
|
|
4
|
+
url: https://gofastmcp.com
|
|
5
|
+
about: Please review the documentation before opening an issue.
|
|
6
|
+
- name: MCP Python SDK
|
|
7
|
+
url: https://github.com/modelcontextprotocol/python-sdk/issues
|
|
8
|
+
about: Issues related to the low-level MCP Python SDK, including the FastMCP 1.0 module that is included in the `mcp` package, should be filed on the official MCP repository.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: 💡 Enhancement Request
|
|
2
|
+
description: Suggest an idea or improvement for FastMCP
|
|
3
|
+
labels: [enhancement, pending]
|
|
4
|
+
|
|
5
|
+
body:
|
|
6
|
+
- type: markdown
|
|
7
|
+
attributes:
|
|
8
|
+
value: Thank you for contributing to FastMCP! We value your ideas for improving the framework. 💡
|
|
9
|
+
|
|
10
|
+
- type: textarea
|
|
11
|
+
id: description
|
|
12
|
+
attributes:
|
|
13
|
+
label: Enhancement Description
|
|
14
|
+
description: |
|
|
15
|
+
Please describe the enhancement you'd like to see in FastMCP.
|
|
16
|
+
|
|
17
|
+
- What problem would this solve?
|
|
18
|
+
- How would this improve your workflow or experience with FastMCP?
|
|
19
|
+
- Are there any alternative solutions you've considered?
|
|
20
|
+
validations:
|
|
21
|
+
required: true
|
|
22
|
+
|
|
23
|
+
- type: textarea
|
|
24
|
+
id: use_case
|
|
25
|
+
attributes:
|
|
26
|
+
label: Use Case
|
|
27
|
+
description: |
|
|
28
|
+
Describe a specific use case or scenario where this enhancement would be beneficial.
|
|
29
|
+
If possible, provide an example of how you envision using this feature.
|
|
30
|
+
|
|
31
|
+
- type: textarea
|
|
32
|
+
id: example
|
|
33
|
+
attributes:
|
|
34
|
+
label: Proposed Implementation
|
|
35
|
+
description: >
|
|
36
|
+
If you have ideas about how this enhancement could be implemented,
|
|
37
|
+
please share them here. Code snippets, pseudocode, or general approaches are welcome.
|
|
38
|
+
render: Python
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastmcp
|
|
3
|
-
Version: 2.1
|
|
3
|
+
Version: 2.2.1
|
|
4
4
|
Summary: The fast, Pythonic way to build MCP servers.
|
|
5
5
|
Project-URL: Homepage, https://gofastmcp.com
|
|
6
6
|
Project-URL: Repository, https://github.com/jlowin/fastmcp
|
|
@@ -17,10 +17,11 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
17
17
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
18
|
Classifier: Typing :: Typed
|
|
19
19
|
Requires-Python: >=3.10
|
|
20
|
-
Requires-Dist:
|
|
21
|
-
Requires-Dist:
|
|
20
|
+
Requires-Dist: exceptiongroup>=1.2.2
|
|
21
|
+
Requires-Dist: httpx>=0.28.1
|
|
22
22
|
Requires-Dist: mcp<2.0.0,>=1.6.0
|
|
23
23
|
Requires-Dist: openapi-pydantic>=0.5.1
|
|
24
|
+
Requires-Dist: python-dotenv>=1.1.0
|
|
24
25
|
Requires-Dist: rich>=13.9.4
|
|
25
26
|
Requires-Dist: typer>=0.15.2
|
|
26
27
|
Requires-Dist: websockets>=15.0.1
|
|
@@ -94,6 +95,7 @@ FastMCP handles the complex protocol details and server management, letting you
|
|
|
94
95
|
- [Proxy Servers](#proxy-servers)
|
|
95
96
|
- [Composing MCP Servers](#composing-mcp-servers)
|
|
96
97
|
- [OpenAPI \& FastAPI Generation](#openapi--fastapi-generation)
|
|
98
|
+
- [Handling `stderr`](#handling-stderr)
|
|
97
99
|
- [Running Your Server](#running-your-server)
|
|
98
100
|
- [Development Mode (Recommended for Building \& Testing)](#development-mode-recommended-for-building--testing)
|
|
99
101
|
- [Claude Desktop Integration (For Regular Use)](#claude-desktop-integration-for-regular-use)
|
|
@@ -121,7 +123,7 @@ FastMCP provides a high-level, Pythonic interface for building and interacting w
|
|
|
121
123
|
|
|
122
124
|
## Why FastMCP?
|
|
123
125
|
|
|
124
|
-
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. FastMCP handles all the complex protocol details and server management, so you can focus on building great tools. It
|
|
126
|
+
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. 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.
|
|
125
127
|
|
|
126
128
|
FastMCP aims to be:
|
|
127
129
|
|
|
@@ -580,13 +582,13 @@ proxy_client = Client(
|
|
|
580
582
|
)
|
|
581
583
|
|
|
582
584
|
# Create a proxy server that connects to the client and exposes its capabilities
|
|
583
|
-
proxy = FastMCP.
|
|
585
|
+
proxy = FastMCP.from_client(proxy_client, name="Stdio-to-SSE Proxy")
|
|
584
586
|
|
|
585
587
|
if __name__ == "__main__":
|
|
586
588
|
proxy.run(transport='sse')
|
|
587
589
|
```
|
|
588
590
|
|
|
589
|
-
`FastMCP.
|
|
591
|
+
`FastMCP.from_client` is a class method that connects to the target, discovers its capabilities, and dynamically builds the proxy server instance.
|
|
590
592
|
|
|
591
593
|
|
|
592
594
|
|
|
@@ -694,6 +696,12 @@ mcp_server = FastMCP.from_openapi(openapi_spec, client=http_client)
|
|
|
694
696
|
if __name__ == "__main__":
|
|
695
697
|
mcp_server.run()
|
|
696
698
|
```
|
|
699
|
+
|
|
700
|
+
### Handling `stderr`
|
|
701
|
+
The MCP spec allows for the server to write anything it wants to `stderr`, and it
|
|
702
|
+
doesn't specify the format in any way. FastMCP will forward the server's `stderr`
|
|
703
|
+
to the client's `stderr`.
|
|
704
|
+
|
|
697
705
|
## Running Your Server
|
|
698
706
|
|
|
699
707
|
Choose the method that best suits your needs:
|
|
@@ -66,6 +66,7 @@ FastMCP handles the complex protocol details and server management, letting you
|
|
|
66
66
|
- [Proxy Servers](#proxy-servers)
|
|
67
67
|
- [Composing MCP Servers](#composing-mcp-servers)
|
|
68
68
|
- [OpenAPI \& FastAPI Generation](#openapi--fastapi-generation)
|
|
69
|
+
- [Handling `stderr`](#handling-stderr)
|
|
69
70
|
- [Running Your Server](#running-your-server)
|
|
70
71
|
- [Development Mode (Recommended for Building \& Testing)](#development-mode-recommended-for-building--testing)
|
|
71
72
|
- [Claude Desktop Integration (For Regular Use)](#claude-desktop-integration-for-regular-use)
|
|
@@ -93,7 +94,7 @@ FastMCP provides a high-level, Pythonic interface for building and interacting w
|
|
|
93
94
|
|
|
94
95
|
## Why FastMCP?
|
|
95
96
|
|
|
96
|
-
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. FastMCP handles all the complex protocol details and server management, so you can focus on building great tools. It
|
|
97
|
+
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. 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.
|
|
97
98
|
|
|
98
99
|
FastMCP aims to be:
|
|
99
100
|
|
|
@@ -552,13 +553,13 @@ proxy_client = Client(
|
|
|
552
553
|
)
|
|
553
554
|
|
|
554
555
|
# Create a proxy server that connects to the client and exposes its capabilities
|
|
555
|
-
proxy = FastMCP.
|
|
556
|
+
proxy = FastMCP.from_client(proxy_client, name="Stdio-to-SSE Proxy")
|
|
556
557
|
|
|
557
558
|
if __name__ == "__main__":
|
|
558
559
|
proxy.run(transport='sse')
|
|
559
560
|
```
|
|
560
561
|
|
|
561
|
-
`FastMCP.
|
|
562
|
+
`FastMCP.from_client` is a class method that connects to the target, discovers its capabilities, and dynamically builds the proxy server instance.
|
|
562
563
|
|
|
563
564
|
|
|
564
565
|
|
|
@@ -666,6 +667,12 @@ mcp_server = FastMCP.from_openapi(openapi_spec, client=http_client)
|
|
|
666
667
|
if __name__ == "__main__":
|
|
667
668
|
mcp_server.run()
|
|
668
669
|
```
|
|
670
|
+
|
|
671
|
+
### Handling `stderr`
|
|
672
|
+
The MCP spec allows for the server to write anything it wants to `stderr`, and it
|
|
673
|
+
doesn't specify the format in any way. FastMCP will forward the server's `stderr`
|
|
674
|
+
to the client's `stderr`.
|
|
675
|
+
|
|
669
676
|
## Running Your Server
|
|
670
677
|
|
|
671
678
|
Choose the method that best suits your needs:
|
|
@@ -5,6 +5,10 @@ description: Learn how to use the FastMCP Client to interact with MCP servers.
|
|
|
5
5
|
icon: user-robot
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
import { VersionBadge } from '/snippets/version-badge.mdx'
|
|
9
|
+
|
|
10
|
+
<VersionBadge version="2.0.0" />
|
|
11
|
+
|
|
8
12
|
The `fastmcp.Client` provides a high-level, asynchronous interface for interacting with any Model Context Protocol (MCP) server, whether it's built with FastMCP or another implementation. It simplifies communication by handling protocol details and connection management.
|
|
9
13
|
|
|
10
14
|
## FastMCP Client
|
|
@@ -248,5 +252,5 @@ async def safe_call_tool():
|
|
|
248
252
|
Other errors, like connection failures, will raise standard Python exceptions (e.g., `ConnectionError`, `TimeoutError`).
|
|
249
253
|
|
|
250
254
|
<Tip>
|
|
251
|
-
The client transport often has its own error-handling mechanisms, so you can not always trap errors like those raised by `call_tool` outside of the `async with` block. Instead, you can call `
|
|
255
|
+
The client transport often has its own error-handling mechanisms, so you can not always trap errors like those raised by `call_tool` outside of the `async with` block. Instead, you can call `call_tool(..., _return_raw_result=True)` to get the raw `mcp.types.CallToolResult` object and handle errors yourself by checking its `isError` attribute.
|
|
252
256
|
</Tip>
|
|
@@ -7,7 +7,7 @@ icon: link
|
|
|
7
7
|
|
|
8
8
|
The FastMCP `Client` relies on a `ClientTransport` object to handle the specifics of connecting to and communicating with an MCP server. FastMCP provides several built-in transport implementations for common connection methods.
|
|
9
9
|
|
|
10
|
-
While the `Client` often infers the correct transport automatically (see [Client Overview](/clients/
|
|
10
|
+
While the `Client` often infers the correct transport automatically (see [Client Overview](/clients/client#transport-inference)), you can also instantiate transports explicitly for more control.
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
## Stdio Transports
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
{
|
|
51
51
|
"group": "Clients",
|
|
52
52
|
"pages": [
|
|
53
|
-
"clients/
|
|
53
|
+
"clients/client",
|
|
54
54
|
"clients/transports"
|
|
55
55
|
]
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"group": "Patterns",
|
|
59
59
|
"pages": [
|
|
60
|
-
"patterns/
|
|
60
|
+
"patterns/proxy",
|
|
61
61
|
"patterns/composition",
|
|
62
62
|
"patterns/decorating-methods",
|
|
63
63
|
"patterns/openapi",
|
|
@@ -32,7 +32,7 @@ from fastmcp import FastMCP
|
|
|
32
32
|
|
|
33
33
|
mcp = FastMCP("My MCP Server")
|
|
34
34
|
|
|
35
|
-
@mcp.tool
|
|
35
|
+
@mcp.tool()
|
|
36
36
|
def greet(name: str) -> str:
|
|
37
37
|
return f"Hello, {name}!"
|
|
38
38
|
```
|
|
@@ -48,7 +48,7 @@ from fastmcp import FastMCP, Client
|
|
|
48
48
|
|
|
49
49
|
mcp = FastMCP("My MCP Server")
|
|
50
50
|
|
|
51
|
-
@mcp.tool
|
|
51
|
+
@mcp.tool()
|
|
52
52
|
def greet(name: str) -> str:
|
|
53
53
|
return f"Hello, {name}!"
|
|
54
54
|
|
|
@@ -75,7 +75,7 @@ from fastmcp import FastMCP, Client
|
|
|
75
75
|
|
|
76
76
|
mcp = FastMCP("My MCP Server")
|
|
77
77
|
|
|
78
|
-
@mcp.tool
|
|
78
|
+
@mcp.tool()
|
|
79
79
|
def greet(name: str) -> str:
|
|
80
80
|
return f"Hello, {name}!"
|
|
81
81
|
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Server Composition
|
|
3
|
+
sidebarTitle: Composition
|
|
4
|
+
description: Combine multiple FastMCP servers into a single, larger application using mounting and importing.
|
|
5
|
+
icon: puzzle-piece
|
|
6
|
+
---
|
|
7
|
+
import { VersionBadge } from '/snippets/version-badge.mdx'
|
|
8
|
+
|
|
9
|
+
<VersionBadge version="2.2.0" />
|
|
10
|
+
|
|
11
|
+
As your MCP applications grow, you might want to organize your tools, resources, and prompts into logical modules or reuse existing server components. FastMCP supports composition through two methods:
|
|
12
|
+
|
|
13
|
+
- **`import_server`**: For a one-time copy of components with prefixing (static composition).
|
|
14
|
+
- **`mount`**: For creating a live link where the main server delegates requests to the subserver (dynamic composition).
|
|
15
|
+
|
|
16
|
+
## Why Compose Servers?
|
|
17
|
+
|
|
18
|
+
- **Modularity**: Break down large applications into smaller, focused servers (e.g., a `WeatherServer`, a `DatabaseServer`, a `CalendarServer`).
|
|
19
|
+
- **Reusability**: Create common utility servers (e.g., a `TextProcessingServer`) and mount them wherever needed.
|
|
20
|
+
- **Teamwork**: Different teams can work on separate FastMCP servers that are later combined.
|
|
21
|
+
- **Organization**: Keep related functionality grouped together logically.
|
|
22
|
+
|
|
23
|
+
### Importing vs Mounting
|
|
24
|
+
|
|
25
|
+
The choice of importing or mounting depends on your use case and requirements. In general, importing is best for simpler cases because it copies the imported server's components into the main server, treating them as native integrations. Mounting is best for more complex cases where you need to delegate requests to the subserver at runtime.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
| Feature | Importing | Mounting |
|
|
29
|
+
|---------|----------------|---------|
|
|
30
|
+
| **Method** | `FastMCP.import_server()` | `FastMCP.mount()` |
|
|
31
|
+
| **Composition Type** | One-time copy (static) | Live link (dynamic) |
|
|
32
|
+
| **Updates** | Changes to subserver NOT reflected | Changes to subserver immediately reflected |
|
|
33
|
+
| **Lifespan** | Not managed | Automatically managed |
|
|
34
|
+
| **Synchronicity** | Async (must be awaited) | Sync |
|
|
35
|
+
| **Best For** | Bundling finalized components | Modular runtime composition |
|
|
36
|
+
|
|
37
|
+
### Proxy Servers
|
|
38
|
+
|
|
39
|
+
FastMCP supports [MCP proxying](/patterns/proxy), which allows you to mirror a local or remote server in a local FastMCP instance. Proxies are fully compatible with both importing and mounting.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Importing (Static Composition)
|
|
43
|
+
|
|
44
|
+
The `import_server()` method copies all components (tools, resources, templates, prompts) from one `FastMCP` instance (the *subserver*) into another (the *main server*). A `prefix` is added to avoid naming conflicts.
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from fastmcp import FastMCP
|
|
48
|
+
import asyncio
|
|
49
|
+
|
|
50
|
+
# --- Define Subservers ---
|
|
51
|
+
|
|
52
|
+
# Weather Service
|
|
53
|
+
weather_mcp = FastMCP(name="WeatherService")
|
|
54
|
+
|
|
55
|
+
@weather_mcp.tool()
|
|
56
|
+
def get_forecast(city: str) -> dict:
|
|
57
|
+
"""Get weather forecast."""
|
|
58
|
+
return {"city": city, "forecast": "Sunny"}
|
|
59
|
+
|
|
60
|
+
@weather_mcp.resource("data://cities/supported")
|
|
61
|
+
def list_supported_cities() -> list[str]:
|
|
62
|
+
"""List cities with weather support."""
|
|
63
|
+
return ["London", "Paris", "Tokyo"]
|
|
64
|
+
|
|
65
|
+
# Calculator Service
|
|
66
|
+
calc_mcp = FastMCP(name="CalculatorService")
|
|
67
|
+
|
|
68
|
+
@calc_mcp.tool()
|
|
69
|
+
def add(a: int, b: int) -> int:
|
|
70
|
+
"""Add two numbers."""
|
|
71
|
+
return a + b
|
|
72
|
+
|
|
73
|
+
@calc_mcp.prompt()
|
|
74
|
+
def explain_addition() -> str:
|
|
75
|
+
"""Explain the concept of addition."""
|
|
76
|
+
return "Addition is the process of combining two or more numbers."
|
|
77
|
+
|
|
78
|
+
# --- Define Main Server ---
|
|
79
|
+
main_mcp = FastMCP(name="MainApp")
|
|
80
|
+
|
|
81
|
+
# --- Import Subservers ---
|
|
82
|
+
async def setup():
|
|
83
|
+
# Import weather service with prefix "weather"
|
|
84
|
+
await main_mcp.import_server("weather", weather_mcp)
|
|
85
|
+
|
|
86
|
+
# Import calculator service with prefix "calc"
|
|
87
|
+
await main_mcp.import_server("calc", calc_mcp)
|
|
88
|
+
|
|
89
|
+
# --- Now, main_mcp contains *copied* components ---
|
|
90
|
+
# Tools:
|
|
91
|
+
# - "weather_get_forecast"
|
|
92
|
+
# - "calc_add"
|
|
93
|
+
# Resources:
|
|
94
|
+
# - "weather+data://cities/supported" (prefixed URI)
|
|
95
|
+
# Prompts:
|
|
96
|
+
# - "calc_explain_addition"
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
# In a real app, you might run this async or setup imports differently
|
|
100
|
+
asyncio.run(setup())
|
|
101
|
+
# Run the main server, which now includes components from both subservers
|
|
102
|
+
main_mcp.run()
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### How Importing Works
|
|
106
|
+
|
|
107
|
+
When you call `await main_mcp.import_server(prefix, subserver)`:
|
|
108
|
+
|
|
109
|
+
1. **Tools**: All tools from `subserver` are added to `main_mcp`. Their names are automatically prefixed using the `prefix` and a default separator (`_`).
|
|
110
|
+
- `subserver.tool(name="my_tool")` becomes `main_mcp.tool(name="{prefix}_my_tool")`.
|
|
111
|
+
2. **Resources**: All resources from `subserver` are added. Their URIs are prefixed using the `prefix` and a default separator (`+`).
|
|
112
|
+
- `subserver.resource(uri="data://info")` becomes `main_mcp.resource(uri="{prefix}+data://info")`.
|
|
113
|
+
3. **Resource Templates**: All templates from `subserver` are added. Their URI *templates* are prefixed similarly to resources.
|
|
114
|
+
- `subserver.resource(uri="data://{id}")` becomes `main_mcp.resource(uri="{prefix}+data://{id}")`.
|
|
115
|
+
4. **Prompts**: All prompts from `subserver` are added, with names prefixed like tools.
|
|
116
|
+
- `subserver.prompt(name="my_prompt")` becomes `main_mcp.prompt(name="{prefix}_my_prompt")`.
|
|
117
|
+
|
|
118
|
+
Note that `import_server` performs a **one-time copy** of components from the `subserver` into the `main_mcp` instance at the time the method is called. Changes made to the `subserver` *after* `import_server` is called **will not** be reflected in `main_mcp`. Also, the `subserver`'s `lifespan` context is **not** executed by the main server when using `import_server`.
|
|
119
|
+
|
|
120
|
+
### Customizing Separators
|
|
121
|
+
|
|
122
|
+
You might prefer different separators for the prefixed names and URIs. You can customize these when calling `import_server()`:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
await main_mcp.import_server(
|
|
126
|
+
prefix="api",
|
|
127
|
+
app=some_subserver,
|
|
128
|
+
tool_separator="/", # Tool name becomes: "api/sub_tool_name"
|
|
129
|
+
resource_separator=":", # Resource URI becomes: "api:data://sub_resource"
|
|
130
|
+
prompt_separator="." # Prompt name becomes: "api.sub_prompt_name"
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
<Warning>
|
|
135
|
+
Be cautious when choosing separators. Some MCP clients (like Claude Desktop) might have restrictions on characters allowed in tool names (e.g., `/` might not be supported). The defaults (`_` for names, `+` for URIs) are generally safe.
|
|
136
|
+
</Warning>
|
|
137
|
+
|
|
138
|
+
## Mounting (Live Linking)
|
|
139
|
+
|
|
140
|
+
The `mount()` method creates a **live link** between the `main_mcp` server and the `subserver`. Instead of copying components, requests for components matching the `prefix` are **delegated** to the `subserver` at runtime.
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
import asyncio
|
|
144
|
+
from fastmcp import FastMCP, Client
|
|
145
|
+
|
|
146
|
+
# --- Define Subserver ---
|
|
147
|
+
dynamic_mcp = FastMCP(name="DynamicService")
|
|
148
|
+
@dynamic_mcp.tool()
|
|
149
|
+
def initial_tool(): return "Initial Tool Exists"
|
|
150
|
+
|
|
151
|
+
# --- Define Main Server ---
|
|
152
|
+
main_mcp = FastMCP(name="MainAppLive")
|
|
153
|
+
|
|
154
|
+
# --- Mount Subserver (Sync operation) ---
|
|
155
|
+
main_mcp.mount("dynamic", dynamic_mcp)
|
|
156
|
+
|
|
157
|
+
print("Mounted dynamic_mcp.")
|
|
158
|
+
|
|
159
|
+
# --- Add a tool AFTER mounting ---
|
|
160
|
+
@dynamic_mcp.tool()
|
|
161
|
+
def added_later(): return "Tool Added Dynamically!"
|
|
162
|
+
|
|
163
|
+
print("Added 'added_later' tool to dynamic_mcp.")
|
|
164
|
+
|
|
165
|
+
# --- Test Access ---
|
|
166
|
+
async def test_dynamic_mount():
|
|
167
|
+
# Need to use await for get_tools now
|
|
168
|
+
tools_before = await main_mcp.get_tools()
|
|
169
|
+
print("Tools available via main_mcp:", list(tools_before.keys()))
|
|
170
|
+
# Expected: ['dynamic_initial_tool', 'dynamic_added_later']
|
|
171
|
+
|
|
172
|
+
async with Client(main_mcp) as client:
|
|
173
|
+
# Call the dynamically added tool via the main server
|
|
174
|
+
result = await client.call_tool("dynamic_added_later")
|
|
175
|
+
print("Result of calling dynamic_added_later:", result[0].text)
|
|
176
|
+
# Expected: Tool Added Dynamically!
|
|
177
|
+
|
|
178
|
+
if __name__ == "__main__":
|
|
179
|
+
# Need async context to test
|
|
180
|
+
asyncio.run(test_dynamic_mount())
|
|
181
|
+
# To run the server itself:
|
|
182
|
+
# main_mcp.run()
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### How Mounting Works
|
|
186
|
+
|
|
187
|
+
When you call `main_mcp.mount(prefix, server)`:
|
|
188
|
+
|
|
189
|
+
1. **Live Link**: A live connection is established between `main_mcp` and the `subserver`.
|
|
190
|
+
2. **Dynamic Updates**: Changes made to the `subserver` (e.g., adding new tools) **will be reflected** immediately when accessing components through `main_mcp`.
|
|
191
|
+
3. **Lifespan Management**: The `subserver`'s `lifespan` context **is automatically managed** and executed within the `main_mcp`'s lifespan.
|
|
192
|
+
4. **Delegation**: Requests for components matching the prefix are delegated to the subserver at runtime.
|
|
193
|
+
|
|
194
|
+
The same prefixing rules apply as with `import_server` for naming tools, resources, templates, and prompts.
|
|
195
|
+
|
|
196
|
+
### Customizing Separators
|
|
197
|
+
|
|
198
|
+
Similar to `import_server`, you can customize the separators for the prefixed names and URIs:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
main_mcp.mount(
|
|
202
|
+
prefix="api",
|
|
203
|
+
app=some_subserver,
|
|
204
|
+
tool_separator="/", # Tool name becomes: "api/sub_tool_name"
|
|
205
|
+
resource_separator=":", # Resource URI becomes: "api:data://sub_resource"
|
|
206
|
+
prompt_separator="." # Prompt name becomes: "api.sub_prompt_name"
|
|
207
|
+
)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
## Example: Modular Application
|
|
212
|
+
|
|
213
|
+
Here's how a modular application might use `import_server`:
|
|
214
|
+
|
|
215
|
+
<CodeGroup>
|
|
216
|
+
```python main.py
|
|
217
|
+
from fastmcp import FastMCP
|
|
218
|
+
import asyncio
|
|
219
|
+
|
|
220
|
+
# Import the servers (see other files)
|
|
221
|
+
from modules.text_server import text_mcp
|
|
222
|
+
from modules.data_server import data_mcp
|
|
223
|
+
|
|
224
|
+
app = FastMCP(name="MainApplication")
|
|
225
|
+
|
|
226
|
+
# Setup function for async imports
|
|
227
|
+
async def setup():
|
|
228
|
+
# Import the utility servers
|
|
229
|
+
await app.import_server("text", text_mcp)
|
|
230
|
+
await app.import_server("data", data_mcp)
|
|
231
|
+
|
|
232
|
+
@app.tool()
|
|
233
|
+
def process_and_analyze(record_id: int) -> str:
|
|
234
|
+
"""Fetches a record and analyzes its string representation."""
|
|
235
|
+
# In a real application, you'd use proper methods to interact between
|
|
236
|
+
# imported tools rather than accessing internal managers
|
|
237
|
+
|
|
238
|
+
# Get record data
|
|
239
|
+
record = {"id": record_id, "value": random.random()}
|
|
240
|
+
|
|
241
|
+
# Count words in the record string representation
|
|
242
|
+
word_count = len(str(record).split())
|
|
243
|
+
|
|
244
|
+
return (
|
|
245
|
+
f"Record {record_id} has {word_count} words in its string "
|
|
246
|
+
f"representation."
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
if __name__ == "__main__":
|
|
250
|
+
# Run async setup before starting the server
|
|
251
|
+
asyncio.run(setup())
|
|
252
|
+
# Run the server
|
|
253
|
+
app.run()
|
|
254
|
+
```
|
|
255
|
+
```python modules/text_server.py
|
|
256
|
+
from fastmcp import FastMCP
|
|
257
|
+
|
|
258
|
+
text_mcp = FastMCP(name="TextUtilities")
|
|
259
|
+
|
|
260
|
+
@text_mcp.tool()
|
|
261
|
+
def count_words(text: str) -> int:
|
|
262
|
+
"""Counts words in a text."""
|
|
263
|
+
return len(text.split())
|
|
264
|
+
|
|
265
|
+
@text_mcp.resource("resource://stopwords")
|
|
266
|
+
def get_stopwords() -> list[str]:
|
|
267
|
+
"""Return a list of common stopwords."""
|
|
268
|
+
return ["the", "a", "is", "in"]
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
```python modules/data_server.py
|
|
272
|
+
from fastmcp import FastMCP
|
|
273
|
+
import random
|
|
274
|
+
from typing import dict
|
|
275
|
+
|
|
276
|
+
data_mcp = FastMCP(name="DataAPI")
|
|
277
|
+
|
|
278
|
+
@data_mcp.tool()
|
|
279
|
+
def fetch_record(record_id: int) -> dict:
|
|
280
|
+
"""Fetches a dummy data record."""
|
|
281
|
+
return {"id": record_id, "value": random.random()}
|
|
282
|
+
|
|
283
|
+
@data_mcp.resource("data://schema/{table}")
|
|
284
|
+
def get_table_schema(table: str) -> dict:
|
|
285
|
+
"""Provides a dummy schema for a table."""
|
|
286
|
+
return {"table": table, "columns": ["id", "value"]}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
</CodeGroup>
|
|
290
|
+
Now, running `main.py` starts a server that exposes:
|
|
291
|
+
- `text_count_words`
|
|
292
|
+
- `data_fetch_record`
|
|
293
|
+
- `process_and_analyze`
|
|
294
|
+
- `text+resource://stopwords`
|
|
295
|
+
- `data+data://schema/{table}` (template)
|
|
296
|
+
|
|
297
|
+
This pattern promotes code organization and reuse within your FastMCP projects.
|