mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-21 15:54:28 +01:00
fix: Update @mcp.resource to use function documentation as default descrip… (#489)
This commit is contained in:
@@ -136,3 +136,22 @@ class TestFunctionResource:
|
||||
content = await resource.read()
|
||||
assert content == "Hello, world!"
|
||||
assert resource.mime_type == "text/plain"
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_from_function(self):
|
||||
"""Test creating a FunctionResource from a function."""
|
||||
|
||||
async def get_data() -> str:
|
||||
"""get_data returns a string"""
|
||||
return "Hello, world!"
|
||||
|
||||
resource = FunctionResource.from_function(
|
||||
fn=get_data,
|
||||
uri="function://test",
|
||||
name="test",
|
||||
)
|
||||
|
||||
assert resource.description == "get_data returns a string"
|
||||
assert resource.mime_type == "text/plain"
|
||||
assert resource.name == "test"
|
||||
assert resource.uri == AnyUrl("function://test")
|
||||
|
||||
@@ -441,6 +441,24 @@ class TestServerResources:
|
||||
== base64.b64encode(b"Binary file data").decode()
|
||||
)
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_function_resource(self):
|
||||
mcp = FastMCP()
|
||||
|
||||
@mcp.resource("function://test", name="test_get_data")
|
||||
def get_data() -> str:
|
||||
"""get_data returns a string"""
|
||||
return "Hello, world!"
|
||||
|
||||
async with client_session(mcp._mcp_server) as client:
|
||||
resources = await client.list_resources()
|
||||
assert len(resources.resources) == 1
|
||||
resource = resources.resources[0]
|
||||
assert resource.description == "get_data returns a string"
|
||||
assert resource.uri == AnyUrl("function://test")
|
||||
assert resource.name == "test_get_data"
|
||||
assert resource.mimeType == "text/plain"
|
||||
|
||||
|
||||
class TestServerResourceTemplates:
|
||||
@pytest.mark.anyio
|
||||
|
||||
Reference in New Issue
Block a user