-
Notifications
You must be signed in to change notification settings - Fork 2k
chore: Update SDK documentation #4155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
docs/python-sdk/fastmcp-apps.mdx → docs/python-sdk/fastmcp-apps-__init__.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| --- | ||
| title: apps | ||
| sidebarTitle: apps | ||
| title: __init__ | ||
| sidebarTitle: __init__ | ||
| --- | ||
|
|
||
| # `fastmcp.apps` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| --- | ||
| title: app | ||
| sidebarTitle: app | ||
| --- | ||
|
|
||
| # `fastmcp.apps.app` | ||
|
|
||
|
|
||
| FastMCPApp — a Provider that represents a composable MCP application. | ||
|
|
||
| FastMCPApp binds entry-point tools (model calls these) together with backend | ||
| tools (the UI calls these via CallTool). Backend tools are tagged with | ||
| ``meta["fastmcp"]["app"]`` so they can be found through the provider chain | ||
| even when transforms (namespace, visibility, etc.) have renamed or hidden | ||
| them — the server sets a context var that tells ``Provider.get_tool`` to | ||
| fall back to a direct lookup for app-visible tools. | ||
|
|
||
| Usage:: | ||
|
|
||
| from fastmcp import FastMCP, FastMCPApp | ||
|
|
||
| app = FastMCPApp("Dashboard") | ||
|
|
||
| @app.ui() | ||
| def show_dashboard() -> Component: | ||
| return Column(...) | ||
|
|
||
| @app.tool() | ||
| def save_contact(name: str, email: str) -> str: | ||
| return name | ||
|
|
||
| server = FastMCP("Platform") | ||
| server.add_provider(app) | ||
|
|
||
|
|
||
| ## Classes | ||
|
|
||
| ### `FastMCPApp` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L144" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
|
|
||
| A Provider that represents an MCP application. | ||
|
|
||
| Binds together entry-point tools (``@app.ui``), backend tools | ||
| (``@app.tool``), and the Prefab renderer resource. Backend tools | ||
| are tagged with ``meta["fastmcp"]["app"]`` so ``Provider.get_tool`` | ||
| can find them by original name even when transforms have been applied. | ||
|
|
||
|
|
||
| **Methods:** | ||
|
|
||
| #### `tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L168" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| tool(self, name_or_fn: F) -> F | ||
| ``` | ||
|
|
||
| #### `tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L180" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| tool(self, name_or_fn: str | None = None) -> Callable[[F], F] | ||
| ``` | ||
|
|
||
| #### `tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L191" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| tool(self, name_or_fn: str | AnyFunction | None = None) -> Any | ||
| ``` | ||
|
|
||
| Register a backend tool that the UI calls via CallTool. | ||
|
|
||
| Backend tools default to ``visibility=["app"]``. Pass ``model=True`` | ||
| to also expose the tool to the model (``visibility=["app", "model"]``). | ||
|
|
||
| Supports multiple calling patterns:: | ||
|
|
||
| @app.tool | ||
| def save(name: str): ... | ||
|
|
||
| @app.tool() | ||
| def save(name: str): ... | ||
|
|
||
| @app.tool("custom_name") | ||
| def save(name: str): ... | ||
|
|
||
|
|
||
| #### `ui` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L258" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| ui(self, name_or_fn: F) -> F | ||
| ``` | ||
|
|
||
| #### `ui` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L273" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| ui(self, name_or_fn: str | None = None) -> Callable[[F], F] | ||
| ``` | ||
|
|
||
| #### `ui` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L287" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| ui(self, name_or_fn: str | AnyFunction | None = None) -> Any | ||
| ``` | ||
|
|
||
| Register a UI entry-point tool that the model calls. | ||
|
|
||
| Entry-point tools default to ``visibility=["model"]`` and auto-wire | ||
| the Prefab renderer resource and CSP. They are tagged with the app | ||
| name so structured content includes ``_meta.fastmcp.app``. | ||
|
|
||
| Supports multiple calling patterns:: | ||
|
|
||
| @app.ui | ||
| def dashboard() -> Component: ... | ||
|
|
||
| @app.ui() | ||
| def dashboard() -> Component: ... | ||
|
|
||
| @app.ui("my_dashboard") | ||
| def dashboard() -> Component: ... | ||
|
|
||
|
|
||
| #### `add_tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L362" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| add_tool(self, tool: Tool | Callable[..., Any]) -> Tool | ||
| ``` | ||
|
|
||
| Add a tool to this app programmatically. | ||
|
|
||
| The tool is tagged with this app's name for routing. | ||
|
|
||
|
|
||
| #### `lifespan` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L418" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| lifespan(self) -> AsyncIterator[None] | ||
| ``` | ||
|
|
||
| #### `run` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/app.py#L426" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| run(self, transport: Literal['stdio', 'http', 'sse', 'streamable-http'] | None = None, **kwargs: Any) -> None | ||
| ``` | ||
|
|
||
| Create a temporary FastMCP server and run this app standalone. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| title: approval | ||
| sidebarTitle: approval | ||
| --- | ||
|
|
||
| # `fastmcp.apps.approval` | ||
|
|
||
|
|
||
| Approval — a Provider that adds human-in-the-loop approval to any server. | ||
|
|
||
| The LLM presents a summary of what it's about to do, and the user | ||
| approves or rejects via buttons. The result is sent back into the | ||
| conversation as a message, prompting the LLM's next turn. | ||
|
|
||
| Requires ``fastmcp[apps]`` (prefab-ui). | ||
|
|
||
| Usage:: | ||
|
|
||
| from fastmcp import FastMCP | ||
| from fastmcp.apps.approval import Approval | ||
|
|
||
| mcp = FastMCP("My Server") | ||
| mcp.add_provider(Approval()) | ||
|
|
||
|
|
||
| ## Classes | ||
|
|
||
| ### `Approval` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/approval.py#L49" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
|
|
||
| A Provider that adds human-in-the-loop approval to a server. | ||
|
|
||
| The LLM calls the ``request_approval`` tool with a summary and | ||
| optional details. The user sees an approval card with Approve and | ||
| Reject buttons. Clicking either sends a message back into the | ||
| conversation (via ``SendMessage``), triggering the LLM's next turn. | ||
|
|
||
| The message appears as if the user sent it, so the LLM sees | ||
| something like ``'"Deploy v3.2 to production" is APPROVED'``. | ||
|
|
||
| Example:: | ||
|
|
||
| from fastmcp import FastMCP | ||
| from fastmcp.apps.approval import Approval | ||
|
|
||
| mcp = FastMCP("My Server") | ||
| mcp.add_provider(Approval()) | ||
|
|
||
| Customized:: | ||
|
|
||
| Approval( | ||
| title="Deploy Gate", | ||
| approve_text="Ship it", | ||
| approve_variant="default", | ||
| reject_text="Abort", | ||
| reject_variant="destructive", | ||
| ) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| title: choice | ||
| sidebarTitle: choice | ||
| --- | ||
|
|
||
| # `fastmcp.apps.choice` | ||
|
|
||
|
|
||
| Choice — a Provider that lets the user pick from a set of options. | ||
|
|
||
| The LLM presents options, the user clicks one, and the selection | ||
| flows back into the conversation as a message. | ||
|
|
||
| Requires ``fastmcp[apps]`` (prefab-ui). | ||
|
|
||
| Usage:: | ||
|
|
||
| from fastmcp import FastMCP | ||
| from fastmcp.apps.choice import Choice | ||
|
|
||
| mcp = FastMCP("My Server") | ||
| mcp.add_provider(Choice()) | ||
|
|
||
|
|
||
| ## Classes | ||
|
|
||
| ### `Choice` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/choice.py#L46" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
|
|
||
| A Provider that lets the user choose from a set of options. | ||
|
|
||
| The LLM calls ``choose`` with a prompt and a list of options. | ||
| The user sees a card with one button per option. Clicking a button | ||
| sends the selection back into the conversation via ``SendMessage``, | ||
| triggering the LLM's next turn. | ||
|
|
||
| Example:: | ||
|
|
||
| from fastmcp import FastMCP | ||
| from fastmcp.apps.choice import Choice | ||
|
|
||
| mcp = FastMCP("My Server") | ||
| mcp.add_provider(Choice()) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| --- | ||
| title: config | ||
| sidebarTitle: config | ||
| --- | ||
|
|
||
| # `fastmcp.apps.config` | ||
|
|
||
|
|
||
| MCP Apps support — extension negotiation and typed UI metadata models. | ||
|
|
||
| Provides constants and Pydantic models for the MCP Apps extension | ||
| (io.modelcontextprotocol/ui), enabling tools and resources to carry | ||
| UI metadata for clients that support interactive app rendering. | ||
|
|
||
|
|
||
| ## Functions | ||
|
|
||
| ### `app_config_to_meta_dict` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/config.py#L173" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| app_config_to_meta_dict(app: AppConfig | dict[str, Any]) -> dict[str, Any] | ||
| ``` | ||
|
|
||
|
|
||
| Convert an AppConfig or dict to the wire-format dict for ``meta["ui"]``. | ||
|
|
||
|
|
||
| ## Classes | ||
|
|
||
| ### `ResourceCSP` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/config.py#L20" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
|
|
||
| Content Security Policy for MCP App resources. | ||
|
|
||
| Declares which external origins the app is allowed to connect to or | ||
| load resources from. Hosts use these declarations to build the | ||
| ``Content-Security-Policy`` header for the sandboxed iframe. | ||
|
|
||
|
|
||
| ### `ResourcePermissions` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/config.py#L52" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
|
|
||
| Iframe sandbox permissions for MCP App resources. | ||
|
|
||
| Each field, when set (typically to ``{}``), requests that the host | ||
| grant the corresponding Permission Policy feature to the sandboxed | ||
| iframe. Hosts MAY honour these; apps should use JS feature detection | ||
| as a fallback. | ||
|
|
||
|
|
||
| ### `AppConfig` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/config.py#L79" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
|
|
||
| Configuration for MCP App tools and resources. | ||
|
|
||
| Controls how a tool or resource participates in the MCP Apps extension. | ||
| On tools, ``resource_uri`` and ``visibility`` specify which UI resource | ||
| to render and where the tool appears. On resources, those fields must | ||
| be left unset (the resource itself is the UI). | ||
|
|
||
| All fields use ``exclude_none`` serialization so only explicitly-set | ||
| values appear on the wire. Aliases match the MCP Apps wire format | ||
| (camelCase). | ||
|
|
||
|
|
||
| ### `PrefabAppConfig` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/config.py#L117" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
|
|
||
| App configuration for Prefab tools with sensible defaults. | ||
|
|
||
| Like ``app=True`` but customizable. Auto-wires the Prefab renderer | ||
| URI and merges the renderer's CSP with any additional domains you | ||
| specify. The renderer resource is registered automatically. | ||
|
|
||
| Example:: | ||
|
|
||
| @mcp.tool(app=PrefabAppConfig()) # same as app=True | ||
|
|
||
| @mcp.tool(app=PrefabAppConfig( | ||
| csp=ResourceCSP(frame_domains=["https://example.com"]), | ||
| )) | ||
|
|
||
|
|
||
| **Methods:** | ||
|
|
||
| #### `model_post_init` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/apps/config.py#L133" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | ||
|
|
||
| ```python | ||
| model_post_init(self, __context: Any) -> None | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing the former
python-sdk/fastmcp-appspage with onlypython-sdk/fastmcp-apps-__init__means the already-published/python-sdk/fastmcp-appsURL no longer has a backing MDX file or redirect; I searched the docs config forfastmcp-appsand only the new slug remains. Any external links or bookmarks to the package reference will 404 unless the old page is kept or a redirect is added.Useful? React with 👍 / 👎.