Skip to content

fix: re-add lightweight MCP servers section to system prompt for OpenAI compatibility#11323

Draft
roomote[bot] wants to merge 1 commit intomainfrom
fix/mcp-tools-openai-system-prompt
Draft

fix: re-add lightweight MCP servers section to system prompt for OpenAI compatibility#11323
roomote[bot] wants to merge 1 commit intomainfrom
fix/mcp-tools-openai-system-prompt

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Feb 9, 2026

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--toolName naming convention.

Solution: Re-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 available tool names
  • Server-specific instructions (from the MCP protocol instructions field)

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 generator
  • src/core/prompts/sections/index.ts - Re-exports the new section
  • src/core/prompts/system.ts - Includes the new section in the system prompt
  • src/core/prompts/sections/__tests__/mcp-servers.spec.ts - 14 tests covering all edge cases

Test Procedure

  • Unit tests: cd src && npx vitest run core/prompts/sections/__tests__/mcp-servers.spec.ts (14 tests passing)
  • Full prompt test suite: cd src && npx vitest run core/prompts/ (207 tests passing across 20 test files, zero regressions)
  • All monorepo lint and type-check tasks pass

Feedback and guidance are welcome.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

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.

  • Behavior:
    • Re-adds lightweight MCP SERVERS section to system prompt for OpenAI compatibility.
    • Includes naming convention explanation and list of connected servers and tools.
    • Avoids duplicating tool schemas or descriptions.
  • Files Changed:
    • 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.
  • Testing:
    • 14 unit tests in mcp-servers.spec.ts.
    • Full prompt test suite with 207 tests passing.

This description was created by Ellipsis for 1a418f7. You can customize this summary. It will automatically update as commits are pushed.

…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
@roomote
Copy link
Contributor Author

roomote bot commented Feb 9, 2026

Rooviewer Clock   See task

Review complete. The implementation is clean and well-structured. One test coverage gap noted.

  • Update createMockMcpHub in system-prompt.spec.ts to include tools so the snapshot for "with-mcp-hub-provided" actually captures the new MCP SERVERS section (comment)

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) : ""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

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.

[BUG] Agents unable to call MCP tools when using ChatGPT

1 participant