What are Dynamic Resources in n8n MCP Server
main{id}). All dynamic resources return data in application/json format.repository·main·Indexed 23 days ago
https://github.com/leonardsellem/n8n-mcp-serverA Model Context Protocol (MCP) server that enables AI assistants to interact with n8n workflow automation using natural language. It provides tools for managing workflows (list, create, update, delete, activate), handling executions (run, stop, list, get), and triggering workflows via webhooks. The server also exposes dynamic resources for inspecting workflows and execution details via parameterized URIs.
{id}). All dynamic resources return data in application/json format.The server exposes two primary ways for an AI assistant to interact with n8n:
Tools are executable operations located in src/tools/. They follow a pattern of a definition (name, description, input schema) and a handler function.
create, list, update, delete, activate, and deactivate workflows.run, list, and manage workflow executions.Resources provide data access through URI-based templates located in src/resources/.
src/resources/static/): Fixed resources, such as general workflow listings.src/resources/dynamic/): Parameterized resources, such as specific workflow details retrieved via a unique ID.application/json and require the configured n8n API key for authentication.When extending the n8n MCP Server, adhere to these principles:
this.handleApiError in clients or returning isError: true in tools).Every tool provided by the server includes a JSON Schema that defines its required and optional parameters. These schemas are passed to the AI assistant to enable automatic parameter validation and suggestions. For example, a tool designed to retrieve a workflow will require an id property of type string.
{
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The ID of the workflow to retrieve"
}
},
"required": ["id"]
}To maintain clean tests, use the tests/mocks/ directory for shared resources:
axios-mock-adapter to simulate HTTP responses. A helper resetAxiosMock() should be used to clear the adapter between tests.mockWorkflows or mockExecutions) in a shared file to avoid duplication.tests/test-setup.ts to perform global actions like jest.clearAllMocks() and resetting the Axios mock before each test.// tests/test-setup.ts
import { jest } from '@jest/globals';
import { resetAxiosMock } from './mocks/axios-mock';
beforeEach(() => {
jest.clearAllMocks();
resetAxiosMock();
});The n8n MCP Server uses a layered architecture to separate communication, logic, and data access. This design ensures that the server can handle requests from AI assistants via the Model Context Protocol (MCP) while interacting with the n8n API through a dedicated client layer.
stdio).N8nClient.Environment class.The n8n MCP Server implements the Model Context Protocol (MCP) to bridge AI assistants with n8n. The API is organized into two primary functional categories:
The architecture separates the Client Layer (n8n API communication), Transport Layer (MCP protocol implementation), Tools Layer (executable operations), and Resources Layer (data access). All interactions require an n8n API key configured in your environment.
The codebase is organized into several functional modules:
src/api/: Contains the API client used to communicate with n8n.src/config/: Handles configuration and environment settings.src/errors/: Centralized error handling logic.src/resources/: Implementation of MCP resources, split into static/ and dynamic/ (parameterized) subdirectories.src/tools/: Implementation of MCP tools, categorized into workflow/ (workflow management) and execution/ (execution management).src/types/: TypeScript type definitions.src/utils/: Shared utility functions.tests/: Test suites including unit/, integration/, and e2e/.build/: The directory containing compiled JavaScript output.The n8n MCP Server employs a three-tier testing strategy to ensure reliability:
tests/unit/): These test individual components in isolation. The directory structure mirrors the src/ directory (e.g., src/api/client.ts is tested in tests/unit/api/client.test.ts).tests/integration/): These verify interactions between components, such as ensuring tools correctly utilize the API client or that resources format API data correctly.tests/e2e/): These test the entire system as a whole, from the transport layer through to the API client and back.Shared fixtures and mocks are located in tests/mocks/.
Tests are automatically executed in CI environments during pull requests and commits to the main branch. To successfully merge code, the following requirements must be met:
To compile the TypeScript source code into JavaScript for production or distribution, run the build command. This generates the compiled output in the build/ directory and prepares the executable script files.
npm run build