openllmetry icon indicating copy to clipboard operation
openllmetry copied to clipboard

๐Ÿ› Bug Report: MCP instrumentation breaks fastmcp-slim client-only imports

Open wangjiawei-vegetable opened this issue 1 month ago โ€ข 3 comments

Component

All Packages โ€” specifically opentelemetry-instrumentation-mcp.

Description

Enabling McpInstrumentor causes OAuth and Client imports to fail when only fastmcp-slim[client] is installed.

The same imports succeed without instrumentation. A client-only application should be able to enable MCP instrumentation without installing FastMCP server dependencies.

Reproduction steps

Create a fresh environment and install the released packages:

uv venv --python 3.12
uv pip install --python .venv/bin/python \
  'opentelemetry-instrumentation-mcp==0.62.4' \
  'fastmcp-slim[client]==3.4.8' \
  'mcp==1.30.0'

First, verify that client imports work without instrumentation:

.venv/bin/python - <<'PY'
from fastmcp.client.auth import OAuth
from fastmcp import Client

print("Client imports succeeded")
PY

Then run the same imports with instrumentation enabled, in a fresh process:

.venv/bin/python - <<'PY'
from opentelemetry.instrumentation.mcp import McpInstrumentor

McpInstrumentor().instrument()

from fastmcp.client.auth import OAuth
from fastmcp import Client
PY

The first process succeeds. The second fails during import. No MCP server, network connection, or credentials are needed to reproduce this.

Expected behavior

OAuth and Client imports should succeed with MCP instrumentation enabled.

Instrumentation should preserve the client-only installation boundary and avoid loading optional FastMCP server components until they are explicitly imported.

Actual behavior

The instrumented process attempts to import FastMCP server support and fails:

ModuleNotFoundError: No module named 'uncalled_for'

ImportError: FastMCP server support is not installed.
Install `fastmcp` or `fastmcp-slim[server]`.

Python version and environment

Python:                           3.12.14
opentelemetry-instrumentation-mcp: 0.62.4
fastmcp-slim[client]:              3.4.8
mcp:                              1.30.0

Additional context

The constructor hook in fastmcp_instrumentation.py is registered against the top-level fastmcp package and wraps FastMCP.__init__.

Resolving that attribute invokes FastMCPโ€™s lazy import mechanism, which loads fastmcp.server.server and its optional dependencies.

A proposed fix is available in PR #4611: register the constructor hook against fastmcp.server.server instead. The PR includes fresh-process regression tests for both import orders and verifies that server-name capture still works with a full installation.

This report concerns the client-only import failure. The reproduction uses MCP SDK 1.x, so it is separate from the SDK 2.x API compatibility issue reported in #4413.

Duplicate check

  • [x] I searched existing issues and did not find a report of this client-only import failure.

Willing to submit a PR?

Yes โ€” a proposed fix is already submitted in #4611 for review.

wangjiawei-vegetable avatar Oct 12 '26 03:10 wangjiawei-vegetable

Hi! I'm interested in contributing to this issue as my first open-source contribution. I'd like to work on it if it's still available. Could you please confirm? Thank you!

Rakshana0205 avatar Oct 13 '26 12:10 Rakshana0205

Hi @Rakshana0205, thanks for your interest! I've already submitted a proposed fix in #4611, so work on this issue is already underway. You're welcome to take a look at the PR and share any feedback.

wangjiawei-vegetable avatar Oct 13 '26 12:10 wangjiawei-vegetable

Thank you for your reply! I understand that the fix for this issue is already underway. I'm looking to contribute to the project as a beginner. Could you please let me know if there is another open issue I could work on?

Rakshana0205 avatar Oct 14 '26 08:10 Rakshana0205