mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-14 17:49:11 +02:00
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
87 lines
3.1 KiB
Text
87 lines
3.1 KiB
Text
---
|
|
title: apps
|
|
sidebarTitle: apps
|
|
---
|
|
|
|
# `fastmcp.server.apps`
|
|
|
|
|
|
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
|
|
|
|
### `ui_to_meta_dict` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/apps.py#L129" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
ui_to_meta_dict(ui: ToolUI | ResourceUI | dict[str, Any]) -> dict[str, Any]
|
|
```
|
|
|
|
|
|
Convert a UI model or dict to the wire-format dict for ``meta["ui"]``.
|
|
|
|
|
|
### `resolve_ui_mime_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/apps.py#L136" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
resolve_ui_mime_type(uri: str, explicit_mime_type: str | None) -> str | None
|
|
```
|
|
|
|
|
|
Return the appropriate MIME type for a resource URI.
|
|
|
|
For ``ui://`` scheme resources, defaults to ``UI_MIME_TYPE`` when no
|
|
explicit MIME type is provided. This ensures UI resources are correctly
|
|
identified regardless of how they're registered (via FastMCP.resource,
|
|
the standalone @resource decorator, or resource templates).
|
|
|
|
**Args:**
|
|
- `uri`: The resource URI string
|
|
- `explicit_mime_type`: The MIME type explicitly provided by the user
|
|
|
|
**Returns:**
|
|
- The resolved MIME type (explicit value, UI default, or None)
|
|
|
|
|
|
## Classes
|
|
|
|
### `ResourceCSP` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/apps.py#L18" 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/jlowin/fastmcp/blob/main/src/fastmcp/server/apps.py#L50" 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.
|
|
|
|
|
|
### `ToolUI` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/apps.py#L77" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Typed ``_meta.ui`` for tools — links a tool to its UI resource.
|
|
|
|
All fields use ``exclude_none`` serialization so only explicitly-set
|
|
values appear on the wire. Aliases match the MCP Apps wire format
|
|
(camelCase).
|
|
|
|
|
|
### `ResourceUI` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/apps.py#L110" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Typed ``_meta.ui`` for resources — rendering hints for UI-capable clients.
|
|
|