Skip to content

Harden fastmcp metadata parsing in proxy paths#3412

Merged
jlowin merged 1 commit intomainfrom
codex/fix-proxy-provider-crash-on-malformed-metadata
Mar 7, 2026
Merged

Harden fastmcp metadata parsing in proxy paths#3412
jlowin merged 1 commit intomainfrom
codex/fix-proxy-provider-crash-on-malformed-metadata

Conversation

@jlowin
Copy link
Member

@jlowin jlowin commented Mar 6, 2026

Motivation

  • Proxy component ingestion assumed meta["fastmcp"] (or legacy _fastmcp) is always a mapping, so a remote server returning a non-dict value could cause .get("tags") to raise and crash proxy listing/ingestion paths.
  • The change defends against malformed upstream metadata by treating non-dict fastmcp/_fastmcp values as absent, restoring the previous tolerant behavior and preventing a remote DoS vector.

Description

  • Make get_fastmcp_metadata(meta) defensive: it now returns the first namespace value that is a dict and otherwise returns {} so non-dict upstream values are ignored.
  • Add unit tests for the helper to verify valid fastmcp dict is returned, legacy _fastmcp is used when appropriate, and non-dict values are ignored.
  • Files changed: src/fastmcp/utilities/components.py (metadata parsing logic) and tests/utilities/test_components.py (new tests).

Example usage after the change:

meta = {"fastmcp": "not-a-dict", "_fastmcp": {"tags": ["legacy"]}}
metadata = get_fastmcp_metadata(meta)
tags = metadata.get("tags", [])  # safe, legacy tags preserved

Testing

  • Ran uv sync successfully to prepare the environment.
  • Ran the full test suite with uv run pytest -n auto, which surfaced unrelated existing failures/timeouts in this environment (several unrelated tests failed); these failures are not caused by this patch.
  • Ran focused tests covering the change with uv run pytest tests/utilities/test_components.py tests/server/providers/proxy/test_proxy_server.py -n auto, which completed successfully (the component/proxy tests passed).
  • Attempted uv run prek run --all-files but hook initialization failed due to external network access when fetching hooks (pre-commit mirror bootstrap error), so lint hooks were not executed in this environment.

Codex Task

🤖 Generated with GPT-5.2-Codex
@marvin-context-protocol marvin-context-protocol bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. server Related to FastMCP server implementation or server-side functionality. labels Mar 6, 2026
@jlowin
Copy link
Member Author

jlowin commented Mar 7, 2026

Auto-reviewed and merging on behalf of @jlowin — CI is green (Windows OAuth proxy timeouts are pre-existing flaky tests).

@jlowin jlowin merged commit 706b56d into main Mar 7, 2026
8 checks passed
@jlowin jlowin deleted the codex/fix-proxy-provider-crash-on-malformed-metadata branch March 7, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. codex server Related to FastMCP server implementation or server-side functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant