File size: 2,088 Bytes
79df050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
import pytest

from features.mcp.mcp_client import MCPClient


def test_create_tool_from_data_preserves_output_schema():
    client = MCPClient("server", {"command": "noop"})

    tool = client._create_tool_from_data(
        {
            "name": "remote_tool",
            "description": "Remote tool",
            "inputSchema": {"type": "object", "properties": {}},
            "outputSchema": {
                "type": "object",
                "properties": {"success": {"type": "boolean"}},
                "required": ["success"],
            },
        }
    )

    assert tool is not None
    assert tool.outputSchema["properties"]["success"]["type"] == "boolean"


@pytest.mark.asyncio
async def test_call_tool_returns_structured_content(monkeypatch):
    client = MCPClient("server", {"command": "noop"})

    async def fake_send_request(method, params):
        return {
            "result": {
                "content": [{"type": "text", "text": "fallback text"}],
                "structuredContent": {
                    "success": True,
                    "value": "structured",
                },
            }
        }

    monkeypatch.setattr(client, "_send_request", fake_send_request)

    result = await client._call_tool("remote_tool", {})

    assert result == {
        "success": True,
        "value": "structured",
    }


@pytest.mark.asyncio
async def test_call_tool_preserves_error_semantics_with_structured_content(monkeypatch):
    client = MCPClient("server", {"command": "noop"})

    async def fake_send_request(method, params):
        return {
            "result": {
                "content": [{"type": "text", "text": "failed"}],
                "structuredContent": {
                    "error_code": "REMOTE_ERROR",
                },
                "isError": True,
            }
        }

    monkeypatch.setattr(client, "_send_request", fake_send_request)

    result = await client._call_tool("remote_tool", {})

    assert result == {
        "error_code": "REMOTE_ERROR",
        "success": False,
        "error": "failed",
    }