How do I connect n8n to OpenAI's Codex with MCP?

Codex can run your n8n workflows on request, and it can build new ones while you describe them. Both run on MCP, and each takes a command or two in the Codex CLI. Here is each route, step by step.

The short answer

There are two ways to connect n8n to Codex with MCP. The first is n8n's built-in MCP server: turn on Instance-level MCP in n8n settings, mark the workflows you want available, run codex mcp add with the server URL, then codex mcp login to approve access. The second is the open-source n8n-mcp server, which you add with one codex mcp add command and your n8n API key, so Codex can read node documentation and build, fix and run workflows in your instance.

Key takeaways

  • MCP is an open standard that lets an AI app call tools in other software. n8n speaks it two ways: a built-in server and a community server.
  • n8n's built-in server lets Codex find and run the workflows you expose, with OAuth sign-in. Nothing is exposed until you turn each one on.
  • The community n8n-mcp server gives Codex the documentation for every node and, with an API key, the power to create and edit workflows.
  • Codex stores every MCP server in config.toml, and the CLI, the IDE extension and the ChatGPT desktop app all read the same file.

Questions before you start.

Short answers to what people ask before they open the terminal. Anything else, ask below: the answer comes from this guide and the official docs.

Does the Codex CLI have to be installed first?

Yes. Every step in this guide is a codex command, so the Codex CLI has to be on your machine and signed in before you start. Type codex in a terminal: if it opens a session, you are ready. If the terminal says the command is not found, install the CLI first and come back.

What do I need from n8n before step one?

For the built-in server, you need to be an owner or admin of the n8n instance, because the switch that turns MCP on lives in the instance settings. For n8n-mcp, you need the instance URL and an n8n API key, which any user can create under Settings. A workflow or two worth running makes the first test meaningful.

Do I need Node.js on my computer?

Only for the community server. n8n-mcp starts with npx, and npx comes with Node.js, so install Node.js first if that is your route. The built-in server needs nothing on your computer beyond the Codex CLI. The details are in setting up n8n-mcp.

Which route should I set up first?

Start with the built-in server if you mostly want to run workflows you already have, because it signs in with OAuth and keeps no key in a file. Start with n8n-mcp if you want Codex to build workflows with you. The trade-off is laid out in which route to pick.

How to connect n8n to Codex with MCP, in about a minute A video with no sound. Every word is on screen.
Read the video transcript
  1. SMGP explains. How to connect n8n to Codex with MCP. Two routes, in about a minute.
  2. MCP is an open standard.
  3. It lets an AI app call tools in other software.
  4. Two routes, two jobs.
  5. Route A: n8n's built-in MCP server runs your workflows.
  6. Route B: the community n8n-mcp server builds them.
  7. Turn on the built-in server.
  8. Settings, then Instance-level MCP. Enable MCP access.
  9. Copy the Server URL. It ends in /mcp-server/http.
  10. Mark each workflow Available in MCP.
  11. codex mcp add n8n --url, then codex mcp login n8n.
  12. One command adds n8n-mcp to Codex.
  13. With your n8n URL and API key, Codex can create, edit and test workflows.
  14. The CLI, the editor and the ChatGPT app share the same setup.
  15. Then ask in plain English.
  16. Run the weekly report and tell me what changed.
  17. Which workflows failed overnight, and why?
  18. Build a lead intake workflow from this description.
  19. Expose only the workflows you mean to.
  20. Prefer OAuth. Keep config.toml private.
  21. This is AI engineering in one afternoon.
  22. The workflows hold the steps. The agent supplies the judgment.
  23. SMGP. Embedded GTM engineering and embedded AI engineering. smgp.co

What is MCP, and why connect n8n to Codex?

MCP stands for Model Context Protocol. It is an open standard that lets an AI app call tools in other software, the way a USB port lets any device plug into any computer. The software runs a small server that lists what it can do, and the AI app calls those tools when a conversation needs them.

Codex is OpenAI’s coding agent, and the Codex CLI runs it in your terminal. n8n is the workflow automation platform we run our own company on. Connect the two through MCP and Codex can run the report workflow, read what failed overnight, or build a new workflow while you describe it in plain English, without you opening the n8n editor.

This guide uses the Codex CLI. Codex keeps every MCP server in one configuration file, and the CLI, the IDE extension and the ChatGPT desktop app all read it, so a server you add here shows up in the others too.

What are the two ways to connect n8n to Codex?

There are two routes, and they do different jobs.

Route A is n8n’s built-in MCP server. It is part of n8n itself. Once you turn it on, a connected client can search your workflows and run the ones you have marked as available, and recent n8n versions let it build and edit workflows and data tables too. You sign in with OAuth, so no key gets pasted anywhere.

Route B is the community n8n-mcp server, an open-source project on GitHub under the MIT license. It runs on your computer and gives Codex the documentation for every n8n node, plus tools that validate a workflow before it goes live. Add your n8n API key and it can also create, update, run and inspect workflows through n8n’s REST API.

