fix: remove MIME type validation from MCPServer Resource#2235
Merged
Conversation
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
felixweinberger
approved these changes
Mar 6, 2026
This was referenced Mar 6, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Removes the MIME type validation regex from
MCPServer.Resource.mime_type.Closes #1756. Supersedes #1819 and #2067.
Motivation and Context
The
pattern=constraint onResource.mime_typewas the only MIME type validation anywhere in the MCP ecosystem, and it rejected valid RFC 2045 MIME types — most notably quoted parameter values liketext/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:
Resource.mimeTypemimeType?: stringz.optional(z.string())MIMEType stringstring? MimeTypemime_type: str | None = NoneResourceTemplateField(default="text/plain")Resource(before this PR)Field(pattern=r"^[a-zA-Z0-9]+/...")The inconsistency with
ResourceTemplatein the same module is the clearest signal — if templated resources don't need validation, concrete ones don't either.How Has This Been Tested?
test_resource_mime_typewith a quoted-parameter case that the old regex rejectedtests/server/mcpserver/resources/+tests/issues/test_1754_*+tests/issues/test_152_*)base.pyBreaking Changes
None. Strictly more permissive.
Types of changes
Checklist
Additional context
Two prior PRs attempted this:
email.message-based RFC 2045 validator (40+ lines) — right problem, wrong direction (more validation, not less); also predates thefastmcp→mcpserverrename"/" in valuecheck — reasonable, but still diverges fromResourceTemplateand the other SDKsThis PR just deletes the pattern:
+1/-5source diff.AI Disclaimer