60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
147 lines
4.7 KiB
Plaintext
147 lines
4.7 KiB
Plaintext
---
|
|
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.
|
|
|