-
Notifications
You must be signed in to change notification settings - Fork 6k
feat(SDK): add MCP management support #5638
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 ✍️ ✅ |
There was a problem hiding this 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".
| 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}`); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
|
I have read the CLA Document and I hereby sign the CLA |
Summary
codex.mcp.*helpers in the TypeScript SDK so Node consumers can list, add/remove, log in/out, and toggle MCP servers--configoverride handling betweenCodexExecand the new MCP layer; mirror the CLI’s TOML write logic for persistent togglesMotivation
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