fastmcp 2.2.10__tar.gz → 2.3.0rc1__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 (171) hide show
  1. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/PKG-INFO +2 -2
  2. fastmcp-2.3.0rc1/docs/deployment/authentication.mdx +15 -0
  3. fastmcp-2.3.0rc1/docs/deployment/running-server.mdx +192 -0
  4. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/docs.json +11 -3
  5. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/getting-started/quickstart.mdx +1 -1
  6. fastmcp-2.3.0rc1/docs/patterns/http-requests.mdx +79 -0
  7. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/proxy.mdx +2 -2
  8. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/context.mdx +78 -90
  9. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/fastmcp.mdx +30 -144
  10. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/pyproject.toml +8 -1
  11. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/__init__.py +2 -1
  12. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/cli/cli.py +1 -1
  13. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/client.py +3 -2
  14. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/transports.py +45 -1
  15. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/prompts/prompt.py +10 -15
  16. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/prompts/prompt_manager.py +3 -10
  17. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/resource.py +2 -7
  18. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/resource_manager.py +2 -4
  19. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/template.py +11 -24
  20. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/types.py +15 -44
  21. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/__init__.py +1 -0
  22. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/context.py +50 -38
  23. fastmcp-2.3.0rc1/src/fastmcp/server/dependencies.py +35 -0
  24. fastmcp-2.3.0rc1/src/fastmcp/server/http.py +309 -0
  25. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/openapi.py +5 -16
  26. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/proxy.py +4 -13
  27. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/server.py +196 -271
  28. fastmcp-2.3.0rc1/src/fastmcp/server/streamable_http_manager.py +241 -0
  29. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/settings.py +7 -0
  30. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/tools/tool.py +14 -23
  31. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/tools/tool_manager.py +3 -9
  32. fastmcp-2.3.0rc1/src/fastmcp/utilities/cache.py +26 -0
  33. fastmcp-2.3.0rc1/src/fastmcp/utilities/tests.py +113 -0
  34. fastmcp-2.3.0rc1/test.py +12 -0
  35. fastmcp-2.3.0rc1/tests/client/test_sse.py +92 -0
  36. fastmcp-2.3.0rc1/tests/client/test_streamable_http.py +102 -0
  37. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/prompts/test_prompt_manager.py +22 -29
  38. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_resource_template.py +25 -29
  39. fastmcp-2.3.0rc1/tests/server/test_context.py +59 -0
  40. fastmcp-2.3.0rc1/tests/server/test_http_dependencies.py +102 -0
  41. fastmcp-2.3.0rc1/tests/server/test_lifespan.py +236 -0
  42. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/tools/test_tool_manager.py +57 -48
  43. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/uv.lock +573 -577
  44. fastmcp-2.2.10/src/fastmcp/utilities/http.py +0 -44
  45. fastmcp-2.2.10/src/fastmcp/utilities/tests.py +0 -41
  46. fastmcp-2.2.10/tests/server/test_lifespan.py +0 -112
  47. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.cursor/rules/core-mcp-objects.mdc +0 -0
  48. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/ISSUE_TEMPLATE/bug.yml +0 -0
  49. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  50. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/ISSUE_TEMPLATE/enhancement.yml +0 -0
  51. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/release.yml +0 -0
  52. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/workflows/publish.yml +0 -0
  53. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/workflows/run-static.yml +0 -0
  54. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/workflows/run-tests.yml +0 -0
  55. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.gitignore +0 -0
  56. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.pre-commit-config.yaml +0 -0
  57. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/LICENSE +0 -0
  58. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/README.md +0 -0
  59. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/Windows_Notes.md +0 -0
  60. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/assets/demo-inspector.png +0 -0
  61. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/clients/client.mdx +0 -0
  62. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/clients/transports.mdx +0 -0
  63. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/getting-started/installation.mdx +0 -0
  64. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/getting-started/welcome.mdx +0 -0
  65. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/composition.mdx +0 -0
  66. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/contrib.mdx +0 -0
  67. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/decorating-methods.mdx +0 -0
  68. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/fastapi.mdx +0 -0
  69. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/openapi.mdx +0 -0
  70. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/testing.mdx +0 -0
  71. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/prompts.mdx +0 -0
  72. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/resources.mdx +0 -0
  73. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/tools.mdx +0 -0
  74. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/snippets/version-badge.mdx +0 -0
  75. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/style.css +0 -0
  76. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/complex_inputs.py +0 -0
  77. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/desktop.py +0 -0
  78. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/echo.py +0 -0
  79. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/memory.py +0 -0
  80. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/mount_example.py +0 -0
  81. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/sampling.py +0 -0
  82. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/screenshot.py +0 -0
  83. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/serializer.py +0 -0
  84. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/simple_echo.py +0 -0
  85. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/README.md +0 -0
  86. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/pyproject.toml +0 -0
  87. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/__init__.py +0 -0
  88. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/__main__.py +0 -0
  89. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/hub.py +0 -0
  90. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/lights/__init__.py +0 -0
  91. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/lights/hue_utils.py +0 -0
  92. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/lights/server.py +0 -0
  93. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/py.typed +0 -0
  94. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/settings.py +0 -0
  95. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/uv.lock +0 -0
  96. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/text_me.py +0 -0
  97. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/justfile +0 -0
  98. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/cli/__init__.py +0 -0
  99. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/cli/claude.py +0 -0
  100. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/__init__.py +0 -0
  101. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/base.py +0 -0
  102. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/logging.py +0 -0
  103. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/roots.py +0 -0
  104. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/sampling.py +0 -0
  105. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/README.md +0 -0
  106. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/bulk_tool_caller/README.md +0 -0
  107. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/bulk_tool_caller/__init__.py +0 -0
  108. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/bulk_tool_caller/bulk_tool_caller.py +0 -0
  109. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/bulk_tool_caller/example.py +0 -0
  110. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/mcp_mixin/README.md +0 -0
  111. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/mcp_mixin/__init__.py +0 -0
  112. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/mcp_mixin/example.py +0 -0
  113. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/mcp_mixin/mcp_mixin.py +0 -0
  114. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/exceptions.py +0 -0
  115. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/prompts/__init__.py +0 -0
  116. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/py.typed +0 -0
  117. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/__init__.py +0 -0
  118. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/tools/__init__.py +0 -0
  119. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/__init__.py +0 -0
  120. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/decorators.py +0 -0
  121. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/json_schema.py +0 -0
  122. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/logging.py +0 -0
  123. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/openapi.py +0 -0
  124. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/types.py +0 -0
  125. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/__init__.py +0 -0
  126. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/cli/test_run.py +0 -0
  127. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/__init__.py +0 -0
  128. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/test_client.py +0 -0
  129. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/test_logs.py +0 -0
  130. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/test_roots.py +0 -0
  131. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/test_sampling.py +0 -0
  132. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/conftest.py +0 -0
  133. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/contrib/__init__.py +0 -0
  134. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/contrib/test_bulk_tool_caller.py +0 -0
  135. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/contrib/test_mcp_mixin.py +0 -0
  136. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/prompts/__init__.py +0 -0
  137. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/prompts/test_prompt.py +0 -0
  138. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/__init__.py +0 -0
  139. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_file_resources.py +0 -0
  140. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_function_resources.py +0 -0
  141. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_resource_manager.py +0 -0
  142. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_resources.py +0 -0
  143. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/__init__.py +0 -0
  144. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_auth_integration.py +0 -0
  145. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_file_server.py +0 -0
  146. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_import_server.py +0 -0
  147. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_mount.py +0 -0
  148. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_openapi.py +0 -0
  149. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_proxy.py +0 -0
  150. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_run_server.py +0 -0
  151. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_server.py +0 -0
  152. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_server_interactions.py +0 -0
  153. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_tool_annotations.py +0 -0
  154. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/test_examples.py +0 -0
  155. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/test_servers/fastmcp_server.py +0 -0
  156. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/test_servers/sse.py +0 -0
  157. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/test_servers/stdio.py +0 -0
  158. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/tools/__init__.py +0 -0
  159. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/tools/test_tool.py +0 -0
  160. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/__init__.py +0 -0
  161. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/__init__.py +0 -0
  162. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/conftest.py +0 -0
  163. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/test_openapi.py +0 -0
  164. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/test_openapi_advanced.py +0 -0
  165. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/test_openapi_fastapi.py +0 -0
  166. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_decorated_function.py +0 -0
  167. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_json_schema.py +0 -0
  168. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_logging.py +0 -0
  169. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_tests.py +0 -0
  170. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_typeadapter.py +0 -0
  171. {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastmcp
3
- Version: 2.2.10
3
+ Version: 2.3.0rc1
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
@@ -19,7 +19,7 @@ Classifier: Typing :: Typed
19
19
  Requires-Python: >=3.10
20
20
  Requires-Dist: exceptiongroup>=1.2.2
21
21
  Requires-Dist: httpx>=0.28.1
22
- Requires-Dist: mcp<2.0.0,>=1.7.1
22
+ Requires-Dist: mcp
23
23
  Requires-Dist: openapi-pydantic>=0.5.1
24
24
  Requires-Dist: python-dotenv>=1.1.0
25
25
  Requires-Dist: rich>=13.9.4
@@ -0,0 +1,15 @@
1
+ ---
2
+ title: Authentication
3
+ sidebarTitle: Authentication
4
+ description: Secure your FastMCP server with authentication.
5
+ icon: lock
6
+ ---
7
+ import { VersionBadge } from '/snippets/version-badge.mdx'
8
+
9
+ <VersionBadge version="2.2.7" />
10
+
11
+ This document will cover how to implement authentication for your FastMCP servers.
12
+
13
+ FastMCP leverages the OAuth 2.0 support provided by the underlying Model Context Protocol (MCP) SDK.
14
+
15
+ For now, refer to the [MCP Server Authentication documentation](/servers/fastmcp#authentication) for initial details and the [official MCP SDK documentation](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization) for more.
@@ -0,0 +1,192 @@
1
+ ---
2
+ title: Running Your FastMCP Server
3
+ sidebarTitle: Running the Server
4
+ description: Learn how to run and deploy your FastMCP server using various transport protocols like STDIO, Streamable HTTP, and SSE.
5
+ icon: circle-play
6
+ ---
7
+ import { VersionBadge } from '/snippets/version-badge.mdx'
8
+
9
+
10
+ FastMCP servers can be run in different ways depending on your application's needs, from local command-line tools to persistent web services. This guide covers the primary methods for running your server, focusing on the available transport protocols: STDIO, Streamable HTTP, and SSE.
11
+
12
+ ## The `run()` Method
13
+
14
+ The main way to run a FastMCP server from a Python script is by calling the `run()` method on a `FastMCP` instance.
15
+
16
+ <Tip>
17
+ For maximum compatibility, it's best practice to place the `run()` call within an `if __name__ == "__main__":` block. This ensures the server starts only when the script is executed directly, not when imported as a module.
18
+ </Tip>
19
+
20
+ ```python {9-10} my_server.py
21
+ from fastmcp import FastMCP
22
+
23
+ mcp = FastMCP(name="MyServer")
24
+
25
+ @mcp.tool()
26
+ def hello(name: str) -> str:
27
+ return f"Hello, {name}!"
28
+
29
+ if __name__ == "__main__":
30
+ mcp.run()
31
+ ```
32
+ You can now run this MCP server by executing `python my_server.py`.
33
+
34
+ MCP servers can be run with a variety of different transport options, depending on your application's requirements. The `run()` method can take a `transport` argument and other transport-specific keyword arguments to configure how the server operates.
35
+
36
+ ## Transport Options
37
+
38
+ Below is a comparison of available transport options to help you choose the right one for your needs:
39
+
40
+ | Transport | Use Cases | Recommendation |
41
+ | --------- | --------- | -------------- |
42
+ | **STDIO** | Local tools, command-line scripts, and integrations with clients like Claude Desktop | Best for local tools and when clients manage server processes |
43
+ | **Streamable HTTP** | Web-based deployments, microservices, exposing MCP over a network | Recommended choice for new web-based deployments |
44
+ | **SSE** | Existing web-based deployments that rely on SSE | Suitable for compatibility with SSE clients; prefer Streamable HTTP for new projects |
45
+
46
+ ### STDIO
47
+
48
+ The STDIO transport is the default and most widely compatible option for local MCP server execution. It is ideal for local tools, command-line integrations, and clients like Claude Desktop. However, it has the disadvantage of having to run the MCP code locally, which can introduce security concerns with third-party servers.
49
+
50
+ STDIO is the default transport, so you don't need to specify it when calling `run()`. However, you can specify it explicitly to make your intent clear:
51
+
52
+ ```python {6}
53
+ from fastmcp import FastMCP
54
+
55
+ mcp = FastMCP()
56
+
57
+ if __name__ == "__main__":
58
+ mcp.run(transport="stdio")
59
+ ```
60
+
61
+ When using Stdio transport, you will typically *not* run the server yourself as a separate process. Rather, your *clients* will spin up a new server process for each session. As such, no additional configuration is required.
62
+
63
+ ### Streamable HTTP
64
+
65
+ <VersionBadge version="2.3.0" />
66
+
67
+ Streamable HTTP is a modern, efficient transport for exposing your MCP server via HTTP. It is generally recommended over SSE for new web-based deployments.
68
+
69
+ To run a server using Streamable HTTP, you can use the `run()` method with the `transport` argument set to `"streamable-http"`. This will start a Uvicorn server on the default host (`127.0.0.1`), port (`8000`), and path (`/mcp`).
70
+ <CodeGroup>
71
+ ```python {6} server.py
72
+ from fastmcp import FastMCP
73
+
74
+ mcp = FastMCP()
75
+
76
+ if __name__ == "__main__":
77
+ mcp.run(transport="streamable-http")
78
+ ```
79
+ ```python {5} client.py
80
+ import asyncio
81
+ from fastmcp import Client
82
+
83
+ async def example():
84
+ async with Client("http://127.0.0.1:8000/mcp") as client:
85
+ await client.ping()
86
+
87
+ if __name__ == "__main__":
88
+ asyncio.run(example())
89
+ ```
90
+ </CodeGroup>
91
+
92
+ To customize the host, port, path, or log level, provide appropriate keyword arguments to the `run()` method.
93
+
94
+ <CodeGroup>
95
+ ```python {8-11} server.py
96
+ from fastmcp import FastMCP
97
+
98
+ mcp = FastMCP()
99
+
100
+ if __name__ == "__main__":
101
+ mcp.run(
102
+ transport="streamable-http",
103
+ host="127.0.0.1",
104
+ port=4200,
105
+ path="/my-custom-path",
106
+ log_level="debug",
107
+ )
108
+ ```
109
+ ```python {5} client.py
110
+ import asyncio
111
+ from fastmcp import Client
112
+
113
+ async def example():
114
+ async with Client("http://127.0.0.1:4200/my-custom-path") as client:
115
+ await client.ping()
116
+
117
+ if __name__ == "__main__":
118
+ asyncio.run(example())
119
+ ```
120
+ </CodeGroup>
121
+
122
+
123
+ ### SSE
124
+
125
+ Server-Sent Events (SSE) is an HTTP-based protocol for server-to-client streaming. While FastMCP supports SSE, Streamable HTTP is preferred for new projects.
126
+
127
+ To run a server using SSE, you can use the `run()` method with the `transport` argument set to `"sse"`. This will start a Uvicorn server on the default host (`127.0.0.1`), port (`8000`), and with default SSE path (`/sse`) and message path (`/messages/`).
128
+
129
+ <CodeGroup>
130
+ ```python {6} server.py
131
+ from fastmcp import FastMCP
132
+
133
+ mcp = FastMCP()
134
+
135
+ if __name__ == "__main__":
136
+ mcp.run(transport="sse")
137
+ ```
138
+ ```python {3,7} client.py
139
+ import asyncio
140
+ from fastmcp import Client
141
+ from fastmcp.client.transports import SSETransport
142
+
143
+ async def example():
144
+ async with Client(
145
+ transport=SSETransport("http://127.0.0.1:8000/sse")
146
+ ) as client:
147
+ await client.ping()
148
+
149
+ if __name__ == "__main__":
150
+ asyncio.run(example())
151
+ ```
152
+ </CodeGroup>
153
+
154
+ <Tip>
155
+ Notice that the client in the above example uses an explicit `SSETransport` to connect to the server. FastMCP will attempt to infer the appropriate transport from the provided configuration, but HTTP URLs are assumed to be Streamable HTTP (as of FastMCP 2.3.0).
156
+ </Tip>
157
+
158
+ To customize the host, port, or log level, provide appropriate keyword arguments to the `run()` method. You can also adjust the SSE path (which clients should connect to) and the message POST endpoint (which clients use to send subsequent messages).
159
+
160
+ <CodeGroup>
161
+ ```python {8-12} server.py
162
+ from fastmcp import FastMCP
163
+
164
+ mcp = FastMCP()
165
+
166
+ if __name__ == "__main__":
167
+ mcp.run(
168
+ transport="sse",
169
+ host="127.0.0.1",
170
+ port=4200,
171
+ log_level="debug",
172
+ path="/my-custom-sse-path",
173
+ message_path="/my-custom-message-path/",
174
+ )
175
+ ```
176
+ ```python {7} client.py
177
+ import asyncio
178
+ from fastmcp import Client
179
+ from fastmcp.client.transports import SSETransport
180
+
181
+ async def example():
182
+ async with Client(
183
+ transport=SSETransport("http://127.0.0.1:4200/my-custom-sse-path")
184
+ ) as client:
185
+ await client.ping()
186
+
187
+ if __name__ == "__main__":
188
+ asyncio.run(example())
189
+ ```
190
+ </CodeGroup>
191
+
192
+ Your client only needs to know the host, port, and "main" path; the message path will be transmitted to it as part of the connection handshake.
@@ -49,7 +49,16 @@
49
49
  "servers/tools",
50
50
  "servers/resources",
51
51
  "servers/prompts",
52
- "servers/context"
52
+ "servers/context",
53
+ "patterns/proxy",
54
+ "patterns/composition"
55
+ ]
56
+ },
57
+ {
58
+ "group": "Deployment",
59
+ "pages": [
60
+ "deployment/running-server",
61
+ "deployment/authentication"
53
62
  ]
54
63
  },
