-
Notifications
You must be signed in to change notification settings - Fork 2k
Add MCP Apps Phase 1 — SDK compatibility (SEP-1865) #3009
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
131e2e5
Add MCP Apps Phase 1 — SDK compatibility (SEP-1865)
jlowin b63f231
Fix ty type-narrowing errors in skills.py and test_dependencies.py
jlowin b7c7df0
Apply ui:// MIME default across all resource registration paths
jlowin 7efc3bc
Address review nitpicks: case-insensitive URI scheme, remove redundan…
jlowin b5eb878
Restore isinstance check for incorrect decorator usage detection
jlowin eec2da9
Validate uri is string early in FastMCP.resource() before processing
jlowin 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
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
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
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,93 @@ | ||
| """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. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
| UI_EXTENSION_ID = "io.modelcontextprotocol/ui" | ||
| UI_MIME_TYPE = "text/html;profile=mcp-app" | ||
|
|
||
|
|
||
| class ToolUI(BaseModel): | ||
| """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). | ||
| """ | ||
|
|
||
| resource_uri: str | None = Field( | ||
| default=None, | ||
| alias="resourceUri", | ||
| description="URI of the UI resource (typically ui:// scheme)", | ||
| ) | ||
| visibility: list[str] | None = Field( | ||
| default=None, | ||
| description="Where this tool is visible: 'app', 'model', or both", | ||
| ) | ||
| csp: str | None = Field(default=None, description="Content Security Policy") | ||
| permissions: list[str] | None = Field( | ||
| default=None, description="iframe permissions" | ||
| ) | ||
| domain: str | None = Field(default=None, description="Domain for the iframe") | ||
| prefers_border: bool | None = Field( | ||
| default=None, | ||
| alias="prefersBorder", | ||
| description="Whether the UI prefers a visible border", | ||
| ) | ||
|
|
||
| model_config = {"populate_by_name": True} | ||
|
|
||
|
|
||
| class ResourceUI(BaseModel): | ||
| """Typed ``_meta.ui`` for resources — rendering hints for UI-capable clients.""" | ||
|
|
||
| csp: str | None = Field(default=None, description="Content Security Policy") | ||
| permissions: list[str] | None = Field( | ||
| default=None, description="iframe permissions" | ||
| ) | ||
| domain: str | None = Field(default=None, description="Domain for the iframe") | ||
| prefers_border: bool | None = Field( | ||
| default=None, | ||
| alias="prefersBorder", | ||
| description="Whether the UI prefers a visible border", | ||
| ) | ||
|
|
||
| model_config = {"populate_by_name": True} | ||
|
|
||
|
|
||
| def 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"]``.""" | ||
| if isinstance(ui, (ToolUI, ResourceUI)): | ||
| return ui.model_dump(by_alias=True, exclude_none=True) | ||
| return ui | ||
|
|
||
|
|
||
| def 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) | ||
| """ | ||
| if explicit_mime_type is not None: | ||
| return explicit_mime_type | ||
| # Case-insensitive scheme check per RFC 3986 | ||
| if uri.lower().startswith("ui://"): | ||
| return UI_MIME_TYPE | ||
| return None |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.