mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 22:14:18 +02:00
Harden fastmcp metadata parsing in proxy paths (#3412)
🤖 Generated with GPT-5.2-Codex
This commit is contained in:
parent
ea19a2a5f5
commit
706b56d555
2 changed files with 27 additions and 1 deletions
|
|
@ -31,7 +31,13 @@ def get_fastmcp_metadata(meta: dict[str, Any] | None) -> FastMCPMeta:
|
|||
"""
|
||||
if not meta:
|
||||
return {}
|
||||
return cast(FastMCPMeta, meta.get("fastmcp") or meta.get("_fastmcp") or {})
|
||||
|
||||
for key in ("fastmcp", "_fastmcp"):
|
||||
metadata = meta.get(key)
|
||||
if isinstance(metadata, dict):
|
||||
return cast(FastMCPMeta, metadata)
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
def _convert_set_default_none(maybe_set: set[T] | Sequence[T] | None) -> set[T]:
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from fastmcp.utilities.components import (
|
|||
FastMCPComponent,
|
||||
FastMCPMeta,
|
||||
_convert_set_default_none,
|
||||
get_fastmcp_metadata,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -251,6 +252,25 @@ class TestKeyPrefix:
|
|||
assert WithPrefix.make_key("test") == "custom:test"
|
||||
|
||||
|
||||
class TestGetFastMCPMetadata:
|
||||
"""Tests for get_fastmcp_metadata helper."""
|
||||
|
||||
def test_returns_fastmcp_namespace_when_dict(self):
|
||||
meta = {"fastmcp": {"tags": ["a"]}, "_fastmcp": {"tags": ["b"]}}
|
||||
|
||||
assert get_fastmcp_metadata(meta) == {"tags": ["a"]}
|
||||
|
||||
def test_falls_back_to_legacy_namespace_when_dict(self):
|
||||
meta = {"fastmcp": "invalid", "_fastmcp": {"tags": ["legacy"]}}
|
||||
|
||||
assert get_fastmcp_metadata(meta) == {"tags": ["legacy"]}
|
||||
|
||||
def test_ignores_non_dict_metadata(self):
|
||||
assert get_fastmcp_metadata({"fastmcp": "invalid"}) == {}
|
||||
assert get_fastmcp_metadata({"fastmcp": ["invalid"]}) == {}
|
||||
assert get_fastmcp_metadata({"_fastmcp": "invalid"}) == {}
|
||||
|
||||
|
||||
class TestComponentEnableDisable:
|
||||
"""Tests for the enable/disable methods raising NotImplementedError."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue