fastmcp 2.3.2__tar.gz → 2.3.3__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.
Files changed (176) hide show
  1. {fastmcp-2.3.2 → fastmcp-2.3.3}/PKG-INFO +1 -1
  2. fastmcp-2.3.3/docs/servers/composition.mdx +212 -0
  3. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/complex_inputs.py +1 -1
  4. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/desktop.py +1 -1
  5. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/server/server.py +5 -3
  6. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/utilities/tests.py +4 -2
  7. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/client/test_sse.py +9 -2
  8. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_mount.py +15 -0
  9. fastmcp-2.3.2/docs/servers/composition.mdx +0 -340
  10. {fastmcp-2.3.2 → fastmcp-2.3.3}/.cursor/rules/core-mcp-objects.mdc +0 -0
  11. {fastmcp-2.3.2 → fastmcp-2.3.3}/.github/ISSUE_TEMPLATE/bug.yml +0 -0
  12. {fastmcp-2.3.2 → fastmcp-2.3.3}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  13. {fastmcp-2.3.2 → fastmcp-2.3.3}/.github/ISSUE_TEMPLATE/enhancement.yml +0 -0
  14. {fastmcp-2.3.2 → fastmcp-2.3.3}/.github/release.yml +0 -0
  15. {fastmcp-2.3.2 → fastmcp-2.3.3}/.github/workflows/publish.yml +0 -0
  16. {fastmcp-2.3.2 → fastmcp-2.3.3}/.github/workflows/run-static.yml +0 -0
  17. {fastmcp-2.3.2 → fastmcp-2.3.3}/.github/workflows/run-tests.yml +0 -0
  18. {fastmcp-2.3.2 → fastmcp-2.3.3}/.gitignore +0 -0
  19. {fastmcp-2.3.2 → fastmcp-2.3.3}/.pre-commit-config.yaml +0 -0
  20. {fastmcp-2.3.2 → fastmcp-2.3.3}/LICENSE +0 -0
  21. {fastmcp-2.3.2 → fastmcp-2.3.3}/README.md +0 -0
  22. {fastmcp-2.3.2 → fastmcp-2.3.3}/Windows_Notes.md +0 -0
  23. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/assets/demo-inspector.png +0 -0
  24. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/clients/client.mdx +0 -0
  25. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/clients/transports.mdx +0 -0
  26. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/deployment/asgi.mdx +0 -0
  27. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/deployment/authentication.mdx +0 -0
  28. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/deployment/cli.mdx +0 -0
  29. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/deployment/running-server.mdx +0 -0
  30. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/docs.json +0 -0
  31. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/getting-started/installation.mdx +0 -0
  32. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/getting-started/quickstart.mdx +0 -0
  33. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/getting-started/welcome.mdx +0 -0
  34. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/patterns/contrib.mdx +0 -0
  35. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/patterns/decorating-methods.mdx +0 -0
  36. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/patterns/fastapi.mdx +0 -0
  37. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/patterns/http-requests.mdx +0 -0
  38. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/patterns/openapi.mdx +0 -0
  39. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/patterns/testing.mdx +0 -0
  40. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/servers/context.mdx +0 -0
  41. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/servers/fastmcp.mdx +0 -0
  42. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/servers/prompts.mdx +0 -0
  43. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/servers/proxy.mdx +0 -0
  44. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/servers/resources.mdx +0 -0
  45. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/servers/tools.mdx +0 -0
  46. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/snippets/version-badge.mdx +0 -0
  47. {fastmcp-2.3.2 → fastmcp-2.3.3}/docs/style.css +0 -0
  48. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/echo.py +0 -0
  49. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/memory.py +0 -0
  50. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/mount_example.py +0 -0
  51. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/sampling.py +0 -0
  52. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/screenshot.py +0 -0
  53. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/serializer.py +0 -0
  54. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/simple_echo.py +0 -0
  55. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/README.md +0 -0
  56. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/pyproject.toml +0 -0
  57. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/src/smart_home/__init__.py +0 -0
  58. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/src/smart_home/__main__.py +0 -0
  59. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/src/smart_home/hub.py +0 -0
  60. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/src/smart_home/lights/__init__.py +0 -0
  61. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/src/smart_home/lights/hue_utils.py +0 -0
  62. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/src/smart_home/lights/server.py +0 -0
  63. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/src/smart_home/py.typed +0 -0
  64. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/src/smart_home/settings.py +0 -0
  65. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/smart_home/uv.lock +0 -0
  66. {fastmcp-2.3.2 → fastmcp-2.3.3}/examples/text_me.py +0 -0
  67. {fastmcp-2.3.2 → fastmcp-2.3.3}/justfile +0 -0
  68. {fastmcp-2.3.2 → fastmcp-2.3.3}/pyproject.toml +0 -0
  69. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/__init__.py +0 -0
  70. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/cli/__init__.py +0 -0
  71. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/cli/claude.py +0 -0
  72. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/cli/cli.py +0 -0
  73. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/client/__init__.py +0 -0
  74. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/client/base.py +0 -0
  75. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/client/client.py +0 -0
  76. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/client/logging.py +0 -0
  77. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/client/roots.py +0 -0
  78. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/client/sampling.py +0 -0
  79. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/client/transports.py +0 -0
  80. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/README.md +0 -0
  81. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/bulk_tool_caller/README.md +0 -0
  82. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/bulk_tool_caller/__init__.py +0 -0
  83. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/bulk_tool_caller/bulk_tool_caller.py +0 -0
  84. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/bulk_tool_caller/example.py +0 -0
  85. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/mcp_mixin/README.md +0 -0
  86. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/mcp_mixin/__init__.py +0 -0
  87. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/mcp_mixin/example.py +0 -0
  88. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/contrib/mcp_mixin/mcp_mixin.py +0 -0
  89. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/exceptions.py +0 -0
  90. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/low_level/README.md +0 -0
  91. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/low_level/__init__.py +0 -0
  92. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/low_level/sse_server_transport.py +0 -0
  93. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/prompts/__init__.py +0 -0
  94. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/prompts/prompt.py +0 -0
  95. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/prompts/prompt_manager.py +0 -0
  96. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/py.typed +0 -0
  97. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/resources/__init__.py +0 -0
  98. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/resources/resource.py +0 -0
  99. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/resources/resource_manager.py +0 -0
  100. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/resources/template.py +0 -0
  101. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/resources/types.py +0 -0
  102. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/server/__init__.py +0 -0
  103. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/server/context.py +0 -0
  104. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/server/dependencies.py +0 -0
  105. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/server/http.py +0 -0
  106. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/server/openapi.py +0 -0
  107. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/server/proxy.py +0 -0
  108. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/settings.py +0 -0
  109. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/tools/__init__.py +0 -0
  110. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/tools/tool.py +0 -0
  111. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/tools/tool_manager.py +0 -0
  112. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/utilities/__init__.py +0 -0
  113. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/utilities/cache.py +0 -0
  114. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/utilities/decorators.py +0 -0
  115. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/utilities/json_schema.py +0 -0
  116. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/utilities/logging.py +0 -0
  117. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/utilities/openapi.py +0 -0
  118. {fastmcp-2.3.2 → fastmcp-2.3.3}/src/fastmcp/utilities/types.py +0 -0
  119. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/__init__.py +0 -0
  120. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/cli/test_cli.py +0 -0
  121. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/cli/test_run.py +0 -0
  122. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/client/__init__.py +0 -0
  123. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/client/test_client.py +0 -0
  124. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/client/test_logs.py +0 -0
  125. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/client/test_roots.py +0 -0
  126. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/client/test_sampling.py +0 -0
  127. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/client/test_streamable_http.py +0 -0
  128. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/conftest.py +0 -0
  129. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/contrib/__init__.py +0 -0
  130. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/contrib/test_bulk_tool_caller.py +0 -0
  131. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/contrib/test_mcp_mixin.py +0 -0
  132. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/prompts/__init__.py +0 -0
  133. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/prompts/test_prompt.py +0 -0
  134. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/prompts/test_prompt_manager.py +0 -0
  135. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/resources/__init__.py +0 -0
  136. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/resources/test_file_resources.py +0 -0
  137. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/resources/test_function_resources.py +0 -0
  138. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/resources/test_resource_manager.py +0 -0
  139. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/resources/test_resource_template.py +0 -0
  140. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/resources/test_resources.py +0 -0
  141. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/__init__.py +0 -0
  142. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_auth_integration.py +0 -0
  143. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_context.py +0 -0
  144. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_file_server.py +0 -0
  145. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_http_dependencies.py +0 -0
  146. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_http_middleware.py +0 -0
  147. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_import_server.py +0 -0
  148. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_lifespan.py +0 -0
  149. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_openapi.py +0 -0
  150. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_proxy.py +0 -0
  151. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_run_server.py +0 -0
  152. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_server.py +0 -0
  153. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_server_interactions.py +0 -0
  154. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/server/test_tool_annotations.py +0 -0
  155. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/test_deprecated.py +0 -0
  156. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/test_examples.py +0 -0
  157. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/test_servers/fastmcp_server.py +0 -0
  158. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/test_servers/sse.py +0 -0
  159. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/test_servers/stdio.py +0 -0
  160. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/tools/__init__.py +0 -0
  161. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/tools/test_tool.py +0 -0
  162. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/tools/test_tool_manager.py +0 -0
  163. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/__init__.py +0 -0
  164. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/openapi/__init__.py +0 -0
  165. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/openapi/conftest.py +0 -0
  166. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/openapi/test_openapi.py +0 -0
  167. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/openapi/test_openapi_advanced.py +0 -0
  168. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/openapi/test_openapi_fastapi.py +0 -0
  169. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/test_cache.py +0 -0
  170. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/test_decorated_function.py +0 -0
  171. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/test_json_schema.py +0 -0
  172. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/test_logging.py +0 -0
  173. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/test_tests.py +0 -0
  174. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/test_typeadapter.py +0 -0
  175. {fastmcp-2.3.2 → fastmcp-2.3.3}/tests/utilities/test_types.py +0 -0
  176. {fastmcp-2.3.2 → fastmcp-2.3.3}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastmcp
