"""Integration test for navi/mcp/ against a real stdio MCP server."""

import sys

import pytest

from navi.mcp.client import McpClient
from navi.mcp.config import McpServerConfig


@pytest.mark.anyio
async def test_stdio_client_connects_lists_and_calls_tools():
    cfg = McpServerConfig(
        transport="stdio",
        command=sys.executable,
        args=["-m", "tests._mcp_test_server"],
    )
    client = McpClient("test", cfg)
    await client.connect()
    assert client.connected

    tools = await client.list_tools()
    names = {t.name for t in tools}
    assert "hello" in names
    assert "add" in names

    result = await client.call_tool("hello", {"name": "Navi"})
    assert "Hello, Navi!" in result

    result = await client.call_tool("add", {"a": 2, "b": 3})
    assert "5" in result

    await client.disconnect()
    assert not client.connected
