-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(cli): Model Context Protocol (MCP) support — client, TUI overlay, config & basic test #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
Tagging maintainers @tibo-openai @bolinfest for review. Thank you! |
@jagzmz in your example, I see |
Yes, it should be, i picked up an old example i had with me : P, anyways, I have updated the example. |
Nice! Are new feature updates to the TS variant paused ? |
This commit introduces a new MCP (Model Context Protocol) management system within the Codex CLI. Key changes include: - Added MCPClient and MCPManager classes for handling connections to MCP servers and managing tools. - Implemented functionality to initialize MCP connections and retrieve tools from connected servers. - Enhanced the CLI to support new commands for interacting with MCP servers, including a dedicated overlay for server status. - Updated the configuration to allow users to define MCP servers and their connection details. - Introduced new utility functions for flattening tools and parsing tool calls. This feature enhances the extensibility of the Codex CLI by allowing it to interact with external tools via MCP, improving the overall user experience and functionality.
…ions This commit introduces several improvements to the MCP (Model Context Protocol) integration within the Codex CLI: - Added `MCPProvider` and `useMcpManager` hook for managing MCP connections and state in a React context. - Refactored MCP client and manager functionalities to streamline server connections and tool retrieval. - Implemented utility functions for sanitizing tool names and flattening tools from multiple MCP clients. - Updated various components to utilize the new MCP context, enhancing the user interface with real-time server status and tool availability. These changes improve the overall architecture and usability of the MCP features, allowing for a more seamless interaction with external tools.
Changed the description of the "/mcp" command from "Open MCP server selection panel" to "List MCP servers" to better represent its purpose in the Codex CLI.
- Changed the return type of `submitInput` and `onCompact` props from `CompletionResult` and `Promise<void>` to `void` for better clarity and consistency. - Enhanced context display logic to provide clearer feedback when context is low, adjusting thresholds for color changes and messages. - Updated tests to reflect changes in props and ensure proper functionality of the TerminalChatInput component.
- Updated the `disconnectAll` method in `MCPManager` to be asynchronous, allowing for graceful disconnection of all clients. - Added a call to `mcpManager.disconnectAll()` in the `onExit` function to ensure all MCP clients are properly closed when the terminal exits. - Modified the MCP client instantiation to include `stderr: 1` for better error handling during command execution.
…ing display - Refactored the HelpOverlay to enhance the presentation of available commands and keyboard shortcuts. - Consolidated command descriptions and added new commands for better user guidance. - Improved layout and styling for clarity, including padding adjustments and color coding for commands and shortcuts. - Updated exit instructions for consistency with the new design.
- Updated the HelpOverlay component to use non-breaking hyphens in the term "slash‑commands" for improved readability. - Adjusted command descriptions to maintain consistency in formatting, ensuring clarity in the display of available commands.
- Replaced hyphens with en dashes in the HelpOverlay component for consistency and improved readability. - Updated command descriptions to ensure uniform formatting across the help overlay.
…for MCP overlay - Updated the `convertTools` function to set tool parameters to `undefined` if not provided, ensuring consistent behavior. - Added `openMcpOverlay` to multiple test files to enhance coverage for MCP-related functionalities.
- Updated the `pnpm-lock.yaml` to ensure the correct resolution and engine compatibility for `[email protected]`. - Removed the `package-lock.json` file from the `codex-cli` directory as it is no longer needed, streamlining the dependency management process.
- Updated the MCPClient constructor to merge the provided environment variables with the existing process environment, ensuring that all necessary variables are available during command execution.
This reverts commit ea684a4.
- Updated the MCPClient constructor to inherit default environment variables using `getDefaultEnvironment()`, ensuring all necessary variables are available during command execution while still allowing for custom environment overrides.
- Changed the `stderr` option in the MCPClient constructor from `1` to `"pipe"` so the error is PassThrough'd and doesn't pollute the user interface
- Added an en dash separator to the terminal chat input instructions for improved readability and clarity in user guidance.
Hi @bolinfest , would appreciate a review on this pull request. Thanks! I am wondering if new features are halted on the TS variant? |
@jagzmz Hi, sorry for dragging our feet here: we're actively discussing how we want to balance TS versus Rust going forward (and to publish the plan). That said, I think @fouad-openai was going to try to review a number of the TS PRs in once he gets a free moment... |
This PR integrates Model Context Protocol (MCP) into Codex CLI, letting any MCP server’s tools appear as agent‑callable functions.
✨ Key additions
🛠️ Example Configuration
Add an
mcpServers
block to~/.codex/config.json
Each key is a friendly name; values mirror a
spawn
‑style process descriptor:📸 Demo
Attached: TUI listing two live MCP servers