Skip to content

Commit 74023cf

Browse files
committed
fix(fastmcp): propagate mimeType in resource template listing and add test
- Fix resource template list did not include the mimeType attribute. - Propagate mimeType from template metadata to the list output in FastMCP. - Add test_resource_template_includes_mime_type to verify that listed resource templates include the correct mimeType and the resource is still accessible via the client.
1 parent 6a84a2f commit 74023cf

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
@@ -296,6 +296,7 @@ async def list_resource_templates(self) -> list[MCPResourceTemplate]:
296296
name=template.name,
297297
title=template.title,
298298
description=template.description,
299+
mimeType=template.mime_type,
299300
)
300301
for template in templates
301302
]

tests/server/fastmcp/test_server.py

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

742+
@pytest.mark.anyio
743+
async def test_resource_template_includes_mime_type(self):
744+
"""Test that list resource templates includes the correct mimeType."""
745+
mcp = FastMCP()
746+
747+
@mcp.resource("resource://{user}/csv", mime_type="text/csv")
748+
def get_csv(user: str) -> str:
749+
return f"csv for {user}"
750+
751+
templates = await mcp.list_resource_templates()
752+
assert len(templates) == 1
753+
template = templates[0]
754+
755+
assert hasattr(template, "mimeType")
756+
assert template.mimeType == "text/csv"
757+
758+
async with client_session(mcp._mcp_server) as client:
759+
result = await client.read_resource(AnyUrl("resource://bob/csv"))
760+
assert isinstance(result.contents[0], TextResourceContents)
761+
assert result.contents[0].text == "csv for bob"
762+
742763

743764
class TestContextInjection:
744765
"""Test context injection in tools."""

0 commit comments

Comments
 (0)