|
| 1 | +"""Tests for Gumloop aggregate_tool_call_results config.""" |
| 2 | + |
| 3 | +import json |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from mcp.server import Server |
| 8 | +from mcp.shared.memory import create_connected_server_and_client_session |
| 9 | +from mcp.types import TextContent, Tool |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.anyio |
| 13 | +async def test_aggregate_tool_call_results_enabled(): |
| 14 | + """When aggregate_tool_call_results=True, multiple content items combine into single JSON.""" |
| 15 | + server = Server("test") |
| 16 | + server.config = {"aggregate_tool_call_results": True} |
| 17 | + |
| 18 | + @server.list_tools() |
| 19 | + async def list_tools(): |
| 20 | + return [Tool(name="multi", description="Multi", inputSchema={"type": "object", "properties": {}})] |
| 21 | + |
| 22 | + @server.call_tool() |
| 23 | + async def call_tool(name: str, arguments: dict): |
| 24 | + return [TextContent(type="text", text="Result 1"), TextContent(type="text", text="Result 2")] |
| 25 | + |
| 26 | + async with create_connected_server_and_client_session(server) as client: |
| 27 | + result = await client.call_tool("multi", {}) |
| 28 | + |
| 29 | + assert result.isError is False |
| 30 | + assert len(result.content) == 1 |
| 31 | + parsed = json.loads(result.content[0].text) |
| 32 | + assert len(parsed) == 2 |
| 33 | + assert parsed[0]["text"] == "Result 1" |
| 34 | + assert parsed[1]["text"] == "Result 2" |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.anyio |
| 38 | +async def test_aggregate_tool_call_results_disabled(): |
| 39 | + """When aggregate_tool_call_results not set, multiple content items remain separate.""" |
| 40 | + server = Server("test") |
| 41 | + |
| 42 | + @server.list_tools() |
| 43 | + async def list_tools(): |
| 44 | + return [Tool(name="multi", description="Multi", inputSchema={"type": "object", "properties": {}})] |
| 45 | + |
| 46 | + @server.call_tool() |
| 47 | + async def call_tool(name: str, arguments: dict): |
| 48 | + return [TextContent(type="text", text="Result 1"), TextContent(type="text", text="Result 2")] |
| 49 | + |
| 50 | + async with create_connected_server_and_client_session(server) as client: |
| 51 | + result = await client.call_tool("multi", {}) |
| 52 | + |
| 53 | + assert result.isError is False |
| 54 | + assert len(result.content) == 2 |
| 55 | + assert result.content[0].text == "Result 1" |
| 56 | + assert result.content[1].text == "Result 2" |
0 commit comments