fix(mcp): package YAML parser with MCP extra

This commit is contained in:
Sisyphus 2026-08-31 22:11:31 +08:00
parent ae3a572ef3
commit 681554ca36
4 changed files with 13 additions and 3 deletions

View file

@ -158,7 +158,7 @@ def _sanitize_path_parameter_value(param_value: object, param_name: str) -> str:
return quote(value_str, safe="")
def load_openapi_spec(filepath: str) -> dict[str, Any]:
def load_openapi_spec(filepath: str) -> Mapping[str, Any]:
"""
Sync wrapper. For URL specs, use the shared/custom MCP httpx client.
"""
@ -176,7 +176,7 @@ def load_openapi_spec(filepath: str) -> dict[str, Any]:
return asyncio.run(load_openapi_spec_async(filepath))
def _parse_openapi_spec(text: str) -> dict[str, Any]:
def _parse_openapi_spec(text: str) -> Mapping[str, Any]:
"""Parse JSON or YAML OpenAPI documents into a mapping."""
try:
parsed: Any = json.loads(text)

View file

@ -123,7 +123,7 @@ utils = [
"numpydoc>=1.8.0,<2.0",
]
caching = ["diskcache>=5.6.3,<6.0"]
mcp = ["mcp>=2.2.0,<3", "httpx2>=2.5.0,<3", "pydantic>=2.12.0,<3"]
mcp = ["mcp>=2.2.0,<3", "httpx2>=2.5.0,<3", "pydantic>=2.12.0,<3", "pyyaml>=6.0.3,<7.0"]
# Driver for the MongoDB Atlas vector store; Atlas Vector Search has no HTTP query API.
# The floor is 4.9 because that is the release AsyncMongoClient landed in.
# SAML SSO for the admin UI. python3-saml pulls in xmlsec/lxml, whose wheels

View file

@ -119,3 +119,11 @@ def test_load_openapi_spec_supports_local_file_path(tmp_path, monkeypatch: pytes
spec = gen.load_openapi_spec(str(p))
assert spec == expected
def test_load_openapi_spec_rejects_non_object_document(tmp_path) -> None:
p = tmp_path / "openapi.yaml"
p.write_text("- not an OpenAPI object\n", encoding="utf-8")
with pytest.raises(TypeError, match="OpenAPI spec must be a JSON or YAML object"):
gen.load_openapi_spec(str(p))

2
uv.lock generated
View file

@ -4562,6 +4562,7 @@ mcp = [
{ name = "httpx2" },
{ name = "mcp" },
{ name = "pydantic" },
{ name = "pyyaml" },
]
mlflow = [
{ name = "mlflow" },
@ -4840,6 +4841,7 @@ requires-dist = [
{ name = "python3-saml", marker = "extra == 'saml'", specifier = ">=1.16.0,<2.0" },
{ name = "pyyaml", specifier = ">=6.0.3,<7.0" },
{ name = "pyyaml", marker = "extra == 'cli'", specifier = ">=6.0.3,<7.0" },
{ name = "pyyaml", marker = "extra == 'mcp'", specifier = ">=6.0.3,<7.0" },
{ name = "pyyaml", marker = "extra == 'proxy'", specifier = ">=6.0.3,<7.0" },
{ name = "redisvl", marker = "extra == 'extra-proxy'", specifier = ">=0.4.1,<1.0" },
{ name = "requests", marker = "extra == 'cli'", specifier = ">=2.32.0,<3.0" },