Skip to content

fix: improve warning message when MCP tool is skipped in stateless mode#5787

Open
anuragg-saxenaa wants to merge 3 commits intospring-projects:mainfrom
anuragg-saxenaa:fix/issue-5373-mcp-stateless-bidirectional-warning
Open

fix: improve warning message when MCP tool is skipped in stateless mode#5787
anuragg-saxenaa wants to merge 3 commits intospring-projects:mainfrom
anuragg-saxenaa:fix/issue-5373-mcp-stateless-bidirectional-warning

Conversation

@anuragg-saxenaa
Copy link
Copy Markdown

Summary

Fixes #5373.

When a @McpTool method has McpSyncServerExchange or McpSyncRequestContext parameters, SyncStatelessMcpToolProvider silently drops the tool during discovery. The previous warning was:

Stateless servers doesn't support bidirectional parameters. Skipping method public java.lang.String com.example.MyTools.doWork(io.modelcontextprotocol.server.McpSyncServerExchange) with bidirectional parameters

This is hard to parse — method.toString() produces a long reflection signature with no actionable guidance.

New warning:

Skipping MCP tool method 'MyTools.doWork' — stateless servers do not support bidirectional parameters (McpSyncServerExchange). To use this tool, switch to a stateful server (McpServerTransportProvider with session support).

Changes:

  • Shows ClassName.methodName instead of the raw Method.toString() reflection dump
  • Lists only the offending parameter type(s) by simple name
  • Adds a hint pointing to the solution (stateful server)

No behavior change — tools are still filtered the same way. Only the log message is improved.

Testing

All 46 existing McpPredicatesTests pass unchanged — the filter behavior is identical.

…ing-projects#1818)

Add @ConditionalOnProperty to the openAiApi bean inside
OpenAiChatAutoConfiguration so it is only created when either
spring.ai.openai.api-key or spring.ai.openai.chat.api-key is
present. Previously, configuring only spring.ai.openai.image.api-key
caused an IllegalArgumentException at startup because the chat
auto-configuration always tried to resolve a chat API key.

Adds a regression test that loads both chat and image auto-configurations
with only the image API key set, and verifies the context starts
successfully with the image model present and no chat model created.

Signed-off-by: anuragg-saxenaa <anuragg.saxenaa@gmail.com>
Integer.parseInt() throws NumberFormatException for values exceeding
Integer.MAX_VALUE (2147483647). visitIntegerConstant now falls back to
Long.parseLong() for out-of-range values, allowing filter expressions
like `id == 9223372036854775807` to parse correctly without requiring
an explicit 'L' suffix.

Fixes: spring-projectsgh-4705
Signed-off-by: anuragg-saxenaa <anuragg.saxenaa@gmail.com>
…s in stateless mode

The previous warning log in filterMethodWithBidirectionalParameters() used
method.toString() which produces a verbose, hard-to-read signature. Developers
had no actionable context about which tool class and method was silently dropped
or why.

The updated warning includes:
- Declaring class simple name and method name (e.g. 'MyTools.doWork')
- The specific bidirectional parameter types that caused the skip
  (e.g. McpSyncServerExchange)
- A suggestion to switch to a stateful server if bidirectional parameters
  are required

Fixes: spring-projectsgh-5373
Signed-off-by: anuragg-saxenaa <anuragg.saxenaa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tools with McpSyncServerExchange/McpSyncRequestContext parameters are silently ignored in stateless mode

1 participant