Build Custom MCP Server with n8n
Описание и применение
Создайте сервер MCP в n8n за 45–60 минут: веб‑хуки, валидация, маршрутизация, форматирование ответа и аутентификация заголовка, готовый к использованию любыми LLM.
Задача
LLMs need a standardized way to call external tools without hard‑coding provider payloads.
Результат
Within 45–60 minutes, a fully functional MCP server is deployed in n8n, providing authenticated, validated, and error‑handled tool calls for any LLM.
Рабочий процесс
- Create n8n webhook with POST /mcp and Respond with JSON
- Add Function node to validate MCP payload using Ajv schema
- Add Switch node to route based on $json["method"] to tool cases
- For each tool case, add appropriate action nodes (e.g., HTTP Request for Google Search)
- Add Function node to format MCP response {result, error}
- Connect final Function node to webhook response output
- Enable Header Auth on webhook and set secret token in n8n environment
- Test endpoint with curl using Authorization header
- Register tool with LLM (e.g., OpenAI Assistant) using function schema
Доказательства
You can spin up a bespoke Model Context Protocol (MCP) server in under an hour using n8n's visual workflow engine
The webhook is the public entry point the LLM will hit. Using the "Respond with JSON" mode ensures the response complies with MCP's expected shape.
Header authentication is simple, works with any LLM client, and avoids exposing a public API key.
- Дата записи: 2026-09-15T05:01:22.718Z