spring-projects / spring-projects/spring-ai

CallToolResult: support EmbeddedResources

Open
#4,534 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

mcp tool calling
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Using org.springframework.ai.tool.annotation.Tool with return of io.modelcontextprotocol.spec.McpSchema.CallToolResult does not work for io.modelcontextprotocol.spec.McpSchema.EmbeddedResource;

Limitation is probably inside org.springframework.ai.mcp.McpToolUtils, which only provides ImageContent and TextContent but not io.modelcontextprotocol.spec.McpSchema.EmbeddedResource;

return new SharedSyncToolSpecification(tool, (exchangeOrContext, request) -> {
    try {
       String callResult = toolCallback.call(ModelOptionsUtils.toJsonString(request.arguments()),
             new ToolContext(Map.of(TOOL_CONTEXT_MCP_EXCHANGE_KEY, exchangeOrContext)));
       if (mimeType != null && mimeType.toString().startsWith("image")) {
          return new McpSchema.CallToolResult(List
             .of(new McpSchema.ImageContent(List.of(Role.ASSISTANT), null, callResult, mimeType.toString())),
                false);
       }
       return new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(callResult)), false);
    }
    catch (Exception e) {
       return new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(e.getMessage())), true);
    }
});

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 org.springframework.ai.mcp.McpToolUtils and trace how CallToolResult content is handled for ImageContent and TextContent. Compare that path with McpSchema.EmbeddedResource and verify that tool results containing embedded resources are supported without regressing the existing content types.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.