38 lines
1.6 KiB
Python
38 lines
1.6 KiB
Python
"""Public MCP discovery describes the arguments the server actually accepts."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from jsonschema import Draft202012Validator
|
|
|
|
|
|
def test_public_schemas_describe_adapter_arguments():
|
|
import mcp_adapters
|
|
|
|
for name, meta in mcp_adapters.CATALOG.items():
|
|
schema = meta["schema"]
|
|
Draft202012Validator.check_schema(schema)
|
|
assert schema["additionalProperties"] is False, name
|
|
for field, property_schema in schema["properties"].items():
|
|
assert property_schema.get("description"), (name, field)
|
|
|
|
stove = mcp_adapters.CATALOG["stove_estimate"]["schema"]
|
|
valid = {"stove": {"kind": "heating", "bricks": {"ceramic": 500, "fireclay": 100},
|
|
"region": "Приморский край"}}
|
|
assert not list(Draft202012Validator(stove).iter_errors(valid))
|
|
invalid = {"stove": {"kind": "unknown", "bricks": {}, "region": "Приморский край"}}
|
|
assert list(Draft202012Validator(stove).iter_errors(invalid))
|
|
|
|
|
|
def test_tool_results_offer_structured_json_and_text_fallback():
|
|
from external_mcp import _tool_result
|
|
|
|
for name, expected in (("ok", {"value": 42}),
|
|
("bad", {"error": "invalid_request", "detail": "bad"})):
|
|
result = _tool_result(expected)
|
|
assert result.structuredContent == expected
|
|
assert json.loads(result.content[0].text) == expected
|
|
assert result.isError is (name == "bad")
|
|
converted = _tool_result({"file": Path("report.xlsx")})
|
|
assert converted.structuredContent == {"file": "report.xlsx"}
|