Skip to content

fix: reduce MCP tool name delimiter to prevent OpenAI 64-char limit errors #1371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MinesJA
Copy link

@MinesJA MinesJA commented Jun 24, 2025

Fixes issue where MCP tool names exceed OpenAI's 64-character limit by using a shorter delimiter.

Fixes #1289

…rrors

- Change delimiter from "__OAI_CODEX_MCP__" (17 chars) to "__" (2 chars)
- Add validation and truncation logic for tool names exceeding 64 chars
- Skip tools when server name alone is too long
- Add hash suffix for uniqueness when truncating tool names
- Add comprehensive tests for new functionality

Fixes openai#1289

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

github-actions bot commented Jun 24, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@MinesJA
Copy link
Author

MinesJA commented Jun 24, 2025

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Jun 24, 2025
@@ -193,7 +198,46 @@ pub async fn list_all_tools(

for tool in list_result.tools {
// TODO(mbolin): escape tool names that contain invalid characters.
let fq_name = fully_qualified_tool_name(&server_name, &tool.name);
let mut fq_name = fully_qualified_tool_name(&server_name, &tool.name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fully_qualified_tool_name() and try_parse_fully_qualified_tool_name() must be symmetric. It is not clear that this is the case given this implementation.

Someone told me that, empirically, the model doesn't care about the names of the functions all that much and therefore, we could SHA1 the long name or something and things would still work.

Another solution that is somewhat stateful, but more readable for users, would be to get the full list of tool names and only attempt to "fully qualify them" when there is a naming collision.

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.

generated MCP tool names are too long
2 participants