fastmcp 2.3.1__tar.gz → 2.3.2__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.3.1 → fastmcp-2.3.2}/PKG-INFO +2 -2
- {fastmcp-2.3.1 → fastmcp-2.3.2}/README.md +1 -1
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/deployment/asgi.mdx +54 -14
- fastmcp-2.3.2/docs/deployment/cli.mdx +174 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/deployment/running-server.mdx +67 -7
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/docs.json +14 -3
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/getting-started/installation.mdx +4 -3
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/getting-started/welcome.mdx +1 -1
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/servers/fastmcp.mdx +7 -2
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/cli/cli.py +7 -8
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/server/http.py +48 -30
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/server/server.py +147 -46
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/utilities/tests.py +1 -1
- fastmcp-2.3.2/tests/cli/test_cli.py +478 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/client/test_sse.py +2 -2
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/client/test_streamable_http.py +2 -2
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_http_dependencies.py +1 -1
- fastmcp-2.3.2/tests/server/test_http_middleware.py +219 -0
- fastmcp-2.3.2/tests/test_deprecated.py +82 -0
- fastmcp-2.3.1/test.py +0 -12
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.cursor/rules/core-mcp-objects.mdc +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.github/ISSUE_TEMPLATE/bug.yml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.github/ISSUE_TEMPLATE/enhancement.yml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.github/release.yml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.github/workflows/publish.yml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.github/workflows/run-static.yml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.github/workflows/run-tests.yml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.gitignore +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/.pre-commit-config.yaml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/LICENSE +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/Windows_Notes.md +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/assets/demo-inspector.png +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/clients/client.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/clients/transports.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/deployment/authentication.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/getting-started/quickstart.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/patterns/contrib.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/patterns/decorating-methods.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/patterns/fastapi.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/patterns/http-requests.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/patterns/openapi.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/patterns/testing.mdx +0 -0
- {fastmcp-2.3.1/docs/patterns → fastmcp-2.3.2/docs/servers}/composition.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/servers/context.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/servers/prompts.mdx +0 -0
- {fastmcp-2.3.1/docs/patterns → fastmcp-2.3.2/docs/servers}/proxy.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/servers/resources.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/servers/tools.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/snippets/version-badge.mdx +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/docs/style.css +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/complex_inputs.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/desktop.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/echo.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/memory.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/mount_example.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/sampling.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/screenshot.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/serializer.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/simple_echo.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/README.md +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/pyproject.toml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/src/smart_home/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/src/smart_home/__main__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/src/smart_home/hub.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/src/smart_home/lights/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/src/smart_home/lights/hue_utils.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/src/smart_home/lights/server.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/src/smart_home/py.typed +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/src/smart_home/settings.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/smart_home/uv.lock +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/examples/text_me.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/justfile +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/pyproject.toml +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/cli/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/cli/claude.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/client/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/client/base.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/client/client.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/client/logging.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/client/roots.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/client/sampling.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/client/transports.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/README.md +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/bulk_tool_caller/README.md +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/bulk_tool_caller/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/bulk_tool_caller/bulk_tool_caller.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/bulk_tool_caller/example.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/mcp_mixin/README.md +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/mcp_mixin/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/mcp_mixin/example.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/contrib/mcp_mixin/mcp_mixin.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/exceptions.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/low_level/README.md +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/low_level/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/low_level/sse_server_transport.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/prompts/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/prompts/prompt.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/prompts/prompt_manager.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/py.typed +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/resources/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/resources/resource.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/resources/resource_manager.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/resources/template.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/resources/types.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/server/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/server/context.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/server/dependencies.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/server/openapi.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/server/proxy.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/settings.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/tools/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/tools/tool.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/tools/tool_manager.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/utilities/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/utilities/cache.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/utilities/decorators.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/utilities/json_schema.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/utilities/logging.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/utilities/openapi.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/src/fastmcp/utilities/types.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/cli/test_run.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/client/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/client/test_client.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/client/test_logs.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/client/test_roots.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/client/test_sampling.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/conftest.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/contrib/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/contrib/test_bulk_tool_caller.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/contrib/test_mcp_mixin.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/prompts/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/prompts/test_prompt.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/prompts/test_prompt_manager.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/resources/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/resources/test_file_resources.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/resources/test_function_resources.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/resources/test_resource_manager.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/resources/test_resource_template.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/resources/test_resources.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_auth_integration.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_context.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_file_server.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_import_server.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_lifespan.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_mount.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_openapi.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_proxy.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_run_server.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_server.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_server_interactions.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/server/test_tool_annotations.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/test_examples.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/test_servers/fastmcp_server.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/test_servers/sse.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/test_servers/stdio.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/tools/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/tools/test_tool.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/tools/test_tool_manager.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/openapi/__init__.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/openapi/conftest.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/openapi/test_openapi.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/openapi/test_openapi_advanced.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/openapi/test_openapi_fastapi.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/test_cache.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/test_decorated_function.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/test_json_schema.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/test_logging.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/test_tests.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/test_typeadapter.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/tests/utilities/test_types.py +0 -0
- {fastmcp-2.3.1 → fastmcp-2.3.2}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastmcp
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.2
|
|
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
|
|
@@ -44,7 +44,7 @@ Description-Content-Type: text/markdown
|
|
|
44
44
|
> [!NOTE]
|
|
45
45
|
> #### FastMCP 2.0 & The Official MCP SDK
|
|
46
46
|
>
|
|
47
|
-
> Recognize the `FastMCP` name? You might have
|
|
47
|
+
> Recognize the `FastMCP` name? You might have seen the version that was contributed to the [official MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk), which was based on **FastMCP 1.0**.
|
|
48
48
|
>
|
|
49
49
|
> **Welcome to FastMCP 2.0!** This is the actively developed successor, and it significantly expands on 1.0 by introducing powerful client capabilities, server proxying & composition, OpenAPI/FastAPI integration, and more advanced features.
|
|
50
50
|
>
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
> [!NOTE]
|
|
16
16
|
> #### FastMCP 2.0 & The Official MCP SDK
|
|
17
17
|
>
|
|
18
|
-
> Recognize the `FastMCP` name? You might have
|
|
18
|
+
> Recognize the `FastMCP` name? You might have seen the version that was contributed to the [official MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk), which was based on **FastMCP 1.0**.
|
|
19
19
|
>
|
|
20
20
|
> **Welcome to FastMCP 2.0!** This is the actively developed successor, and it significantly expands on 1.0 by introducing powerful client capabilities, server proxying & composition, OpenAPI/FastAPI integration, and more advanced features.
|
|
21
21
|
>
|
|
@@ -5,6 +5,9 @@ description: Integrate FastMCP servers into existing Starlette, FastAPI, or othe
|
|
|
5
5
|
icon: plug
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
import { VersionBadge } from '/snippets/version-badge.mdx'
|
|
9
|
+
|
|
10
|
+
|
|
8
11
|
While FastMCP provides standalone server capabilities, you can also integrate your FastMCP server into existing web applications. This approach is useful for:
|
|
9
12
|
|
|
10
13
|
- Adding MCP functionality to an existing website or API
|
|
@@ -16,10 +19,13 @@ Please note that all FastMCP servers have a `run()` method that can be used to s
|
|
|
16
19
|
|
|
17
20
|
## ASGI Server
|
|
18
21
|
|
|
19
|
-
|
|
20
22
|
FastMCP servers can be created as [Starlette](https://www.starlette.io/) ASGI apps for straightforward hosting or integration into existing applications.
|
|
21
23
|
|
|
22
|
-
The first step is to obtain a Starlette application instance from your FastMCP server using
|
|
24
|
+
The first step is to obtain a Starlette application instance from your FastMCP server using the `http_app()` method:
|
|
25
|
+
|
|
26
|
+
<Tip>
|
|
27
|
+
The `http_app()` method is new in FastMCP 2.3.2. In older versions, use `sse_app()` for SSE transport or `streamable_http_app()` for Streamable HTTP transport.
|
|
28
|
+
</Tip>
|
|
23
29
|
|
|
24
30
|
```python
|
|
25
31
|
from fastmcp import FastMCP
|
|
@@ -30,18 +36,23 @@ mcp = FastMCP("MyServer")
|
|
|
30
36
|
def hello(name: str) -> str:
|
|
31
37
|
return f"Hello, {name}!"
|
|
32
38
|
|
|
33
|
-
# Get a Starlette app instance for
|
|
34
|
-
http_app = mcp.
|
|
35
|
-
|
|
39
|
+
# Get a Starlette app instance for Streamable HTTP transport (recommended)
|
|
40
|
+
http_app = mcp.http_app()
|
|
41
|
+
|
|
42
|
+
# For legacy SSE transport (deprecated)
|
|
43
|
+
sse_app = mcp.http_app(transport="sse")
|
|
36
44
|
```
|
|
37
45
|
|
|
38
|
-
Both
|
|
46
|
+
Both approaches return a Starlette application that can be integrated with other ASGI-compatible web frameworks.
|
|
39
47
|
|
|
40
|
-
The MCP server's endpoint is mounted at the root path `/mcp` for Streamable HTTP transport, and `/sse` for SSE transport, though you can change these paths by passing a `path` argument to the `
|
|
48
|
+
The MCP server's endpoint is mounted at the root path `/mcp` for Streamable HTTP transport, and `/sse` for SSE transport, though you can change these paths by passing a `path` argument to the `http_app()` method:
|
|
41
49
|
|
|
42
50
|
```python
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
# For Streamable HTTP transport
|
|
52
|
+
http_app = mcp.http_app(path="/custom-mcp-path")
|
|
53
|
+
|
|
54
|
+
# For SSE transport (deprecated)
|
|
55
|
+
sse_app = mcp.http_app(path="/custom-sse-path", transport="sse")
|
|
45
56
|
```
|
|
46
57
|
|
|
47
58
|
### Running the Server
|
|
@@ -49,9 +60,12 @@ sse_app = mcp.sse_app(path="/custom-sse-path")
|
|
|
49
60
|
To run the FastMCP server, you can use the `uvicorn` ASGI server:
|
|
50
61
|
|
|
51
62
|
```python
|
|
63
|
+
from fastmcp import FastMCP
|
|
52
64
|
import uvicorn
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
mcp = FastMCP("MyServer")
|
|
67
|
+
|
|
68
|
+
http_app = mcp.http_app()
|
|
55
69
|
|
|
56
70
|
if __name__ == "__main__":
|
|
57
71
|
uvicorn.run(http_app, host="0.0.0.0", port=8000)
|
|
@@ -63,11 +77,35 @@ Or, from the command line:
|
|
|
63
77
|
uvicorn path.to.your.app:http_app --host 0.0.0.0 --port 8000
|
|
64
78
|
```
|
|
65
79
|
|
|
80
|
+
### Custom Middleware
|
|
81
|
+
|
|
82
|
+
<VersionBadge version="2.3.2" />
|
|
83
|
+
|
|
84
|
+
You can add custom Starlette middleware to your FastMCP ASGI apps by passing a list of middleware instances to the app creation methods:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from fastmcp import FastMCP
|
|
88
|
+
from starlette.middleware import Middleware
|
|
89
|
+
from starlette.middleware.cors import CORSMiddleware
|
|
90
|
+
|
|
91
|
+
# Create your FastMCP server
|
|
92
|
+
mcp = FastMCP("MyServer")
|
|
93
|
+
|
|
94
|
+
# Define custom middleware
|
|
95
|
+
custom_middleware = [
|
|
96
|
+
Middleware(CORSMiddleware, allow_origins=["*"]),
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
# Create ASGI app with custom middleware
|
|
100
|
+
http_app = mcp.http_app(middleware=custom_middleware)
|
|
101
|
+
```
|
|
66
102
|
|
|
67
103
|
|
|
68
104
|
## Starlette Integration
|
|
69
105
|
|
|
70
|
-
|
|
106
|
+
<VersionBadge version="2.3.1" />
|
|
107
|
+
|
|
108
|
+
You can mount your FastMCP server in another Starlette application:
|
|
71
109
|
|
|
72
110
|
```python
|
|
73
111
|
from fastmcp import FastMCP
|
|
@@ -78,7 +116,7 @@ from starlette.routing import Mount
|
|
|
78
116
|
mcp = FastMCP("MyServer")
|
|
79
117
|
|
|
80
118
|
# Create the ASGI app
|
|
81
|
-
mcp_app = mcp.
|
|
119
|
+
mcp_app = mcp.http_app(path='/mcp')
|
|
82
120
|
|
|
83
121
|
# Create a Starlette app and mount the MCP server
|
|
84
122
|
app = Starlette(
|
|
@@ -110,7 +148,7 @@ from starlette.routing import Mount
|
|
|
110
148
|
mcp = FastMCP("MyServer")
|
|
111
149
|
|
|
112
150
|
# Create the ASGI app
|
|
113
|
-
mcp_app = mcp.
|
|
151
|
+
mcp_app = mcp.http_app(path='/mcp')
|
|
114
152
|
|
|
115
153
|
# Create nested application structure
|
|
116
154
|
inner_app = Starlette(routes=[Mount("/inner", app=mcp_app)])
|
|
@@ -127,6 +165,8 @@ For Streamable HTTP transport, you **must** pass the lifespan context from the F
|
|
|
127
165
|
</Warning>
|
|
128
166
|
## FastAPI Integration
|
|
129
167
|
|
|
168
|
+
<VersionBadge version="2.3.1" />
|
|
169
|
+
|
|
130
170
|
FastAPI is built on Starlette, so you can mount your FastMCP server in a similar way:
|
|
131
171
|
|
|
132
172
|
```python
|
|
@@ -138,7 +178,7 @@ from starlette.routing import Mount
|
|
|
138
178
|
mcp = FastMCP("MyServer")
|
|
139
179
|
|
|
140
180
|
# Create the ASGI app
|
|
141
|
-
mcp_app = mcp.
|
|
181
|
+
mcp_app = mcp.http_app(path='/mcp')
|
|
142
182
|
|
|
143
183
|
# Create a FastAPI app and mount the MCP server
|
|
144
184
|
app = FastAPI(lifespan=mcp_app.router.lifespan_context)
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: FastMCP CLI
|
|
3
|
+
sidebarTitle: CLI
|
|
4
|
+
description: Learn how to use the FastMCP command-line interface
|
|
5
|
+
icon: terminal
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
import { VersionBadge } from "/snippets/version-badge.mdx"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
FastMCP provides a command-line interface (CLI) that makes it easy to run, develop, and install your MCP servers. The CLI is automatically installed when you install FastMCP.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
fastmcp --help
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Commands Overview
|
|
18
|
+
|
|
19
|
+
| Command | Purpose | Dependency Management |
|
|
20
|
+
| ------- | ------- | --------------------- |
|
|
21
|
+
| `run` | Run a FastMCP server directly | Uses your current environment; you are responsible for ensuring all dependencies are available |
|
|
22
|
+
| `dev` | Run a server with the MCP Inspector for testing | Creates an isolated environment; dependencies must be explicitly specified with `--with` and/or `--with-editable` |
|
|
23
|
+
| `install` | Install a server in the Claude desktop app | Creates an isolated environment; dependencies must be explicitly specified with `--with` and/or `--with-editable` |
|
|
24
|
+
| `version` | Display version information | N/A |
|
|
25
|
+
|
|
26
|
+
## Command Details
|
|
27
|
+
|
|
28
|
+
### `run`
|
|
29
|
+
|
|
30
|
+
Run a FastMCP server directly.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
fastmcp run server.py
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
<Tip>
|
|
37
|
+
This command runs the server directly in your current Python environment. You are responsible for ensuring all dependencies are available.
|
|
38
|
+
</Tip>
|
|
39
|
+
|
|
40
|
+
#### Options
|
|
41
|
+
|
|
42
|
+
| Option | Flag | Description |
|
|
43
|
+
| ------ | ---- | ----------- |
|
|
44
|
+
| Transport | `--transport`, `-t` | Transport protocol to use (`stdio`, `streamable-http`, or `sse`) |
|
|
45
|
+
| Host | `--host` | Host to bind to when using http transport (default: 127.0.0.1) |
|
|
46
|
+
| Port | `--port`, `-p` | Port to bind to when using http transport (default: 8000) |
|
|
47
|
+
| Log Level | `--log-level`, `-l` | Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
|
|
48
|
+
|
|
49
|
+
#### Server Specification
|
|
50
|
+
|
|
51
|
+
The server can be specified in two ways:
|
|
52
|
+
1. `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.
|
|
53
|
+
2. `server.py:custom_name` - imports and uses the specified server object
|
|
54
|
+
|
|
55
|
+
<Tip>
|
|
56
|
+
When using `fastmcp run`, it **ignores** the `if __name__ == "__main__"` block entirely. Instead, it finds your server object and calls its `run()` method directly with the transport options you specify. This means you can use `fastmcp run` to override the transport specified in your code.
|
|
57
|
+
</Tip>
|
|
58
|
+
|
|
59
|
+
For example, if your code contains:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
# server.py
|
|
63
|
+
from fastmcp import FastMCP
|
|
64
|
+
|
|
65
|
+
mcp = FastMCP("MyServer")
|
|
66
|
+
|
|
67
|
+
@mcp.tool()
|
|
68
|
+
def hello(name: str) -> str:
|
|
69
|
+
return f"Hello, {name}!"
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
# This is ignored when using `fastmcp run`!
|
|
73
|
+
mcp.run(transport="stdio")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
You can run it with Streamable HTTP transport regardless of what's in the `__main__` block:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
fastmcp run server.py --transport streamable-http --port 8000
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Example**
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Run a server with Streamable HTTP transport on a custom port
|
|
86
|
+
fastmcp run server.py --transport streamable-http --port 8000
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `dev`
|
|
90
|
+
|
|
91
|
+
Run a MCP server with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) for testing.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
fastmcp dev server.py
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
<Tip>
|
|
98
|
+
This command runs your server in an isolated environment. All dependencies must be explicitly specified using the `--with` and/or `--with-editable` options.
|
|
99
|
+
</Tip>
|
|
100
|
+
|
|
101
|
+
<Warning>
|
|
102
|
+
The `dev` command is a shortcut for testing a server over STDIO only. When the Inspector launches, you may need to:
|
|
103
|
+
1. Select "STDIO" from the transport dropdown
|
|
104
|
+
2. Connect manually
|
|
105
|
+
|
|
106
|
+
This command does not support HTTP testing. To test a server over HTTP:
|
|
107
|
+
1. Start your server manually with HTTP transport using either:
|
|
108
|
+
```bash
|
|
109
|
+
fastmcp run server.py --transport streamable-http
|
|
110
|
+
```
|
|
111
|
+
or
|
|
112
|
+
```bash
|
|
113
|
+
python server.py # Assuming your __main__ block sets HTTP transport
|
|
114
|
+
```
|
|
115
|
+
2. Open the MCP Inspector separately and connect to your running server
|
|
116
|
+
</Warning>
|
|
117
|
+
|
|
118
|
+
#### Options
|
|
119
|
+
|
|
120
|
+
| Option | Flag | Description |
|
|
121
|
+
| ------ | ---- | ----------- |
|
|
122
|
+
| Editable Package | `--with-editable`, `-e` | Directory containing pyproject.toml to install in editable mode |
|
|
123
|
+
| Additional Packages | `--with` | Additional packages to install (can be used multiple times) |
|
|
124
|
+
| Inspector Version | `--inspector-version` | Version of the MCP Inspector to use |
|
|
125
|
+
| UI Port | `--ui-port` | Port for the MCP Inspector UI |
|
|
126
|
+
| Server Port | `--server-port` | Port for the MCP Inspector Proxy server |
|
|
127
|
+
|
|
128
|
+
**Example**
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Run dev server with editable mode and additional packages
|
|
132
|
+
fastmcp dev server.py -e . --with pandas --with matplotlib
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### `install`
|
|
136
|
+
|
|
137
|
+
Install a MCP server in the Claude desktop app.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
fastmcp install server.py
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
<Tip>
|
|
144
|
+
This command installs your server in an isolated environment. All dependencies must be explicitly specified using the `--with` and/or `--with-editable` options.
|
|
145
|
+
</Tip>
|
|
146
|
+
|
|
147
|
+
<Warning>
|
|
148
|
+
The `install` command currently only sets up servers for STDIO transport. When installed in the Claude desktop app, your server will be run using STDIO regardless of any transport configuration in your code.
|
|
149
|
+
</Warning>
|
|
150
|
+
|
|
151
|
+
#### Options
|
|
152
|
+
|
|
153
|
+
| Option | Flag | Description |
|
|
154
|
+
| ------ | ---- | ----------- |
|
|
155
|
+
| Server Name | `--name`, `-n` | Custom name for the server |
|
|
156
|
+
| Editable Package | `--with-editable`, `-e` | Directory containing pyproject.toml to install in editable mode |
|
|
157
|
+
| Additional Packages | `--with` | Additional packages to install (can be used multiple times) |
|
|
158
|
+
| Environment Variables | `--env-var`, `-v` | Environment variables in KEY=VALUE format (can be used multiple times) |
|
|
159
|
+
| Environment File | `--env-file`, `-f` | Load environment variables from a .env file |
|
|
160
|
+
|
|
161
|
+
**Example**
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
# Install server with custom name, dependencies, and environment variables
|
|
165
|
+
fastmcp install server.py -n "My Analysis Server" -e . --with pandas --env-var API_KEY=12345
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### `version`
|
|
169
|
+
|
|
170
|
+
Display version information about FastMCP and related components.
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
fastmcp version
|
|
174
|
+
```
|
|
@@ -11,7 +11,7 @@ FastMCP servers can be run in different ways depending on your application's nee
|
|
|
11
11
|
|
|
12
12
|
## The `run()` Method
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
FastMCP servers can be run directly from Python by calling the `run()` method on a `FastMCP` instance.
|
|
15
15
|
|
|
16
16
|
<Tip>
|
|
17
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.
|
|
@@ -33,6 +33,34 @@ You can now run this MCP server by executing `python my_server.py`.
|
|
|
33
33
|
|
|
34
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
35
|
|
|
36
|
+
## The FastMCP CLI
|
|
37
|
+
|
|
38
|
+
FastMCP also provides a command-line interface for running servers without modifying the source code. After installing FastMCP, you can run your server directly from the command line:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
fastmcp run server.py
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
<Tip>
|
|
45
|
+
**Important**: When using `fastmcp run`, it **ignores** the `if __name__ == "__main__"` block entirely. Instead, it looks for a FastMCP object named `mcp`, `server`, or `app` and calls its `run()` method directly with the transport options you specify.
|
|
46
|
+
|
|
47
|
+
This means you can use `fastmcp run` to override the transport specified in your code, which is particularly useful for testing or changing deployment methods without modifying the code.
|
|
48
|
+
</Tip>
|
|
49
|
+
|
|
50
|
+
You can specify transport options and other configuration:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
fastmcp run server.py --transport sse --port 9000
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For development and testing, you can use the `dev` command to run your server with the MCP Inspector:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
fastmcp dev server.py
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
See the [CLI documentation](/deployment/cli) for detailed information about all available commands and options.
|
|
63
|
+
|
|
36
64
|
## Transport Options
|
|
37
65
|
|
|
38
66
|
Below is a comparison of available transport options to help you choose the right one for your needs:
|
|
@@ -40,8 +68,8 @@ Below is a comparison of available transport options to help you choose the righ
|
|
|
40
68
|
| Transport | Use Cases | Recommendation |
|
|
41
69
|
| --------- | --------- | -------------- |
|
|
42
70
|
| **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
|
|
44
|
-
| **SSE** | Existing web-based deployments that rely on SSE |
|
|
71
|
+
| **Streamable HTTP** | Web-based deployments, microservices, exposing MCP over a network | Recommended choice for web-based deployments |
|
|
72
|
+
| **SSE** | Existing web-based deployments that rely on SSE | Deprecated - prefer Streamable HTTP for new projects |
|
|
45
73
|
|
|
46
74
|
### STDIO
|
|
47
75
|
|
|
@@ -64,7 +92,7 @@ When using Stdio transport, you will typically *not* run the server yourself as
|
|
|
64
92
|
|
|
65
93
|
<VersionBadge version="2.3.0" />
|
|
66
94
|
|
|
67
|
-
Streamable HTTP is a modern, efficient transport for exposing your MCP server via HTTP. It is
|
|
95
|
+
Streamable HTTP is a modern, efficient transport for exposing your MCP server via HTTP. It is the recommended transport for web-based deployments.
|
|
68
96
|
|
|
69
97
|
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
98
|
<CodeGroup>
|
|
@@ -122,7 +150,12 @@ if __name__ == "__main__":
|
|
|
122
150
|
|
|
123
151
|
### SSE
|
|
124
152
|
|
|
125
|
-
|
|
153
|
+
<Warning>
|
|
154
|
+
The SSE transport is deprecated and may be removed in a future version.
|
|
155
|
+
New applications should use Streamable HTTP transport instead.
|
|
156
|
+
</Warning>
|
|
157
|
+
|
|
158
|
+
Server-Sent Events (SSE) is an HTTP-based protocol for server-to-client streaming. While FastMCP still supports SSE, it is deprecated and Streamable HTTP is preferred for new projects.
|
|
126
159
|
|
|
127
160
|
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
161
|
|
|
@@ -170,7 +203,6 @@ if __name__ == "__main__":
|
|
|
170
203
|
port=4200,
|
|
171
204
|
log_level="debug",
|
|
172
205
|
path="/my-custom-sse-path",
|
|
173
|
-
message_path="/my-custom-message-path/",
|
|
174
206
|
)
|
|
175
207
|
```
|
|
176
208
|
```python {7} client.py
|
|
@@ -189,9 +221,37 @@ if __name__ == "__main__":
|
|
|
189
221
|
```
|
|
190
222
|
</CodeGroup>
|
|
191
223
|
|
|
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.
|
|
193
224
|
|
|
194
225
|
|
|
226
|
+
## Async Usage
|
|
227
|
+
|
|
228
|
+
FastMCP provides both synchronous and asynchronous APIs for running your server. The `run()` method seen in previous examples is a synchronous method that internally uses `anyio.run()` to run the asynchronous server. For applications that are already running in an async context, FastMCP provides the `run_async()` method.
|
|
229
|
+
|
|
230
|
+
```python {10-12}
|
|
231
|
+
from fastmcp import FastMCP
|
|
232
|
+
import asyncio
|
|
233
|
+
|
|
234
|
+
mcp = FastMCP(name="MyServer")
|
|
235
|
+
|
|
236
|
+
@mcp.tool()
|
|
237
|
+
def hello(name: str) -> str:
|
|
238
|
+
return f"Hello, {name}!"
|
|
239
|
+
|
|
240
|
+
async def main():
|
|
241
|
+
# Use run_async() in async contexts
|
|
242
|
+
await mcp.run_async(transport="streamable-http")
|
|
243
|
+
|
|
244
|
+
if __name__ == "__main__":
|
|
245
|
+
asyncio.run(main())
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
<Warning>
|
|
249
|
+
The `run()` method cannot be called from inside an async function because it already creates its own async event loop internally. If you attempt to call `run()` from inside an async function, you'll get an error about the event loop already running.
|
|
250
|
+
|
|
251
|
+
Always use `run_async()` inside async functions and `run()` in synchronous contexts.
|
|
252
|
+
</Warning>
|
|
253
|
+
|
|
254
|
+
Both `run()` and `run_async()` accept the same transport arguments, so all the examples above apply to both methods.
|
|
195
255
|
|
|
196
256
|
## Custom Routes
|
|
197
257
|
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"servers/resources",
|
|
51
51
|
"servers/prompts",
|
|
52
52
|
"servers/context",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
53
|
+
"servers/proxy",
|
|
54
|
+
"servers/composition"
|
|
55
55
|
]
|
|
56
56
|
},
|
|
57
57
|
{
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"pages": [
|
|
60
60
|
"deployment/running-server",
|
|
61
61
|
"deployment/asgi",
|
|
62
|
-
"deployment/authentication"
|
|
62
|
+
"deployment/authentication",
|
|
63
|
+
"deployment/cli"
|
|
63
64
|
]
|
|
64
65
|
},
|
|
65
66
|
{
|
|
@@ -86,5 +87,15 @@
|
|
|
86
87
|
}
|
|
87
88
|
]
|
|
88
89
|
},
|
|
90
|
+
"redirects": [
|
|
91
|
+
{
|
|
92
|
+
"destination": "/servers/proxy",
|
|
93
|
+
"source": "/patterns/proxy"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"destination": "/servers/composition",
|
|
97
|
+
"source": "/patterns/composition"
|
|
98
|
+
}
|
|
99
|
+
],
|
|
89
100
|
"theme": "mint"
|
|
90
101
|
}
|
|
@@ -44,7 +44,7 @@ FastMCP root path: ~/Developer/fastmcp
|
|
|
44
44
|
```
|
|
45
45
|
## Upgrading from the Official MCP SDK
|
|
46
46
|
|
|
47
|
-
Upgrading from the official MCP SDK's FastMCP 1.0 to FastMCP 2.0 is
|
|
47
|
+
Upgrading from the official MCP SDK's FastMCP 1.0 to FastMCP 2.0 is generally straightforward. The core server API is highly compatible, and in many cases, changing your import statement from `from mcp.server.fastmcp import FastMCP` to `from fastmcp import FastMCP` will be sufficient.
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
```python {1-5}
|
|
@@ -56,8 +56,9 @@ from fastmcp import FastMCP
|
|
|
56
56
|
|
|
57
57
|
mcp = FastMCP("My MCP Server")
|
|
58
58
|
```
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
<Warning>
|
|
60
|
+
Prior to `fastmcp==2.3.0` and `mcp==1.8.0`, the 2.x API always mirrored the 1.0 API. However, as the projects diverge, this can not be guaranteed. You may see deprecation warnings if you attempt to use 1.0 APIs in FastMCP 2.x. Please refer to this documentation for details on new capabilities.
|
|
61
|
+
</Warning>
|
|
61
62
|
|
|
62
63
|
## Installing for Development
|
|
63
64
|
|
|
@@ -27,7 +27,7 @@ if __name__ == "__main__":
|
|
|
27
27
|
## FastMCP 2.0 and the Official MCP SDK
|
|
28
28
|
|
|
29
29
|
<Tip>
|
|
30
|
-
Recognize the `FastMCP` name? You might have
|
|
30
|
+
Recognize the `FastMCP` name? You might have seen the version that was contributed to the [official MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk), which was based on **FastMCP 1.0**.
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
**Welcome to FastMCP 2.0!** This is the [actively developed successor](https://github.com/jlowin/fastmcp), and it significantly expands on 1.0 by introducing powerful client capabilities, server proxying & composition, OpenAPI/FastAPI integration, and more advanced features.
|
|
@@ -114,11 +114,16 @@ if __name__ == "__main__":
|
|
|
114
114
|
# This runs the server, defaulting to STDIO transport
|
|
115
115
|
mcp.run()
|
|
116
116
|
|
|
117
|
-
# To use a different transport, e.g.,
|
|
117
|
+
# To use a different transport, e.g., HTTP:
|
|
118
118
|
# mcp.run(transport="streamable-http", host="127.0.0.1", port=9000)
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
FastMCP supports several transport options
|
|
121
|
+
FastMCP supports several transport options:
|
|
122
|
+
- STDIO (default, for local tools)
|
|
123
|
+
- Streamable HTTP (recommended for web services)
|
|
124
|
+
- SSE (legacy web transport, deprecated)
|
|
125
|
+
|
|
126
|
+
The server can also be run using the FastMCP CLI.
|
|
122
127
|
|
|
123
128
|
For detailed information on each transport, how to configure them (host, port, paths), and when to use which, please refer to the [**Running Your FastMCP Server**](/deployment/running-server) guide.
|
|
124
129
|
|
|
@@ -327,14 +327,14 @@ def run(
|
|
|
327
327
|
typer.Option(
|
|
328
328
|
"--transport",
|
|
329
329
|
"-t",
|
|
330
|
-
help="Transport protocol to use (stdio or sse)",
|
|
330
|
+
help="Transport protocol to use (stdio, streamable-http, or sse)",
|
|
331
331
|
),
|
|
332
332
|
] = None,
|
|
333
333
|
host: Annotated[
|
|
334
334
|
str | None,
|
|
335
335
|
typer.Option(
|
|
336
336
|
"--host",
|
|
337
|
-
help="Host to bind to when using
|
|
337
|
+
help="Host to bind to when using http transport (default: 127.0.0.1)",
|
|
338
338
|
),
|
|
339
339
|
] = None,
|
|
340
340
|
port: Annotated[
|
|
@@ -342,7 +342,7 @@ def run(
|
|
|
342
342
|
typer.Option(
|
|
343
343
|
"--port",
|
|
344
344
|
"-p",
|
|
345
|
-
help="Port to bind to when using
|
|
345
|
+
help="Port to bind to when using http transport (default: 8000)",
|
|
346
346
|
),
|
|
347
347
|
] = None,
|
|
348
348
|
log_level: Annotated[
|
|
@@ -350,20 +350,19 @@ def run(
|
|
|
350
350
|
typer.Option(
|
|
351
351
|
"--log-level",
|
|
352
352
|
"-l",
|
|
353
|
-
help="Log level
|
|
353
|
+
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
|
|
354
354
|
),
|
|
355
355
|
] = None,
|
|
356
356
|
) -> None:
|
|
357
357
|
"""Run a MCP server.
|
|
358
358
|
|
|
359
|
-
The server can be specified in two ways
|
|
359
|
+
The server can be specified in two ways:
|
|
360
360
|
1. Module approach: server.py - runs the module directly, expecting a server.run() call.\n
|
|
361
361
|
2. Import approach: server.py:app - imports and runs the specified server object.\n\n
|
|
362
362
|
|
|
363
363
|
Note: This command runs the server directly. You are responsible for ensuring
|
|
364
|
-
all dependencies are available
|
|
365
|
-
|
|
366
|
-
""" # noqa: E501
|
|
364
|
+
all dependencies are available.
|
|
365
|
+
"""
|
|
367
366
|
file, server_object = _parse_file_path(file_spec)
|
|
368
367
|
|
|
369
368
|
logger.debug(
|