Use Route A when you want Codex to run what you already have. Use Route B when you want Codex to build and fix workflows with you. We run Route B every day against our own self-hosted n8n, from inside Claude Code, and the Codex setup is the same server with a different configuration file.

How do you turn on n8n’s built-in MCP server?

  1. Open n8n as an instance owner or admin and go to Settings, then Instance-level MCP. Select Enable MCP access.
  2. Under Connection details, select Connect. The Connect a client dialog shows your Server URL, which ends in /mcp-server/http, and a Your client dropdown with steps for CLI clients (Claude Code, Codex, Gemini CLI), web clients (Claude.ai, ChatGPT) and IDEs (Cursor, VS Code, Windsurf). Choose Codex and copy the URL.
  3. Choose how clients sign in. OAuth is the recommended method: when Codex connects, n8n asks you to approve it. The API key tab generates a personal access token instead. It is shown once, and rotating it revokes the old one.
  4. Expose the workflows you want Codex to use. Open a workflow, select the Workflow menu (the three dots), choose Settings and turn on Available in MCP. You can also do this from the workflows list, or for a whole project or folder.

Nothing is exposed until step four. Codex can search for workflows by name, but it can only run the ones you have marked.

How do you connect the built-in server to the Codex CLI?

Two commands. The first adds the server, the second opens your browser so you can approve it in n8n.

codex mcp add n8n --url https://<your-n8n-domain>/mcp-server/http
codex mcp login n8n

Replace the domain with yours. Use http:// if your instance serves plain HTTP, such as http://localhost:5678 on your own machine. Then check the connection from the terminal, and again from inside Codex:

codex mcp list

Start codex and type /mcp to see the active servers and their tools.

The add command writes a table to config.toml in the .codex folder of your home directory. You can write it by hand instead:

[mcp_servers.n8n]
url = "https://<your-n8n-domain>/mcp-server/http"

If you chose the API key method in n8n, the server takes a bearer token. Keep the token out of the file by naming an environment variable that holds it:

[mcp_servers.n8n]
url = "https://<your-n8n-domain>/mcp-server/http"
bearer_token_env_var = "N8N_MCP_TOKEN"

Then export N8N_MCP_TOKEN in your shell before you start Codex. Older Codex builds needed experimental_use_rmcp_client = true under a [features] table before they would use a URL server, so if the add command refuses the URL form, update Codex first.

How do you set up the community n8n-mcp server in Codex?

Route B needs Node.js on your computer, because the server starts with npx. You also need two things from n8n: your instance URL and an API key, which you create under Settings, then n8n API, then Create an API key.

Then one command in your terminal:

codex mcp add n8n-mcp \
  --env MCP_MODE=stdio \
  --env LOG_LEVEL=error \
  --env DISABLE_CONSOLE_OUTPUT=true \
  --env N8N_API_URL=https://your-n8n-instance.com \
  --env N8N_API_KEY=your-api-key \
  -- npx n8n-mcp

On Windows, run it in PowerShell on one line, or use the backtick to continue a line. Everything after the two dashes is the command Codex launches, and each --env pair is a setting handed to it.

The same configuration written by hand in config.toml looks like this:

[mcp_servers.n8n-mcp]
command = "npx"
args = ["n8n-mcp"]
env = { "MCP_MODE" = "stdio", "LOG_LEVEL" = "error", "DISABLE_CONSOLE_OUTPUT" = "true", "N8N_API_URL" = "https://your-n8n-instance.com", "N8N_API_KEY" = "your-api-key" }

What the settings do: MCP_MODE=stdio makes the server talk to Codex over its standard input and output, and the two logging settings keep its own messages out of your conversation. The URL and key are optional. Leave them out and you get documentation-only mode, where Codex can search nodes, read their properties and validate a workflow, but cannot touch your instance. For an n8n on your own machine, the URL is http://localhost:5678.

Start codex and type /mcp to see the server and its tools. The core tools are tools_documentation, search_nodes, get_node, validate_node, validate_workflow, search_templates and get_template. With the API key you also get management tools such as n8n_create_workflow, n8n_get_workflow, n8n_update_partial_workflow, n8n_delete_workflow, n8n_test_workflow, n8n_executions and n8n_manage_credentials.

The project recommends an AGENTS.md file in your project folder with its workflow-building instructions, which Codex reads at the start of every session. If you would rather not run anything on your computer, there is a hosted version at dashboard.n8n-mcp.com with a free tier of 100 tool calls a day. The full setup guide lives in the n8n-mcp repository.

Which route should you pick?

Pick the built-in server when the workflows already exist and you want to run them from a conversation. It is the official feature, it signs in with OAuth, and the token never sits in a file.

