Skip to content

Commit ca5cb4c

Browse files
fix(fastmcp): propagate mimeType in resource template list (#1186)
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
1 parent c3717e7 commit ca5cb4c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ async def list_resource_templates(self) -> list[MCPResourceTemplate]:
320320
name=template.name,
321321
title=template.title,
322322
description=template.description,
323+
mimeType=template.mime_type,
323324
)
324325
for template in templates
325326
]

tests/server/fastmcp/test_server.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,27 @@ def get_data(name: str) -> str:
810810
result = await resource.read()
811811
assert result == "Data for test"
812812

813+
@pytest.mark.anyio
814+
async def test_resource_template_includes_mime_type(self):
815+
"""Test that list resource templates includes the correct mimeType."""
816+
mcp = FastMCP()
817+
818+
@mcp.resource("resource://{user}/csv", mime_type="text/csv")
819+
def get_csv(user: str) -> str:
820+
return f"csv for {user}"
821+
822+
templates = await mcp.list_resource_templates()
823+
assert len(templates) == 1
824+
template = templates[0]
825+
826+
assert hasattr(template, "mimeType")
827+
assert template.mimeType == "text/csv"
828+
829+
async with client_session(mcp._mcp_server) as client:
830+
result = await client.read_resource(AnyUrl("resource://bob/csv"))
831+
assert isinstance(result.contents[0], TextResourceContents)
832+
assert result.contents[0].text == "csv for bob"
833+
813834

814835
class TestContextInjection:
815836
"""Test context injection in tools, resources, and prompts."""

0 commit comments

Comments
 (0)