Skip to content

Customize tools names processing: prefix and cutting #4333

@ashakirin

Description

@ashakirin

Currently Spring AI adds a prefix to resource names (spring_ai_<CLIENT_ID>) in order to prevent tool-name collision for tools coming from different MCP servers

Expected Behavior

(A) Provide an option to customize tool name processing in McpToolsUtils#prefixedToolName:

  • Prefixing of resource names
  • Max length cutting: currently is 64 INCLUSIVE prefix
  • [optionally] pattern for replacing special chars ([^a-zA-Z0-9_-])

(B) [optional]
By receiving tool to execute from LLM, check it's name again for length and pattern and if it doesn't match:

  • display warning
  • cut the name accordingly rules in McpToolsUtils#prefixedToolName

Current Behavior

Currently the prefixing and processing is not customizable

Context
I have interesting effect with some LLMs: Spring AI agent sends about 60 tools to LLM, with prefix like:
spring_ai_mcp_client_server1_<ORIG_TOOL_NAME>.
The most of names are not cut, but some of them are, because of exceed 64 chars limits:
_ai_mcp_client_server1_<ORIG_TOOL_NAME>

After that, some LLMs thinking, that it is mistake to name tool like _ai_mcp_client_server1_<ORIG_TOOL_NAME> and correct them to full name: spring_ai_mcp_client_server1_<ORIG_TOOL_NAME>.
As a result, Spring AI receives full tool name instead cut one and cannot find it in own callback definitions (because there are cut variant is saved: _ai_mcp_client_server1_<ORIG_TOOL_NAME> ).
It causes exception:
No ToolCallback found for tool name: spring_ai_mcp_client_server1_<ORIG_TOOL_NAME>

I am going to provide patch for (A), (B)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions