Summary
The MIME type validation regex in FastMCP's Resource class is more restrictive than RFC 2045 and diverges from the TypeScript SDK (which has no validation). We should consider aligning with the TypeScript SDK approach.
Background
PR #1755 fixed the immediate issue of MIME type parameters being rejected (e.g., text/html;profile=mcp-app), but the current regex still doesn't fully support RFC 2045:
Current regex (after #1755):
pattern=r"^[a-zA-Z0-9]+/[a-zA-Z0-9\-+.]+(;\s*[a-zA-Z0-9\-_.]+=[a-zA-Z0-9\-_.]+)*$"
Limitations:
- Doesn't support quoted string values:
text/plain; charset="utf-8" ❌
- Doesn't allow all valid RFC 2045 token characters (e.g.,
!, #, *, +, etc.)
TypeScript SDK Comparison
The TypeScript SDK does not validate MIME types at all (types.ts:834):
mimeType: z.optional(z.string()),
MCP Spec
The MCP spec defines mimeType as an optional string with no format constraints.
Options
- Remove validation entirely (align with TypeScript SDK and spec)
- Improve the regex to support quoted strings and more token characters
AI Disclaimer
Summary
The MIME type validation regex in FastMCP's
Resourceclass is more restrictive than RFC 2045 and diverges from the TypeScript SDK (which has no validation). We should consider aligning with the TypeScript SDK approach.Background
PR #1755 fixed the immediate issue of MIME type parameters being rejected (e.g.,
text/html;profile=mcp-app), but the current regex still doesn't fully support RFC 2045:Current regex (after #1755):
Limitations:
text/plain; charset="utf-8"❌!,#,*,+, etc.)TypeScript SDK Comparison
The TypeScript SDK does not validate MIME types at all (types.ts:834):
MCP Spec
The MCP spec defines
mimeTypeas an optional string with no format constraints.Options
AI Disclaimer