Skip to content

[codex] Fix FastMCP context argument schemas#7

Merged
cobanov merged 1 commit into
mainfrom
codex/fix-fastmcp-context-schema
May 21, 2026
Merged

[codex] Fix FastMCP context argument schemas#7
cobanov merged 1 commit into
mainfrom
codex/fix-fastmcp-context-schema

Conversation

@cobanov

@cobanov cobanov commented May 21, 2026

Copy link
Copy Markdown
Owner

Summary

Fix FastMCP tool registration so internal Context parameters are injected by the MCP server instead of being exposed as client-facing tool arguments.

Root Cause

The project uses from __future__ import annotations, so ctx: Context was stored as a postponed annotation string at runtime. FastMCP detects context parameters from the runtime annotation before building the tool input schema, so ctx was incorrectly included as a required MCP argument. Clients then failed tool calls with ctx Field required.

Changes

  • Normalize ctx annotations to the runtime Context type before registering predefined tools, get_database_schema, and run_sql.
  • Convert decorator-based registrations where needed so the annotation fix happens before FastMCP builds schemas.
  • Add a regression test proving ctx is absent from client-facing tool schemas while run_sql still requires query.

Validation

  • uv run ruff check src tests
  • uv run pytest

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e86aed5c-23af-40e1-a880-784e7753354f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-fastmcp-context-schema

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cobanov cobanov marked this pull request as ready for review May 21, 2026 23:36
@cobanov cobanov merged commit e7fefdf into main May 21, 2026
6 checks passed
@cobanov cobanov deleted the codex/fix-fastmcp-context-schema branch May 21, 2026 23:36
cobanov added a commit that referenced this pull request May 21, 2026
Patch release shipping the Context-schema fix that landed in #7. With
the bug in 0.3.0, every MCP client call returned `ctx Field required`
because `from __future__ import annotations` hid the Context parameter
from FastMCP's detection, so the server is effectively unusable on 0.3.0
and 0.3.1 is the first working release.
@cobanov cobanov restored the codex/fix-fastmcp-context-schema branch June 23, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant