File size: 1,234 Bytes
ac3dba3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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()))