Actions7
Overview
This node acts as a client for interacting with an MCP (Model Context Protocol) server using Bearer Token authentication. It supports two connection types: Command Line (STDIO) and Server-Sent Events (SSE). The node allows users to perform various operations such as listing resource templates, reading resources, listing tools, executing tools, and managing prompts.
Common scenarios where this node is beneficial include:
- Automating interactions with an MCP server to retrieve or manipulate AI model resources.
- Executing specific tools available on the MCP server programmatically.
- Fetching prompt templates or resource templates for use in workflows.
- Integrating MCP server capabilities into n8n workflows with secure token-based authentication.
Practical example:
- Use the "List Resource Templates" operation to fetch all available resource templates from the MCP server via SSE connection, enabling dynamic workflow branching based on available templates.
- Execute a tool by name with JSON parameters to automate complex AI tasks exposed by the MCP server.
Properties
| Name | Meaning |
|---|---|
| Bearer Token | Your API Bearer token for authentication, primarily used for SSE connection type. |
| Connection Type | Choose the transport type to connect to the MCP server. Options: - Command Line (STDIO) - Server-Sent Events (SSE) |
| SSE URL | The full URL for the Server-Sent Events endpoint (required if using SSE connection). |
| SSE Timeout (Ms) | Timeout in milliseconds for SSE requests (minimum 1000 ms). Default is 60000 ms. |
| SSE Messages POST Endpoint (Optional) | Optional separate URL endpoint for posting messages if different from the SSE URL. |
| SSE Additional Headers (JSON) | Additional HTTP headers to send with SSE requests in JSON format (e.g., {"X-Custom-Header": "value"}). |
| Command | The command to execute for the MCP server process (required if using Command Line connection). |
| Arguments (Space Separated) | Arguments to pass to the command, separated by spaces. |
| Environment Variables (Key=value Pairs, One per Line) | Additional environment variables for the command process, each specified as KEY=VALUE on a new line. |
| Operation | The action to perform on the MCP server. Options include: - Execute Tool - Get Prompt - List Prompts - List Resource Templates - List Resources - List Tools - Read Resource |
| Resource URI | URI of the resource to read (required if operation is "Read Resource"). |
| Tool Name | Name of the tool to execute (required if operation is "Execute Tool"). |
| Tool Parameters | Parameters to pass to the tool in JSON format (required if operation is "Execute Tool"). |
| Prompt Name | Name of the prompt template to get (required if operation is "Get Prompt"). |
Output
The output JSON structure depends on the selected operation:
- List Resource Templates: Outputs
{ resourceTemplates: [...] }— an array of available resource templates retrieved from the MCP server. - List Resources: Outputs
{ resources: [...] }— an array of available resources. - Read Resource: Outputs
{ resource: {...} }— details of a specific resource identified by its URI. - List Tools: Outputs
{ tools: [...] }— an array of available tools, each including name, description, and input schema. - Execute Tool: Outputs
{ result: ... }— the result returned by executing the specified tool with given parameters. - List Prompts: Outputs
{ prompts: [...] }— an array of available prompt templates. - Get Prompt: Outputs
{ prompt: {...} }— details of a specific prompt template.
If binary data were involved, it would be summarized accordingly; however, this node deals primarily with JSON data.
Dependencies
- Requires an active MCP server accessible either via command line or SSE endpoint.
- For SSE connection type, requires a valid Bearer Token for authentication.
- Uses external MCP SDK packages for client communication and transport handling.
- If using Command Line connection, the specified command must be executable in the environment where n8n runs.
- Proper environment variables can be set for the command line process if needed.
Troubleshooting
- Missing Required Parameters: Errors will occur if required parameters like Bearer Token (for SSE), SSE URL, or Command (for CMD) are missing. Ensure all mandatory fields are filled.
- Invalid JSON in Additional Headers or Tool Parameters: The node validates JSON inputs and throws errors if invalid. Verify JSON syntax carefully.
- Connection Failures: If the MCP client cannot connect to the server, check network connectivity, correct URLs, and that the MCP server is running.
- Tool Not Found: When executing a tool, if the specified tool name does not exist, the node lists available tools in the error message. Use one of those names.
- Timeouts: SSE connections have configurable timeouts; increase the timeout if operations take longer than expected.
- Environment Variable Parsing: For command line environment variables, ensure each line follows
KEY=VALUEformat without extra spaces or invalid characters. - Transport Errors: Any transport-level errors are surfaced as node errors. Check logs for detailed messages.
Links and References
- MCP Protocol Documentation (example placeholder link)
- Server-Sent Events (SSE) MDN Reference
- n8n Custom Node Development Guide
- Zod Validation Library (used internally for schema validation)