3
- Version: 2.3.2
3
+ Version: 2.3.3
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
@@ -0,0 +1,212 @@
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.
26
+
27
+ | Feature | Importing | Mounting |
28
+ |---------|----------------|---------|
29
+ | **Method** | `FastMCP.import_server()` | `FastMCP.mount()` |
30
+ | **Composition Type** | One-time copy (static) | Live link (dynamic) |
31
+ | **Updates** | Changes to subserver NOT reflected | Changes to subserver immediately reflected |
32
+ | **Best For** | Bundling finalized components | Modular runtime composition |
33
+
34
+ ### Proxy Servers
35
+
36
+ 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.
37
+
38
+ ## Importing (Static Composition)
39
+
40
+ 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.
41
+
42
+ ```python
43
+ from fastmcp import FastMCP
44
+ import asyncio
45
+
46
+ # Define subservers
47
+ weather_mcp = FastMCP(name="WeatherService")
48
+
49
+ @weather_mcp.tool()
50
+ def get_forecast(city: str) -> dict:
51
+ """Get weather forecast."""
52
+ return {"city": city, "forecast": "Sunny"}
53
+
54
+ @weather_mcp.resource("data://cities/supported")
55
+ def list_supported_cities() -> list[str]:
56
+ """List cities with weather support."""
57
+ return ["London", "Paris", "Tokyo"]
58
+
59
+ # Define main server
60
+ main_mcp = FastMCP(name="MainApp")
61
+
62
+ # Import subserver
63
+ async def setup():
64
+ await main_mcp.import_server("weather", weather_mcp)
65
+
66
+ # Result: main_mcp now contains prefixed components:
67
+ # - Tool: "weather_get_forecast"
68
+ # - Resource: "weather+data://cities/supported"
69
+
70
+ if __name__ == "__main__":
71
+ asyncio.run(setup())
72
+ main_mcp.run()
73
+ ```
74
+
75
+ ### How Importing Works
76
+
77
+ When you call `await main_mcp.import_server(prefix, subserver)`:
78
+
79
+ 1. **Tools**: All tools from `subserver` are added to `main_mcp` with names prefixed using `{prefix}_`.
80
+ - `subserver.tool(name="my_tool")` becomes `main_mcp.tool(name="{prefix}_my_tool")`.
81
+ 2. **Resources**: All resources are added with URIs prefixed using `{prefix}+`.
82
+ - `subserver.resource(uri="data://info")` becomes `main_mcp.resource(uri="{prefix}+data://info")`.
83
+ 3. **Resource Templates**: Templates are prefixed similarly to resources.
84
+ - `subserver.resource(uri="data://{id}")` becomes `main_mcp.resource(uri="{prefix}+data://{id}")`.
85
+ 4. **Prompts**: All prompts are added with names prefixed like tools.
86
+ - `subserver.prompt(name="my_prompt")` becomes `main_mcp.prompt(name="{prefix}_my_prompt")`.
87
+
88
+ Note that `import_server` performs a **one-time copy** of components. Changes made to the `subserver` *after* importing **will not** be reflected in `main_mcp`. The `subserver`'s `lifespan` context is also **not** executed by the main server.
89
+
90
+ ## Mounting (Live Linking)
91
+
92
+ 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.
93
+
94
+ ```python
95
+ import asyncio
96
+ from fastmcp import FastMCP, Client
97
+
98
+ # Define subserver
99
+ dynamic_mcp = FastMCP(name="DynamicService")
100
+
101
+ @dynamic_mcp.tool()
102
+ def initial_tool():
103
+ """Initial tool demonstration."""
104
+ return "Initial Tool Exists"
105
+
106
+ # Mount subserver (synchronous operation)
107
+ main_mcp = FastMCP(name="MainAppLive")
108
+ main_mcp.mount("dynamic", dynamic_mcp)
109
+
110
+ # Add a tool AFTER mounting - it will be accessible through main_mcp
111
+ @dynamic_mcp.tool()
112
+ def added_later():
113
+ """Tool added after mounting."""
114
+ return "Tool Added Dynamically!"
115
+
116
+ # Testing access to mounted tools
117
+ async def test_dynamic_mount():
118
+ tools = await main_mcp.get_tools()
119
+ print("Available tools:", list(tools.keys()))
120
+ # Shows: ['dynamic_initial_tool', 'dynamic_added_later']
121
+
122
+ async with Client(main_mcp) as client:
123
+ result = await client.call_tool("dynamic_added_later")
124
+ print("Result:", result[0].text)
125
+ # Shows: "Tool Added Dynamically!"
126
+
127
+ if __name__ == "__main__":
128
+ asyncio.run(test_dynamic_mount())
129
+ ```
130
+
131
+ ### How Mounting Works
132
+
133
+ When mounting is configured:
134
+
135
+ 1. **Live Link**: The parent server establishes a connection to the mounted server.
136
+ 2. **Dynamic Updates**: Changes to the mounted server are immediately reflected when accessed through the parent.
137
+ 3. **Prefixed Access**: The parent server uses prefixes to route requests to the mounted server.
138
+ 4. **Delegation**: Requests for components matching the prefix are delegated to the mounted server at runtime.
139
+
140
+ The same prefixing rules apply as with `import_server` for naming tools, resources, templates, and prompts.
141
+
142
+ ### Direct vs. Proxy Mounting
143
+
144
+ <VersionBadge version="2.2.7" />
145
+
146
+ FastMCP supports two mounting modes:
147
+
148
+ 1. **Direct Mounting** (default): The parent server directly accesses the mounted server's objects in memory.
149
+ - No client lifecycle events occur on the mounted server
150
+ - The mounted server's lifespan context is not executed
151
+ - Communication is handled through direct method calls
152
+
153
+ 2. **Proxy Mounting**: The parent server treats the mounted server as a separate entity and communicates with it through a client interface.
154
+ - Full client lifecycle events occur on the mounted server
155
+ - The mounted server's lifespan is executed when a client connects
156
+ - Communication happens via an in-memory Client transport
157
+
158
+ ```python
159
+ # Direct mounting (default when no custom lifespan)
160
+ main_mcp.mount("api", api_server)
161
+
162
+ # Proxy mounting (preserves full client lifecycle)
163
+ main_mcp.mount("api", api_server, as_proxy=True)
164
+ ```
165
+
166
+ FastMCP automatically uses proxy mounting when the mounted server has a custom lifespan, but you can override this behavior with the `as_proxy` parameter.
167
+
168
+ #### Interaction with Proxy Servers
169
+
170
+ When using `FastMCP.from_client()` to create a proxy server, mounting that server will always use proxy mounting:
171
+
172
+ ```python
173
+ # Create a proxy for a remote server
174
+ remote_proxy = FastMCP.from_client(Client("http://example.com/mcp"))
175
+
176
+ # Mount the proxy (always uses proxy mounting)
177
+ main_server.mount("remote", remote_proxy)
178
+ ```
179
+
180
+ ## Customizing Separators
181
+
182
+ Both `import_server()` and `mount()` allow you to customize the separators used for prefixing components. The defaults are `_` for tools and prompts, and `+` for resources.
183
+
184
+ <CodeGroup>
185
+
186
+ ```python import_server
187
+ await main_mcp.import_server(
188
+ prefix="api",
189
+ app=some_subserver,
190
+ tool_separator="_", # Tool name becomes: "api_sub_tool_name"
191
+ resource_separator="+", # Resource URI becomes: "api+data://sub_resource"
192
+ prompt_separator="_" # Prompt name becomes: "api_sub_prompt_name"
193
+ )
194
+ ```
195
+
196
+ ```python mount
197
+ main_mcp.mount(
198
+ prefix="api",
199
+ app=some_subserver,
200
+ tool_separator="_", # Tool name becomes: "api_sub_tool_name"
201
+ resource_separator="+", # Resource URI becomes: "api+data://sub_resource"
202
+ prompt_separator="_" # Prompt name becomes: "api_sub_prompt_name"
203
+ )
204
+ ```
205
+ </CodeGroup>
206
+ <Warning>
207
+ 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.
208
+ </Warning>
209
+
210
+ <Tip>
211
+ To "cleanly" import or mount a server, set the prefix and all separators to `""` (empty string). This is generally unecessary but could save a couple tokens at the risk of a name collision!
212
+ </Tip>
@@ -8,7 +8,7 @@ from typing import Annotated
8
8
 
