Skip to content

fix: remove MIME type validation from MCPServer Resource#2235

Merged
maxisbey merged 1 commit intomainfrom
fix/remove-mime-type-validation
Mar 6, 2026
Merged

fix: remove MIME type validation from MCPServer Resource#2235
maxisbey merged 1 commit intomainfrom
fix/remove-mime-type-validation

Conversation

@maxisbey
Copy link
Contributor

@maxisbey maxisbey commented Mar 6, 2026

Removes the MIME type validation regex from MCPServer.Resource.mime_type.

Closes #1756. Supersedes #1819 and #2067.

Motivation and Context

The pattern= constraint on Resource.mime_type was the only MIME type validation anywhere in the MCP ecosystem, and it rejected valid RFC 2045 MIME types — most notably quoted parameter values like text/plain; charset="utf-8".

#1755 partially fixed this by extending the regex to allow unquoted parameters, but the fundamental problem is that no other SDK validates this field at all, and the spec doesn't ask them to:

Where Definition Validation
Spec schema — Resource.mimeType mimeType?: string None
TypeScript SDK z.optional(z.string()) None
Go SDK MIMEType string None
C# SDK string? MimeType None
Python SDK — protocol types mime_type: str | None = None None
Python SDK — ResourceTemplate Field(default="text/plain") None
Python SDK — Resource (before this PR) Field(pattern=r"^[a-zA-Z0-9]+/...") ❌ Regex

The inconsistency with ResourceTemplate in the same module is the clearest signal — if templated resources don't need validation, concrete ones don't either.

How Has This Been Tested?

  • Extended existing test_resource_mime_type with a quoted-parameter case that the old regex rejected
  • All resource tests pass (61 tests across tests/server/mcpserver/resources/ + tests/issues/test_1754_* + tests/issues/test_152_*)
  • 100% branch coverage on base.py

Breaking Changes

None. Strictly more permissive.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Two prior PRs attempted this:

This PR just deletes the pattern: +1/-5 source diff.

AI Disclaimer

The regex pattern on Resource.mime_type was the only MIME type validation
anywhere in the MCP ecosystem. It rejected valid RFC 2045 MIME types such
as quoted parameter values (text/plain; charset="utf-8") and was
inconsistent with ResourceTemplate in the same module, the protocol-level
types in _types.py, and every other SDK.

The MCP spec defines mimeType as an unconstrained optional string.

Github-Issue: #1756
@maxisbey maxisbey requested a review from felixweinberger March 6, 2026 14:47
@maxisbey maxisbey enabled auto-merge (squash) March 6, 2026 14:47
@maxisbey maxisbey merged commit 92f1b15 into main Mar 6, 2026
30 checks passed
@maxisbey maxisbey deleted the fix/remove-mime-type-validation branch March 6, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider removing or relaxing MIME type validation in FastMCP resources

2 participants