n8n

How to Connect OpenAI and n8n for Agent Execution?

Give your AI agent safe access to the right n8n workflows. This setup lets a bot discover, approve, and run selected flows while you stay in control. It is ideal for teams that want AI help without risking random or outdated automations.

Under the hood, an MCP server in n8n exposes simple tools to the agent. A search step pulls workflows from your n8n instance by tag. A Redis list acts as the approved pool so the agent only uses workflows you add. The system also reads each workflow’s input schema from its JSON so parameters are set in the right format. A pass through execute step calls subworkflows without hard coded fields, and a switch routes Add, Remove, List, Search, and Execute actions.

Setup needs an n8n API key, a Redis connection, and an OpenAI key. Tag the workflows you want to expose and add subworkflow triggers with input schema. Expect faster handling of common tasks, fewer run errors, and better control over what the agent can do. Good uses include support triage, data pulls, report runs, and any repeat job an agent can plan and execute.

What are the key features?

  • MCP server trigger exposes tools for Add, Remove, List, Search, and Execute
  • n8n API queries workflows by tag to keep the catalog focused
  • Redis stores the approved workflow list under a single key for fast lookups
  • Switch node routes the requested operation to the right branch
  • Filter steps match workflow IDs so only valid items are added or removed
  • Input schema is read from each workflow’s JSON to guide parameters
  • Execute Workflow uses pass through data to call subworkflows without hard coded fields
  • Clear success and error messages return structured responses to the agent

What are the benefits?

  • Reduce manual routing from hours to minutes by letting the agent find and run approved workflows
  • Cut failed runs by validating input formats from each workflow’s schema before execution
  • Limit access to only approved workflows to avoid duplicates and risky flows
  • Handle many workflows at once with a simple Redis backed allow list
  • Unify discovery and execution so the agent can plan tasks end to end
  • Shorten onboarding time by exposing clear tools for add, remove, list, search, and execute

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with OpenAI, Redis and n8n API. See the Tools Required section above for links to create accounts with these services.
  3. In the n8n credentials manager, create the n8n API credential. If unsure, double click the n8n node, choose 'Credential to connect with', click 'Create new credential', then follow the on screen steps to add your base URL and API key.
  4. In the credentials manager, add your Redis connection. If unsure, double click any Redis node, click 'Create new credential', then enter host, port, and password. Test the connection.
  5. In the credentials manager, add your OpenAI API key. Double click the OpenAI Chat Model node, create a new credential, then paste your API key from the OpenAI account page.
  6. Open the workflows you want the agent to use. Add a Subworkflow trigger in each and define the input schema so parameters are clear.
  7. Tag these workflows with mcp or update the tag in the n8n query node to match your own tag strategy.
  8. Enable the MCP server trigger and the chat trigger in this workflow and set the workflow to active so endpoints are live.
  9. Run the Search tool to fetch candidates and confirm you see the expected workflows. Then run the Add tool with one or more workflow IDs to build the approved list.
  10. Use the List tool to verify Redis now holds your approved workflows. Remove any unwanted items with the Remove tool.
  11. Test Execute with a known workflow ID and a simple JSON payload that matches its input schema. If it fails, confirm the ID exists in the approved list and that the target workflow has a Subworkflow trigger.
  12. If the list looks stale, run the Delete key step to clear the Redis key and rebuild the list. Also make sure the execute step shows no input fields so pass through works. If fields appear, reset that node.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Redis

Sign up

Free plan: $0 / mo, 30 MB, single DB

n8n API

Sign up

Community Edition (self-hosted): $0 (public REST API available). Cloud Starter: $20 / mo billed annually ($24 monthly); API unavailable during free trial.

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.