Actions7
Overview
This node connects to an MCP (Model Context Protocol) server using a Bearer Token for authentication and allows you to perform various operations such as listing available prompts, tools, resources, and resource templates, reading specific resources, executing tools, and retrieving prompt templates. It supports two connection types: Command Line (STDIO) and Server-Sent Events (SSE).
Common scenarios where this node is beneficial include:
- Integrating with an MCP server to dynamically fetch or execute AI model prompts and tools.
- Automating workflows that require interaction with AI resources or tools managed by the MCP server.
- Using SSE for real-time event streaming from the MCP server or command line execution for local or remote MCP server processes.
Practical example:
- You want to list all available prompt templates on your MCP server to select one for further processing.
- You need to execute a specific tool on the MCP server with custom parameters and use its output in your workflow.
- You want to stream events from the MCP server via SSE for live updates.
Properties
| Name | Meaning |
|---|---|
| Bearer Token | Your API Bearer token used for authentication, primarily required when using the SSE connection type. |
| Connection Type | The transport method to connect to the MCP server. Options: - Command Line (STDIO): Runs a local or remote MCP server process. - Server-Sent Events (SSE): Connects via HTTP SSE endpoint. |
| SSE URL | (Required if SSE selected) The full URL of the Server-Sent Events endpoint to connect to the MCP server. |
| SSE Timeout (Ms) | (SSE only) Timeout in milliseconds for SSE requests. Default is 60000 ms (1 minute). |
| SSE Messages POST Endpoint (Optional) | (SSE only) Optional separate URL endpoint for posting messages if different from the SSE URL. |
| SSE Additional Headers (JSON) | (SSE only) Additional HTTP headers to send with SSE requests, provided as a JSON object (e.g., {"X-Custom-Header": "value"}). |
| Command | (Command Line only) The command to execute the MCP server process (e.g., path to executable or command name). |
| Arguments (Space Separated) | (Command Line only) Arguments to pass to the MCP server command, separated by spaces (e.g., --verbose --port 8080). |
| Environment Variables (Key=value Pairs, One per Line) | (Command Line only) Additional environment variables for the command process, each on a new line in KEY=VALUE format (e.g., MY_VAR=123). |
| Operation | The operation 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 | (Required for Read Resource operation) The URI of the resource to read. |
| Tool Name | (Required for Execute Tool operation) The name of the tool to execute. |
| Tool Parameters | (Required for Execute Tool operation) Parameters to pass to the tool in JSON format. |
| Prompt Name | (Required for Get Prompt operation) The name of the prompt template to retrieve. |
Output
The node outputs JSON data depending on the selected operation:
- List Prompts: Outputs
{ "prompts": [...] }— an array of available prompt templates. - List Tools: Outputs
{ "tools": [...] }— an array of available tools with their names, descriptions, and input schemas. - Execute Tool: Outputs
{ "result": ... }— the result returned by the executed tool, which can be any JSON-serializable value. - Get Prompt: Outputs
{ "prompt": {...} }— details of a specific prompt template. - List Resources: Outputs
{ "resources": [...] }— an array of available resources. - List Resource Templates: Outputs
{ "resourceTemplates": [...] }— an array of resource templates. - Read Resource: Outputs
{ "resource": {...} }— the content of a specific resource identified by URI.
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, requires a valid Bearer Token for authentication.
- Uses external MCP SDK packages for client communication and transport layers.
- Node expects environment variables starting with
MCP_to be passed as environment variables to the command line process if using the command line connection. - No internal credential names are exposed; users must provide their own API Bearer token or command line access.
Troubleshooting
- Missing Required Parameters: Errors will occur if mandatory parameters like Bearer Token (for SSE), SSE URL, or Command (for command line) are missing.
- Invalid JSON in Headers or Tool Parameters: If JSON inputs (like additional headers or tool parameters) are malformed, the node throws errors indicating invalid JSON.
- Connection Failures: Failure to connect to the MCP server (either via SSE or command line) results in errors with messages like "Failed to connect to MCP server".
- Tool Not Found: When executing a tool, if the specified tool name does not exist, the node lists available tools in the error message.
- Timeouts: SSE connections have configurable timeouts; if the server does not respond within the timeout, the request may fail.
- Transport Errors: Any transport-level errors during communication with the MCP server are surfaced as node errors.
- Environment Variable Parsing: For command line connection, environment variables must be correctly formatted as
KEY=VALUEpairs, one per line.
To resolve these issues:
- Ensure all required parameters are set correctly.
- Validate JSON inputs before running the node.
- Verify connectivity and credentials for the MCP server.
- Check that the tool or resource names exist on the MCP server.
- Adjust SSE timeout settings if necessary.
Links and References
- Model Context Protocol (MCP) Documentation (example placeholder, replace with actual MCP docs if available)
- Server-Sent Events (SSE) MDN Reference
- n8n Custom Node Development Guide