Repository navigation
Conversation
…ssing Task._invoke_tool() unconditionally called get_context() and awaited ctx.info() before running inference. fastmcp raises when there is no active request context, and ctx.info() raises while the MCP session has not been established (request_context is None). Because the server is built with mask_error_details=True, the client only saw a generic, undiagnosable "Error calling tool 'pp_structurev3'" - the tool could not be invoked at all in that environment (issue PaddlePaddle#18391). Move the log into a best-effort helper that skips logging when the context or the session is unavailable, so informational logging can never fail a tool call. The inference path itself is unchanged.
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 this PR does
Makes the per-call informational log in
Task._invoke_toolbest-effort, so a missing MCP request context or an unestablished MCP session can no longer fail a tool call.mcp_server/paddleocr_mcp/tasks/base.pycurrently does:before running inference.
fastmcp.server.dependencies.get_context()raises when there is no active request context, andContext.info()raises while the session is not established:Because the server is created with
mask_error_details=True, an MCP client only sees the genericError calling tool 'pp_structurev3', with no indication that the log is what failed — the tool becomes uncallable and undiagnosable from the client side (reported in #18391; thePPStructureV3pipeline itself works when called directly in the same venv).Why it's needed
Logging is not part of the tool's contract. A transport/session that has not (yet) established a session must degrade to "no log line", not to a failed tool call. This is the guard the issue asks for, applied in the one place the context is actually touched, so it covers every task (
ocr,pp_structurev3,paddleocr_vl, …) rather than a single tool.How to verify
The guard has three branches; all three were exercised against the real module with a stubbed
fastmcp.server.dependencies:request_context is NoneRuntimeError→ maskedError calling toolget_context()raises)RuntimeErrorRisk & scope
predict()and result formatting are untouched.fastmcp/mcpversion bounds inmcp_server/pyproject.toml) is a packaging policy decision and is intentionally not changed here.Linked issues
Relates to #18391