9
9
  from pydantic import BaseModel, Field
10
10
 
11
- from fastmcp.server import FastMCP
11
+ from fastmcp import FastMCP
12
12
 
13
13
  mcp = FastMCP("Shrimp Tank")
14
14
 
@@ -6,7 +6,7 @@ A simple example that exposes the desktop directory as a resource.
6
6
 
7
7
  from pathlib import Path
8
8
 
9
- from fastmcp.server import FastMCP
9
+ from fastmcp import FastMCP
10
10
 
11
11
  # Create server
12
12
  mcp = FastMCP("Demo")
@@ -869,7 +869,7 @@ class FastMCP(Generic[LifespanResultT]):
869
869
  elif transport == "sse":
870
870
  return create_sse_app(
871
871
  server=self,
872
- message_path=path or self.settings.message_path,
872
+ message_path=self.settings.message_path,
873
873
  sse_path=path or self.settings.sse_path,
874
874
  auth_server_provider=self._auth_server_provider,
875
875
  auth_settings=self.settings.auth,
@@ -1094,11 +1094,13 @@ class FastMCP(Generic[LifespanResultT]):
1094
1094
 
1095
1095
  def _validate_resource_prefix(prefix: str) -> None:
1096
1096
  valid_resource = "resource://path/to/resource"
1097
+ test_case = f"{prefix}{valid_resource}"
1097
1098
  try:
1098
- AnyUrl(f"{prefix}{valid_resource}")
1099
+ AnyUrl(test_case)
1099
1100
  except pydantic.ValidationError as e:
1100
1101
  raise ValueError(
1101
- f"Resource prefix or separator would result in an invalid resource URI: {e}"
1102
+ "Resource prefix or separator would result in an "
1103
+ f"invalid resource URI (test case was {test_case!r}): {e}"
1102
1104
  )
1103
1105
 
1104
1106
 
@@ -71,7 +71,7 @@ def _run_server(mcp_server: FastMCP, transport: Literal["sse"], port: int) -> No
71
71
 
72
72
  @contextmanager
73
73
  def run_server_in_process(
74
- server_fn: Callable[[str, int], None],
74
+ server_fn: Callable[[str, int], None], *args
75
75
  ) -> Generator[str, None, None]:
76
76
  """
77
77
  Context manager that runs a Starlette app in a separate process and returns the
@@ -88,7 +88,9 @@ def run_server_in_process(
88
88
  s.bind((host, 0))
89
89
  port = s.getsockname()[1]
90
90
 
91
- proc = multiprocessing.Process(target=server_fn, args=(host, port), daemon=True)
91
+ proc = multiprocessing.Process(
92
+ target=server_fn, args=(host, port, *args), daemon=True
93
+ )
92
94
  proc.start()
93
95
 
94
96
  # Wait for server to be running
@@ -56,9 +56,9 @@ def fastmcp_server():
56
56
  return server
57
57
 
58
58
 
59
- def run_server(host: str, port: int) -> None:
59
+ def run_server(host: str, port: int, path: str | None = None) -> None:
60
60
  try:
61
- app = fastmcp_server().http_app(transport="sse")
61
+ app = fastmcp_server().http_app(transport="sse", path=path)
62
62
  server = uvicorn.Server(
63
63
  config=uvicorn.Config(app=app, host=host, port=port, log_level="error")
64
64
  )
@@ -109,6 +109,13 @@ def run_nested_server(host: str, port: int) -> None:
109
109
  sys.exit(0)
110
110
 
111
111
 
112
+ async def test_run_server_on_path():
113
+ with run_server_in_process(run_server, "/help") as url:
114
+ async with Client(transport=SSETransport(f"{url}/help")) as client:
115
+ result = await client.ping()
116
+ assert result is True
117
+
118
+
112
119
  async def test_nested_sse_server_resolves_correctly():
113
120
  # tests patch for
114
121
  # https://github.com/modelcontextprotocol/python-sdk/pull/659
@@ -106,6 +106,21 @@ class TestBasicMount:
106
106
  with pytest.raises(NotFoundError, match="Unknown tool: sub_sub_tool"):
107
107
  await main_app._mcp_call_tool("sub_sub_tool", {})
108
108
 
109
+ async def test_mount_with_no_prefix(self):
110
+ main_app = FastMCP("MainApp")
111
+ sub_app = FastMCP("SubApp")
112
+
113
+ @sub_app.tool()
114
+ def sub_tool() -> str:
115
+ return "This is from the sub app"
116
+
117
+ main_app.mount(
118
+ prefix="", server=sub_app, tool_separator="", resource_separator=""
119
+ )
120
+
121
+ tools = await main_app.get_tools()
122
+ assert "sub_tool" in tools
123
+
109
124
 
110
125
  class TestMultipleServerMount:
111
126
  """Test mounting multiple servers simultaneously."""
@@ -1,340 +0,0 @@
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
- | **Best For** | Bundling finalized components | Modular runtime composition |
34
-
35
- ### Proxy Servers
36
-
37
- 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.
38
-
39
-
40
- ## Importing (Static Composition)
41
-
42
- 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.
43
-
44
- ```python
45
- from fastmcp import FastMCP
46
- import asyncio
47
-
48
- # --- Define Subservers ---
49
-
50
- # Weather Service
51
- weather_mcp = FastMCP(name="WeatherService")
52
-
53
- @weather_mcp.tool()
54
- def get_forecast(city: str) -> dict:
55
- """Get weather forecast."""
56
- return {"city": city, "forecast": "Sunny"}
57
-
58
- @weather_mcp.resource("data://cities/supported")
59
- def list_supported_cities() -> list[str]:
60
- """List cities with weather support."""
61
- return ["London", "Paris", "Tokyo"]
62
-
63
- # Calculator Service
64
- calc_mcp = FastMCP(name="CalculatorService")
65
-
66
- @calc_mcp.tool()
67
- def add(a: int, b: int) -> int:
68
- """Add two numbers."""
69
- return a + b
70
-
71
- @calc_mcp.prompt()
72
- def explain_addition() -> str:
73
- """Explain the concept of addition."""
74
- return "Addition is the process of combining two or more numbers."
75
-
76
- # --- Define Main Server ---
77
- main_mcp = FastMCP(name="MainApp")
78
-
79
- # --- Import Subservers ---
80
- async def setup():
81
- # Import weather service with prefix "weather"
82
- await main_mcp.import_server("weather", weather_mcp)
83
-
84
- # Import calculator service with prefix "calc"
85
- await main_mcp.import_server("calc", calc_mcp)
86
-
87
- # --- Now, main_mcp contains *copied* components ---
88
- # Tools:
89
- # - "weather_get_forecast"
90
- # - "calc_add"
91
- # Resources:
92
- # - "weather+data://cities/supported" (prefixed URI)
93
- # Prompts:
94
- # - "calc_explain_addition"
95
-
96
- if __name__ == "__main__":
97
- # In a real app, you might run this async or setup imports differently
98
- asyncio.run(setup())
99
- # Run the main server, which now includes components from both subservers
100
- main_mcp.run()
101
- ```
102
-
103
- ### How Importing Works
104
-
105
- When you call `await main_mcp.import_server(prefix, subserver)`:
106
-
107
- 1. **Tools**: All tools from `subserver` are added to `main_mcp`. Their names are automatically prefixed using the `prefix` and a default separator (`_`).
108
- - `subserver.tool(name="my_tool")` becomes `main_mcp.tool(name="{prefix}_my_tool")`.
109
- 2. **Resources**: All resources from `subserver` are added. Their URIs are prefixed using the `prefix` and a default separator (`+`).
110
- - `subserver.resource(uri="data://info")` becomes `main_mcp.resource(uri="{prefix}+data://info")`.
111
- 3. **Resource Templates**: All templates from `subserver` are added. Their URI *templates* are prefixed similarly to resources.
112
- - `subserver.resource(uri="data://{id}")` becomes `main_mcp.resource(uri="{prefix}+data://{id}")`.
113
- 4. **Prompts**: All prompts from `subserver` are added, with names prefixed like tools.
114
- - `subserver.prompt(name="my_prompt")` becomes `main_mcp.prompt(name="{prefix}_my_prompt")`.
115
-
116
- 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`.
117
-
118
- ### Customizing Separators
119
-
120
- You might prefer different separators for the prefixed names and URIs. You can customize these when calling `import_server()`:
121
-
122
- ```python
123
- await main_mcp.import_server(
124
- prefix="api",
125
- app=some_subserver,
126
- tool_separator="/", # Tool name becomes: "api/sub_tool_name"
127
- resource_separator=":", # Resource URI becomes: "api:data://sub_resource"
128
- prompt_separator="." # Prompt name becomes: "api.sub_prompt_name"
129
- )
130
- ```
131
-
132
- <Warning>
133
- 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.
134
- </Warning>
135
-
136
- ## Mounting (Live Linking)
137
-
138
- 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.
139
-
140
- ```python
141
- import asyncio
142
- from fastmcp import FastMCP, Client
143
-
144
- # --- Define Subserver ---
145
- dynamic_mcp = FastMCP(name="DynamicService")
146
- @dynamic_mcp.tool()
147
- def initial_tool(): return "Initial Tool Exists"
148
-
149
- # --- Define Main Server ---
150
- main_mcp = FastMCP(name="MainAppLive")
151
-
152
- # --- Mount Subserver (Sync operation) ---
153
- main_mcp.mount("dynamic", dynamic_mcp)
154
-
155
- print("Mounted dynamic_mcp.")
156
-
157
- # --- Add a tool AFTER mounting ---
158
- @dynamic_mcp.tool()
159
- def added_later(): return "Tool Added Dynamically!"
160
-
161
- print("Added 'added_later' tool to dynamic_mcp.")
162
-
163
- # --- Test Access ---
164
- async def test_dynamic_mount():
165
- # Need to use await for get_tools now
166
- tools_before = await main_mcp.get_tools()
167
- print("Tools available via main_mcp:", list(tools_before.keys()))
168
- # Expected: ['dynamic_initial_tool', 'dynamic_added_later']
169
-
170
- async with Client(main_mcp) as client:
171
- # Call the dynamically added tool via the main server
172
- result = await client.call_tool("dynamic_added_later")
173
- print("Result of calling dynamic_added_later:", result[0].text)
174
- # Expected: Tool Added Dynamically!
175
-
176
- if __name__ == "__main__":
177
- # Need async context to test
178
- asyncio.run(test_dynamic_mount())
179
- # To run the server itself:
180
- # main_mcp.run()
181
- ```
182
-
183
- ### How Mounting Works
184
-
185
- Mounting creates a relationship between two servers where one server (the parent) delegates certain operations to another (the mounted server) based on prefixes. When mounting is configured:
186
-
187
- 1. **Live Link**: The parent server establishes a connection to the mounted server.
188
- 2. **Dynamic Updates**: Changes made to the mounted server (e.g., adding new tools) are immediately reflected when accessed through the parent server.
189
- 3. **Prefixed Access**: The parent server uses prefixes to route requests to the mounted server.
190
- 4. **Delegation**: Requests for components matching the prefix are delegated to the mounted server at runtime.
191
-
192
- The same prefixing rules apply as with `import_server` for naming tools, resources, templates, and prompts.
193
-
194
- ### Customizing Separators
195
-
196
- Similar to `import_server`, you can customize the separators for the prefixed names and URIs:
197
-
198
- ```python
199
- main_mcp.mount(
200
- prefix="api",
201
- app=some_subserver,
202
- tool_separator="/", # Tool name becomes: "api/sub_tool_name"
203
- resource_separator=":", # Resource URI becomes: "api:data://sub_resource"
204
- prompt_separator="." # Prompt name becomes: "api.sub_prompt_name"
205
- )
206
- ```
207
-
208
- ### Direct vs. Proxy Mounting
209
-
210
- <VersionBadge version="2.2.7" />
211
-
212
- FastMCP supports two modes for mounting servers:
213
-
214
- 1. **Direct Mounting** (default): The parent server directly accesses the mounted server's objects in memory for optimal performance and observability. In this mode:
215
- - No client lifecycle events occur on the mounted server
216
- - The mounted server's lifespan context is not executed
217
- - Communication is handled through direct method calls
218
-
219
- 2. **Proxy Mounting**: The parent server treats the mounted server as a separate entity and communicates with it through a client interface. In this mode:
220
- - Full client lifecycle events occur on the mounted server
221
- - The mounted server's lifespan is executed when a client connects
222
- - Communication happens via an in-memory Client transport
223
- - This preserves all client-facing behaviors but is slightly less efficient
224
-
225
- You can control which mode to use with the `as_proxy` parameter:
226
-
227
- ```python
228
- # Direct mounting (default when no custom lifespan)
229
- main_mcp.mount("api", api_server)
230
-
231
- # Proxy mounting (preserves full client lifecycle)
232
- main_mcp.mount("api", api_server, as_proxy=True)
233
- ```
234
-
235
- FastMCP automatically uses proxy mounting when the mounted server has a custom lifespan, but you can override this behavior by explicitly setting `as_proxy=False` or `as_proxy=True`.
236
-
237
- #### Interaction with Proxy Servers
238
-
239
- When using `FastMCP.from_client()` to create a proxy server, mounting that server will always use proxy mounting since the proxy server is already designed to be accessed via a client interface.
240
-
241
- ```python
242
- from fastmcp import FastMCP, Client
243
-
244
- # Create a proxy for a remote server
245
- remote_proxy = FastMCP.from_client(Client("http://example.com/mcp"))
246
-
247
- # Mount the proxy - this will preserve full client lifecycle
248
- main_server.mount("remote", remote_proxy)
249
- ```
250
-
251
- This is particularly useful for incorporating remote servers into your local application architecture.
252
-
253
-
254
- ## Example: Modular Application
255
-
256
- Here's how a modular application might use `import_server`:
257
-
258
- <CodeGroup>
259
- ```python main.py
260
- from fastmcp import FastMCP
261
- import asyncio
262
-
263
- # Import the servers (see other files)
264
- from modules.text_server import text_mcp
265
- from modules.data_server import data_mcp
266
-
267
- app = FastMCP(name="MainApplication")
268
-
269
- # Setup function for async imports
270
- async def setup():
271
- # Import the utility servers
272
- await app.import_server("text", text_mcp)
273
- await app.import_server("data", data_mcp)
274
-
275
- @app.tool()
276
- def process_and_analyze(record_id: int) -> str:
277
- """Fetches a record and analyzes its string representation."""
278
- # In a real application, you'd use proper methods to interact between
279
- # imported tools rather than accessing internal managers
280
-
281
- # Get record data
282
- record = {"id": record_id, "value": random.random()}
283
-
284
- # Count words in the record string representation
285
- word_count = len(str(record).split())
286
-
287
- return (
288
- f"Record {record_id} has {word_count} words in its string "
289
- f"representation."
290
- )
291
-
292
- if __name__ == "__main__":
293
- # Run async setup before starting the server
294
- asyncio.run(setup())
295
- # Run the server
296
- app.run()
297
- ```
298
- ```python modules/text_server.py
299
- from fastmcp import FastMCP
300
-
301
- text_mcp = FastMCP(name="TextUtilities")
302
-
303
- @text_mcp.tool()
304
- def count_words(text: str) -> int:
305
- """Counts words in a text."""
306
- return len(text.split())
307
-
308
- @text_mcp.resource("resource://stopwords")
309
- def get_stopwords() -> list[str]:
310
- """Return a list of common stopwords."""
311
- return ["the", "a", "is", "in"]
312
- ```
313
-
314
- ```python modules/data_server.py
315
- from fastmcp import FastMCP
316
- import random
317
- from typing import dict
318
-
319
- data_mcp = FastMCP(name="DataAPI")
320
-
321
- @data_mcp.tool()
322
- def fetch_record(record_id: int) -> dict:
323
- """Fetches a dummy data record."""
324
- return {"id": record_id, "value": random.random()}
325
-
326
- @data_mcp.resource("data://schema/{table}")
327
- def get_table_schema(table: str) -> dict:
328
- """Provides a dummy schema for a table."""
329
- return {"table": table, "columns": ["id", "value"]}
330
- ```
331
-
332
- </CodeGroup>
333
- Now, running `main.py` starts a server that exposes:
334
- - `text_count_words`
335
- - `data_fetch_record`
336
- - `process_and_analyze`
337
- - `text+resource://stopwords`
338
- - `data+data://schema/{table}` (template)
339
-
340
- This pattern promotes code organization and reuse within your FastMCP projects.