mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-11 08:09:10 +02:00
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
163 lines
5.2 KiB
Text
163 lines
5.2 KiB
Text
---
|
|
title: app
|
|
sidebarTitle: app
|
|
---
|
|
|
|
# `fastmcp.server.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 get global keys —
|
|
UUID-suffixed stable identifiers that survive namespace transforms when
|
|
servers are composed — so ``CallTool(save_contact)`` keeps working even when
|
|
the app is mounted under a namespace.
|
|
|
|
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) -> dict:
|
|
return {"name": name, "email": email}
|
|
|
|
server = FastMCP("Platform")
|
|
server.add_provider(app)
|
|
|
|
|
|
## Functions
|
|
|
|
### `get_global_tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/app.py#L61" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_global_tool(name: str) -> Tool | None
|
|
```
|
|
|
|
|
|
Look up a tool by its global key, or return None.
|
|
|
|
|
|
## Classes
|
|
|
|
### `FastMCPApp` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/app.py#L167" 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``), the Prefab renderer resource, and global-key
|
|
infrastructure so that composed/namespaced servers can still reach
|
|
backend tools by stable identifiers.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/app.py#L189" 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/src/fastmcp/server/app.py#L201" 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/src/fastmcp/server/app.py#L212" 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 get a global key for composition safety and 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/src/fastmcp/server/app.py#L274" 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/src/fastmcp/server/app.py#L289" 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/src/fastmcp/server/app.py#L303" 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 do NOT get a global key —
|
|
the model resolves them through the normal transform chain.
|
|
|
|
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/src/fastmcp/server/app.py#L389" 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.
|
|
|
|
If the tool has ``meta["ui"]["globalKey"]``, it is assumed to already
|
|
be configured (but still registered for lookup). Otherwise it is
|
|
treated as a backend tool and gets a global key assigned automatically.
|
|
|
|
Pass ``fn`` to register the original callable in the resolver so that
|
|
``CallTool(fn)`` can resolve to the global key.
|
|
|
|
|
|
#### `lifespan` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/app.py#L453" 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/src/fastmcp/server/app.py#L461" 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.
|
|
|