-
Notifications
You must be signed in to change notification settings - Fork 3.3k
MIME type validation regex doesn't support parameters (e.g., text/html;profile=mcp-app) #1754
Copy link
Copy link
Closed
Description
Bug Description
The MIME type validation regex in FastMCP's resource handler doesn't support MIME type parameters, which are valid per RFC 2045.
Code Location
File: src/mcp/server/fastmcp/resources/base.py, line 31
mime_type: str = Field(
default="text/plain",
description="MIME type of the resource content",
pattern=r"^[a-zA-Z0-9]+/[a-zA-Z0-9\-+.]+$", # ← Doesn't allow params
)Problem
The regex ^[a-zA-Z0-9]+/[a-zA-Z0-9\-+.]+$ only matches type/subtype but rejects valid MIME types with parameters like:
text/html;profile=mcp-appapplication/json; charset=utf-8
Why This Matters
The MCP Apps SDK requires resources to use the MIME type text/html;profile=mcp-app to identify MCP App widgets.
When trying to register a resource with this MIME type in Python:
@mcp.resource("ui://my-app/widget.html", mime_type="text/html;profile=mcp-app")
def widget() -> str:
return Path("widget.html").read_text()It fails with:
pydantic_core._pydantic_core.ValidationError: 1 validation error for FunctionResource
mime_type
String should match pattern '^[a-zA-Z0-9]+/[a-zA-Z0-9\-+.]+$'
[type=string_pattern_mismatch, input_value='text/html;profile=mcp-app', input_type=str]
Suggested Fix
Update the regex to support optional parameters per RFC 2045:
pattern=r"^[a-zA-Z0-9]+/[a-zA-Z0-9\-+.]+(;\s*[a-zA-Z0-9\-]+=[a-zA-Z0-9\-]+)*$"Or remove the pattern validation entirely and trust the developer.
Environment
- Python SDK version: 1.23.1
- Python: 3.11
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels