Repository navigation
fix(instrumentation): preserve FastMCP client-only imports - #4611
wangjiawei-vegetable wants to merge 3 commits into
Conversation
charan-rathore
left a comment
There was a problem hiding this comment.
Ran this branch locally against the issue repro. On main, instrumenting with only fastmcp-slim[client] installed raises "ImportError: FastMCP server support is not installed" as soon as the client import happens. On this branch the new import tests pass (2 passed, 4 server-variant skips in a slim-only env) and no fastmcp.server modules get loaded. Moving the post-import hook to fastmcp.server.server keeps server-name capture intact for full installs in both import orders, and uninstrument is untouched (it never unwrapped the post-import hook anyway). Nice, focused fix.
a6e2ac1 to
e92e1cd
Compare
|
Hi @doronkopit5, a gentle follow-up on this PR fixing FastMCP client-only imports. Could you take a look when you have a chance? Happy to address any review feedback. Thanks! |
Enabling
McpInstrumentorbreaks OAuth and Client imports when onlyfastmcp-slim[client]==3.4.8is installed. The constructor hook runs as soon as the top-levelfastmcppackage loads and resolves its lazyFastMCPattribute, pulling in optional server dependencies and raisingFastMCP server support is not installed.Fixes #4612
Register the constructor hook on
fastmcp.server.serverinstead. Server-name capture still works when the server module is imported before or after instrumentation, while client-only imports keep the server unloaded and retain client instrumentation.Minimal reproduction with the published package:
Validation:
uncalled_for/ server-support error.Scope of the FastMCP 3.4.8 checks: the four existing server integration tests fail with both the upstream constructor hook and this change (resource reads, server spans, and workflow attributes). These failures also occur before this fix. The 3.4.8 matrix here validates imports and constructor name capture; the package suite validates existing server tracing with the repository's FastMCP 2.14.3 test dependency.
Summary by CodeRabbit
Bug Fixes
.mcpsuffix regardless of import order or import path.Tests