Spaces:
Running
Running
zzstoatzz commited on
Commit ·
1814d17
1
Parent(s): 8e4c972
update path and mdxify
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- docs/docs.json +271 -170
- docs/python-sdk/fastmcp-cli-__init__.mdx +9 -0
- docs/python-sdk/fastmcp-cli-claude.mdx +43 -0
- docs/python-sdk/fastmcp-cli-cli.mdx +65 -0
- docs/python-sdk/fastmcp-cli-run.mdx +106 -0
- docs/python-sdk/fastmcp-client-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-client-auth-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-client-auth-bearer.mdx +18 -0
- docs/python-sdk/fastmcp-client-auth-oauth.mdx +103 -0
- docs/python-sdk/fastmcp-client-client.mdx +94 -0
- docs/python-sdk/fastmcp-client-logging.mdx +14 -0
- docs/python-sdk/fastmcp-client-oauth_callback.mdx +63 -0
- docs/python-sdk/fastmcp-client-progress.mdx +8 -0
- docs/python-sdk/fastmcp-client-roots.mdx +20 -0
- docs/python-sdk/fastmcp-client-sampling.mdx +14 -0
- docs/python-sdk/fastmcp-client-transports.mdx +191 -0
- docs/python-sdk/fastmcp-exceptions.mdx +65 -0
- docs/python-sdk/fastmcp-prompts-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-prompts-prompt.mdx +84 -0
- docs/python-sdk/fastmcp-prompts-prompt_manager.mdx +43 -0
- docs/python-sdk/fastmcp-resources-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-resources-resource.mdx +90 -0
- docs/python-sdk/fastmcp-resources-resource_manager.mdx +111 -0
- docs/python-sdk/fastmcp-resources-template.mdx +104 -0
- docs/python-sdk/fastmcp-resources-types.mdx +83 -0
- docs/python-sdk/fastmcp-server-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-server-auth-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-server-auth-auth.mdx +10 -0
- docs/python-sdk/fastmcp-server-auth-providers-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-server-auth-providers-bearer.mdx +69 -0
- docs/python-sdk/fastmcp-server-auth-providers-bearer_env.mdx +22 -0
- docs/python-sdk/fastmcp-server-auth-providers-in_memory.mdx +15 -0
- docs/python-sdk/fastmcp-server-context.mdx +118 -0
- docs/python-sdk/fastmcp-server-dependencies.mdx +36 -0
- docs/python-sdk/fastmcp-server-http.mdx +113 -0
- docs/python-sdk/fastmcp-server-middleware.mdx +56 -0
- docs/python-sdk/fastmcp-server-openapi.mdx +58 -0
- docs/python-sdk/fastmcp-server-proxy.mdx +101 -0
- docs/python-sdk/fastmcp-server-server.mdx +542 -0
- docs/python-sdk/fastmcp-settings.mdx +59 -0
- docs/python-sdk/fastmcp-tools-__init__.mdx +8 -0
- docs/python-sdk/fastmcp-tools-tool.mdx +68 -0
- docs/python-sdk/fastmcp-tools-tool_manager.mdx +58 -0
- docs/python-sdk/fastmcp-tools-tool_transform.mdx +117 -0
- docs/python-sdk/fastmcp-utilities-__init__.mdx +9 -0
- docs/python-sdk/fastmcp-utilities-cache.mdx +30 -0
- docs/python-sdk/fastmcp-utilities-components.mdx +52 -0
- docs/python-sdk/fastmcp-utilities-exceptions.mdx +20 -0
- docs/python-sdk/fastmcp-utilities-http.mdx +18 -0
- docs/python-sdk/fastmcp-utilities-json_schema.mdx +25 -0
docs/docs.json
CHANGED
|
@@ -1,178 +1,279 @@
|
|
| 1 |
{
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
},
|
| 7 |
-
"
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
"
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
"
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
]
|
| 73 |
-
},
|
| 74 |
-
{
|
| 75 |
-
"group": "Authentication",
|
| 76 |
-
"icon": "shield-check",
|
| 77 |
-
"pages": [
|
| 78 |
-
"servers/auth/bearer"
|
| 79 |
-
]
|
| 80 |
-
},
|
| 81 |
-
"servers/middleware",
|
| 82 |
-
"servers/openapi",
|
| 83 |
-
"servers/proxy",
|
| 84 |
-
"servers/composition",
|
| 85 |
-
{
|
| 86 |
-
"group": "Deployment",
|
| 87 |
-
"icon": "upload",
|
| 88 |
-
"pages": [
|
| 89 |
-
"deployment/running-server",
|
| 90 |
-
"deployment/asgi"
|
| 91 |
-
]
|
| 92 |
-
}
|
| 93 |
-
]
|
| 94 |
-
},
|
| 95 |
-
{
|
| 96 |
-
"group": "Clients",
|
| 97 |
-
"pages": [
|
| 98 |
-
"clients/client",
|
| 99 |
-
"clients/transports",
|
| 100 |
-
{
|
| 101 |
-
"group": "Authentication",
|
| 102 |
-
"icon": "user-shield",
|
| 103 |
-
"pages": [
|
| 104 |
-
"clients/auth/oauth",
|
| 105 |
-
"clients/auth/bearer"
|
| 106 |
-
]
|
| 107 |
-
},
|
| 108 |
-
"clients/advanced-features"
|
| 109 |
-
]
|
| 110 |
-
},
|
| 111 |
-
{
|
| 112 |
-
"group": "Integrations",
|
| 113 |
-
"pages": [
|
| 114 |
-
"integrations/anthropic",
|
| 115 |
-
"integrations/claude-desktop",
|
| 116 |
-
"integrations/openai",
|
| 117 |
-
"integrations/gemini",
|
| 118 |
-
"integrations/contrib"
|
| 119 |
-
]
|
| 120 |
-
},
|
| 121 |
-
{
|
| 122 |
-
"group": "Patterns",
|
| 123 |
-
"pages": [
|
| 124 |
-
"patterns/tool-transformation",
|
| 125 |
-
"patterns/decorating-methods",
|
| 126 |
-
"patterns/http-requests",
|
| 127 |
-
"patterns/testing",
|
| 128 |
-
"patterns/cli"
|
| 129 |
-
]
|
| 130 |
-
}
|
| 131 |
-
],
|
| 132 |
-
"icon": "book"
|
| 133 |
-
},
|
| 134 |
-
{
|
| 135 |
-
"anchor": "Tutorials",
|
| 136 |
-
"groups": [
|
| 137 |
-
{
|
| 138 |
-
"group": "MCP",
|
| 139 |
-
"pages": [
|
| 140 |
-
"tutorials/mcp",
|
| 141 |
-
"tutorials/create-mcp-server",
|
| 142 |
-
"tutorials/rest-api"
|
| 143 |
-
]
|
| 144 |
-
}
|
| 145 |
-
],
|
| 146 |
-
"icon": "graduation-cap"
|
| 147 |
-
},
|
| 148 |
-
{
|
| 149 |
-
"anchor": "Changelog",
|
| 150 |
-
"icon": "list-check",
|
| 151 |
"pages": [
|
| 152 |
-
|
| 153 |
]
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
"pages": [
|
| 159 |
-
|
|
|
|
| 160 |
]
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
},
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
"search": {
|
| 175 |
-
"prompt": "Search the docs..."
|
| 176 |
-
},
|
| 177 |
-
"theme": "mint"
|
| 178 |
-
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"$schema": "https://mintlify.com/docs.json",
|
| 3 |
+
"appearance": {
|
| 4 |
+
"default": "system",
|
| 5 |
+
"strict": false
|
| 6 |
+
},
|
| 7 |
+
"background": {
|
| 8 |
+
"color": {
|
| 9 |
+
"dark": "#222831",
|
| 10 |
+
"light": "#EEEEEE"
|
| 11 |
},
|
| 12 |
+
"decoration": "windows"
|
| 13 |
+
},
|
| 14 |
+
"banner": {
|
| 15 |
+
"content": "[FastMCP Cloud](https://fastmcp.link/x0Kyhy2) is coming!"
|
| 16 |
+
},
|
| 17 |
+
"colors": {
|
| 18 |
+
"dark": "#f72585",
|
| 19 |
+
"light": "#4cc9f0",
|
| 20 |
+
"primary": "#2d00f7"
|
| 21 |
+
},
|
| 22 |
+
"description": "The fast, Pythonic way to build MCP servers and clients.",
|
| 23 |
+
"favicon": {
|
| 24 |
+
"dark": "/assets/favicon.ico",
|
| 25 |
+
"light": "/assets/favicon.ico"
|
| 26 |
+
},
|
| 27 |
+
"footer": {
|
| 28 |
+
"socials": {
|
| 29 |
+
"bluesky": "https://bsky.app/profile/jlowin.dev",
|
| 30 |
+
"github": "https://github.com/jlowin/fastmcp",
|
| 31 |
+
"x": "https://x.com/jlowin"
|
| 32 |
+
}
|
| 33 |
+
},
|
| 34 |
+
"integrations": {
|
| 35 |
+
"ga4": {
|
| 36 |
+
"measurementId": "G-64R5W1TJXG"
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"name": "FastMCP",
|
| 40 |
+
"navbar": {
|
| 41 |
+
"primary": {
|
| 42 |
+
"href": "https://github.com/jlowin/fastmcp",
|
| 43 |
+
"type": "github"
|
| 44 |
+
}
|
| 45 |
+
},
|
| 46 |
+
"navigation": {
|
| 47 |
+
"anchors": [
|
| 48 |
+
{
|
| 49 |
+
"anchor": "Documentation",
|
| 50 |
+
"groups": [
|
| 51 |
+
{
|
| 52 |
+
"group": "Get Started",
|
| 53 |
+
"pages": [
|
| 54 |
+
"getting-started/welcome",
|
| 55 |
+
"getting-started/installation",
|
| 56 |
+
"getting-started/quickstart",
|
| 57 |
+
"updates"
|
| 58 |
+
]
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"group": "Servers",
|
| 62 |
+
"pages": [
|
| 63 |
+
"servers/fastmcp",
|
| 64 |
+
{
|
| 65 |
+
"group": "Core Components",
|
| 66 |
+
"icon": "toolbox",
|
| 67 |
+
"pages": [
|
| 68 |
+
"servers/tools",
|
| 69 |
+
"servers/resources",
|
| 70 |
+
"servers/prompts",
|
| 71 |
+
"servers/context"
|
| 72 |
+
]
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"group": "Authentication",
|
| 76 |
+
"icon": "shield-check",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
"pages": [
|
| 78 |
+
"servers/auth/bearer"
|
| 79 |
]
|
| 80 |
+
},
|
| 81 |
+
"servers/middleware",
|
| 82 |
+
"servers/openapi",
|
| 83 |
+
"servers/proxy",
|
| 84 |
+
"servers/composition",
|
| 85 |
+
{
|
| 86 |
+
"group": "Deployment",
|
| 87 |
+
"icon": "upload",
|
| 88 |
"pages": [
|
| 89 |
+
"deployment/running-server",
|
| 90 |
+
"deployment/asgi"
|
| 91 |
]
|
| 92 |
+
}
|
| 93 |
+
]
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"group": "Clients",
|
| 97 |
+
"pages": [
|
| 98 |
+
"clients/client",
|
| 99 |
+
"clients/transports",
|
| 100 |
+
{
|
| 101 |
+
"group": "Authentication",
|
| 102 |
+
"icon": "user-shield",
|
| 103 |
+
"pages": [
|
| 104 |
+
"clients/auth/oauth",
|
| 105 |
+
"clients/auth/bearer"
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
"clients/advanced-features"
|
| 109 |
+
]
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"group": "Integrations",
|
| 113 |
+
"pages": [
|
| 114 |
+
"integrations/anthropic",
|
| 115 |
+
"integrations/claude-desktop",
|
| 116 |
+
"integrations/openai",
|
| 117 |
+
"integrations/gemini",
|
| 118 |
+
"integrations/contrib"
|
| 119 |
+
]
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"group": "Patterns",
|
| 123 |
+
"pages": [
|
| 124 |
+
"patterns/tool-transformation",
|
| 125 |
+
"patterns/decorating-methods",
|
| 126 |
+
"patterns/http-requests",
|
| 127 |
+
"patterns/testing",
|
| 128 |
+
"patterns/cli"
|
| 129 |
+
]
|
| 130 |
+
}
|
| 131 |
+
],
|
| 132 |
+
"icon": "book"
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"anchor": "Tutorials",
|
| 136 |
+
"groups": [
|
| 137 |
+
{
|
| 138 |
+
"group": "MCP",
|
| 139 |
+
"pages": [
|
| 140 |
+
"tutorials/mcp",
|
| 141 |
+
"tutorials/create-mcp-server",
|
| 142 |
+
"tutorials/rest-api"
|
| 143 |
+
]
|
| 144 |
+
}
|
| 145 |
+
],
|
| 146 |
+
"icon": "graduation-cap"
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"anchor": "Changelog",
|
| 150 |
+
"icon": "list-check",
|
| 151 |
+
"pages": [
|
| 152 |
+
"changelog"
|
| 153 |
]
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"anchor": "Community",
|
| 157 |
+
"icon": "users",
|
| 158 |
+
"pages": [
|
| 159 |
+
"community/showcase"
|
| 160 |
+
]
|
| 161 |
+
},
|
| 162 |
+
{
|
| 163 |
+
"anchor": "SDK Reference",
|
| 164 |
+
"icon": "code",
|
| 165 |
+
"pages": [
|
| 166 |
+
"python-sdk/fastmcp-exceptions",
|
| 167 |
+
"python-sdk/fastmcp-settings",
|
| 168 |
+
{
|
| 169 |
+
"group": "fastmcp.cli",
|
| 170 |
+
"pages": [
|
| 171 |
+
"python-sdk/fastmcp-cli-__init__",
|
| 172 |
+
"python-sdk/fastmcp-cli-claude",
|
| 173 |
+
"python-sdk/fastmcp-cli-cli",
|
| 174 |
+
"python-sdk/fastmcp-cli-run"
|
| 175 |
+
]
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"group": "fastmcp.client",
|
| 179 |
+
"pages": [
|
| 180 |
+
{
|
| 181 |
+
"group": "auth",
|
| 182 |
+
"pages": [
|
| 183 |
+
"python-sdk/fastmcp-client-auth-bearer",
|
| 184 |
+
"python-sdk/fastmcp-client-auth-oauth"
|
| 185 |
+
]
|
| 186 |
+
},
|
| 187 |
+
"python-sdk/fastmcp-client-client",
|
| 188 |
+
"python-sdk/fastmcp-client-logging",
|
| 189 |
+
"python-sdk/fastmcp-client-oauth_callback",
|
| 190 |
+
"python-sdk/fastmcp-client-progress",
|
| 191 |
+
"python-sdk/fastmcp-client-roots",
|
| 192 |
+
"python-sdk/fastmcp-client-sampling",
|
| 193 |
+
"python-sdk/fastmcp-client-transports"
|
| 194 |
+
]
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"group": "fastmcp.prompts",
|
| 198 |
+
"pages": [
|
| 199 |
+
"python-sdk/fastmcp-prompts-prompt",
|
| 200 |
+
"python-sdk/fastmcp-prompts-prompt_manager"
|
| 201 |
+
]
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
"group": "fastmcp.resources",
|
| 205 |
+
"pages": [
|
| 206 |
+
"python-sdk/fastmcp-resources-resource",
|
| 207 |
+
"python-sdk/fastmcp-resources-resource_manager",
|
| 208 |
+
"python-sdk/fastmcp-resources-template",
|
| 209 |
+
"python-sdk/fastmcp-resources-types"
|
| 210 |
+
]
|
| 211 |
+
},
|
| 212 |
+
{
|
| 213 |
+
"group": "fastmcp.server",
|
| 214 |
+
"pages": [
|
| 215 |
+
{
|
| 216 |
+
"group": "auth",
|
| 217 |
+
"pages": [
|
| 218 |
+
"python-sdk/fastmcp-server-auth-auth",
|
| 219 |
+
{
|
| 220 |
+
"group": "providers",
|
| 221 |
+
"pages": [
|
| 222 |
+
"python-sdk/fastmcp-server-auth-providers-bearer",
|
| 223 |
+
"python-sdk/fastmcp-server-auth-providers-bearer_env",
|
| 224 |
+
"python-sdk/fastmcp-server-auth-providers-in_memory"
|
| 225 |
+
]
|
| 226 |
+
}
|
| 227 |
+
]
|
| 228 |
+
},
|
| 229 |
+
"python-sdk/fastmcp-server-context",
|
| 230 |
+
"python-sdk/fastmcp-server-dependencies",
|
| 231 |
+
"python-sdk/fastmcp-server-http",
|
| 232 |
+
"python-sdk/fastmcp-server-middleware",
|
| 233 |
+
"python-sdk/fastmcp-server-openapi",
|
| 234 |
+
"python-sdk/fastmcp-server-proxy",
|
| 235 |
+
"python-sdk/fastmcp-server-server"
|
| 236 |
+
]
|
| 237 |
+
},
|
| 238 |
+
{
|
| 239 |
+
"group": "fastmcp.tools",
|
| 240 |
+
"pages": [
|
| 241 |
+
"python-sdk/fastmcp-tools-tool",
|
| 242 |
+
"python-sdk/fastmcp-tools-tool_manager",
|
| 243 |
+
"python-sdk/fastmcp-tools-tool_transform"
|
| 244 |
+
]
|
| 245 |
+
},
|
| 246 |
+
{
|
| 247 |
+
"group": "fastmcp.utilities",
|
| 248 |
+
"pages": [
|
| 249 |
+
"python-sdk/fastmcp-utilities-__init__",
|
| 250 |
+
"python-sdk/fastmcp-utilities-cache",
|
| 251 |
+
"python-sdk/fastmcp-utilities-components",
|
| 252 |
+
"python-sdk/fastmcp-utilities-exceptions",
|
| 253 |
+
"python-sdk/fastmcp-utilities-http",
|
| 254 |
+
"python-sdk/fastmcp-utilities-json_schema",
|
| 255 |
+
"python-sdk/fastmcp-utilities-logging",
|
| 256 |
+
"python-sdk/fastmcp-utilities-mcp_config",
|
| 257 |
+
"python-sdk/fastmcp-utilities-openapi",
|
| 258 |
+
"python-sdk/fastmcp-utilities-types"
|
| 259 |
+
]
|
| 260 |
+
}
|
| 261 |
+
]
|
| 262 |
+
}
|
| 263 |
+
]
|
| 264 |
+
},
|
| 265 |
+
"redirects": [
|
| 266 |
+
{
|
| 267 |
+
"destination": "/servers/proxy",
|
| 268 |
+
"source": "/patterns/proxy"
|
| 269 |
},
|
| 270 |
+
{
|
| 271 |
+
"destination": "/servers/composition",
|
| 272 |
+
"source": "/patterns/composition"
|
| 273 |
+
}
|
| 274 |
+
],
|
| 275 |
+
"search": {
|
| 276 |
+
"prompt": "Search the docs..."
|
| 277 |
+
},
|
| 278 |
+
"theme": "mint"
|
| 279 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/python-sdk/fastmcp-cli-__init__.mdx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
FastMCP CLI package.
|
docs/python-sdk/fastmcp-cli-claude.mdx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: claude
|
| 3 |
+
sidebarTitle: claude
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.claude`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Claude app integration utilities.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `get_claude_config_path`
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
get_claude_config_path() -> Path | None
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Get the Claude config directory based on platform.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
### `update_claude_config`
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
update_claude_config(file_spec: str, server_name: str) -> bool
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Add or update a FastMCP server in Claude's configuration.
|
| 31 |
+
|
| 32 |
+
**Args:**
|
| 33 |
+
- `file_spec`: Path to the server file, optionally with :object suffix
|
| 34 |
+
- `server_name`: Name for the server in Claude's config
|
| 35 |
+
- `with_editable`: Optional directory to install in editable mode
|
| 36 |
+
- `with_packages`: Optional list of additional packages to install
|
| 37 |
+
- `env_vars`: Optional dictionary of environment variables. These are merged with
|
| 38 |
+
any existing variables, with new values taking precedence.
|
| 39 |
+
|
| 40 |
+
**Raises:**
|
| 41 |
+
- `RuntimeError`: If Claude Desktop's config directory is not found, indicating
|
| 42 |
+
Claude Desktop may not be installed or properly set up.
|
| 43 |
+
|
docs/python-sdk/fastmcp-cli-cli.mdx
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: cli
|
| 3 |
+
sidebarTitle: cli
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.cli`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
FastMCP CLI tools.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `version`
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
version(ctx: Context)
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
### `dev`
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
dev(server_spec: str = typer.Argument(..., help='Python file to run, optionally with :object suffix'), with_editable: Annotated[Path | None, typer.Option('--with-editable', '-e', help='Directory containing pyproject.toml to install in editable mode', exists=True, file_okay=False, resolve_path=True)] = None, with_packages: Annotated[list[str], typer.Option('--with', help='Additional packages to install')] = [], inspector_version: Annotated[str | None, typer.Option('--inspector-version', help='Version of the MCP Inspector to use')] = None, ui_port: Annotated[int | None, typer.Option('--ui-port', help='Port for the MCP Inspector UI')] = None, server_port: Annotated[int | None, typer.Option('--server-port', help='Port for the MCP Inspector Proxy server')] = None) -> None
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Run a MCP server with the MCP Inspector.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
### `run`
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
run(ctx: typer.Context, server_spec: str = typer.Argument(..., help='Python file, object specification (file:obj), or URL'), transport: Annotated[str | None, typer.Option('--transport', '-t', help='Transport protocol to use (stdio, streamable-http, or sse)')] = None, host: Annotated[str | None, typer.Option('--host', help='Host to bind to when using http transport (default: 127.0.0.1)')] = None, port: Annotated[int | None, typer.Option('--port', '-p', help='Port to bind to when using http transport (default: 8000)')] = None, log_level: Annotated[str | None, typer.Option('--log-level', '-l', help='Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)')] = None) -> None
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Run a MCP server or connect to a remote one.
|
| 37 |
+
|
| 38 |
+
The server can be specified in three ways:
|
| 39 |
+
1. Module approach: server.py - runs the module directly, looking for an object named mcp/server/app.
|
| 40 |
+
|
| 41 |
+
2. Import approach: server.py:app - imports and runs the specified server object.
|
| 42 |
+
|
| 43 |
+
3. URL approach: http://server-url - connects to a remote server and creates a proxy.
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Note: This command runs the server directly. You are responsible for ensuring
|
| 48 |
+
all dependencies are available.
|
| 49 |
+
|
| 50 |
+
Server arguments can be passed after -- :
|
| 51 |
+
fastmcp run server.py -- --config config.json --debug
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
### `install`
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
install(server_spec: str = typer.Argument(..., help='Python file to run, optionally with :object suffix'), server_name: Annotated[str | None, typer.Option('--name', '-n', help="Custom name for the server (defaults to server's name attribute or file name)")] = None, with_editable: Annotated[Path | None, typer.Option('--with-editable', '-e', help='Directory containing pyproject.toml to install in editable mode', exists=True, file_okay=False, resolve_path=True)] = None, with_packages: Annotated[list[str], typer.Option('--with', help='Additional packages to install')] = [], env_vars: Annotated[list[str], typer.Option('--env-var', '-v', help='Environment variables in KEY=VALUE format')] = [], env_file: Annotated[Path | None, typer.Option('--env-file', '-f', help='Load environment variables from a .env file', exists=True, file_okay=True, dir_okay=False, resolve_path=True)] = None) -> None
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Install a MCP server in the Claude desktop app.
|
| 62 |
+
|
| 63 |
+
Environment variables are preserved once added and only updated if new values
|
| 64 |
+
are explicitly provided.
|
| 65 |
+
|
docs/python-sdk/fastmcp-cli-run.mdx
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: run
|
| 3 |
+
sidebarTitle: run
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.cli.run`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
FastMCP run command implementation.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `is_url`
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
is_url(path: str) -> bool
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Check if a string is a URL.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
### `parse_file_path`
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
parse_file_path(server_spec: str) -> tuple[Path, str | None]
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Parse a file path that may include a server object specification.
|
| 31 |
+
|
| 32 |
+
**Args:**
|
| 33 |
+
- `server_spec`: Path to file, optionally with :object suffix
|
| 34 |
+
|
| 35 |
+
**Returns:**
|
| 36 |
+
- Tuple of (file_path, server_object)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
### `import_server`
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import_server(file: Path, server_object: str | None = None) -> Any
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Import a MCP server from a file.
|
| 47 |
+
|
| 48 |
+
**Args:**
|
| 49 |
+
- `file`: Path to the file
|
| 50 |
+
- `server_object`: Optional object name in format "module:object" or just "object"
|
| 51 |
+
|
| 52 |
+
**Returns:**
|
| 53 |
+
- The server object
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
### `create_client_server`
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
create_client_server(url: str) -> Any
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Create a FastMCP server from a client URL.
|
| 64 |
+
|
| 65 |
+
**Args:**
|
| 66 |
+
- `url`: The URL to connect to
|
| 67 |
+
|
| 68 |
+
**Returns:**
|
| 69 |
+
- A FastMCP server instance
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
### `import_server_with_args`
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
import_server_with_args(file: Path, server_object: str | None = None, server_args: list[str] | None = None) -> Any
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
Import a server with optional command line arguments.
|
| 80 |
+
|
| 81 |
+
**Args:**
|
| 82 |
+
- `file`: Path to the server file
|
| 83 |
+
- `server_object`: Optional server object name
|
| 84 |
+
- `server_args`: Optional command line arguments to inject
|
| 85 |
+
|
| 86 |
+
**Returns:**
|
| 87 |
+
- The imported server object
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
### `run_command`
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
run_command(server_spec: str, transport: str | None = None, host: str | None = None, port: int | None = None, log_level: str | None = None, server_args: list[str] | None = None) -> None
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
Run a MCP server or connect to a remote one.
|
| 98 |
+
|
| 99 |
+
**Args:**
|
| 100 |
+
- `server_spec`: Python file, object specification (file:obj), or URL
|
| 101 |
+
- `transport`: Transport protocol to use
|
| 102 |
+
- `host`: Host to bind to when using http transport
|
| 103 |
+
- `port`: Port to bind to when using http transport
|
| 104 |
+
- `log_level`: Log level
|
| 105 |
+
- `server_args`: Additional arguments to pass to the server
|
| 106 |
+
|
docs/python-sdk/fastmcp-client-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-client-auth-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.auth`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-client-auth-bearer.mdx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: bearer
|
| 3 |
+
sidebarTitle: bearer
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.auth.bearer`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `BearerAuth`
|
| 11 |
+
|
| 12 |
+
**Methods:**
|
| 13 |
+
|
| 14 |
+
#### `auth_flow`
|
| 15 |
+
|
| 16 |
+
```python
|
| 17 |
+
auth_flow(self, request)
|
| 18 |
+
```
|
docs/python-sdk/fastmcp-client-auth-oauth.mdx
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: oauth
|
| 3 |
+
sidebarTitle: oauth
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.auth.oauth`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `default_cache_dir`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
default_cache_dir() -> Path
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### `OAuth`
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
OAuth(mcp_url: str, scopes: str | list[str] | None = None, client_name: str = 'FastMCP Client', token_storage_cache_dir: Path | None = None, additional_client_metadata: dict[str, Any] | None = None) -> _MCPOAuthClientProvider
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Create an OAuthClientProvider for an MCP server.
|
| 24 |
+
|
| 25 |
+
This is intended to be provided to the `auth` parameter of an
|
| 26 |
+
httpx.AsyncClient (or appropriate FastMCP client/transport instance)
|
| 27 |
+
|
| 28 |
+
**Args:**
|
| 29 |
+
- `mcp_url`: Full URL to the MCP endpoint (e.g.,
|
| 30 |
+
- `"http`: //host/mcp/sse")
|
| 31 |
+
- `scopes`: OAuth scopes to request. Can be a
|
| 32 |
+
- `client_name`: Name for this client during registration
|
| 33 |
+
- `token_storage_cache_dir`: Directory for FileTokenStorage
|
| 34 |
+
- `additional_client_metadata`: Extra fields for OAuthClientMetadata
|
| 35 |
+
|
| 36 |
+
**Returns:**
|
| 37 |
+
- OAuthClientProvider
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
## Classes
|
| 41 |
+
|
| 42 |
+
### `ServerOAuthMetadata`
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
More flexible OAuth metadata model that accepts broader ranges of values
|
| 46 |
+
than the restrictive MCP standard model.
|
| 47 |
+
|
| 48 |
+
This handles real-world OAuth servers like PayPal that may support
|
| 49 |
+
additional methods not in the MCP specification.
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
### `OAuthClientProvider`
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
OAuth client provider with more flexible OAuth metadata discovery.
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
### `FileTokenStorage`
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
File-based token storage implementation for OAuth credentials and tokens.
|
| 62 |
+
Implements the mcp.client.auth.TokenStorage protocol.
|
| 63 |
+
|
| 64 |
+
Each instance is tied to a specific server URL for proper token isolation.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
**Methods:**
|
| 68 |
+
|
| 69 |
+
#### `get_base_url`
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
get_base_url(url: str) -> str
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Extract the base URL (scheme + host) from a URL.
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
#### `get_cache_key`
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
get_cache_key(self) -> str
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
Generate a safe filesystem key from the server's base URL.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
#### `clear`
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
clear(self) -> None
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
Clear all cached data for this server.
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
#### `clear_all`
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
clear_all(cls, cache_dir: Path | None = None) -> None
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
Clear all cached data for all servers.
|
| 103 |
+
|
docs/python-sdk/fastmcp-client-client.mdx
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: client
|
| 3 |
+
sidebarTitle: client
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.client`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `Client`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
MCP client that delegates connection management to a Transport instance.
|
| 15 |
+
|
| 16 |
+
The Client class is responsible for MCP protocol logic, while the Transport
|
| 17 |
+
handles connection establishment and management. Client provides methods for
|
| 18 |
+
working with resources, prompts, tools and other MCP capabilities.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
transport: Connection source specification, which can be:
|
| 22 |
+
- ClientTransport: Direct transport instance
|
| 23 |
+
- FastMCP: In-process FastMCP server
|
| 24 |
+
- AnyUrl | str: URL to connect to
|
| 25 |
+
- Path: File path for local socket
|
| 26 |
+
- MCPConfig: MCP server configuration
|
| 27 |
+
- dict: Transport configuration
|
| 28 |
+
roots: Optional RootsList or RootsHandler for filesystem access
|
| 29 |
+
sampling_handler: Optional handler for sampling requests
|
| 30 |
+
log_handler: Optional handler for log messages
|
| 31 |
+
message_handler: Optional handler for protocol messages
|
| 32 |
+
progress_handler: Optional handler for progress notifications
|
| 33 |
+
timeout: Optional timeout for requests (seconds or timedelta)
|
| 34 |
+
init_timeout: Optional timeout for initial connection (seconds or timedelta).
|
| 35 |
+
Set to 0 to disable. If None, uses the value in the FastMCP global settings.
|
| 36 |
+
|
| 37 |
+
Examples:
|
| 38 |
+
```python # Connect to FastMCP server client =
|
| 39 |
+
Client("http://localhost:8080")
|
| 40 |
+
|
| 41 |
+
async with client:
|
| 42 |
+
# List available resources resources = await client.list_resources()
|
| 43 |
+
|
| 44 |
+
# Call a tool result = await client.call_tool("my_tool", {"param":
|
| 45 |
+
"value"})
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
**Methods:**
|
| 50 |
+
|
| 51 |
+
#### `session`
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
session(self) -> ClientSession
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Get the current active session. Raises RuntimeError if not connected.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
#### `initialize_result`
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
initialize_result(self) -> mcp.types.InitializeResult
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
Get the result of the initialization request.
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
#### `set_roots`
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
set_roots(self, roots: RootsList | RootsHandler) -> None
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Set the roots for the client. This does not automatically call `send_roots_list_changed`.
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
#### `set_sampling_callback`
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
set_sampling_callback(self, sampling_callback: SamplingHandler) -> None
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
Set the sampling callback for the client.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
#### `is_connected`
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
is_connected(self) -> bool
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
Check if the client is currently connected.
|
| 94 |
+
|
docs/python-sdk/fastmcp-client-logging.mdx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: logging
|
| 3 |
+
sidebarTitle: logging
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.logging`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `create_log_callback`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
create_log_callback(handler: LogHandler | None = None) -> LoggingFnT
|
| 14 |
+
```
|
docs/python-sdk/fastmcp-client-oauth_callback.mdx
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: oauth_callback
|
| 3 |
+
sidebarTitle: oauth_callback
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.oauth_callback`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
OAuth callback server for handling authorization code flows.
|
| 11 |
+
|
| 12 |
+
This module provides a reusable callback server that can handle OAuth redirects
|
| 13 |
+
and display styled responses to users.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
## Functions
|
| 17 |
+
|
| 18 |
+
### `create_callback_html`
|
| 19 |
+
|
| 20 |
+
```python
|
| 21 |
+
create_callback_html(message: str, is_success: bool = True, title: str = 'FastMCP OAuth', server_url: str | None = None) -> str
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Create a styled HTML response for OAuth callbacks.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
### `create_oauth_callback_server`
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
create_oauth_callback_server(port: int, callback_path: str = '/callback', server_url: str | None = None, response_future: asyncio.Future | None = None) -> Server
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Create an OAuth callback server.
|
| 36 |
+
|
| 37 |
+
**Args:**
|
| 38 |
+
- `port`: The port to run the server on
|
| 39 |
+
- `callback_path`: The path to listen for OAuth redirects on
|
| 40 |
+
- `server_url`: Optional server URL to display in success messages
|
| 41 |
+
- `response_future`: Optional future to resolve when OAuth callback is received
|
| 42 |
+
|
| 43 |
+
**Returns:**
|
| 44 |
+
- Configured uvicorn Server instance (not yet running)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
## Classes
|
| 48 |
+
|
| 49 |
+
### `CallbackResponse`
|
| 50 |
+
|
| 51 |
+
**Methods:**
|
| 52 |
+
|
| 53 |
+
#### `from_dict`
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
from_dict(cls, data: dict[str, str]) -> CallbackResponse
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
#### `to_dict`
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
to_dict(self) -> dict[str, str]
|
| 63 |
+
```
|
docs/python-sdk/fastmcp-client-progress.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: progress
|
| 3 |
+
sidebarTitle: progress
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.progress`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-client-roots.mdx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: roots
|
| 3 |
+
sidebarTitle: roots
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.roots`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `convert_roots_list`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
convert_roots_list(roots: RootsList) -> list[mcp.types.Root]
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### `create_roots_callback`
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
create_roots_callback(handler: RootsList | RootsHandler) -> ListRootsFnT
|
| 20 |
+
```
|
docs/python-sdk/fastmcp-client-sampling.mdx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: sampling
|
| 3 |
+
sidebarTitle: sampling
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.sampling`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `create_sampling_callback`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
create_sampling_callback(sampling_handler: SamplingHandler) -> SamplingFnT
|
| 14 |
+
```
|
docs/python-sdk/fastmcp-client-transports.mdx
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: transports
|
| 3 |
+
sidebarTitle: transports
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.client.transports`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `infer_transport`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
infer_transport(transport: ClientTransport | FastMCP | FastMCP1Server | AnyUrl | Path | MCPConfig | dict[str, Any] | str) -> ClientTransport
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
Infer the appropriate transport type from the given transport argument.
|
| 19 |
+
|
| 20 |
+
This function attempts to infer the correct transport type from the provided
|
| 21 |
+
argument, handling various input types and converting them to the appropriate
|
| 22 |
+
ClientTransport subclass.
|
| 23 |
+
|
| 24 |
+
The function supports these input types:
|
| 25 |
+
- ClientTransport: Used directly without modification
|
| 26 |
+
- FastMCP or FastMCP1Server: Creates an in-memory FastMCPTransport
|
| 27 |
+
- Path or str (file path): Creates PythonStdioTransport (.py) or NodeStdioTransport (.js)
|
| 28 |
+
- AnyUrl or str (URL): Creates StreamableHttpTransport (default) or SSETransport (for /sse endpoints)
|
| 29 |
+
- MCPConfig or dict: Creates MCPConfigTransport, potentially connecting to multiple servers
|
| 30 |
+
|
| 31 |
+
For HTTP URLs, they are assumed to be Streamable HTTP URLs unless they end in `/sse`.
|
| 32 |
+
|
| 33 |
+
For MCPConfig with multiple servers, a composite client is created where each server
|
| 34 |
+
is mounted with its name as prefix. This allows accessing tools and resources from multiple
|
| 35 |
+
servers through a single unified client interface, using naming patterns like
|
| 36 |
+
`servername_toolname` for tools and `protocol://servername/path` for resources.
|
| 37 |
+
If the MCPConfig contains only one server, a direct connection is established without prefixing.
|
| 38 |
+
|
| 39 |
+
Examples:
|
| 40 |
+
```python
|
| 41 |
+
# Connect to a local Python script
|
| 42 |
+
transport = infer_transport("my_script.py")
|
| 43 |
+
|
| 44 |
+
# Connect to a remote server via HTTP
|
| 45 |
+
transport = infer_transport("http://example.com/mcp")
|
| 46 |
+
|
| 47 |
+
# Connect to multiple servers using MCPConfig
|
| 48 |
+
config = {
|
| 49 |
+
"mcpServers": {
|
| 50 |
+
"weather": {"url": "http://weather.example.com/mcp"},
|
| 51 |
+
"calendar": {"url": "http://calendar.example.com/mcp"}
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
transport = infer_transport(config)
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
## Classes
|
| 59 |
+
|
| 60 |
+
### `SessionKwargs`
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Keyword arguments for the MCP ClientSession constructor.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
### `ClientTransport`
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Abstract base class for different MCP client transport mechanisms.
|
| 70 |
+
|
| 71 |
+
A Transport is responsible for establishing and managing connections
|
| 72 |
+
to an MCP server, and providing a ClientSession within an async context.
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
### `WSTransport`
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
Transport implementation that connects to an MCP server via WebSockets.
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
### `SSETransport`
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
Transport implementation that connects to an MCP server via Server-Sent Events.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
### `StreamableHttpTransport`
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
Transport implementation that connects to an MCP server via Streamable HTTP Requests.
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
### `StdioTransport`
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
Base transport for connecting to an MCP server via subprocess with stdio.
|
| 97 |
+
|
| 98 |
+
This is a base class that can be subclassed for specific command-based
|
| 99 |
+
transports like Python, Node, Uvx, etc.
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
### `PythonStdioTransport`
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
Transport for running Python scripts.
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
### `FastMCPStdioTransport`
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
Transport for running FastMCP servers using the FastMCP CLI.
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
### `NodeStdioTransport`
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
Transport for running Node.js scripts.
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
### `UvxStdioTransport`
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
Transport for running commands via the uvx tool.
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
### `NpxStdioTransport`
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
Transport for running commands via the npx tool.
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
### `FastMCPTransport`
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
In-memory transport for FastMCP servers.
|
| 136 |
+
|
| 137 |
+
This transport connects directly to a FastMCP server instance in the same
|
| 138 |
+
Python process. It works with both FastMCP 2.x servers and FastMCP 1.0
|
| 139 |
+
servers from the low-level MCP SDK. This is particularly useful for unit
|
| 140 |
+
tests or scenarios where client and server run in the same runtime.
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
### `MCPConfigTransport`
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
Transport for connecting to one or more MCP servers defined in an MCPConfig.
|
| 147 |
+
|
| 148 |
+
This transport provides a unified interface to multiple MCP servers defined in an MCPConfig
|
| 149 |
+
object or dictionary matching the MCPConfig schema. It supports two key scenarios:
|
| 150 |
+
|
| 151 |
+
1. If the MCPConfig contains exactly one server, it creates a direct transport to that server.
|
| 152 |
+
2. If the MCPConfig contains multiple servers, it creates a composite client by mounting
|
| 153 |
+
all servers on a single FastMCP instance, with each server's name used as its mounting prefix.
|
| 154 |
+
|
| 155 |
+
In the multi-server case, tools are accessible with the prefix pattern `{server_name}_{tool_name}`
|
| 156 |
+
and resources with the pattern `protocol://{server_name}/path/to/resource`.
|
| 157 |
+
|
| 158 |
+
This is particularly useful for creating clients that need to interact with multiple specialized
|
| 159 |
+
MCP servers through a single interface, simplifying client code.
|
| 160 |
+
|
| 161 |
+
Examples:
|
| 162 |
+
```python
|
| 163 |
+
from fastmcp import Client
|
| 164 |
+
from fastmcp.utilities.mcp_config import MCPConfig
|
| 165 |
+
|
| 166 |
+
# Create a config with multiple servers
|
| 167 |
+
config = {
|
| 168 |
+
"mcpServers": {
|
| 169 |
+
"weather": {
|
| 170 |
+
"url": "https://weather-api.example.com/mcp",
|
| 171 |
+
"transport": "streamable-http"
|
| 172 |
+
},
|
| 173 |
+
"calendar": {
|
| 174 |
+
"url": "https://calendar-api.example.com/mcp",
|
| 175 |
+
"transport": "streamable-http"
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
# Create a client with the config
|
| 181 |
+
client = Client(config)
|
| 182 |
+
|
| 183 |
+
async with client:
|
| 184 |
+
# Access tools with prefixes
|
| 185 |
+
weather = await client.call_tool("weather_get_forecast", {"city": "London"})
|
| 186 |
+
events = await client.call_tool("calendar_list_events", {"date": "2023-06-01"})
|
| 187 |
+
|
| 188 |
+
# Access resources with prefixed URIs
|
| 189 |
+
icons = await client.read_resource("weather://weather/icons/sunny")
|
| 190 |
+
```
|
| 191 |
+
|
docs/python-sdk/fastmcp-exceptions.mdx
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: exceptions
|
| 3 |
+
sidebarTitle: exceptions
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.exceptions`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Custom exceptions for FastMCP.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `FastMCPError`
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Base error for FastMCP.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
### `ValidationError`
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Error in validating parameters or return values.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
### `ResourceError`
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Error in resource operations.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
### `ToolError`
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Error in tool operations.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
### `PromptError`
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Error in prompt operations.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
### `InvalidSignature`
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Invalid signature for use with FastMCP.
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
### `ClientError`
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Error in client operations.
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
### `NotFoundError`
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Object not found.
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
### `DisabledError`
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Object is disabled.
|
| 65 |
+
|
docs/python-sdk/fastmcp-prompts-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.prompts`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-prompts-prompt.mdx
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: prompt
|
| 3 |
+
sidebarTitle: prompt
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.prompts.prompt`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Base classes for FastMCP prompts.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `Message`
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
Message(content: str | MCPContent, role: Role | None = None, **kwargs: Any) -> PromptMessage
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
A user-friendly constructor for PromptMessage.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
## Classes
|
| 24 |
+
|
| 25 |
+
### `PromptArgument`
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
An argument that can be passed to a prompt.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
### `Prompt`
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
A prompt template that can be rendered with parameters.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
**Methods:**
|
| 38 |
+
|
| 39 |
+
#### `to_mcp_prompt`
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
to_mcp_prompt(self, **overrides: Any) -> MCPPrompt
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
Convert the prompt to an MCP prompt.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
#### `from_function`
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from_function(fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
Create a Prompt from a function.
|
| 55 |
+
|
| 56 |
+
The function can return:
|
| 57 |
+
- A string (converted to a message)
|
| 58 |
+
- A Message object
|
| 59 |
+
- A dict (converted to a message)
|
| 60 |
+
- A sequence of any of the above
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
### `FunctionPrompt`
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
A prompt that is a function.
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
**Methods:**
|
| 70 |
+
|
| 71 |
+
#### `from_function`
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
from_function(cls, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionPrompt
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
Create a Prompt from a function.
|
| 78 |
+
|
| 79 |
+
The function can return:
|
| 80 |
+
- A string (converted to a message)
|
| 81 |
+
- A Message object
|
| 82 |
+
- A dict (converted to a message)
|
| 83 |
+
- A sequence of any of the above
|
| 84 |
+
|
docs/python-sdk/fastmcp-prompts-prompt_manager.mdx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: prompt_manager
|
| 3 |
+
sidebarTitle: prompt_manager
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.prompts.prompt_manager`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `PromptManager`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Manages FastMCP prompts.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
**Methods:**
|
| 17 |
+
|
| 18 |
+
#### `mount`
|
| 19 |
+
|
| 20 |
+
```python
|
| 21 |
+
mount(self, server: MountedServer) -> None
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
Adds a mounted server as a source for prompts.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
#### `add_prompt_from_fn`
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
add_prompt_from_fn(self, fn: Callable[..., PromptResult | Awaitable[PromptResult]], name: str | None = None, description: str | None = None, tags: set[str] | None = None) -> FunctionPrompt
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Create a prompt from a function.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
#### `add_prompt`
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
add_prompt(self, prompt: Prompt) -> Prompt
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Add a prompt to the manager.
|
| 43 |
+
|
docs/python-sdk/fastmcp-resources-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.resources`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-resources-resource.mdx
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: resource
|
| 3 |
+
sidebarTitle: resource
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.resources.resource`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Base classes and interfaces for FastMCP resources.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `Resource`
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Base class for all resources.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
**Methods:**
|
| 20 |
+
|
| 21 |
+
#### `from_function`
|
| 22 |
+
|
| 23 |
+
```python
|
| 24 |
+
from_function(fn: Callable[[], Any], uri: str | AnyUrl, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResource
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
#### `set_default_mime_type`
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
set_default_mime_type(cls, mime_type: str | None) -> str
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Set default MIME type if not provided.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
#### `set_default_name`
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
set_default_name(self) -> Self
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Set default name from URI if not provided.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#### `to_mcp_resource`
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
to_mcp_resource(self, **overrides: Any) -> MCPResource
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Convert the resource to an MCPResource.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
#### `key`
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
key(self) -> str
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
The key of the component. This is used for internal bookkeeping
|
| 61 |
+
and may reflect e.g. prefixes or other identifiers. You should not depend on
|
| 62 |
+
keys having a certain value, as the same tool loaded from different
|
| 63 |
+
hierarchies of servers may have different keys.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
### `FunctionResource`
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
A resource that defers data loading by wrapping a function.
|
| 70 |
+
|
| 71 |
+
The function is only called when the resource is read, allowing for lazy loading
|
| 72 |
+
of potentially expensive data. This is particularly useful when listing resources,
|
| 73 |
+
as the function won't be called until the resource is actually accessed.
|
| 74 |
+
|
| 75 |
+
The function can return:
|
| 76 |
+
- str for text content (default)
|
| 77 |
+
- bytes for binary content
|
| 78 |
+
- other types will be converted to JSON
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
**Methods:**
|
| 82 |
+
|
| 83 |
+
#### `from_function`
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
from_function(cls, fn: Callable[[], Any], uri: str | AnyUrl, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResource
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
Create a FunctionResource from a function.
|
| 90 |
+
|
docs/python-sdk/fastmcp-resources-resource_manager.mdx
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: resource_manager
|
| 3 |
+
sidebarTitle: resource_manager
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.resources.resource_manager`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Resource manager functionality.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `ResourceManager`
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Manages FastMCP resources.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
**Methods:**
|
| 20 |
+
|
| 21 |
+
#### `mount`
|
| 22 |
+
|
| 23 |
+
```python
|
| 24 |
+
mount(self, server: MountedServer) -> None
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
Adds a mounted server as a source for resources and templates.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
#### `add_resource_or_template_from_fn`
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
add_resource_or_template_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource | ResourceTemplate
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
Add a resource or template to the manager from a function.
|
| 37 |
+
|
| 38 |
+
**Args:**
|
| 39 |
+
- `fn`: The function to register as a resource or template
|
| 40 |
+
- `uri`: The URI for the resource or template
|
| 41 |
+
- `name`: Optional name for the resource or template
|
| 42 |
+
- `description`: Optional description of the resource or template
|
| 43 |
+
- `mime_type`: Optional MIME type for the resource or template
|
| 44 |
+
- `tags`: Optional set of tags for categorizing the resource or template
|
| 45 |
+
|
| 46 |
+
**Returns:**
|
| 47 |
+
- The added resource or template. If a resource or template with the same URI already exists,
|
| 48 |
+
- returns the existing resource or template.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
#### `add_resource_from_fn`
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
add_resource_from_fn(self, fn: Callable[..., Any], uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> Resource
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Add a resource to the manager from a function.
|
| 58 |
+
|
| 59 |
+
**Args:**
|
| 60 |
+
- `fn`: The function to register as a resource
|
| 61 |
+
- `uri`: The URI for the resource
|
| 62 |
+
- `name`: Optional name for the resource
|
| 63 |
+
- `description`: Optional description of the resource
|
| 64 |
+
- `mime_type`: Optional MIME type for the resource
|
| 65 |
+
- `tags`: Optional set of tags for categorizing the resource
|
| 66 |
+
|
| 67 |
+
**Returns:**
|
| 68 |
+
- The added resource. If a resource with the same URI already exists,
|
| 69 |
+
- returns the existing resource.
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
#### `add_resource`
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
add_resource(self, resource: Resource) -> Resource
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
Add a resource to the manager.
|
| 79 |
+
|
| 80 |
+
**Args:**
|
| 81 |
+
- `resource`: A Resource instance to add. The resource's .key attribute
|
| 82 |
+
will be used as the storage key. To overwrite it, call
|
| 83 |
+
Resource.with_key() before calling this method.
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
#### `add_template_from_fn`
|
| 87 |
+
|
| 88 |
+
```python
|
| 89 |
+
add_template_from_fn(self, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> ResourceTemplate
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
Create a template from a function.
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
#### `add_template`
|
| 96 |
+
|
| 97 |
+
```python
|
| 98 |
+
add_template(self, template: ResourceTemplate) -> ResourceTemplate
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
Add a template to the manager.
|
| 102 |
+
|
| 103 |
+
**Args:**
|
| 104 |
+
- `template`: A ResourceTemplate instance to add. The template's .key attribute
|
| 105 |
+
will be used as the storage key. To overwrite it, call
|
| 106 |
+
ResourceTemplate.with_key() before calling this method.
|
| 107 |
+
|
| 108 |
+
**Returns:**
|
| 109 |
+
- The added template. If a template with the same URI already exists,
|
| 110 |
+
- returns the existing template.
|
| 111 |
+
|
docs/python-sdk/fastmcp-resources-template.mdx
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: template
|
| 3 |
+
sidebarTitle: template
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.resources.template`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Resource template functionality.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `build_regex`
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
build_regex(template: str) -> re.Pattern
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
### `match_uri_template`
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
match_uri_template(uri: str, uri_template: str) -> dict[str, str] | None
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## Classes
|
| 26 |
+
|
| 27 |
+
### `ResourceTemplate`
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
A template for dynamically creating resources.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
**Methods:**
|
| 34 |
+
|
| 35 |
+
#### `from_function`
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
from_function(fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
#### `set_default_mime_type`
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
set_default_mime_type(cls, mime_type: str | None) -> str
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Set default MIME type if not provided.
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
#### `matches`
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
matches(self, uri: str) -> dict[str, Any] | None
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
Check if URI matches template and extract parameters.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
#### `to_mcp_template`
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
Convert the resource template to an MCPResourceTemplate.
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
#### `from_mcp_template`
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
from_mcp_template(cls, mcp_template: MCPResourceTemplate) -> ResourceTemplate
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
Creates a FastMCP ResourceTemplate from a raw MCP ResourceTemplate object.
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
#### `key`
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
key(self) -> str
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
The key of the component. This is used for internal bookkeeping
|
| 84 |
+
and may reflect e.g. prefixes or other identifiers. You should not depend on
|
| 85 |
+
keys having a certain value, as the same tool loaded from different
|
| 86 |
+
hierarchies of servers may have different keys.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
### `FunctionResourceTemplate`
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
A template for dynamically creating resources.
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
**Methods:**
|
| 96 |
+
|
| 97 |
+
#### `from_function`
|
| 98 |
+
|
| 99 |
+
```python
|
| 100 |
+
from_function(cls, fn: Callable[..., Any], uri_template: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None, enabled: bool | None = None) -> FunctionResourceTemplate
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
Create a template from a function.
|
| 104 |
+
|
docs/python-sdk/fastmcp-resources-types.mdx
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: types
|
| 3 |
+
sidebarTitle: types
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.resources.types`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Concrete resource implementations.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `TextResource`
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
A resource that reads from a string.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
### `BinaryResource`
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
A resource that reads from bytes.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
### `FileResource`
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
A resource that reads from a file.
|
| 29 |
+
|
| 30 |
+
Set is_binary=True to read file as binary data instead of text.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
**Methods:**
|
| 34 |
+
|
| 35 |
+
#### `validate_absolute_path`
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
validate_absolute_path(cls, path: Path) -> Path
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
Ensure path is absolute.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
#### `set_binary_from_mime_type`
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
Set is_binary based on mime_type if not explicitly set.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
### `HttpResource`
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
A resource that reads from an HTTP endpoint.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
### `DirectoryResource`
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
A resource that lists files in a directory.
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
**Methods:**
|
| 66 |
+
|
| 67 |
+
#### `validate_absolute_path`
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
validate_absolute_path(cls, path: Path) -> Path
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
Ensure path is absolute.
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
#### `list_files`
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
list_files(self) -> list[Path]
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
List files in the directory.
|
| 83 |
+
|
docs/python-sdk/fastmcp-server-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-server-auth-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-server-auth-auth.mdx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: auth
|
| 3 |
+
sidebarTitle: auth
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth.auth`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `OAuthProvider`
|
docs/python-sdk/fastmcp-server-auth-providers-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth.providers`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-server-auth-providers-bearer.mdx
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: bearer
|
| 3 |
+
sidebarTitle: bearer
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth.providers.bearer`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `JWKData`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
JSON Web Key data structure.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
### `JWKSData`
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
JSON Web Key Set data structure.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
### `RSAKeyPair`
|
| 23 |
+
|
| 24 |
+
**Methods:**
|
| 25 |
+
|
| 26 |
+
#### `generate`
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
generate(cls) -> 'RSAKeyPair'
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
Generate an RSA key pair for testing.
|
| 33 |
+
|
| 34 |
+
**Returns:**
|
| 35 |
+
- (private_key_pem, public_key_pem)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
#### `create_token`
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
create_token(self, subject: str = 'fastmcp-user', issuer: str = 'https://fastmcp.example.com', audience: str | None = None, scopes: list[str] | None = None, expires_in_seconds: int = 3600, additional_claims: dict[str, Any] | None = None, kid: str | None = None) -> str
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Generate a test JWT token for testing purposes.
|
| 45 |
+
|
| 46 |
+
**Args:**
|
| 47 |
+
- `private_key_pem`: RSA private key in PEM format
|
| 48 |
+
- `subject`: Subject claim (usually user ID)
|
| 49 |
+
- `issuer`: Issuer claim
|
| 50 |
+
- `audience`: Audience claim (optional)
|
| 51 |
+
- `scopes`: List of scopes to include
|
| 52 |
+
- `expires_in_seconds`: Token expiration time in seconds
|
| 53 |
+
- `additional_claims`: Any additional claims to include
|
| 54 |
+
- `kid`: Key ID for JWKS lookup (optional)
|
| 55 |
+
|
| 56 |
+
**Returns:**
|
| 57 |
+
- Signed JWT token string
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
### `BearerAuthProvider`
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Simple JWT Bearer Token validator for hosted MCP servers.
|
| 64 |
+
Uses RS256 asymmetric encryption. Supports either static public key
|
| 65 |
+
or JWKS URI for key rotation.
|
| 66 |
+
|
| 67 |
+
Note that this provider DOES NOT permit client registration or revocation, or any OAuth flows.
|
| 68 |
+
It is intended to be used with a control plane that manages clients and tokens.
|
| 69 |
+
|
docs/python-sdk/fastmcp-server-auth-providers-bearer_env.mdx
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: bearer_env
|
| 3 |
+
sidebarTitle: bearer_env
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth.providers.bearer_env`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `EnvBearerAuthProviderSettings`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Settings for the BearerAuthProvider.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
### `EnvBearerAuthProvider`
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
A BearerAuthProvider that loads settings from environment variables. Any
|
| 20 |
+
providing setting will always take precedence over the environment
|
| 21 |
+
variables.
|
| 22 |
+
|
docs/python-sdk/fastmcp-server-auth-providers-in_memory.mdx
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: in_memory
|
| 3 |
+
sidebarTitle: in_memory
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.auth.providers.in_memory`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `InMemoryOAuthProvider`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
An in-memory OAuth provider for testing purposes.
|
| 14 |
+
It simulates the OAuth 2.1 flow locally without external calls.
|
| 15 |
+
|
docs/python-sdk/fastmcp-server-context.mdx
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: context
|
| 3 |
+
sidebarTitle: context
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.context`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `set_context`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
set_context(context: Context) -> Generator[Context, None, None]
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
## Classes
|
| 17 |
+
|
| 18 |
+
### `Context`
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Context object providing access to MCP capabilities.
|
| 22 |
+
|
| 23 |
+
This provides a cleaner interface to MCP's RequestContext functionality.
|
| 24 |
+
It gets injected into tool and resource functions that request it via type hints.
|
| 25 |
+
|
| 26 |
+
To use context in a tool function, add a parameter with the Context type annotation:
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
@server.tool
|
| 30 |
+
def my_tool(x: int, ctx: Context) -> str:
|
| 31 |
+
# Log messages to the client
|
| 32 |
+
ctx.info(f"Processing {x}")
|
| 33 |
+
ctx.debug("Debug info")
|
| 34 |
+
ctx.warning("Warning message")
|
| 35 |
+
ctx.error("Error message")
|
| 36 |
+
|
| 37 |
+
# Report progress
|
| 38 |
+
ctx.report_progress(50, 100, "Processing")
|
| 39 |
+
|
| 40 |
+
# Access resources
|
| 41 |
+
data = ctx.read_resource("resource://data")
|
| 42 |
+
|
| 43 |
+
# Get request info
|
| 44 |
+
request_id = ctx.request_id
|
| 45 |
+
client_id = ctx.client_id
|
| 46 |
+
|
| 47 |
+
return str(x)
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
The context parameter name can be anything as long as it's annotated with Context.
|
| 51 |
+
The context is optional - tools that don't need it can omit the parameter.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
**Methods:**
|
| 55 |
+
|
| 56 |
+
#### `request_context`
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
request_context(self) -> RequestContext
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
Access to the underlying request context.
|
| 63 |
+
|
| 64 |
+
If called outside of a request context, this will raise a ValueError.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
#### `client_id`
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
client_id(self) -> str | None
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
Get the client ID if available.
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
#### `request_id`
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
request_id(self) -> str
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Get the unique ID for this request.
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
#### `session_id`
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
session_id(self) -> str | None
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
Get the MCP session ID for HTTP transports.
|
| 92 |
+
|
| 93 |
+
Returns the session ID that can be used as a key for session-based
|
| 94 |
+
data storage (e.g., Redis) to share data between tool calls within
|
| 95 |
+
the same client session.
|
| 96 |
+
|
| 97 |
+
**Returns:**
|
| 98 |
+
- The session ID for HTTP transports (SSE, StreamableHTTP), or None
|
| 99 |
+
- for stdio and in-memory transports which don't use session IDs.
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
#### `session`
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
session(self)
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
Access to the underlying session for advanced usage.
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
#### `get_http_request`
|
| 112 |
+
|
| 113 |
+
```python
|
| 114 |
+
get_http_request(self) -> Request
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
Get the active starlette request.
|
| 118 |
+
|
docs/python-sdk/fastmcp-server-dependencies.mdx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: dependencies
|
| 3 |
+
sidebarTitle: dependencies
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.dependencies`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `get_context`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
get_context() -> Context
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### `get_http_request`
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
get_http_request() -> Request
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
### `get_http_headers`
|
| 23 |
+
|
| 24 |
+
```python
|
| 25 |
+
get_http_headers(include_all: bool = False) -> dict[str, str]
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Extract headers from the current HTTP request if available.
|
| 30 |
+
|
| 31 |
+
Never raises an exception, even if there is no active HTTP request (in which case
|
| 32 |
+
an empty dict is returned).
|
| 33 |
+
|
| 34 |
+
By default, strips problematic headers like `content-length` that cause issues if forwarded to downstream clients.
|
| 35 |
+
If `include_all` is True, all headers are returned.
|
| 36 |
+
|
docs/python-sdk/fastmcp-server-http.mdx
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: http
|
| 3 |
+
sidebarTitle: http
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.http`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `set_http_request`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
set_http_request(request: Request) -> Generator[Request, None, None]
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### `setup_auth_middleware_and_routes`
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
setup_auth_middleware_and_routes(auth: OAuthProvider) -> tuple[list[Middleware], list[BaseRoute], list[str]]
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Set up authentication middleware and routes if auth is enabled.
|
| 24 |
+
|
| 25 |
+
**Args:**
|
| 26 |
+
- `auth`: The OAuthProvider authorization server provider
|
| 27 |
+
|
| 28 |
+
**Returns:**
|
| 29 |
+
- Tuple of (middleware, auth_routes, required_scopes)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
### `create_base_app`
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
create_base_app(routes: list[BaseRoute], middleware: list[Middleware], debug: bool = False, lifespan: Callable | None = None) -> StarletteWithLifespan
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Create a base Starlette app with common middleware and routes.
|
| 40 |
+
|
| 41 |
+
**Args:**
|
| 42 |
+
- `routes`: List of routes to include in the app
|
| 43 |
+
- `middleware`: List of middleware to include in the app
|
| 44 |
+
- `debug`: Whether to enable debug mode
|
| 45 |
+
- `lifespan`: Optional lifespan manager for the app
|
| 46 |
+
|
| 47 |
+
**Returns:**
|
| 48 |
+
- A Starlette application
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
### `create_sse_app`
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
create_sse_app(server: FastMCP[LifespanResultT], message_path: str, sse_path: str, auth: OAuthProvider | None = None, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Return an instance of the SSE server app.
|
| 59 |
+
|
| 60 |
+
**Args:**
|
| 61 |
+
- `server`: The FastMCP server instance
|
| 62 |
+
- `message_path`: Path for SSE messages
|
| 63 |
+
- `sse_path`: Path for SSE connections
|
| 64 |
+
- `auth`: Optional auth provider
|
| 65 |
+
- `debug`: Whether to enable debug mode
|
| 66 |
+
- `routes`: Optional list of custom routes
|
| 67 |
+
- `middleware`: Optional list of middleware
|
| 68 |
+
|
| 69 |
+
Returns:
|
| 70 |
+
A Starlette application with RequestContextMiddleware
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
### `create_streamable_http_app`
|
| 74 |
+
|
| 75 |
+
```python
|
| 76 |
+
create_streamable_http_app(server: FastMCP[LifespanResultT], streamable_http_path: str, event_store: EventStore | None = None, auth: OAuthProvider | None = None, json_response: bool = False, stateless_http: bool = False, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
Return an instance of the StreamableHTTP server app.
|
| 81 |
+
|
| 82 |
+
**Args:**
|
| 83 |
+
- `server`: The FastMCP server instance
|
| 84 |
+
- `streamable_http_path`: Path for StreamableHTTP connections
|
| 85 |
+
- `event_store`: Optional event store for session management
|
| 86 |
+
- `auth`: Optional auth provider
|
| 87 |
+
- `json_response`: Whether to use JSON response format
|
| 88 |
+
- `stateless_http`: Whether to use stateless mode (new transport per request)
|
| 89 |
+
- `debug`: Whether to enable debug mode
|
| 90 |
+
- `routes`: Optional list of custom routes
|
| 91 |
+
- `middleware`: Optional list of middleware
|
| 92 |
+
|
| 93 |
+
**Returns:**
|
| 94 |
+
- A Starlette application with StreamableHTTP support
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
## Classes
|
| 98 |
+
|
| 99 |
+
### `StarletteWithLifespan`
|
| 100 |
+
|
| 101 |
+
**Methods:**
|
| 102 |
+
|
| 103 |
+
#### `lifespan`
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
lifespan(self) -> Lifespan
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### `RequestContextMiddleware`
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
Middleware that stores each request in a ContextVar
|
| 113 |
+
|
docs/python-sdk/fastmcp-server-middleware.mdx
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: middleware
|
| 3 |
+
sidebarTitle: middleware
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.middleware`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `make_middleware_wrapper`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
make_middleware_wrapper(middleware: Middleware, call_next: CallNext[T, R]) -> CallNext[T, R]
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Create a wrapper that applies a single middleware to a context. The
|
| 18 |
+
closure bakes in the middleware and call_next function, so it can be
|
| 19 |
+
passed to other functions that expect a call_next function.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
## Classes
|
| 23 |
+
|
| 24 |
+
### `CallNext`
|
| 25 |
+
|
| 26 |
+
### `CallToolResult`
|
| 27 |
+
|
| 28 |
+
### `ListToolsResult`
|
| 29 |
+
|
| 30 |
+
### `ListResourcesResult`
|
| 31 |
+
|
| 32 |
+
### `ListResourceTemplatesResult`
|
| 33 |
+
|
| 34 |
+
### `ListPromptsResult`
|
| 35 |
+
|
| 36 |
+
### `ServerResultProtocol`
|
| 37 |
+
|
| 38 |
+
### `MiddlewareContext`
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Unified context for all middleware operations.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
**Methods:**
|
| 45 |
+
|
| 46 |
+
#### `copy`
|
| 47 |
+
|
| 48 |
+
```python
|
| 49 |
+
copy(self, **kwargs: Any) -> MiddlewareContext[T]
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### `Middleware`
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Base class for FastMCP middleware with dispatching hooks.
|
| 56 |
+
|
docs/python-sdk/fastmcp-server-openapi.mdx
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: openapi
|
| 3 |
+
sidebarTitle: openapi
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.openapi`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
FastMCP server implementation for OpenAPI integration.
|
| 10 |
+
|
| 11 |
+
## Classes
|
| 12 |
+
|
| 13 |
+
### `MCPType`
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Type of FastMCP component to create from a route.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
### `RouteType`
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Deprecated: Use MCPType instead.
|
| 23 |
+
|
| 24 |
+
This enum is kept for backward compatibility and will be removed in a future version.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
### `RouteMap`
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Mapping configuration for HTTP routes to FastMCP component types.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
### `OpenAPITool`
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Tool implementation for OpenAPI endpoints.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
### `OpenAPIResource`
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Resource implementation for OpenAPI endpoints.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
### `OpenAPIResourceTemplate`
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Resource template implementation for OpenAPI endpoints.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
### `FastMCPOpenAPI`
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
FastMCP server implementation that creates components from an OpenAPI schema.
|
| 55 |
+
|
| 56 |
+
This class parses an OpenAPI specification and creates appropriate FastMCP components
|
| 57 |
+
(Tools, Resources, ResourceTemplates) based on route mappings.
|
| 58 |
+
|
docs/python-sdk/fastmcp-server-proxy.mdx
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: proxy
|
| 3 |
+
sidebarTitle: proxy
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.proxy`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `ProxyToolManager`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
A ToolManager that sources its tools from a remote client in addition to local and mounted tools.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
### `ProxyResourceManager`
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
### `ProxyPromptManager`
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
### `ProxyTool`
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
A Tool that represents and executes a tool on a remote server.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
**Methods:**
|
| 35 |
+
|
| 36 |
+
#### `from_mcp_tool`
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from_mcp_tool(cls, client: Client, mcp_tool: mcp.types.Tool) -> ProxyTool
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Factory method to create a ProxyTool from a raw MCP tool schema.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
### `ProxyResource`
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
A Resource that represents and reads a resource from a remote server.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
**Methods:**
|
| 52 |
+
|
| 53 |
+
#### `from_mcp_resource`
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
from_mcp_resource(cls, client: Client, mcp_resource: mcp.types.Resource) -> ProxyResource
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
Factory method to create a ProxyResource from a raw MCP resource schema.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
### `ProxyTemplate`
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
A ResourceTemplate that represents and creates resources from a remote server template.
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
**Methods:**
|
| 69 |
+
|
| 70 |
+
#### `from_mcp_template`
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
from_mcp_template(cls, client: Client, mcp_template: mcp.types.ResourceTemplate) -> ProxyTemplate
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
Factory method to create a ProxyTemplate from a raw MCP template schema.
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
### `ProxyPrompt`
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
A Prompt that represents and renders a prompt from a remote server.
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
**Methods:**
|
| 86 |
+
|
| 87 |
+
#### `from_mcp_prompt`
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
from_mcp_prompt(cls, client: Client, mcp_prompt: mcp.types.Prompt) -> ProxyPrompt
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
Factory method to create a ProxyPrompt from a raw MCP prompt schema.
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
### `FastMCPProxy`
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
A FastMCP server that acts as a proxy to a remote MCP-compliant server.
|
| 100 |
+
It uses specialized managers that fulfill requests via an HTTP client.
|
| 101 |
+
|
docs/python-sdk/fastmcp-server-server.mdx
ADDED
|
@@ -0,0 +1,542 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: server
|
| 3 |
+
sidebarTitle: server
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.server.server`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
FastMCP - A more ergonomic interface for MCP servers.
|
| 10 |
+
|
| 11 |
+
## Functions
|
| 12 |
+
|
| 13 |
+
### `add_resource_prefix`
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
add_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Add a prefix to a resource URI.
|
| 21 |
+
|
| 22 |
+
Args:
|
| 23 |
+
uri: The original resource URI
|
| 24 |
+
prefix: The prefix to add
|
| 25 |
+
|
| 26 |
+
Returns:
|
| 27 |
+
The resource URI with the prefix added
|
| 28 |
+
|
| 29 |
+
Examples:
|
| 30 |
+
>>> add_resource_prefix("resource://path/to/resource", "prefix")
|
| 31 |
+
"resource://prefix/path/to/resource" # with new style
|
| 32 |
+
>>> add_resource_prefix("resource://path/to/resource", "prefix")
|
| 33 |
+
"prefix+resource://path/to/resource" # with legacy style
|
| 34 |
+
>>> add_resource_prefix("resource:///absolute/path", "prefix")
|
| 35 |
+
"resource://prefix//absolute/path" # with new style
|
| 36 |
+
|
| 37 |
+
Raises:
|
| 38 |
+
ValueError: If the URI doesn't match the expected protocol://path format
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
### `remove_resource_prefix`
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
remove_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> str
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Remove a prefix from a resource URI.
|
| 49 |
+
|
| 50 |
+
Args:
|
| 51 |
+
uri: The resource URI with a prefix
|
| 52 |
+
prefix: The prefix to remove
|
| 53 |
+
prefix_format: The format of the prefix to remove
|
| 54 |
+
Returns:
|
| 55 |
+
The resource URI with the prefix removed
|
| 56 |
+
|
| 57 |
+
Examples:
|
| 58 |
+
>>> remove_resource_prefix("resource://prefix/path/to/resource", "prefix")
|
| 59 |
+
"resource://path/to/resource" # with new style
|
| 60 |
+
>>> remove_resource_prefix("prefix+resource://path/to/resource", "prefix")
|
| 61 |
+
"resource://path/to/resource" # with legacy style
|
| 62 |
+
>>> remove_resource_prefix("resource://prefix//absolute/path", "prefix")
|
| 63 |
+
"resource:///absolute/path" # with new style
|
| 64 |
+
|
| 65 |
+
Raises:
|
| 66 |
+
ValueError: If the URI doesn't match the expected protocol://path format
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
### `has_resource_prefix`
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
has_resource_prefix(uri: str, prefix: str, prefix_format: Literal['protocol', 'path'] | None = None) -> bool
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Check if a resource URI has a specific prefix.
|
| 77 |
+
|
| 78 |
+
Args:
|
| 79 |
+
uri: The resource URI to check
|
| 80 |
+
prefix: The prefix to look for
|
| 81 |
+
|
| 82 |
+
Returns:
|
| 83 |
+
True if the URI has the specified prefix, False otherwise
|
| 84 |
+
|
| 85 |
+
Examples:
|
| 86 |
+
>>> has_resource_prefix("resource://prefix/path/to/resource", "prefix")
|
| 87 |
+
True # with new style
|
| 88 |
+
>>> has_resource_prefix("prefix+resource://path/to/resource", "prefix")
|
| 89 |
+
True # with legacy style
|
| 90 |
+
>>> has_resource_prefix("resource://other/path/to/resource", "prefix")
|
| 91 |
+
False
|
| 92 |
+
|
| 93 |
+
Raises:
|
| 94 |
+
ValueError: If the URI doesn't match the expected protocol://path format
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
## Classes
|
| 98 |
+
|
| 99 |
+
### `FastMCP`
|
| 100 |
+
|
| 101 |
+
**Methods:**
|
| 102 |
+
|
| 103 |
+
#### `settings`
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
settings(self) -> Settings
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
#### `name`
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
name(self) -> str
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
#### `instructions`
|
| 116 |
+
|
| 117 |
+
```python
|
| 118 |
+
instructions(self) -> str | None
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
#### `run`
|
| 122 |
+
|
| 123 |
+
```python
|
| 124 |
+
run(self, transport: Literal['stdio', 'streamable-http', 'sse'] | None = None, **transport_kwargs: Any) -> None
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
Run the FastMCP server. Note this is a synchronous function.
|
| 128 |
+
|
| 129 |
+
**Args:**
|
| 130 |
+
- `transport`: Transport protocol to use ("stdio", "sse", or "streamable-http")
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
#### `add_middleware`
|
| 134 |
+
|
| 135 |
+
```python
|
| 136 |
+
add_middleware(self, middleware: Middleware) -> None
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
#### `custom_route`
|
| 140 |
+
|
| 141 |
+
```python
|
| 142 |
+
custom_route(self, path: str, methods: list[str], name: str | None = None, include_in_schema: bool = True)
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
Decorator to register a custom HTTP route on the FastMCP server.
|
| 146 |
+
|
| 147 |
+
Allows adding arbitrary HTTP endpoints outside the standard MCP protocol,
|
| 148 |
+
which can be useful for OAuth callbacks, health checks, or admin APIs.
|
| 149 |
+
The handler function must be an async function that accepts a Starlette
|
| 150 |
+
Request and returns a Response.
|
| 151 |
+
|
| 152 |
+
**Args:**
|
| 153 |
+
- `path`: URL path for the route (e.g., "/oauth/callback")
|
| 154 |
+
- `methods`: List of HTTP methods to support (e.g., ["GET", "POST"])
|
| 155 |
+
- `name`: Optional name for the route (to reference this route with
|
| 156 |
+
Starlette's reverse URL lookup feature)
|
| 157 |
+
- `include_in_schema`: Whether to include in OpenAPI schema, defaults to True
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
#### `add_tool`
|
| 161 |
+
|
| 162 |
+
```python
|
| 163 |
+
add_tool(self, tool: Tool) -> None
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
Add a tool to the server.
|
| 167 |
+
|
| 168 |
+
The tool function can optionally request a Context object by adding a parameter
|
| 169 |
+
with the Context type annotation. See the @tool decorator for examples.
|
| 170 |
+
|
| 171 |
+
**Args:**
|
| 172 |
+
- `tool`: The Tool instance to register
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
#### `remove_tool`
|
| 176 |
+
|
| 177 |
+
```python
|
| 178 |
+
remove_tool(self, name: str) -> None
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
Remove a tool from the server.
|
| 182 |
+
|
| 183 |
+
**Args:**
|
| 184 |
+
- `name`: The name of the tool to remove
|
| 185 |
+
|
| 186 |
+
**Raises:**
|
| 187 |
+
- `NotFoundError`: If the tool is not found
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
#### `tool`
|
| 191 |
+
|
| 192 |
+
```python
|
| 193 |
+
tool(self, name_or_fn: AnyFunction) -> FunctionTool
|
| 194 |
+
```
|
| 195 |
+
|
| 196 |
+
#### `tool`
|
| 197 |
+
|
| 198 |
+
```python
|
| 199 |
+
tool(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionTool]
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
#### `tool`
|
| 203 |
+
|
| 204 |
+
```python
|
| 205 |
+
tool(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionTool] | FunctionTool
|
| 206 |
+
```
|
| 207 |
+
|
| 208 |
+
Decorator to register a tool.
|
| 209 |
+
|
| 210 |
+
Tools can optionally request a Context object by adding a parameter with the
|
| 211 |
+
Context type annotation. The context provides access to MCP capabilities like
|
| 212 |
+
logging, progress reporting, and resource access.
|
| 213 |
+
|
| 214 |
+
This decorator supports multiple calling patterns:
|
| 215 |
+
- @server.tool (without parentheses)
|
| 216 |
+
- @server.tool (with empty parentheses)
|
| 217 |
+
- @server.tool("custom_name") (with name as first argument)
|
| 218 |
+
- @server.tool(name="custom_name") (with name as keyword argument)
|
| 219 |
+
- server.tool(function, name="custom_name") (direct function call)
|
| 220 |
+
|
| 221 |
+
**Args:**
|
| 222 |
+
- `name_or_fn`: Either a function (when used as @tool), a string name, or None
|
| 223 |
+
- `name`: Optional name for the tool (keyword-only, alternative to name_or_fn)
|
| 224 |
+
- `description`: Optional description of what the tool does
|
| 225 |
+
- `tags`: Optional set of tags for categorizing the tool
|
| 226 |
+
- `annotations`: Optional annotations about the tool's behavior (e.g. {"is_async": True})
|
| 227 |
+
- `exclude_args`: Optional list of argument names to exclude from the tool schema
|
| 228 |
+
- `enabled`: Optional boolean to enable or disable the tool
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
#### `add_resource`
|
| 232 |
+
|
| 233 |
+
```python
|
| 234 |
+
add_resource(self, resource: Resource) -> None
|
| 235 |
+
```
|
| 236 |
+
|
| 237 |
+
Add a resource to the server.
|
| 238 |
+
|
| 239 |
+
**Args:**
|
| 240 |
+
- `resource`: A Resource instance to add
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
#### `add_template`
|
| 244 |
+
|
| 245 |
+
```python
|
| 246 |
+
add_template(self, template: ResourceTemplate) -> None
|
| 247 |
+
```
|
| 248 |
+
|
| 249 |
+
Add a resource template to the server.
|
| 250 |
+
|
| 251 |
+
**Args:**
|
| 252 |
+
- `template`: A ResourceTemplate instance to add
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
#### `add_resource_fn`
|
| 256 |
+
|
| 257 |
+
```python
|
| 258 |
+
add_resource_fn(self, fn: AnyFunction, uri: str, name: str | None = None, description: str | None = None, mime_type: str | None = None, tags: set[str] | None = None) -> None
|
| 259 |
+
```
|
| 260 |
+
|
| 261 |
+
Add a resource or template to the server from a function.
|
| 262 |
+
|
| 263 |
+
If the URI contains parameters (e.g. "resource://{param}") or the function
|
| 264 |
+
has parameters, it will be registered as a template resource.
|
| 265 |
+
|
| 266 |
+
**Args:**
|
| 267 |
+
- `fn`: The function to register as a resource
|
| 268 |
+
- `uri`: The URI for the resource
|
| 269 |
+
- `name`: Optional name for the resource
|
| 270 |
+
- `description`: Optional description of the resource
|
| 271 |
+
- `mime_type`: Optional MIME type for the resource
|
| 272 |
+
- `tags`: Optional set of tags for categorizing the resource
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
#### `resource`
|
| 276 |
+
|
| 277 |
+
```python
|
| 278 |
+
resource(self, uri: str) -> Callable[[AnyFunction], Resource | ResourceTemplate]
|
| 279 |
+
```
|
| 280 |
+
|
| 281 |
+
Decorator to register a function as a resource.
|
| 282 |
+
|
| 283 |
+
The function will be called when the resource is read to generate its content.
|
| 284 |
+
The function can return:
|
| 285 |
+
- str for text content
|
| 286 |
+
- bytes for binary content
|
| 287 |
+
- other types will be converted to JSON
|
| 288 |
+
|
| 289 |
+
Resources can optionally request a Context object by adding a parameter with the
|
| 290 |
+
Context type annotation. The context provides access to MCP capabilities like
|
| 291 |
+
logging, progress reporting, and session information.
|
| 292 |
+
|
| 293 |
+
If the URI contains parameters (e.g. "resource://{param}") or the function
|
| 294 |
+
has parameters, it will be registered as a template resource.
|
| 295 |
+
|
| 296 |
+
**Args:**
|
| 297 |
+
- `uri`: URI for the resource (e.g. "resource://my-resource" or "resource://{param}")
|
| 298 |
+
- `name`: Optional name for the resource
|
| 299 |
+
- `description`: Optional description of the resource
|
| 300 |
+
- `mime_type`: Optional MIME type for the resource
|
| 301 |
+
- `tags`: Optional set of tags for categorizing the resource
|
| 302 |
+
- `enabled`: Optional boolean to enable or disable the resource
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
#### `add_prompt`
|
| 306 |
+
|
| 307 |
+
```python
|
| 308 |
+
add_prompt(self, prompt: Prompt) -> None
|
| 309 |
+
```
|
| 310 |
+
|
| 311 |
+
Add a prompt to the server.
|
| 312 |
+
|
| 313 |
+
**Args:**
|
| 314 |
+
- `prompt`: A Prompt instance to add
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
#### `prompt`
|
| 318 |
+
|
| 319 |
+
```python
|
| 320 |
+
prompt(self, name_or_fn: AnyFunction) -> FunctionPrompt
|
| 321 |
+
```
|
| 322 |
+
|
| 323 |
+
#### `prompt`
|
| 324 |
+
|
| 325 |
+
```python
|
| 326 |
+
prompt(self, name_or_fn: str | None = None) -> Callable[[AnyFunction], FunctionPrompt]
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
+
#### `prompt`
|
| 330 |
+
|
| 331 |
+
```python
|
| 332 |
+
prompt(self, name_or_fn: str | AnyFunction | None = None) -> Callable[[AnyFunction], FunctionPrompt] | FunctionPrompt
|
| 333 |
+
```
|
| 334 |
+
|
| 335 |
+
Decorator to register a prompt.
|
| 336 |
+
|
| 337 |
+
Prompts can optionally request a Context object by adding a parameter with the
|
| 338 |
+
Context type annotation. The context provides access to MCP capabilities like
|
| 339 |
+
logging, progress reporting, and session information.
|
| 340 |
+
|
| 341 |
+
This decorator supports multiple calling patterns:
|
| 342 |
+
- @server.prompt (without parentheses)
|
| 343 |
+
- @server.prompt() (with empty parentheses)
|
| 344 |
+
- @server.prompt("custom_name") (with name as first argument)
|
| 345 |
+
- @server.prompt(name="custom_name") (with name as keyword argument)
|
| 346 |
+
- server.prompt(function, name="custom_name") (direct function call)
|
| 347 |
+
|
| 348 |
+
Args:
|
| 349 |
+
name_or_fn: Either a function (when used as @prompt), a string name, or None
|
| 350 |
+
name: Optional name for the prompt (keyword-only, alternative to name_or_fn)
|
| 351 |
+
description: Optional description of what the prompt does
|
| 352 |
+
tags: Optional set of tags for categorizing the prompt
|
| 353 |
+
enabled: Optional boolean to enable or disable the prompt
|
| 354 |
+
|
| 355 |
+
Example:
|
| 356 |
+
@server.prompt
|
| 357 |
+
def analyze_table(table_name: str) -> list\[Message]:
|
| 358 |
+
schema = read_table_schema(table_name)
|
| 359 |
+
return [
|
| 360 |
+
{
|
| 361 |
+
"role": "user",
|
| 362 |
+
"content": f"Analyze this schema:
|
| 363 |
+
{schema}"
|
| 364 |
+
}
|
| 365 |
+
]
|
| 366 |
+
|
| 367 |
+
@server.prompt()
|
| 368 |
+
def analyze_with_context(table_name: str, ctx: Context) -> list\[Message]:
|
| 369 |
+
ctx.info(f"Analyzing table {table_name}")
|
| 370 |
+
schema = read_table_schema(table_name)
|
| 371 |
+
return [
|
| 372 |
+
{
|
| 373 |
+
"role": "user",
|
| 374 |
+
"content": f"Analyze this schema:
|
| 375 |
+
{schema}"
|
| 376 |
+
}
|
| 377 |
+
]
|
| 378 |
+
|
| 379 |
+
@server.prompt("custom_name")
|
| 380 |
+
def analyze_file(path: str) -> list\[Message]:
|
| 381 |
+
content = await read_file(path)
|
| 382 |
+
return [
|
| 383 |
+
{
|
| 384 |
+
"role": "user",
|
| 385 |
+
"content": {
|
| 386 |
+
"type": "resource",
|
| 387 |
+
"resource": {
|
| 388 |
+
"uri": f"file://{path}",
|
| 389 |
+
"text": content
|
| 390 |
+
}
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
]
|
| 394 |
+
|
| 395 |
+
@server.prompt(name="custom_name")
|
| 396 |
+
def another_prompt(data: str) -> list\[Message]:
|
| 397 |
+
return [{"role": "user", "content": data}]
|
| 398 |
+
|
| 399 |
+
# Direct function call
|
| 400 |
+
server.prompt(my_function, name="custom_name")
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
#### `sse_app`
|
| 404 |
+
|
| 405 |
+
```python
|
| 406 |
+
sse_app(self, path: str | None = None, message_path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
| 407 |
+
```
|
| 408 |
+
|
| 409 |
+
Create a Starlette app for the SSE server.
|
| 410 |
+
|
| 411 |
+
**Args:**
|
| 412 |
+
- `path`: The path to the SSE endpoint
|
| 413 |
+
- `message_path`: The path to the message endpoint
|
| 414 |
+
- `middleware`: A list of middleware to apply to the app
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
#### `streamable_http_app`
|
| 418 |
+
|
| 419 |
+
```python
|
| 420 |
+
streamable_http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None) -> StarletteWithLifespan
|
| 421 |
+
```
|
| 422 |
+
|
| 423 |
+
Create a Starlette app for the StreamableHTTP server.
|
| 424 |
+
|
| 425 |
+
**Args:**
|
| 426 |
+
- `path`: The path to the StreamableHTTP endpoint
|
| 427 |
+
- `middleware`: A list of middleware to apply to the app
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
#### `http_app`
|
| 431 |
+
|
| 432 |
+
```python
|
| 433 |
+
http_app(self, path: str | None = None, middleware: list[ASGIMiddleware] | None = None, json_response: bool | None = None, stateless_http: bool | None = None, transport: Literal['streamable-http', 'sse'] = 'streamable-http') -> StarletteWithLifespan
|
| 434 |
+
```
|
| 435 |
+
|
| 436 |
+
Create a Starlette app using the specified HTTP transport.
|
| 437 |
+
|
| 438 |
+
**Args:**
|
| 439 |
+
- `path`: The path for the HTTP endpoint
|
| 440 |
+
- `middleware`: A list of middleware to apply to the app
|
| 441 |
+
- `transport`: Transport protocol to use - either "streamable-http" (default) or "sse"
|
| 442 |
+
|
| 443 |
+
**Returns:**
|
| 444 |
+
- A Starlette application configured with the specified transport
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
#### `mount`
|
| 448 |
+
|
| 449 |
+
```python
|
| 450 |
+
mount(self, server: FastMCP[LifespanResultT], prefix: str | None = None, as_proxy: bool | None = None) -> None
|
| 451 |
+
```
|
| 452 |
+
|
| 453 |
+
Mount another FastMCP server on this server with an optional prefix.
|
| 454 |
+
|
| 455 |
+
Unlike importing (with import_server), mounting establishes a dynamic connection
|
| 456 |
+
between servers. When a client interacts with a mounted server's objects through
|
| 457 |
+
the parent server, requests are forwarded to the mounted server in real-time.
|
| 458 |
+
This means changes to the mounted server are immediately reflected when accessed
|
| 459 |
+
through the parent.
|
| 460 |
+
|
| 461 |
+
When a server is mounted with a prefix:
|
| 462 |
+
- Tools from the mounted server are accessible with prefixed names.
|
| 463 |
+
Example: If server has a tool named "get_weather", it will be available as "prefix_get_weather".
|
| 464 |
+
- Resources are accessible with prefixed URIs.
|
| 465 |
+
Example: If server has a resource with URI "weather://forecast", it will be available as
|
| 466 |
+
"weather://prefix/forecast".
|
| 467 |
+
- Templates are accessible with prefixed URI templates.
|
| 468 |
+
Example: If server has a template with URI "weather://location/{id}", it will be available
|
| 469 |
+
as "weather://prefix/location/{id}".
|
| 470 |
+
- Prompts are accessible with prefixed names.
|
| 471 |
+
Example: If server has a prompt named "weather_prompt", it will be available as
|
| 472 |
+
"prefix_weather_prompt".
|
| 473 |
+
|
| 474 |
+
When a server is mounted without a prefix (prefix=None), its tools, resources, templates,
|
| 475 |
+
and prompts are accessible with their original names. Multiple servers can be mounted
|
| 476 |
+
without prefixes, and they will be tried in order until a match is found.
|
| 477 |
+
|
| 478 |
+
There are two modes for mounting servers:
|
| 479 |
+
1. Direct mounting (default when server has no custom lifespan): The parent server
|
| 480 |
+
directly accesses the mounted server's objects in-memory for better performance.
|
| 481 |
+
In this mode, no client lifecycle events occur on the mounted server, including
|
| 482 |
+
lifespan execution.
|
| 483 |
+
|
| 484 |
+
2. Proxy mounting (default when server has a custom lifespan): The parent server
|
| 485 |
+
treats the mounted server as a separate entity and communicates with it via a
|
| 486 |
+
Client transport. This preserves all client-facing behaviors, including lifespan
|
| 487 |
+
execution, but with slightly higher overhead.
|
| 488 |
+
|
| 489 |
+
**Args:**
|
| 490 |
+
- `server`: The FastMCP server to mount.
|
| 491 |
+
- `prefix`: Optional prefix to use for the mounted server's objects. If None,
|
| 492 |
+
the server's objects are accessible with their original names.
|
| 493 |
+
- `as_proxy`: Whether to treat the mounted server as a proxy. If None (default),
|
| 494 |
+
automatically determined based on whether the server has a custom lifespan
|
| 495 |
+
(True if it has a custom lifespan, False otherwise).
|
| 496 |
+
- `tool_separator`: Deprecated. Separator character for tool names.
|
| 497 |
+
- `resource_separator`: Deprecated. Separator character for resource URIs.
|
| 498 |
+
- `prompt_separator`: Deprecated. Separator character for prompt names.
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
#### `from_openapi`
|
| 502 |
+
|
| 503 |
+
```python
|
| 504 |
+
from_openapi(cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, route_maps: list[RouteMap] | None = None, route_map_fn: OpenAPIRouteMapFn | None = None, mcp_component_fn: OpenAPIComponentFn | None = None, mcp_names: dict[str, str] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI
|
| 505 |
+
```
|
| 506 |
+
|
| 507 |
+
Create a FastMCP server from an OpenAPI specification.
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
#### `from_fastapi`
|
| 511 |
+
|
| 512 |
+
```python
|
| 513 |
+
from_fastapi(cls, app: Any, name: str | None = None, route_maps: list[RouteMap] | None = None, route_map_fn: OpenAPIRouteMapFn | None = None, mcp_component_fn: OpenAPIComponentFn | None = None, mcp_names: dict[str, str] | None = None, httpx_client_kwargs: dict[str, Any] | None = None, tags: set[str] | None = None, **settings: Any) -> FastMCPOpenAPI
|
| 514 |
+
```
|
| 515 |
+
|
| 516 |
+
Create a FastMCP server from a FastAPI application.
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
#### `as_proxy`
|
| 520 |
+
|
| 521 |
+
```python
|
| 522 |
+
as_proxy(cls, backend: Client[ClientTransportT] | ClientTransport | FastMCP[Any] | AnyUrl | Path | MCPConfig | dict[str, Any] | str, **settings: Any) -> FastMCPProxy
|
| 523 |
+
```
|
| 524 |
+
|
| 525 |
+
Create a FastMCP proxy server for the given backend.
|
| 526 |
+
|
| 527 |
+
The ``backend`` argument can be either an existing :class:`~fastmcp.client.Client`
|
| 528 |
+
instance or any value accepted as the ``transport`` argument of
|
| 529 |
+
:class:`~fastmcp.client.Client`. This mirrors the convenience of the
|
| 530 |
+
``Client`` constructor.
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
#### `from_client`
|
| 534 |
+
|
| 535 |
+
```python
|
| 536 |
+
from_client(cls, client: Client[ClientTransportT], **settings: Any) -> FastMCPProxy
|
| 537 |
+
```
|
| 538 |
+
|
| 539 |
+
Create a FastMCP proxy server from a FastMCP client.
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
### `MountedServer`
|
docs/python-sdk/fastmcp-settings.mdx
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: settings
|
| 3 |
+
sidebarTitle: settings
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.settings`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `ExtendedEnvSettingsSource`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
A special EnvSettingsSource that allows for multiple env var prefixes to be used.
|
| 14 |
+
|
| 15 |
+
Raises a deprecation warning if the old `FASTMCP_SERVER_` prefix is used.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
**Methods:**
|
| 19 |
+
|
| 20 |
+
#### `get_field_value`
|
| 21 |
+
|
| 22 |
+
```python
|
| 23 |
+
get_field_value(self, field: FieldInfo, field_name: str) -> tuple[Any, str, bool]
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
### `ExtendedSettingsConfigDict`
|
| 27 |
+
|
| 28 |
+
### `Settings`
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
FastMCP settings.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
**Methods:**
|
| 35 |
+
|
| 36 |
+
#### `settings_customise_sources`
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
settings_customise_sources(cls, settings_cls: type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource) -> tuple[PydanticBaseSettingsSource, ...]
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
#### `settings`
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
settings(self) -> Self
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
This property is for backwards compatibility with FastMCP < 2.8.0,
|
| 49 |
+
which accessed fastmcp.settings.settings
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
#### `setup_logging`
|
| 53 |
+
|
| 54 |
+
```python
|
| 55 |
+
setup_logging(self) -> Self
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Finalize the settings.
|
| 59 |
+
|
docs/python-sdk/fastmcp-tools-__init__.mdx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.tools`
|
| 7 |
+
|
| 8 |
+
*This module is empty or contains only private/internal implementations.*
|
docs/python-sdk/fastmcp-tools-tool.mdx
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: tool
|
| 3 |
+
sidebarTitle: tool
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.tools.tool`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `default_serializer`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
default_serializer(data: Any) -> str
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
## Classes
|
| 17 |
+
|
| 18 |
+
### `Tool`
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Internal tool registration info.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
**Methods:**
|
| 25 |
+
|
| 26 |
+
#### `to_mcp_tool`
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
to_mcp_tool(self, **overrides: Any) -> MCPTool
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
#### `from_function`
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
from_function(fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
Create a Tool from a function.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
#### `from_tool`
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
from_tool(cls, tool: Tool, transform_fn: Callable[..., Any] | None = None, name: str | None = None, transform_args: dict[str, ArgTransform] | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### `FunctionTool`
|
| 48 |
+
|
| 49 |
+
**Methods:**
|
| 50 |
+
|
| 51 |
+
#### `from_function`
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
from_function(cls, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> FunctionTool
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Create a Tool from a function.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
### `ParsedFunction`
|
| 61 |
+
|
| 62 |
+
**Methods:**
|
| 63 |
+
|
| 64 |
+
#### `from_function`
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: bool = True) -> ParsedFunction
|
| 68 |
+
```
|
docs/python-sdk/fastmcp-tools-tool_manager.mdx
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: tool_manager
|
| 3 |
+
sidebarTitle: tool_manager
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.tools.tool_manager`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `ToolManager`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Manages FastMCP tools.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
**Methods:**
|
| 17 |
+
|
| 18 |
+
#### `mount`
|
| 19 |
+
|
| 20 |
+
```python
|
| 21 |
+
mount(self, server: MountedServer) -> None
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
Adds a mounted server as a source for tools.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
#### `add_tool_from_fn`
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
add_tool_from_fn(self, fn: Callable[..., Any], name: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, exclude_args: list[str] | None = None) -> Tool
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Add a tool to the server.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
#### `add_tool`
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
add_tool(self, tool: Tool) -> Tool
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Register a tool with the server.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#### `remove_tool`
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
remove_tool(self, key: str) -> None
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Remove a tool from the server.
|
| 52 |
+
|
| 53 |
+
**Args:**
|
| 54 |
+
- `key`: The key of the tool to remove
|
| 55 |
+
|
| 56 |
+
**Raises:**
|
| 57 |
+
- `NotFoundError`: If the tool is not found
|
| 58 |
+
|
docs/python-sdk/fastmcp-tools-tool_transform.mdx
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: tool_transform
|
| 3 |
+
sidebarTitle: tool_transform
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.tools.tool_transform`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `ArgTransform`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Configuration for transforming a parent tool's argument.
|
| 14 |
+
|
| 15 |
+
This class allows fine-grained control over how individual arguments are transformed
|
| 16 |
+
when creating a new tool from an existing one. You can rename arguments, change their
|
| 17 |
+
descriptions, add default values, or hide them from clients while passing constants.
|
| 18 |
+
|
| 19 |
+
Attributes:
|
| 20 |
+
name: New name for the argument. Use None to keep original name, or ... for no change.
|
| 21 |
+
description: New description for the argument. Use None to remove description, or ... for no change.
|
| 22 |
+
default: New default value for the argument. Use ... for no change.
|
| 23 |
+
default_factory: Callable that returns a default value. Cannot be used with default.
|
| 24 |
+
type: New type for the argument. Use ... for no change.
|
| 25 |
+
hide: If True, hide this argument from clients but pass a constant value to parent.
|
| 26 |
+
required: If True, make argument required (remove default). Use ... for no change.
|
| 27 |
+
examples: Examples for the argument. Use ... for no change.
|
| 28 |
+
|
| 29 |
+
Examples:
|
| 30 |
+
# Rename argument 'old_name' to 'new_name'
|
| 31 |
+
ArgTransform(name="new_name")
|
| 32 |
+
|
| 33 |
+
# Change description only
|
| 34 |
+
ArgTransform(description="Updated description")
|
| 35 |
+
|
| 36 |
+
# Add a default value (makes argument optional)
|
| 37 |
+
ArgTransform(default=42)
|
| 38 |
+
|
| 39 |
+
# Add a default factory (makes argument optional)
|
| 40 |
+
ArgTransform(default_factory=lambda: time.time())
|
| 41 |
+
|
| 42 |
+
# Change the type
|
| 43 |
+
ArgTransform(type=str)
|
| 44 |
+
|
| 45 |
+
# Hide the argument entirely from clients
|
| 46 |
+
ArgTransform(hide=True)
|
| 47 |
+
|
| 48 |
+
# Hide argument but pass a constant value to parent
|
| 49 |
+
ArgTransform(hide=True, default="constant_value")
|
| 50 |
+
|
| 51 |
+
# Hide argument but pass a factory-generated value to parent
|
| 52 |
+
ArgTransform(hide=True, default_factory=lambda: uuid.uuid4().hex)
|
| 53 |
+
|
| 54 |
+
# Make an optional parameter required (removes any default)
|
| 55 |
+
ArgTransform(required=True)
|
| 56 |
+
|
| 57 |
+
# Combine multiple transformations
|
| 58 |
+
ArgTransform(name="new_name", description="New desc", default=None, type=int)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
### `TransformedTool`
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
A tool that is transformed from another tool.
|
| 65 |
+
|
| 66 |
+
This class represents a tool that has been created by transforming another tool.
|
| 67 |
+
It supports argument renaming, schema modification, custom function injection,
|
| 68 |
+
and provides context for the forward() and forward_raw() functions.
|
| 69 |
+
|
| 70 |
+
The transformation can be purely schema-based (argument renaming, dropping, etc.)
|
| 71 |
+
or can include a custom function that uses forward() to call the parent tool
|
| 72 |
+
with transformed arguments.
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
**Methods:**
|
| 76 |
+
|
| 77 |
+
#### `from_tool`
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
from_tool(cls, tool: Tool, name: str | None = None, description: str | None = None, tags: set[str] | None = None, transform_fn: Callable[..., Any] | None = None, transform_args: dict[str, ArgTransform] | None = None, annotations: ToolAnnotations | None = None, serializer: Callable[[Any], str] | None = None, enabled: bool | None = None) -> TransformedTool
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
Create a transformed tool from a parent tool.
|
| 84 |
+
|
| 85 |
+
**Args:**
|
| 86 |
+
- `tool`: The parent tool to transform.
|
| 87 |
+
- `transform_fn`: Optional custom function. Can use forward() and forward_raw()
|
| 88 |
+
to call the parent tool. Functions with **kwargs receive transformed
|
| 89 |
+
argument names.
|
| 90 |
+
- `name`: New name for the tool. Defaults to parent tool's name.
|
| 91 |
+
- `transform_args`: Optional transformations for parent tool arguments.
|
| 92 |
+
Only specified arguments are transformed, others pass through unchanged:
|
| 93 |
+
- str: Simple rename
|
| 94 |
+
- ArgTransform: Complex transformation (rename/description/default/drop)
|
| 95 |
+
- None: Drop the argument
|
| 96 |
+
- `description`: New description. Defaults to parent's description.
|
| 97 |
+
- `tags`: New tags. Defaults to parent's tags.
|
| 98 |
+
- `annotations`: New annotations. Defaults to parent's annotations.
|
| 99 |
+
- `serializer`: New serializer. Defaults to parent's serializer.
|
| 100 |
+
|
| 101 |
+
**Returns:**
|
| 102 |
+
- TransformedTool with the specified transformations.
|
| 103 |
+
|
| 104 |
+
Examples:
|
| 105 |
+
- # Transform specific arguments only
|
| 106 |
+
- Tool.from_tool(parent, transform_args={"old": "new"}) # Others unchanged
|
| 107 |
+
- # Custom function with partial transforms
|
| 108 |
+
- async def custom(x: int, y: int) -> str:
|
| 109 |
+
result = await forward(x=x, y=y)
|
| 110 |
+
return f"Custom: {result}"
|
| 111 |
+
- Tool.from_tool(parent, transform_fn=custom, transform_args={"a": "x", "b": "y"})
|
| 112 |
+
- # Using **kwargs (gets all args, transformed and untransformed)
|
| 113 |
+
- async def flexible(**kwargs) -> str:
|
| 114 |
+
result = await forward(**kwargs)
|
| 115 |
+
return f"Got: {kwargs}"
|
| 116 |
+
- Tool.from_tool(parent, transform_fn=flexible, transform_args={"a": "x"})
|
| 117 |
+
|
docs/python-sdk/fastmcp-utilities-__init__.mdx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: __init__
|
| 3 |
+
sidebarTitle: __init__
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.utilities`
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
FastMCP utility modules.
|
docs/python-sdk/fastmcp-utilities-cache.mdx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: cache
|
| 3 |
+
sidebarTitle: cache
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.utilities.cache`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `TimedCache`
|
| 11 |
+
|
| 12 |
+
**Methods:**
|
| 13 |
+
|
| 14 |
+
#### `set`
|
| 15 |
+
|
| 16 |
+
```python
|
| 17 |
+
set(self, key: Any, value: Any) -> None
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
#### `get`
|
| 21 |
+
|
| 22 |
+
```python
|
| 23 |
+
get(self, key: Any) -> Any
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
#### `clear`
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
clear(self) -> None
|
| 30 |
+
```
|
docs/python-sdk/fastmcp-utilities-components.mdx
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: components
|
| 3 |
+
sidebarTitle: components
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.utilities.components`
|
| 7 |
+
|
| 8 |
+
## Classes
|
| 9 |
+
|
| 10 |
+
### `FastMCPComponent`
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Base class for FastMCP tools, prompts, resources, and resource templates.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
**Methods:**
|
| 17 |
+
|
| 18 |
+
#### `key`
|
| 19 |
+
|
| 20 |
+
```python
|
| 21 |
+
key(self) -> str
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
The key of the component. This is used for internal bookkeeping
|
| 25 |
+
and may reflect e.g. prefixes or other identifiers. You should not depend on
|
| 26 |
+
keys having a certain value, as the same tool loaded from different
|
| 27 |
+
hierarchies of servers may have different keys.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
#### `with_key`
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
with_key(self, key: str) -> Self
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
#### `enable`
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
enable(self) -> None
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Enable the component.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#### `disable`
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
disable(self) -> None
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Disable the component.
|
| 52 |
+
|
docs/python-sdk/fastmcp-utilities-exceptions.mdx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: exceptions
|
| 3 |
+
sidebarTitle: exceptions
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.utilities.exceptions`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `iter_exc`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
iter_exc(group: BaseExceptionGroup)
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### `get_catch_handlers`
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
get_catch_handlers() -> Mapping[type[BaseException] | Iterable[type[BaseException]], Callable[[BaseExceptionGroup[Any]], Any]]
|
| 20 |
+
```
|
docs/python-sdk/fastmcp-utilities-http.mdx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: http
|
| 3 |
+
sidebarTitle: http
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.utilities.http`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `find_available_port`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
find_available_port() -> int
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Find an available port by letting the OS assign one.
|
| 18 |
+
|
docs/python-sdk/fastmcp-utilities-json_schema.mdx
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: json_schema
|
| 3 |
+
sidebarTitle: json_schema
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# `fastmcp.utilities.json_schema`
|
| 7 |
+
|
| 8 |
+
## Functions
|
| 9 |
+
|
| 10 |
+
### `compress_schema`
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
compress_schema(schema: dict, prune_params: list[str] | None = None, prune_defs: bool = True, prune_additional_properties: bool = True, prune_titles: bool = False) -> dict
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Remove the given parameters from the schema.
|
| 18 |
+
|
| 19 |
+
**Args:**
|
| 20 |
+
- `schema`: The schema to compress
|
| 21 |
+
- `prune_params`: List of parameter names to remove from properties
|
| 22 |
+
- `prune_defs`: Whether to remove unused definitions
|
| 23 |
+
- `prune_additional_properties`: Whether to remove additionalProperties: false
|
| 24 |
+
- `prune_titles`: Whether to remove title fields from the schema
|
| 25 |
+
|