Spaces:
Running
Running
File size: 2,502 Bytes
016762e 1b6e518 016762e 4e8b154 016762e 4e8b154 aa46c09 016762e 4e8b154 016762e aa46c09 016762e aa46c09 ff32168 016762e 4e8b154 016762e aa46c09 016762e 4e8b154 1b6e518 4e8b154 d4fceae 016762e 4e8b154 aa46c09 016762e 4e8b154 1b6e518 4e8b154 d4fceae 016762e 4e8b154 1b6e518 4e8b154 d4fceae 016762e 4e8b154 016762e 26e35ea d4fceae | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | """Tests for example servers"""
from pydantic import AnyUrl
from fastmcp import Client
async def test_simple_echo():
"""Test the simple echo server"""
from examples.simple_echo import mcp
async with Client(mcp) as client:
result = await client.call_tool_mcp("echo", {"text": "hello"})
assert len(result.content) == 1
assert result.content[0].text == "hello" # type: ignore[attr-defined]
async def test_complex_inputs():
"""Test the complex inputs server"""
from examples.complex_inputs import mcp
async with Client(mcp) as client:
tank = {"shrimp": [{"name": "bob"}, {"name": "alice"}]}
result = await client.call_tool_mcp(
"name_shrimp", {"tank": tank, "extra_names": ["charlie"]}
)
assert len(result.content) == 1
assert result.content[0].text == '["bob","alice","charlie"]' # type: ignore[attr-defined]
async def test_desktop(monkeypatch):
"""Test the desktop server"""
from examples.desktop import mcp
async with Client(mcp) as client:
# Test the add function
result = await client.call_tool_mcp("add", {"a": 1, "b": 2})
assert len(result.content) == 1
assert result.content[0].text == "3" # type: ignore[attr-defined]
async with Client(mcp) as client:
result = await client.read_resource(AnyUrl("greeting://rooter12"))
assert len(result) == 1
assert result[0].text == "Hello, rooter12!" # type: ignore[attr-defined]
async def test_echo():
"""Test the echo server"""
from examples.echo import mcp
async with Client(mcp) as client:
result = await client.call_tool_mcp("echo_tool", {"text": "hello"})
assert len(result.content) == 1
assert result.content[0].text == "hello" # type: ignore[attr-defined]
async with Client(mcp) as client:
result = await client.read_resource(AnyUrl("echo://static"))
assert len(result) == 1
assert result[0].text == "Echo!" # type: ignore[attr-defined]
async with Client(mcp) as client:
result = await client.read_resource(AnyUrl("echo://server42"))
assert len(result) == 1
assert result[0].text == "Echo: server42" # type: ignore[attr-defined]
async with Client(mcp) as client:
result = await client.get_prompt("echo", {"text": "hello"})
assert len(result.messages) == 1
assert result.messages[0].content.text == "hello" # type: ignore[attr-defined]
|