FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(fastmcp): propagate mimeType in resource template list by pchoudhury22 · Pull Request #1186 · modelcontextprotocol/python-sdk · GitHub

1 change: 1 addition & 0 deletions src/mcp/server/fastmcp/server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ async def list_resource_templates(self) -> list[MCPResourceTemplate]:
name=template.name,
title=template.title,
description=template.description,
mimeType=template.mime_type,
)
for template in templates
]
Expand Down
21 changes: 21 additions & 0 deletions tests/server/fastmcp/test_server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,27 @@ def get_data(name: str) -> str:
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."""
Expand Down
Loading

Back | FazBrowse Home | New Git URL