Skip to content

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

Draft
roomote[bot] wants to merge 1 commit intomainfrom
fix/mcp-tools-chatgpt-11317
Draft

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

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/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:

  • That mcp--serverName--toolName functions represent MCP server tools
  • When and why to use these tools
  • Any server-specific instructions the MCP server provides

Solution: Re-add a lightweight MCP servers section to the system prompt that:

  1. Lists connected MCP servers and their tool name mappings (e.g., mcp--git--git_log)
  2. Includes MCP server-specific instructions when provided by the server
  3. Explains the mcp--serverName--toolName naming convention
  4. Provides brief guidance to prefer MCP tools when they match the task

This 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 section
  • src/core/prompts/sections/index.ts - Re-export the new section
  • src/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 cases

Test Procedure

  • Added 11 unit tests covering: undefined mcpHub, no servers, disconnected servers, connected servers with tools, enabledForPrompt filtering, server instructions, servers with no tools, multiple servers, connecting status, and all-tools-disabled cases.
  • All existing system prompt tests (13), sections tests (40), and MCP native tools tests (10) continue to pass.
  • Run tests: cd src && npx vitest run core/prompts/sections/__tests__/mcp-servers.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue.
  • Scope: Changes are focused on the linked issue.
  • Self-Review: Self-reviewed the code.
  • Testing: New tests added with 11 test cases.
  • Documentation Impact: No documentation updates required.
  • Contribution Guidelines: Read and agreed.

Documentation Updates

  • No documentation updates are required.

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.

  • Behavior:
    • Re-adds lightweight MCP servers section to system prompt in mcp-servers.ts for OpenAI compatibility.
    • Includes server names, tool mappings, and instructions without duplicating tool schemas.
    • Integrated into system prompt generation in system.ts when MCP is enabled.
  • Tests:
    • Adds 11 unit tests in mcp-servers.spec.ts for various scenarios including connected/disconnected servers, tool filtering, and server instructions.
  • Exports:
    • Exports getMcpServersSection in index.ts.

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

@roomote
Copy link
Contributor Author

roomote bot commented Feb 9, 2026

Rooviewer Clock   See task

Reviewed all changed files, relevant type definitions (McpServer, McpTool, buildMcpToolName), the native tools pipeline (mcp_server.ts), and adjacent sections (capabilities.ts, modes.ts). Ran all new and existing tests -- all pass. No issues found.

The implementation is clean: getMcpServersSection correctly uses buildMcpToolName (same as the native tools pipeline) for consistent tool name generation, properly filters by connected status and enabledForPrompt, handles all edge cases (undefined hub, no servers, disconnected servers, no tools, empty tools), and integrates into the system prompt only when MCP is enabled.

  • No issues found

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

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