Skip to content

Commit baa4857

Browse files
committed
fix: remove MIME type validation from MCPServer Resource
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
1 parent b33c811 commit baa4857

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/mcp/server/mcpserver/resources/base.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ class Resource(BaseModel, abc.ABC):
2323
name: str | None = Field(description="Name of the resource", default=None)
2424
title: str | None = Field(description="Human-readable title of the resource", default=None)
2525
description: str | None = Field(description="Description of the resource", default=None)
26-
mime_type: str = Field(
27-
default="text/plain",
28-
description="MIME type of the resource content",
29-
pattern=r"^[a-zA-Z0-9]+/[a-zA-Z0-9\-+.]+(;\s*[a-zA-Z0-9\-_.]+=[a-zA-Z0-9\-_.]+)*$",
30-
)
26+
mime_type: str = Field(default="text/plain", description="MIME type of the resource content")
3127
icons: list[Icon] | None = Field(default=None, description="Optional list of icons for this resource")
3228
annotations: Annotations | None = Field(default=None, description="Optional annotations for the resource")
3329
meta: dict[str, Any] | None = Field(default=None, description="Optional metadata for this resource")

tests/server/mcpserver/resources/test_resources.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ def dummy_func() -> str: # pragma: no cover
9191
)
9292
assert resource.mime_type == "application/json"
9393

94+
# RFC 2045 quoted parameter value (gh-1756)
95+
resource = FunctionResource(
96+
uri="resource://test",
97+
fn=dummy_func,
98+
mime_type='text/plain; charset="utf-8"',
99+
)
100+
assert resource.mime_type == 'text/plain; charset="utf-8"'
101+
94102
@pytest.mark.anyio
95103
async def test_resource_read_abstract(self):
96104
"""Test that Resource.read() is abstract."""

0 commit comments

Comments
 (0)