fix: re-add lightweight MCP servers section to system prompt for OpenAI compatibility #11322
+245
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11317
Description
This PR attempts to address Issue #11317 where OpenAI/ChatGPT models are unable to detect or call MCP tools.
Root Cause: In PR #10895, the MCP SERVERS section was removed from the system prompt when MCP tools were migrated to native tool definitions. While Claude and Gemini handle native tool definitions well on their own, OpenAI models need additional system prompt context to understand:
mcp--serverName--toolNamefunctions represent MCP server toolsSolution: Re-add a lightweight MCP servers section to the system prompt that:
mcp--git--git_log)mcp--serverName--toolNamenaming conventionThis is intentionally more lightweight than the old removed section -- no duplicated tool schemas or descriptions (already in native tool definitions), just the mapping context and server instructions that are currently missing.
Files changed:
src/core/prompts/sections/mcp-servers.ts- New lightweight MCP servers sectionsrc/core/prompts/sections/index.ts- Re-export the new sectionsrc/core/prompts/system.ts- Include the section in the prompt (only when MCP is enabled)src/core/prompts/sections/__tests__/mcp-servers.spec.ts- 11 tests covering all edge casesTest Procedure
cd src && npx vitest run core/prompts/sections/__tests__/mcp-servers.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
Feedback and guidance are welcome. This is an attempt to address the issue; the approach preserves the benefits of native tool calling (no schema duplication) while restoring contextual information that helps OpenAI models understand and use MCP tools.
Important
Re-adds a lightweight MCP servers section to the system prompt for OpenAI compatibility, including server names, tool mappings, and instructions, with tests for various scenarios.
mcp-servers.tsfor OpenAI compatibility.system.tswhen MCP is enabled.mcp-servers.spec.tsfor various scenarios including connected/disconnected servers, tool filtering, and server instructions.getMcpServersSectioninindex.ts.This description was created by
for 803a264. You can customize this summary. It will automatically update as commits are pushed.