|
| 1 | +import sys |
| 2 | +import pytest |
| 3 | +from mcp.client.session import ClientSession |
| 4 | +from mcp.client.stdio import StdioServerParameters, stdio_client |
| 5 | +from mcp_server_iris.server import server |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +async def iris_config(request): |
| 10 | + return { |
| 11 | + "IRIS_HOSTNAME": request.config.option.iris_host, |
| 12 | + "IRIS_PORT": str(request.config.option.iris_port), |
| 13 | + "IRIS_NAMESPACE": request.config.option.iris_namespace, |
| 14 | + "IRIS_USERNAME": request.config.option.iris_username, |
| 15 | + "IRIS_PASSWORD": request.config.option.iris_password, |
| 16 | + } |
| 17 | + |
| 18 | + |
| 19 | +def test_server_initialization(): |
| 20 | + """Test that the server initializes correctly.""" |
| 21 | + assert server.name == "InterSystems IRIS MCP Server" |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.asyncio |
| 25 | +async def test_list_tools(): |
| 26 | + """Test that list_tools returns expected tools.""" |
| 27 | + tools = await server.list_tools() |
| 28 | + assert len(tools) > 0 |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.asyncio |
| 32 | +async def test_params_in_tool(): |
| 33 | + # print(f"Tools: {tools}") |
| 34 | + tools = await server.list_tools() |
| 35 | + execute_sql_tool = next(t for t in tools if t.name == "execute_sql") |
| 36 | + props = list(execute_sql_tool.inputSchema["properties"].keys()) |
| 37 | + assert len(props) == 2 |
| 38 | + assert props[0] == "query" |
| 39 | + assert props[1] == "params" |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.asyncio |
| 43 | +async def test_call_tool_execute_sql(iris_config): |
| 44 | + """Test calling execute_sql with a query.""" |
| 45 | + async with stdio_client(StdioServerParameters(command=sys.executable, args=["-m", "mcp_server_iris"], env=iris_config)) as (read, write): |
| 46 | + async with ClientSession(read, write) as session: |
| 47 | + await session.initialize() |
| 48 | + _ = await session.call_tool( |
| 49 | + "execute_sql", |
| 50 | + { |
| 51 | + "query": "select $namespace, $zversion", |
| 52 | + "params": [], |
| 53 | + }, |
| 54 | + ) |
0 commit comments