You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(mcp): restore analytics capture for standalone FastMCP 4 (#936)
* fix(mcp): capture standalone FastMCP on the v2 registry
Select the adapter by handler registry so standalone FastMCP 4 captures
tool calls without changing the customer's instrument() invocation.
Preserve application-owned arguments, including mounted tools, and use
native v2 model fields when FastMCP exposes deprecated v1 aliases.
Add HTTP regression coverage for both protocol eras, late tool registration,
repeat instrumentation, failed tools, unavailable capture, and mounted
argument ownership. Include FastMCP 4 in the existing MCP v2 CI matrix,
document adapter behavior, and add a Sampo patch changeset.
Validation on current main: MCP v1 suite 307 passed; MCP v2 suite 291 passed,
13 skipped. Ruff lint/format, filtered mypy (231 source files), import
warning check, and actionlint passed. Real stdio tools emitted HTTP capture
batches to a local receiver under both protocol eras, two events per run.
Authenticated wizard installation and hosted ingestion remain untested.
* fix(mcp): preserve FastMCP schemas across setup order and versions
Keep a weak reference to the standalone FastMCP wrapper in shared tracking
state so a later wrapper install enriches existing low-level instrumentation
without wrapping handlers twice. Resolve schemas for the client-requested
tool version before stripping analytics-owned arguments.
Consolidate adapter imports at the optional MCP dependency boundary instead
of repeating imports in dispatch branches. Keep FastMCP-specific imports
lazy so the official SDK remains usable without that optional package.
Validation: reproduced both setup-order failures and the versioned-tool
argument failure before fixing them. MCP v1 suite 307 passed; MCP v2 suite
296 passed, 13 skipped. Ruff format/lint and filtered mypy passed.
Fresh-process checks passed with MCP absent and with FastMCP absent.
* fix(mcp): strip FastMCP analytics arguments from what was advertised
Decide which analytics parameters to remove before dispatch from the tools/list
the process served, recorded per tool in mutate_tool_schema, instead of asking
FastMCP for the tool schema on every call. The live lookup remains only for tools
never listed here or when the client pins a tool version, and now logs when it
fails. Tools supplied by ToolInjectionMiddleware are listed but not resolvable via
get_tool(), so the per-call lookup advertised `context` and then forwarded it,
failing validation.
Tested: posthog/test/mcp under mcp 2.2.0 + fastmcp 4.0.3 (297 passed, 13
skipped, new middleware test red before the fix) and under mcp 1.30.0 + fastmcp
3.2.0 (307 passed); ruff, mypy-baseline clean.
Reviewer note: tool_model_parameter_injected still exists alongside the new
tool_injected_parameters set because four adapters read it; folding it in is a
follow-up.
Claude-Session: https://claude.ai/code/session_015wZCNFdfPNK9k4utwJ5bMu
* chore(mcp): verify middleware dispatch without schema lookup
Extend FastMCP HTTP coverage to prove middleware tools dispatch when get_tool returns None. Exercise calls before listing, all advertised analytics arguments after listing, and application-owned arguments in both paths. Document why unknown arguments remain intact.
Validation: MCP v1 suite 307 passed; MCP v2 suite 299 passed, 13 skipped. Ruff check and format checks passed for MCP source and tests. Repository-wide filtered mypy passed for 231 source files.
* fix(mcp): resolve FastMCP argument ownership per request
Remove the server-wide injected-parameter cache. Resolve effective schemas with the current request context, middleware, and requested tool version before stripping analytics arguments. Avoid using cached model ownership when schema resolution fails.
Add interleaved-client regression cases for dynamic providers, middleware tools, and middleware overrides in both listing orders. The provider and middleware cases reproduced a missing application-owned llm_model argument before the fix. Document the per-call schema lookup.
Validation: MCP v1 suite 307 passed; MCP v2 suite 305 passed, 13 skipped. Ruff check and format passed for MCP source and tests. Repository-wide filtered mypy passed for 231 files.
0 commit comments