Add MCP Apps Phase 1 — SDK compatibility (SEP-1865)#3009
Conversation
Test Failure AnalysisSummary: Two tests are failing because Root Cause: In The validation check that should raise the helpful Suggested Solution: Move the Option 1 (Recommended): Add type guard to def resolve_ui_mime_type(uri: str, explicit_mime_type: str | None) -> str | None:
"""Return the appropriate MIME type for a resource URI."""
if explicit_mime_type is not None:
return explicit_mime_type
# Guard against incorrect decorator usage (uri will be a function object)
if not isinstance(uri, str):
return None
# Case-insensitive scheme check per RFC 3986
if uri.lower().startswith("ui://"):
return UI_MIME_TYPE
return NoneOption 2: Move the call to Detailed AnalysisFailed Tests
Stack Trace@mcp.resource # Missing parentheses
def get_data() -> str:
return "Hello, world!"
# This triggers:
src/fastmcp/server/server.py:1596: in resource
mime_type = resolve_ui_mime_type(uri, mime_type)
src/fastmcp/server/apps.py:91: in resolve_ui_mime_type
if uri.lower().startswith("ui://"):
^^^^^^^^^
E AttributeError: 'function' object has no attribute 'lower'Expected BehaviorThe tests expect this error: TypeError: The @resource decorator was used incorrectly.
It requires a URI as the first argument.
Use @resource('uri') instead of @resourceThis error is defined in Related Files
Updated analysis for latest workflow run. Previous analyses addressed different failures. |
WalkthroughAdds Phase 1 MCP Apps (SDK Compatibility): new constants Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/fastmcp/server/server.py (1)
1663-1676: Adduiparameter toprompt()decorator for consistency withtool()andresource().The
tool()andresource()decorators both have auiparameter (ToolUIandResourceUIrespectively), butprompt()is missing this parameter. Per the requirement that changes affecting tool interactions must be adopted and applied across all major MCP object types (Tools, Resources, Resource Templates, and Prompts), theprompt()decorator should also support theuiparameter to maintain consistency. Consider addingui: PromptUI | dict[str, Any] | None = Noneor clarifying the architectural reason for excluding it from prompts.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db962695ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Default MIME type for ui:// scheme resources | ||
| if mime_type is None and isinstance(uri, str) and uri.startswith("ui://"): | ||
| mime_type = UI_MIME_TYPE |
There was a problem hiding this comment.
Apply ui:// MIME defaults outside FastMCP.resource
This default only runs for FastMCP.resource, so ui:// resources registered via the standalone fastmcp.resources.resource decorator (used by FileSystemProvider) or via resource templates still keep the generic text/plain default from ResourceMeta. That means UI bundles discovered through filesystem-based servers will advertise mimeType: text/plain, so MCP Apps clients that key off the MIME type won’t recognize them as UI resources. Consider moving the ui:// MIME default into a shared helper and applying it in the standalone decorator (and template path) as well.
Useful? React with 👍 / 👎.
Test Failure AnalysisSummary: The static analysis job failed because the type checker v0.0.14 detected two unused Root Cause: The type checker has improved in v0.0.14 and no longer reports the type errors that these suppression comments were originally added for. The Suggested Solution: Remove the two unused
The code will continue to work correctly—these comments are no longer needed because the underlying type errors have been resolved. Detailed AnalysisThe CI logs show: This is happening because:
Related Files
|
Per review feedback: the ui:// MIME type default was only being applied in FastMCP.resource(), leaving standalone @resource decorators and resource templates with the generic text/plain default. Now resolve_ui_mime_type() is used in all three paths, so ui:// resources are correctly identified regardless of how they're registered.
cfe97f9 to
b7c7df0
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/fastmcp/server/apps.py (1)
88-91: Consider case-insensitive URI scheme matching.Per RFC 3986, URI schemes are case-insensitive. While
ui://is likely always lowercase in practice, a case-insensitive check would be more robust.♻️ Optional: Case-insensitive scheme check
- if uri.startswith("ui://"): + if uri.lower().startswith("ui://"): return UI_MIME_TYPEsrc/fastmcp/server/server.py (1)
1595-1602: Redundant type check foruriparameter.The
isinstance(uri, str)check at line 1596 is always true since theuriparameter is typed asstr. The check can be removed.♻️ Optional: Remove redundant isinstance check
# Apply default MIME type for ui:// scheme resources - if isinstance(uri, str): - mime_type = resolve_ui_mime_type(uri, mime_type) + mime_type = resolve_ui_mime_type(uri, mime_type)
…t check, fix docs example
FastMCP servers can now participate in the MCP Apps ecosystem. Phase 1 is the wire-level plumbing — extension negotiation, typed UI metadata on tools and resources, and the
ui://resource scheme. Users who bring their own HTML bundles can serve them as spec-compliant MCP Apps without any additional framework.The server advertises
io.modelcontextprotocol/uiin capabilities,ui://resources default to the correct MIME type, and_meta.uiflows through to all clients (per the spec, visibility enforcement is the host's job, not the server's). Tools can detect client extension support at runtime viactx.client_supports_extension(extension_id)— a general-purpose method that scales to future extensions.Phase 2 (component DSL, renderer,
FastMCPApp) builds on this foundation.