Repository navigation
Conversation
…18391) Task._invoke_tool() sent an info notification through get_context() unconditionally. Without an active context, or with a context whose MCP session is not established, FastMCP raises and the tool call fails with "session is not available because the MCP session has not been established yet". The notification is now best-effort. Also constrain the dependencies to a combination that imports and runs: fastmcp>=4.0.0,<5.0.0 with mcp>=2.0.0,<3.0.0. The previous open-ended bounds allowed older fastmcp releases (e.g. 2.14.x) next to mcp 2.x, which fails at import time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Task._invoke_tool()(shared byocr,pp_structurev3,paddleocr_vl, …) sent an informational notification with:With FastMCP 4.x,
Context.info()goes throughContext.session, which raises when the MCP session is not established (request_context is None):and
get_context()raisesNo active context found.when the tool is called outside a request. Because the server usesmask_error_details=True, clients only seeError calling tool 'pp_structurev3'.I reproduced both errors in-process with fastmcp 4.1.4 / mcp 2.3.0 by calling the
pp_structurev3tool (stub inference) under aContextwithout a request context, and without any context.Changes
_notify_client()helper intasks/base.py: gets the context and probesctx.session. If either raisesRuntimeError, the notification is skipped instead of failing the tool. This still notifies in FastMCP's background-task mode, where the session is stored on the context butrequest_contextisNone.mcp_server/pyproject.toml:mcp>=1.5.0/fastmcp>=2.0.0→mcp>=2.0.0,<3.0.0/fastmcp>=4.0.0,<5.0.0. Several fastmcp releases (2.10.0, 2.14.0) declaremcpwithout an upper bound, and fastmcp 2.x/3.x import names thatmcp2.x renamed, so the old bounds allowed combinations that fail at import. The new bounds match what a fresh resolve already installs (fastmcp 4.1.4 + mcp 2.3.0).If you would rather keep supporting the fastmcp 2.x / mcp 1.x line, I can change this to
fastmcp>=2.14,<3+mcp>=1.24,<2instead. The code change works on both.Tests
tests/unit/test_mcp_task_context.pycalls thepp_structurev3tool:Contextwhoserequest_contextisNone,fastmcp.Client, asserting the info notification is still delivered.(1) and (2) fail on
main, and all three pass with the fix on fastmcp 4.0.0 + mcp 2.0.0 (the lower bounds) and on fastmcp 4.1.4 + mcp 2.3.0.python -m paddleocr_mcp --helpstarts on both. As with PR 1, the module skips when the MCP deps are not installed.Fixes #18391
🤖 Generated with Claude Code