mcp server done
Some checks failed
MCP Tests / mcp-tests (pull_request) Failing after 4s

This commit is contained in:
Danilo Reyes
2026-02-01 10:36:54 -06:00
parent ecf058aacf
commit 8946ade5e8
15 changed files with 214 additions and 190 deletions

View File

@@ -4,7 +4,7 @@ from __future__ import annotations
import time
from mcp_server.server import handle_request
from mcp_server import tools
MAX_LATENCY_SECONDS = 2
@@ -12,7 +12,7 @@ MAX_LATENCY_SECONDS = 2
def test_list_tools_is_fast() -> None:
"""ListTools responds under the latency target."""
start = time.perf_counter()
handle_request({"method": "listTools", "params": {}})
tools.list_tools_payload()
duration = time.perf_counter() - start
assert duration < MAX_LATENCY_SECONDS
@@ -20,6 +20,6 @@ def test_list_tools_is_fast() -> None:
def test_invoke_tool_is_fast() -> None:
"""InvokeTool responds under the latency target."""
start = time.perf_counter()
handle_request({"method": "invokeTool", "params": {"name": "show-constitution", "args": {}}})
tools.invoke_tool("show-constitution", {})
duration = time.perf_counter() - start
assert duration < MAX_LATENCY_SECONDS

View File

@@ -1,56 +1,27 @@
"""Server dispatch tests."""
"""Server tool wiring tests."""
from __future__ import annotations
from mcp_server import server as server_module
from mcp_server.server import handle_request
METHOD_NOT_FOUND = -32601
from mcp_server import tools
def test_list_tools_round_trip() -> None:
"""ListTools returns catalog entries."""
response = handle_request({"method": "listTools", "params": {}})
tools = response["result"]["tools"]
assert isinstance(tools, list)
assert any(entry["name"] == "show-constitution" for entry in tools)
payload = tools.list_tools_payload()
tool_list = payload["tools"]
assert isinstance(tool_list, list)
assert any(entry["name"] == "show-constitution" for entry in tool_list)
def test_invoke_tool_round_trip() -> None:
"""InvokeTool returns standard shape."""
response = handle_request(
{"method": "invokeTool", "params": {"name": "show-constitution", "args": {}}}
)
result = response["result"]
result = tools.invoke_tool("show-constitution", {})
assert result["status"] in {"ok", "unsupported", "invalid_input"}
assert "output" in result
def test_sync_docs_response_shape() -> None:
"""SyncDocs returns expected fields."""
response = handle_request({"method": "syncDocs", "params": {}})
result = response["result"]
result = tools.invoke_tool("sync-docs", {})
assert "status" in result
assert "missingInDocs" in result
def test_invalid_method() -> None:
"""Unknown method yields error."""
response = handle_request({"method": "unknown", "params": {}})
assert "error" in response
assert response["error"]["code"] == METHOD_NOT_FOUND
def test_unavailable_service_returns_actions(monkeypatch) -> None:
"""Invoke tool failure returns guidance."""
def boom(*_: object, **__: object) -> dict:
raise RuntimeError("boom")
monkeypatch.setattr(server_module, "invoke_tool", boom)
response = handle_request(
{"method": "invokeTool", "params": {"name": "list-mcp-tasks", "args": {}}}
)
assert "result" in response
assert response["result"]["status"] == "failed"
assert "actions" in response["result"]
assert "missingInDocs" in result["output"]

View File

@@ -21,7 +21,7 @@ def test_invoke_tool_handles_unknown() -> None:
"""Unknown tool returns unsupported guidance."""
result = tools.invoke_tool("missing-tool", {})
assert result["status"] == "unsupported"
assert "listTools" in result["actions"][0]
assert "tools/list" in result["actions"][0]
def test_list_tools_payload_shape() -> None: