Actions7
Overview
This node provides integration 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 performing various operations such as reading a resource by its URI, listing resources, resource templates, tools, prompts, getting a prompt template, and executing a specific tool on the MCP server.
Typical use cases include:
- Fetching or reading specific resources from an MCP server by URI.
- Listing available resources, tools, or prompts to dynamically discover capabilities.
- Executing tools remotely on the MCP server with specified parameters.
- Integrating MCP server functionality into automated workflows that require authenticated access via bearer tokens.
For example, you might use this node to read a configuration resource from the MCP server or execute a tool that processes data and returns results, all within an n8n workflow.
Properties
| Name | Meaning |
|---|---|
| Bearer Token | Your API Bearer token for authentication, required especially when using SSE connection type. |
| Connection Type | Transport method to connect to the MCP server. Options: - Command Line (STDIO): Runs a local command/process. - Server-Sent Events (SSE): Connects via SSE endpoint URL. |
| SSE URL | Full URL of 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, provided as a JSON object (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 (optional). |
| Environment Variables (Key=value Pairs, One per Line) | Additional environment variables for the command process, each on a new line (optional). |
| Resource URI | URI of the resource to read (required for the "Read Resource" operation). |
| 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 |
| Tool Name | Name of the tool to execute (required for "Execute Tool" operation). |
| Tool Parameters | JSON object of parameters to pass to the tool (required for "Execute Tool" operation). |
| Prompt Name | Name of the prompt template to get (required for "Get Prompt" operation). |
Output
The node outputs JSON data depending on the selected operation:
- Read Resource: Outputs a JSON object with a
resourcefield containing the resource data retrieved from the MCP server. - List Resources: Outputs a JSON object with a
resourcesarray listing available resources. - List Resource Templates: Outputs a JSON object with a
resourceTemplatesarray. - List Tools: Outputs a JSON object with a
toolsarray, where each tool includes its name, description, and input schema. - Execute Tool: Outputs a JSON object with a
resultfield containing the execution result of the specified tool. - List Prompts: Outputs a JSON object with a
promptsarray listing available prompt templates. - Get Prompt: Outputs a JSON object with a
promptfield containing the requested prompt template.
If binary data were involved, it would be summarized accordingly; however, this node deals primarily with JSON data.
Dependencies
- Requires an MCP server accessible either via a command-line interface or SSE endpoint.
- For SSE connection, 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 mandatory parameters like Bearer Token (for SSE), Command (for cmd), or Resource URI (for readResource) are missing.
- Invalid JSON in Additional Headers or Tool Parameters: The node validates JSON inputs and throws errors if invalid JSON is provided.
- Connection Failures: If the MCP client cannot connect to the server (due to wrong URL, network issues, or authentication failure), an error will be thrown indicating connection failure.
- Tool Not Found: When executing a tool, if the specified tool name does not exist on the MCP server, an error lists available tools.
- Transport Errors: Errors during communication with the MCP server (transport errors) will cause the node to fail with descriptive messages.
- Timeouts: SSE connections have configurable timeouts; if the timeout is too short, requests may fail prematurely.
- Environment Variable Parsing: Environment variables for the command-line connection must be in
KEY=VALUEformat, one per line; malformed lines are ignored.
To resolve these issues, ensure all required parameters are correctly set, JSON inputs are valid, the MCP server is reachable, and credentials are correct.
Links and References
- MCP Protocol Documentation (example placeholder link)
- Server-Sent Events (SSE) MDN Reference
- n8n Documentation
- Zod Validation Library (used internally for schema validation)