codex icon indicating copy to clipboard operation
codex copied to clipboard

Direct MCP tool invocation

Open yitoli-c opened this issue 1 month ago • 3 comments

What feature would you like to see?

A syntax to directly invoking a mcp tool would be nice, similar to in copilot, #mcp-tool-name could be useful at times.

Currently missing from both codex CLI/vscode extension.

Additional information

No response

yitoli-c avatar Dec 12 '25 22:12 yitoli-c

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #5917

Powered by Codex Action

github-actions[bot] avatar Dec 12 '25 22:12 github-actions[bot]

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

Powered by Codex Action

Negative. The issue proposed as a dup doesn't seem to have proper solution to the problem described. The issue duplication shouldn't happen unless there is clear documentation or code reference to the solution.

yusun029 avatar Dec 13 '25 03:12 yusun029

检测到可能重复的问题。请核实并关闭您的问题。

Codex Action提供支持

否。被标记为重复的问题似乎没有针对所述问题的合适解决方案。除非有明确的文档或代码参考指向解决方案,否则不应该出现问题重复的情况。


I’ve found a solution, but the process is quite tedious.

I’ll provide a simple use case that allows Codex to invoke MCP autonomously or via a manually triggered slash command. You need to enable the skill feature in Codex and write your own slash commands. My example uses the Chrome DevTools MCP.

Below, I’ve attached the content I wrote for config.toml, ~/.codex/prompts, and ~/.codex/skills. My system is Ubuntu 25.10 with Bash shell. I’m using the latest codex-cli version 0.72.0 and gpt-5.2-medium.

(We must ensure the workhorse model can use this to guarantee it has the capability and intent to call MCP even in extremely difficult tasks. We can't just say high and xhigh models can call it because they are smart enough—do I not deserve to call MCP just because I'm doing a simple task?)

config.toml Example:

model = "gpt-5.2"
disable_response_storage = true
model_verbosity = "low"
model_reasoning_effort = "high"

[features]
undo = true
view_image_tool = true
shell_tool = true
web_search_request = true
remote_compaction = true
parallel = true
warnings = true
skills = true               # Important: Enable skills
rmcp_client = true          # Important: Enable remote MCP client
apply_patch_freeform = true
unified_exec = true
shell_snapshot = true
tui2 = true
remote_models = true

[mcp_servers.chrome-devtools]
    command = "npx"
    args = ["-y","chrome-devtools-mcp@latest","--browserUrl","http://127.0.0.1:9222"]
    startup_timeout_ms = 40000

[mcp_servers.chrome-devtools.env]
HTTPS_PROXY = "http://127.0.0.1:7890"
HTTP_PROXY = "http://127.0.0.1:7890"
NO_PROXY = "localhost,127.0.0.1"

Custom Prompt Example (~/.codex/prompts/chrome-devtools-mcp.md):

---
description: Ask Codex to use Chrome DevTools MCP to do sth.
argument-hint: request or feature description
---
Now, you must use the Chrome DevTools MCP, to do or follow the order below.

Before using Chrome DevTools MCP, verify Chrome is available on port 9222 by requesting http://127.0.0.1:9222/json/version. If unreachable or invalid, run codexgg to restart the Chrome instance used by MCP, wait until the endpoint responds successfully, then proceed with DevTools actions.

#One-liner self-check and auto-restart:
curl -fsS http://127.0.0.1:9222/json/version >/dev/null || codexgg

#The ORDER is below:
$ARGUMENTS

Custom Skills Example (~/.codex/skills/chrome-browser-automation.md):

---
name: chrome-browser-automation
description: Use Chrome DevTools MCP to automatically control a real local Chrome browser for page access, clicking, form filling, and frontend debugging; this skill should be actively considered when the user requests to "actually open/operate a page with a browser" rather than simply sending HTTP requests or looking at source code.
---

This skill encapsulates the prompts you've already configured in `/home/proview/.codex/prompts/chrome-devtools-mcp.md`, serving as a bridge between Codex and the local automated Chrome browser via Chrome DevTools MCP.

**This skill should be actively used when the following needs arise:**
- Need to "actually open a browser page" and perform actions within it (navigate, click, input, scroll, etc.).
- Need to observe page behavior in a browser context, rather than relying solely on HTML scraping or APIs.
- Need to use DevTools capabilities (e.g., debugging frontend, viewing console output, etc.).

When using this skill, please strictly follow the logic and order of the original prompt below (copied from the prompts file):

```md
---
description: Ask Codex to use Chrome DevTools MCP to do sth.
argument-hint: request or feature description
---
Now, you must use the Chrome DevTools MCP, to do or follow the order below.

Before using Chrome DevTools MCP, verify Chrome is available on port 9222 by requesting [http://127.0.0.1:9222/json/version](http://127.0.0.1:9222/json/version). If unreachable or invalid, run codexgg to restart the Chrome instance used by MCP, wait until the endpoint responds successfully, then proceed with DevTools actions.

#One-liner self-check and auto-restart:
curl -fsS [http://127.0.0.1:9222/json/version](http://127.0.0.1:9222/json/version) >/dev/null || codexgg

#The ORDER is below:
$ARGUMENTS
```

**Behavioral Guidelines:**

  - Upon triggering this skill, first check `http://127.0.0.1:9222/json/version` as per the prompt above, executing `codexgg` if necessary until the browser is ready;
  - Then, complete the user-described operations in the real browser via Chrome DevTools MCP;
  - If the user's request has little to do with "actually opening and operating a browser page" (e.g., just parsing a snippet of HTML code), do not use this skill.

<!-- end list -->


Usage Instructions

Regarding usage: If you want Codex to use Chrome DevTools automatically, you can indicate in your prompt that browser work is required, so Codex actually uses the skills to complete the task.

If your task is strongly related to the browser—for example, if you need to use Chrome DevTools to inspect your frontend rendering or if you momentarily don't want to use Postman MCP for network configuration and need DevTools instead—you can directly use the slash command:

/prompts:chrome-devtools-mcp [add your task here]

...to complete the browser automation task.

Of course, given the differences between devices, Chrome DevTools MCP configurations vary wildly, so I won't go into further detail here.

Proview-China avatar Dec 14 '25 15:12 Proview-China