Overview
The node acts as a client interface to an MCP (Model Context Protocol) server, enabling interaction with various MCP resources such as prompts, tools, and other resources. It supports multiple operations including listing available prompts, tools, and resources, reading specific resources, executing tools, and retrieving prompt templates.
This node is beneficial in scenarios where you want to integrate advanced model context capabilities into your workflows, such as dynamically fetching prompt templates, executing AI-powered tools, or managing resources hosted on an MCP server.
For example:
- Listing all available prompt templates to select one for further processing.
- Executing a specific tool with custom parameters to perform a task like text generation or data transformation.
- Reading a resource by its URI to obtain detailed information or content.
Properties
Name | Meaning |
---|---|
Connection Type | Choose the transport type to connect to MCP server. Options: - Command Line (STDIO) - Server-Sent Events (SSE) |
Output
The output JSON structure depends on the selected operation:
List Prompts: Outputs an object with a
prompts
field containing an array of available prompt templates.{ "prompts": [ /* array of prompt objects */ ] }
Other operations (not requested here but relevant for context):
listResources
: outputs{ resources: [...] }
readResource
: outputs{ resource: { ... } }
listTools
: outputs{ tools: [{ name, description, schemaKeys }] }
executeTool
: outputs{ result: <tool execution result> }
getPrompt
: outputs{ prompt: { ... } }
The node does not output binary data; all outputs are JSON objects representing the requested data.
Dependencies
Requires connection to an MCP server via either:
- A command line interface using STDIO transport.
- Server-Sent Events (SSE) transport over HTTP(S).
The node expects appropriate credentials for the chosen connection type:
- For STDIO: an API key or authentication token configured in n8n credentials.
- For SSE: an API key or authentication token configured separately.
Environment variables starting with
MCP_
can be used to pass additional environment settings when using the command line transport.The node uses external libraries from the MCP SDK to manage connections and interactions.
Troubleshooting
Connection issues: If the node fails to connect to the MCP server, verify that the connection type matches the server setup and that credentials are correctly configured.
Operation failures: Errors like "Failed to list prompts" or "Failed to execute tool" usually indicate communication problems or invalid parameters. Check the error message for details.
Invalid tool parameters: When executing a tool, ensure the parameters are valid JSON objects. Parsing errors will cause the node to throw descriptive errors.
Tool not found: If attempting to execute a tool that does not exist, the node lists available tools in the error message to help correct the tool name.
Empty results: For operations like listing tools or prompts, if no items are returned, confirm that the MCP server has those resources available.
Links and References
- MCP SDK documentation (general): https://modelcontextprotocol.org/sdk
- n8n documentation on creating custom nodes: https://docs.n8n.io/integrations/creating-nodes/
- Server-Sent Events (SSE) overview: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events
- Zod validation library (used internally for schema validation): https://github.com/colinhacks/zod