spring-projects / spring-projects/spring-ai
Pluggable Java-method tool-definition strategies & typed inputSchema in MCP
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Hi @ThomasVitale,
I’ve tried to expose the REST methods of my application using MCP, but I haven’t
found an easy way to do so. I’d like to leverage Swagger v3 annotations for
tool definitions, but MethodToolCallbackProvider doesn’t support this
approach. The main issues are:
- Only
@Toolannotations are considered. There’s no way to plug in an
alternative strategy for creating tool definitions. - Parameter names are extracted from the bytecode. Without the
-parameters
compiler flag, descriptive names aren’t available.
I propose the following enhancements:
- Allow injection of alternative strategies for generating tool definitions
from different kinds of method metadata. The strategy based on
@Toolannotations could remain one of the built-in options. - Introduce a clear mapping between tool-definition parameter names and the
original Java method parameters.
Moreover, implementing this parameter mapping would be much simpler if
ToolDefinition.inputSchema were a typed object (as defined in the
MCP specification)
instead of a raw JSON string. This would allow implementations to assume that
parameters in the tool definition appear in the same order as in the bytecode.
Would it be feasible to introduce these backward-incompatible changes to
ToolDefinition, MethodToolCallbackProvider, and MethodToolCallback?
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the ToolDefinition, MethodToolCallbackProvider, and MethodToolCallback APIs, then compare inputSchema with the linked MCP specification. Define how alternative method-metadata strategies and parameter-name mappings should work, including the proposed typed inputSchema; the issue is done when those compatibility and design questions are resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100