fix(fastmcp): propagate mimeType in resource template list (#1186)

Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
This commit is contained in:
pchoudhury22 2025-09-17 19:20:41 +05:30 • committed by GitHub
commit ca5cb4cb67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View file

@ -320,6 +320,7 @@ class FastMCP(Generic[LifespanResultT]):
name=template.name,
title=template.title,
description=template.description,
mimeType=template.mime_type,
)
for template in templates
]

View file

@ -810,6 +810,27 @@ class TestServerResourceTemplates:
result = await resource.read()
assert result == "Data for test"
@pytest.mark.anyio
async def test_resource_template_includes_mime_type(self):
"""Test that list resource templates includes the correct mimeType."""
mcp = FastMCP()
@mcp.resource("resource://{user}/csv", mime_type="text/csv")
def get_csv(user: str) -> str:
return f"csv for {user}"
templates = await mcp.list_resource_templates()
assert len(templates) == 1
template = templates[0]
assert hasattr(template, "mimeType")
assert template.mimeType == "text/csv"
async with client_session(mcp._mcp_server) as client:
result = await client.read_resource(AnyUrl("resource://bob/csv"))
assert isinstance(result.contents[0], TextResourceContents)
assert result.contents[0].text == "csv for bob"
class TestContextInjection:
"""Test context injection in tools, resources, and prompts."""