agent-integration-guides / tests /test_server.py
markedet's picture
Add agent integration guides (EXP-044)
ac3dba3 verified
Raw History Blame Contribute Delete
1.23 kB
"""End-to-end test of examples/github_mcp_server.py over stdio with the SDK client.
Needs network access (calls the public GitHub API, unauthenticated, 3 requests).
Run: .venv/bin/python tests/test_server.py
"""
import asyncio
import sys
from pathlib import Path
from mcp import Client, StdioServerParameters
EX = Path(__file__).resolve().parent.parent / "examples"
async def main() -> int:
params = StdioServerParameters(command=sys.executable, args=[str(EX / "github_mcp_server.py")], cwd=str(EX))
async with Client(params) as c:
names = sorted(t.name for t in (await c.list_tools()).tools)
assert names == ["get_repo", "list_releases"], names
r = await c.call_tool("get_repo", {"owner": "modelcontextprotocol", "repo": "python-sdk"})
assert not r.is_error and r.structured_content["full_name"] == "modelcontextprotocol/python-sdk"
r = await c.call_tool("list_releases", {"owner": "modelcontextprotocol", "repo": "python-sdk", "limit": 2})
assert not r.is_error
bad = await c.call_tool("get_repo", {"owner": "../x", "repo": "y"})
assert bad.is_error
print("test_server: OK")
return 0
if __name__ == "__main__":
sys.exit(asyncio.run(main()))