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:
parent
c3717e7ad3
commit
ca5cb4cb67
2 changed files with 22 additions and 0 deletions
|
|
@ -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
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue