fix: re-add lightweight MCP servers section to system prompt for OpenAI compatibility#11323
fix: re-add lightweight MCP servers section to system prompt for OpenAI compatibility#11323roomote[bot] wants to merge 1 commit intomainfrom
Conversation
…AI compatibility OpenAI models (e.g., GPT-5.2) fail to call MCP tools because they need explicit system prompt context about available MCP servers and the mcp--serverName--toolName naming convention. Claude and Gemini models handle this from native tool definitions alone, but OpenAI models do not. This commit adds a lightweight MCP SERVERS section to the system prompt that includes: - The mcp--serverName--toolName naming convention explanation - A list of connected servers and their tool names - Server-specific instructions (from the MCP protocol instructions field) This does NOT duplicate tool schemas or descriptions (already provided via native tool definitions), keeping the prompt compact. Closes #11317
Review complete. The implementation is clean and well-structured. One test coverage gap noted.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| // Tools catalog is not included in the system prompt. | ||
| const toolsCatalog = "" | ||
|
|
||
| const mcpServersSection = shouldIncludeMcp ? getMcpServersSection(mcpHub) : "" |
There was a problem hiding this comment.
The existing createMockMcpHub(true) in system-prompt.spec.ts creates a mock server without a tools array. Since getMcpServersSection skips servers with no enabled tools, this new section always evaluates to "" in the integration test, and the with-mcp-hub-provided.snap snapshot was not updated. This means there is no integration-level test verifying the new MCP SERVERS section actually appears in the final system prompt output. Consider adding tools (with at least one enabled tool) to the mock so the snapshot captures and locks down this new behavior.
Fix it with Roo Code or mention @roomote and request a fix.
Related GitHub Issue
Closes: #11317
Description
This PR attempts to address Issue #11317 where OpenAI models (e.g., GPT-5.2) fail to call MCP tools.
Root Cause: In PR #10895, the MCP SERVERS section was removed from the system prompt. While Claude and Gemini models can infer tool usage from native function definitions alone, OpenAI models need more explicit system prompt context about available MCP servers and the
mcp--serverName--toolNamenaming convention.Solution: Re-adds a lightweight MCP SERVERS section to the system prompt that includes:
mcp--serverName--toolNamenaming convention explanationinstructionsfield)This intentionally does NOT duplicate tool schemas or descriptions (already provided via native tool definitions), keeping the prompt compact while giving models the context they need.
Files Changed
src/core/prompts/sections/mcp-servers.ts- New lightweight MCP servers section generatorsrc/core/prompts/sections/index.ts- Re-exports the new sectionsrc/core/prompts/system.ts- Includes the new section in the system promptsrc/core/prompts/sections/__tests__/mcp-servers.spec.ts- 14 tests covering all edge casesTest Procedure
cd src && npx vitest run core/prompts/sections/__tests__/mcp-servers.spec.ts(14 tests passing)cd src && npx vitest run core/prompts/(207 tests passing across 20 test files, zero regressions)Feedback and guidance are welcome.
Pre-Submission Checklist
Documentation Updates
Additional Notes
This is a minimal, targeted fix. The new MCP section is only included when the mode has access to MCP tools and there are connected servers with enabled tools.
Important
Re-adds lightweight MCP SERVERS section to system prompt for OpenAI compatibility, including naming conventions and server lists, without duplicating tool schemas.
mcp-servers.ts: New section generator for MCP servers.system.ts: Integrates new section into system prompt.mcp-servers.spec.ts: 14 tests for edge cases.mcp-servers.spec.ts.This description was created by
for 1a418f7. You can customize this summary. It will automatically update as commits are pushed.