Skip to content

Conversation

@SockingPanda
Copy link

Summary

  • expose codex.mcp.* helpers in the TypeScript SDK so Node consumers can list, add/remove, log in/out, and toggle MCP servers
  • share CLI binary resolution and --config override handling between CodexExec and the new MCP layer; mirror the CLI’s TOML write logic for persistent toggles
  • document the new surface (README + sample) and add targeted unit tests

Motivation

Tracking: #5637

The CLI already ships comprehensive codex mcp … subcommands, but the TypeScript SDK could only observe MCP tool calls. This PR brings parity so external tools/plugins can manage MCP servers without dropping down to manual CLI invocations.

Testing

  • pnpm test -- mcp.test.ts
  • pnpm run build

@github-actions
Copy link

github-actions bot commented Oct 24, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 65 to 76
async add(name: string, transport: McpAddTransportOptions, fields: McpMutableFields = {}): Promise<void> {
const args = ["mcp", "add", name];
if (transport.type === "stdio") {
args.push("--");
args.push(transport.command);
if (transport.args && transport.args.length) {
args.push(...transport.args);
}
if (transport.env) {
for (const [key, value] of Object.entries(transport.env)) {
args.push("--env", `${key}=${value}`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Pass --env options before command delimiter

When constructing the mcp add call for stdio transports, --env pairs are appended after "--" and the command (args.push("--"); args.push(transport.command); … args.push("--env", …)). In the CLI, arguments after -- are treated as the child process command and are never parsed by codex mcp. As a result any environment variables provided through this API are ignored and instead become arguments to the MCP server itself. This means codex.mcp.add("foo", {type: "stdio", env: {TOKEN: "abc"}, …}) will not set TOKEN for the server. The --env flags need to be inserted before the -- separator.

Useful? React with 👍 / 👎.

@SockingPanda
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Oct 25, 2025
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.

1 participant