spring-projects / spring-projects/spring-ai

[Bug - MCP server] Tool output schemas are not generated for primitives or "simple" types

Open Beginner friendly
#6,773 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Bug description

This tool will silently not get an output schema

@McpTool(generateOutputSchema = true)
public int returnsInt() {
     return 1;
}

Environment

Spring AI version: 2.0.0

Expected behavior

Generate this output schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "integer",
  "format": "int32"
}

Details

Primitive types are filtered here

https://github.com/spring-projects/spring-ai/blob/573d6d342e047d69f16fb3959568e9d1766e24e8/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/provider/tool/SyncMcpToolProvider.java#L124-L131

I know the schema is simple, but what's the reason to not generate it? It's useful for the LLM to know what type a tool returns, even when the type is simple.

I tried to git blame this to see if I could determine the reason this filtering was added, but it was bulk imported as part of a 50k LOC commit.

Probably if generateOutputSchema is set to true, and the code decides that it will not be honoured, then there should be a warning logged

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/provider/tool/SyncMcpToolProvider.java around lines 124-131, where primitive types are filtered. Check how generateOutputSchema is handled for int and other simple return types, then verify that returnsInt() produces the expected integer JSON schema when the flag is true.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.