Add resources parameter to MCPServer (#2414)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
parent
f27d2aac05
commit
c5f12ec1e9
1 changed files with 170 additions and 185 deletions
|
|
@ -685,6 +685,32 @@ class TestServerTools:
|
|||
|
||||
|
||||
class TestServerResources:
|
||||
async def test_init_with_resources(self):
|
||||
def get_text() -> str:
|
||||
"""Seeded resource."""
|
||||
return "Hello from init!"
|
||||
|
||||
resource = FunctionResource.from_function(fn=get_text, uri="resource://init", name="init_resource")
|
||||
|
||||
mcp = MCPServer(resources=[resource])
|
||||
|
||||
async with Client(mcp) as client:
|
||||
assert client.initialize_result.capabilities.resources is not None
|
||||
|
||||
resources = await client.list_resources()
|
||||
assert len(resources.resources) == 1
|
||||
listed = resources.resources[0]
|
||||
assert listed.uri == "resource://init"
|
||||
assert listed.name == "init_resource"
|
||||
assert listed.description == "Seeded resource."
|
||||
|
||||
result = await client.read_resource("resource://init")
|
||||
|
||||
assert len(result.contents) == 1
|
||||
content = result.contents[0]
|
||||
assert isinstance(content, TextResourceContents)
|
||||
assert content.text == "Hello from init!"
|
||||
|
||||
async def test_text_resource(self):
|
||||
mcp = MCPServer()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue