Overview
This node acts as a client interface to an MCP (Model Context Protocol) server, allowing users to interact with various resources, tools, and prompts exposed by the MCP server. It supports two connection types: Command Line (STDIO) and Server-Sent Events (SSE). The node can perform multiple operations such as listing available resources, reading a specific resource by its URI, listing and executing tools, and managing prompt templates.
A common use case is integrating external AI or model-related services that expose their capabilities via MCP, enabling workflows to dynamically fetch resources, execute tools, or retrieve prompt templates for further processing.
For example, you might use this node to:
- Read a configuration or data resource from the MCP server by specifying its URI.
- List all available tools on the MCP server and execute one with custom parameters.
- Retrieve prompt templates to feed into other AI nodes in your workflow.
Properties
Name | Meaning |
---|---|
Connection Type | Choose the transport type to connect to MCP server. Options: - Command Line (STDIO) - Server-Sent Events (SSE) |
Resource URI | URI of the resource to read. Required when the operation is "Read Resource". |
Output
The output JSON structure depends on the selected operation. For the Read Resource operation, the output contains:
{
"resource": { /* The content of the resource fetched from the MCP server */ }
}
resource
: The data retrieved from the MCP server corresponding to the specified resource URI. Its structure depends on the resource itself.
In general, the node outputs JSON objects containing keys relevant to the operation performed, such as resources
, tools
, prompts
, prompt
, or result
.
The node does not explicitly handle binary data output.
Dependencies
- Requires connectivity to an MCP server supporting either Command Line (STDIO) or Server-Sent Events (SSE) transport protocols.
- Needs appropriate credentials configured in n8n for the chosen connection type (an API key or authentication token).
- Environment variables starting with
MCP_
may be used to configure the command line environment when using the STDIO connection. - Uses several external libraries internally, including:
@modelcontextprotocol/sdk
for MCP client functionality.zod
for schema validation.n8n-workflow
for error handling.
Troubleshooting
- Connection errors: If the node fails to connect to the MCP server, verify that the server URL or command line command is correct and accessible. Check that required credentials are properly set up.
- Invalid resource URI: When reading a resource, ensure the URI is valid and the resource exists on the MCP server.
- Tool execution failures: Errors during tool execution often stem from invalid or malformed JSON parameters. Make sure the "Tool Parameters" input is a valid JSON object.
- No tools found: If the node reports no tools available, confirm that the MCP server exposes tools and that the connection is healthy.
- Unsupported operation: Selecting an operation not supported by the MCP client will result in an error.
- Parsing errors: Tool parameters must be a JSON object; strings or other types will cause parsing errors.
Links and References
- Model Context Protocol (MCP) SDK (for more details on MCP client usage)
- n8n Documentation (general guidance on creating and using custom nodes)