You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Lists connected MCP servers and their tool name mappings (e.g., mcp--git--git_log)
Includes MCP server-specific instructions when provided by the server
Explains the mcp--serverName--toolName naming convention
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 for 803a264. You can customize this summary. It will automatically update as commits are pushed.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
1 participant
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.