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.
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/PKG-INFO +2 -2
- fastmcp-2.3.0rc1/docs/deployment/authentication.mdx +15 -0
- fastmcp-2.3.0rc1/docs/deployment/running-server.mdx +192 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/docs.json +11 -3
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/getting-started/quickstart.mdx +1 -1
- fastmcp-2.3.0rc1/docs/patterns/http-requests.mdx +79 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/proxy.mdx +2 -2
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/context.mdx +78 -90
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/fastmcp.mdx +30 -144
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/pyproject.toml +8 -1
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/__init__.py +2 -1
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/cli/cli.py +1 -1
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/client.py +3 -2
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/transports.py +45 -1
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/prompts/prompt.py +10 -15
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/prompts/prompt_manager.py +3 -10
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/resource.py +2 -7
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/resource_manager.py +2 -4
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/template.py +11 -24
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/types.py +15 -44
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/__init__.py +1 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/context.py +50 -38
- fastmcp-2.3.0rc1/src/fastmcp/server/dependencies.py +35 -0
- fastmcp-2.3.0rc1/src/fastmcp/server/http.py +309 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/openapi.py +5 -16
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/proxy.py +4 -13
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/server/server.py +196 -271
- fastmcp-2.3.0rc1/src/fastmcp/server/streamable_http_manager.py +241 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/settings.py +7 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/tools/tool.py +14 -23
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/tools/tool_manager.py +3 -9
- fastmcp-2.3.0rc1/src/fastmcp/utilities/cache.py +26 -0
- fastmcp-2.3.0rc1/src/fastmcp/utilities/tests.py +113 -0
- fastmcp-2.3.0rc1/test.py +12 -0
- fastmcp-2.3.0rc1/tests/client/test_sse.py +92 -0
- fastmcp-2.3.0rc1/tests/client/test_streamable_http.py +102 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/prompts/test_prompt_manager.py +22 -29
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_resource_template.py +25 -29
- fastmcp-2.3.0rc1/tests/server/test_context.py +59 -0
- fastmcp-2.3.0rc1/tests/server/test_http_dependencies.py +102 -0
- fastmcp-2.3.0rc1/tests/server/test_lifespan.py +236 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/tools/test_tool_manager.py +57 -48
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/uv.lock +573 -577
- fastmcp-2.2.10/src/fastmcp/utilities/http.py +0 -44
- fastmcp-2.2.10/src/fastmcp/utilities/tests.py +0 -41
- fastmcp-2.2.10/tests/server/test_lifespan.py +0 -112
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.cursor/rules/core-mcp-objects.mdc +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/ISSUE_TEMPLATE/bug.yml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/ISSUE_TEMPLATE/enhancement.yml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/release.yml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/workflows/publish.yml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/workflows/run-static.yml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.github/workflows/run-tests.yml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.gitignore +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/.pre-commit-config.yaml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/LICENSE +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/README.md +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/Windows_Notes.md +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/assets/demo-inspector.png +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/clients/client.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/clients/transports.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/getting-started/installation.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/getting-started/welcome.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/composition.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/contrib.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/decorating-methods.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/fastapi.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/openapi.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/patterns/testing.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/prompts.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/resources.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/servers/tools.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/snippets/version-badge.mdx +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/docs/style.css +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/complex_inputs.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/desktop.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/echo.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/memory.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/mount_example.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/sampling.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/screenshot.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/serializer.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/simple_echo.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/README.md +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/pyproject.toml +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/__main__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/hub.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/lights/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/lights/hue_utils.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/lights/server.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/py.typed +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/src/smart_home/settings.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/smart_home/uv.lock +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/examples/text_me.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/justfile +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/cli/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/cli/claude.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/base.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/logging.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/roots.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/client/sampling.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/README.md +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/bulk_tool_caller/README.md +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/bulk_tool_caller/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/bulk_tool_caller/bulk_tool_caller.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/bulk_tool_caller/example.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/mcp_mixin/README.md +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/mcp_mixin/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/mcp_mixin/example.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/contrib/mcp_mixin/mcp_mixin.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/exceptions.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/prompts/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/py.typed +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/resources/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/tools/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/decorators.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/json_schema.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/logging.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/openapi.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/src/fastmcp/utilities/types.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/cli/test_run.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/test_client.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/test_logs.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/test_roots.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/client/test_sampling.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/conftest.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/contrib/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/contrib/test_bulk_tool_caller.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/contrib/test_mcp_mixin.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/prompts/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/prompts/test_prompt.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_file_resources.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_function_resources.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_resource_manager.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/resources/test_resources.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_auth_integration.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_file_server.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_import_server.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_mount.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_openapi.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_proxy.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_run_server.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_server.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_server_interactions.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/server/test_tool_annotations.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/test_examples.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/test_servers/fastmcp_server.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/test_servers/sse.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/test_servers/stdio.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/tools/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/tools/test_tool.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/__init__.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/conftest.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/test_openapi.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/test_openapi_advanced.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/openapi/test_openapi_fastapi.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_decorated_function.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_json_schema.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_logging.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_tests.py +0 -0
- {fastmcp-2.2.10 → fastmcp-2.3.0rc1}/tests/utilities/test_typeadapter.py +0 -0
- {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.
|
|
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
|
|
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",
|
|
@@ -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
|
+
```
|
|
@@ -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
|
-
|
|
35
|
-
|
|
47
|
+
# Context is available as the ctx parameter
|
|
48
|
+
return "Processed file"
|
|
49
|
+
```
|
|
36
50
|
|
|
37
|
-
|
|
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
|
-
|
|
45
|
-
await ctx.debug(f"Read {len(data)} bytes from {file_uri}")
|
|
53
|
+
<VersionBadge version="2.2.5" />
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
54
|
-
|
|
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
|
-
|
|
69
|
+
#### Prompts
|
|
57
70
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
####
|
|
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
|
-
####
|
|
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.
|