55
64
  {
@@ -62,9 +71,8 @@
62
71
  {
63
72
  "group": "Patterns",
64
73
  "pages": [
65
- "patterns/proxy",
66
- "patterns/composition",
67
74
  "patterns/decorating-methods",
75
+ "patterns/http-requests",
68
76
  "patterns/openapi",
69
77
  "patterns/fastapi",
70
78
  "patterns/contrib",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: Quickstart
3
- icon: rocket
3
+ icon: rocket-launch
4
4
  ---
5
5
 
6
6
  Welcome! This guide will help you quickly set up FastMCP and run your first MCP server.
@@ -0,0 +1,79 @@
1
+ ---
2
+ title: HTTP Requests
3
+ sidebarTitle: HTTP Requests
4
+ description: Accessing and using HTTP requests in FastMCP servers
5
+ icon: network-wired
6
+ ---
7
+ import { VersionBadge } from '/snippets/version-badge.mdx'
8
+
9
+ <VersionBadge version="2.2.11" />
10
+
11
+ ## Overview
12
+
13
+ When running FastMCP as a web server, your MCP tools, resources, and prompts might need to access the underlying HTTP request information, such as headers, client IP, or query parameters.
14
+
15
+ FastMCP provides a clean way to access HTTP request information through a dependency function.
16
+
17
+ ## Accessing HTTP Requests
18
+
19
+ The recommended way to access the current HTTP request is through the `get_http_request()` dependency function:
20
+
21
+ ```python {2, 3, 11}
22
+ from fastmcp import FastMCP
23
+ from fastmcp.server.dependencies import get_http_request
24
+ from starlette.requests import Request
25
+
26
+ mcp = FastMCP(name="HTTPRequestDemo")
27
+
28
+ @mcp.tool()
29
+ async def user_agent_info() -> dict:
30
+ """Return information about the user agent."""
31
+ # Get the HTTP request
32
+ request: Request = get_http_request()
33
+
34
+ # Access request data
35
+ user_agent = request.headers.get("user-agent", "Unknown")
36
+ client_ip = request.client.host if request.client else "Unknown"
37
+
38
+ return {
39
+ "user_agent": user_agent,
40
+ "client_ip": client_ip,
41
+ "path": request.url.path,
42
+ }
43
+ ```
44
+
45
+ This approach works anywhere within a request's execution flow, not just within your MCP function. It's useful when:
46
+
47
+ 1. You need access to HTTP information in helper functions
48
+ 2. You're calling nested functions that need HTTP request data
49
+ 3. You're working with middleware or other request processing code
50
+
51
+ ## Important Notes
52
+
53
+ - HTTP requests are only available when FastMCP is running as part of a web application
54
+ - Accessing the HTTP request outside of a web request context will raise a `RuntimeError`
55
+ - The `get_http_request()` function returns a standard [Starlette Request](https://www.starlette.io/requests/) object
56
+
57
+ ## Common Use Cases
58
+
59
+ ### Accessing Request Headers
60
+
61
+ ```python
62
+ from fastmcp.server.dependencies import get_http_request
63
+
64
+ @mcp.tool()
65
+ async def get_auth_info() -> dict:
66
+ """Get authentication information from request headers."""
67
+ request = get_http_request()
68
+
69
+ # Get authorization header
70
+ auth_header = request.headers.get("authorization", "")
71
+
72
+ # Check for Bearer token
73
+ is_bearer = auth_header.startswith("Bearer ")
74
+
75
+ return {
76
+ "has_auth": bool(auth_header),
77
+ "auth_type": "Bearer" if is_bearer else "Other" if auth_header else "None"
78
+ }
79
+ ```
@@ -1,6 +1,6 @@
1
1
  ---
2
- title: Proxying Servers
3
- sidebarTitle: Proxying
2
+ title: Proxy Servers
3
+ sidebarTitle: Proxy Servers
4
4
  description: Use FastMCP to act as an intermediary or change transport for other MCP servers.
5
5
  icon: arrows-retweet
6
6
  ---
@@ -21,8 +21,21 @@ The `Context` object provides a clean interface to access MCP features within yo
21
21
 
22
22
  ## Accessing the Context
23
23
 
24
+ ### Via Dependency Injection
25
+
24
26
  To use the context object within any of your functions, simply add a parameter to your function signature and type-hint it as `Context`. FastMCP will automatically inject the context instance when your function is called.
25
27
 
28
+ **Key Points:**
29
+
30
+ - The parameter name (e.g., `ctx`, `context`) doesn't matter, only the type hint `Context` is important.
31
+ - The context parameter can be placed anywhere in your function's signature; it will not be exposed to MCP clients as a valid parameter.
32
+ - The context is optional - functions that don't need it can omit the parameter entirely.
33
+ - Context methods are async, so your function usually needs to be async as well.
34
+ - The type hint can be a union (`Context | None`) or use `Annotated[]` and it will still work properly.
35
+ - Context is only available during a request; attempting to use context methods outside a request will raise errors. If you need to debug or call your context methods outside of a request, you can type your variable as `Context | None=None` to avoid missing argument errors.
36
+
37
+ #### Tools
38
+
26
39
  ```python
27
40
  from fastmcp import FastMCP, Context
28
41
 
@@ -31,43 +44,72 @@ mcp = FastMCP(name="ContextDemo")
31
44
  @mcp.tool()
32
45
  async def process_file(file_uri: str, ctx: Context) -> str:
33
46
  """Processes a file, using context for logging and resource access."""
34
- request_id = ctx.request_id
35
- await ctx.info(f"[{request_id}] Starting processing for {file_uri}")
47
+ # Context is available as the ctx parameter
48
+ return "Processed file"
49
+ ```
36
50
 
37
- try:
38
- # Use context to read a resource
39
- contents_list = await ctx.read_resource(file_uri)
40
- if not contents_list:
41
- await ctx.warning(f"Resource {file_uri} is empty.")
42
- return "Resource empty"
51
+ #### Resources and Templates
43
52
 
44
- data = contents_list[0].content # Assuming TextResourceContents
45
- await ctx.debug(f"Read {len(data)} bytes from {file_uri}")
53
+ <VersionBadge version="2.2.5" />
46
54
 
47
- # Report progress
48
- await ctx.report_progress(progress=50, total=100)
49
-
50
- # Simulate work
51
- processed_data = data.upper() # Example processing
55
+ ```python
56
+ @mcp.resource("resource://user-data")
57
+ async def get_user_data(ctx: Context) -> dict:
58
+ """Fetch personalized user data based on the request context."""
59
+ # Context is available as the ctx parameter
60
+ return {"user_id": "example"}
52
61
 
53
- await ctx.report_progress(progress=100, total=100)
54
- await ctx.info(f"Processing complete for {file_uri}")
62
+ @mcp.resource("resource://users/{user_id}/profile")
63
+ async def get_user_profile(user_id: str, ctx: Context) -> dict:
64
+ """Fetch user profile with context-aware logging."""
65
+ # Context is available as the ctx parameter
66
+ return {"id": user_id}
67
+ ```
55
68
 
56
- return f"Processed data length: {len(processed_data)}"
69
+ #### Prompts
57
70
 
58
- except Exception as e:
59
- # Use context to log errors
60
- await ctx.error(f"Error processing {file_uri}: {str(e)}")
61
- raise # Re-raise to send error back to client
71
+ <VersionBadge version="2.2.5" />
72
+
73
+ ```python
74
+ @mcp.prompt()
75
+ async def data_analysis_request(dataset: str, ctx: Context) -> str:
76
+ """Generate a request to analyze data with contextual information."""
77
+ # Context is available as the ctx parameter
78
+ return f"Please analyze the following dataset: {dataset}"
62
79
  ```
63
80
 
64
- **Key Points:**
65
81
 
66
- - The parameter name (e.g., `ctx`, `context`) doesn't matter, only the type hint `Context` is important.
67
- - The context parameter can be placed anywhere in your function's signature.
68
- - The context is optional - functions that don't need it can omit the parameter.
69
- - Context is only available during a request; attempting to use context methods outside a request will raise errors.
70
- - Context methods are async, so your function usually needs to be async as well.
82
+ ### Via Dependency Function
83
+
84
+ <VersionBadge version="2.2.11" />
85
+
86
+ While the simplest way to access context is through function parameter injection as shown above, there are cases where you need to access the context in code that may not be easy to modify to accept a context parameter, or that is nested deeper within your function calls.
87
+
88
+ FastMCP provides dependency functions that allow you to retrieve the active context from anywhere within a server request's execution flow:
89
+
90
+ ```python {2,9}
91
+ from fastmcp import FastMCP, Context
92
+ from fastmcp.server.dependencies import get_context
93
+
94
+ mcp = FastMCP(name="DependencyDemo")
95
+
96
+ # Utility function that needs context but doesn't receive it as a parameter
97
+ async def process_data(data: list[float]) -> dict:
98
+ # Get the active context - only works when called within a request
99
+ ctx = get_context()
100
+ await ctx.info(f"Processing {len(data)} data points")
101
+
102
+ @mcp.tool()
103
+ async def analyze_dataset(dataset_name: str) -> dict:
104
+ # Call utility function that uses context internally
105
+ data = load_data(dataset_name)
106
+ await process_data(data)
107
+ ```
108
+
109
+ **Important Notes:**
110
+
111
+ - The `get_context` function should only be used within the context of a server request. Calling it outside of a request will raise a `RuntimeError`.
112
+ - The `get_context` function is server-only and should not be used in client code.
71
113
 
72
114
  ## Context Capabilities
73
115
 
@@ -253,9 +295,8 @@ async def request_info(ctx: Context) -> dict:
253
295
 
254
296
  ### Advanced Access
255
297
 
256
- For advanced use cases, you can access the underlying MCP session, FastMCP server, and HTTP requests.
257
298
 
258
- #### Accessing FastMCP and Sessions
299
+ #### FastMCP Server and Sessions
259
300
 
260
301
  ```python
261
302
  @mcp.tool()
@@ -271,10 +312,16 @@ async def advanced_tool(ctx: Context) -> str:
271
312
  return f"Server: {server_name}"
272
313
  ```
273
314
 
274
- #### Accessing HTTP Requests
315
+ #### HTTP Requests
275
316
 
276
317
  <VersionBadge version="2.2.7" />
277
318
 
319
+ <Warning>
320
+ The `ctx.get_http_request()` method is deprecated and will be removed in a future version.
321
+ Please use the `get_http_request()` dependency function instead.
322
+ See the [HTTP Requests pattern](/patterns/http-requests) for more details.
323
+ </Warning>
324
+
278
325
  For web applications, you can access the underlying HTTP request:
279
326
 
280
327
  ```python
@@ -299,66 +346,7 @@ async def handle_web_request(ctx: Context) -> dict:
299
346
  - **`ctx.fastmcp -> FastMCP`**: Access the server instance the context belongs to
300
347
  - **`ctx.session`**: Access the raw `mcp.server.session.ServerSession` object
301
348
  - **`ctx.request_context`**: Access the raw `mcp.shared.context.RequestContext` object
302
- - **`ctx.get_http_request() -> Request`**: Access the active Starlette request object (when running with a web server)
303
349
 
304
350
  <Warning>
305
351
  Direct use of `session` or `request_context` requires understanding the low-level MCP Python SDK and may be less stable than using the methods provided directly on the `Context` object.
306
352
  </Warning>
307
-
308
- ## Using Context in Different Components
309
-
310
- All FastMCP components (tools, resources, templates, and prompts) can use the Context object following the same pattern - simply add a parameter with the `Context` type annotation.
311
-
312
- ### Context in Resources and Templates
313
-
314
- Resources and resource templates can access context to customize their behavior:
315
-
316
- ```python
317
- @mcp.resource("resource://user-data")
318
- async def get_user_data(ctx: Context) -> dict:
319
- """Fetch personalized user data based on the request context."""
320
- user_id = ctx.client_id or "anonymous"
321
- await ctx.info(f"Fetching data for user {user_id}")
322
-
323
- # Example of using context for dynamic resource generation
324
- return {
325
- "user_id": user_id,
326
- "last_access": datetime.now().isoformat(),
327
- "request_id": ctx.request_id
328
- }
329
-
330
- @mcp.resource("resource://users/{user_id}/profile")
331
- async def get_user_profile(user_id: str, ctx: Context) -> dict:
332
- """Fetch user profile from database with context-aware logging."""
333
- await ctx.info(f"Fetching profile for user {user_id}")
334
-
335
- # Example of using context in a template resource
336
- # In a real implementation, you might query a database
337
- return {
338
- "id": user_id,
339
- "name": f"User {user_id}",
340
- "request_id": ctx.request_id
341
- }
342
- ```
343
-
344
- ### Context in Prompts
345
-
346
- Prompts can use context to generate more dynamic templates:
347
-
348
- ```python
349
- @mcp.prompt()
350
- async def data_analysis_request(dataset: str, ctx: Context) -> str:
351
- """Generate a request to analyze data with contextual information."""
352
- await ctx.info(f"Generating data analysis prompt for {dataset}")
353
-
354
- # Could use context to read configuration or personalize the prompt
355
- return f"""Please analyze the following dataset: {dataset}
356
-
357
- Request initiated at: {datetime.now().isoformat()}
358
- Request ID: {ctx.request_id}
359
- """
360
- ```
361
-
362
- <VersionBadge version="2.3.0" />
363
-
364
- All FastMCP objects now support context injection using the same consistent pattern, making it easy to add session-aware capabilities to all aspects of your MCP server.