Bloom_Ware / tests /test_mcp_client_contract.py
LawrenceBai's picture
feat: overhaul MCP architecture with structured tool schemas, comprehensive care-mode skill definitions, and enhanced test coverage for pipelines and service integration.
79df050
Raw
History Blame Contribute Delete
2.09 kB
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",
}