Pick n8n-mcp when the job is building. It knows what every node expects, it validates before it saves, and with the API key it creates and edits workflows in your instance while you watch. It suits the person who builds the automations rather than the person who only runs them.

Run both if you build and run. They do not conflict, and together they cover the whole loop: describe a workflow, build it, test it, run it, read the result.

Still deciding between the two platforms? Our comparison of n8n vs Zapier covers how each one bills and when each one fits.

If the apps you need already live in Zapier rather than n8n, Zapier has an MCP server of its own, and the guide to connecting Zapier to Claude with MCP shows how little setup it takes.

What can you do once it is connected?

Run a workflow from a sentence. Ask “Run the weekly client report now and tell me what changed.” Codex calls the workflow through the built-in server and reads the output back to you.

Find out what failed overnight. Ask “Which of my workflows failed in the last day and why?” With the executions tool in n8n-mcp, Codex reads the execution log and points at the node that broke.

Build a lead-intake workflow from a description. Describe the form, the lookup you want on each lead and where the record should land. Codex drafts the workflow with validated nodes and creates it in your instance for you to review.

Add error handling everywhere. Ask Codex to find every workflow with no error handling and add it. One request fixes a backlog that nobody was going to clear by hand.

Turn a Slack message into a CRM update. Expose your CRM update workflow to MCP, then paste the message and ask Codex to log it. The workflow does the writing, so the record looks the same every time.

Replace a failing node. Codex reads the node documentation through search_nodes and get_node, drafts the replacement and validates it before anything touches the live workflow.

Audit the credentials in use. Ask which credentials each workflow uses, through n8n_manage_credentials, to find the old key that is still in play before it expires.

How do you keep it safe?

Expose only what you mean to. Every workflow marked Available in MCP can be run by any connected client, because access is not scoped per client. Treat that list the way you treat admin access.

Prefer OAuth over a pasted token. With OAuth you approve Codex in n8n and can see it in the connected clients list. Clients that use an API key do not appear there.

Keep config.toml private. It holds your API key for n8n-mcp and, if you add one, any OAuth client secret, so never commit it or share it. If a key leaks, rotate it in n8n, which revokes the old one.

Know the emergency switch. Turning off Instance-level MCP disconnects every client at once. On a self-hosted instance, N8N_DISABLED_MODULES=mcp removes the feature entirely, and a reverse proxy in front of n8n has to pass the MCP-Protocol-Version, Mcp-Method and Mcp-Name headers or the connection fails.

Remember what runs. A workflow run through MCP uses the published version by default, so test changes in n8n before you publish them.

Where does this fit in an AI-run company?

AI engineering is the work of building the software a company runs on, and n8n connected to a coding agent like Codex is one of its most useful building blocks. The workflows hold the steps. The agent supplies the judgment, the plain-English interface and the ability to write new workflows when the business changes. That is how a small team gets the operations of a much larger one without hiring for it. Our embedded AI engineering service puts a person inside your company to build exactly this kind of system.

We run our own company this way, with 455 automations built, 194 running today, most of them in n8n and many of them built from a terminal through the server in this guide. The systems are on the how we run on AI page, with dates. If you want to see what one of them would look like inside your company, the next step is a conversation.

Lucas Mack

Written by Lucas Mack

Lucas is the founder and CEO of SMGP. He has done every job in the company, runs the strategy and the sales, and built every system SMGP runs on, from the outbound engine to the finance software. He writes about what he builds and what he has learned building it.

Share this post on LinkedIn (opens in a new tab)

Questions people ask

Do I need to know how to code to connect n8n to Codex?

No. The built-in route is a settings page in n8n plus two commands in the Codex CLI. The n8n-mcp route is one command. If you can paste a command and follow a sign-in screen in your browser, you can do both.

Can Codex see all of my n8n workflows?

No. Codex can search workflows by name, but it can only run the ones you have marked Available in MCP, one at a time or by project or folder. Nothing is exposed until you turn it on, and switching MCP off in settings disconnects every client at once.

What is the difference between the built-in server and n8n-mcp?

The built-in server is part of n8n and is built to run the workflows you already have, with OAuth sign-in. n8n-mcp is an open-source server that runs on your computer, knows the documentation for every n8n node, and with an API key can create, edit, test and inspect workflows through the n8n API. The first runs, the second builds.

Where does Codex keep the MCP configuration?

In the config.toml file in the .codex folder of your home directory. The codex mcp add command writes it for you, and you can edit the file by hand. The Codex CLI, the IDE extension and the ChatGPT desktop app read the same file, so a server you add once is available in all three.

Can I connect an n8n that only runs on my laptop?

Yes. The Codex CLI runs on the same machine, so it can reach a local address. Use the http form of the built-in server URL, or point n8n-mcp at the local address of your instance.

Talk it through with Lucas

Thirty minutes on your business: where a GTM engineer or an AI engineer would make the biggest difference, and what to build first. You leave with a plan either way.

Book a strategy call Contact our team