Overview
This node acts as a client interface to an MCP (Model Context Protocol) server, allowing users to perform various operations such as reading resources, listing available tools, prompts, and resources, executing tools, and retrieving prompt templates. It supports two connection types: Command Line (STDIO) and Server-Sent Events (SSE), enabling flexible integration depending on the environment.
A common use case is automating interactions with an MCP server to fetch or manipulate AI model-related resources programmatically within an n8n workflow. For example, you can read a specific resource by its URI, execute a tool with parameters, or list all available tools and prompts for dynamic workflow decisions.
Properties
| Name | Meaning |
|---|---|
| Connection Type | Choose the transport type to connect to the MCP server. Options: "Command Line (STDIO)", "Server-Sent Events (SSE)" |
| Resource URI | The URI of the resource to read from the MCP server. Required when using the "Read Resource" operation. |
Output
The output JSON structure depends on the selected operation:
Read Resource: Outputs a JSON object with a
resourcefield containing the data of the requested resource.{ "resource": { /* resource data object */ } }Other operations (not requested here but present in code) produce outputs like:
resources: array of available resources,tools: array of available tools with their name, description, and input schema,result: result of executed tool,prompts: list of available prompts,prompt: a specific prompt template.
The node does not output binary data; all outputs are JSON objects representing structured data returned from the MCP server.
Dependencies
Requires access to an MCP server endpoint via either:
- A command line interface (STDIO) client with a configured command and arguments.
- A Server-Sent Events (SSE) client with URL and optional headers.
Requires appropriate credentials configured in n8n for the chosen connection type:
- An API key or authentication token for SSE connection.
- Command and environment variables for STDIO connection.
Environment variables starting with
MCP_can be used to pass additional environment settings to the STDIO client.
Troubleshooting
Connection errors: If the node fails to connect to the MCP server, verify that the credentials and connection parameters (command, URLs, headers) are correctly set and accessible from the n8n environment.
Invalid resource URI: When reading a resource, ensure the
Resource URIis correct and the resource exists on the MCP server.Tool execution failures: Errors during tool execution may occur if the tool name is incorrect or parameters are malformed. Parameters must be valid JSON objects.
Parsing errors: Tool parameters must be valid JSON. Invalid JSON strings will cause parsing errors.
No tools found: If no tools are returned from the MCP server, check the server configuration and permissions.
Error messages thrown by the node include descriptive texts such as:
Failed to connect to MCP server: ...Transport error: ...Tool 'X' does not exist. Available tools: ...Failed to parse tool parameters: ... Make sure the parameters are valid JSON.
Resolving these typically involves verifying credentials, input parameters, and server availability.
Links and References
- MCP (Model Context Protocol) official documentation (hypothetical link based on context)
- n8n documentation on Creating Custom Nodes
- Node.js child process and environment variable management references for STDIO transport setup