MCP Client icon

MCP Client

Use MCP client

Overview

This node acts as a client interface to an MCP (Model Context Protocol) server, allowing users to interact with various MCP resources and tools. It supports multiple operations such as reading resources by URI, listing available resources, tools, and prompts, executing specific tools with parameters, and retrieving prompt templates.

A common use case is integrating external model context data or AI tools into an n8n workflow, enabling dynamic data retrieval or tool execution based on the MCP server's capabilities. For example, you might read a resource containing model metadata or execute a tool that processes input data and returns results for further automation steps.

The node supports two connection types to communicate with the MCP server:

  • Command Line (STDIO): Uses a command-line client process.
  • Server-Sent Events (SSE): Uses an SSE-based transport for event-driven communication.

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 operation is "Read Resource".

Output

The output JSON structure depends on the selected operation:

  • Read Resource: Outputs a single object with a resource field containing the data read from the specified resource URI.

    {
      "resource": { /* resource data object */ }
    }
    
  • List Resources: Outputs an object with a resources array listing available resource identifiers.

    {
      "resources": [ /* array of resource URIs or descriptors */ ]
    }
    
  • List Tools: Outputs an object with a tools array describing available tools, each including name, description, and input schema keys.

    {
      "tools": [
        {
          "name": "toolName",
          "description": "Tool description",
          "schema": ["param1", "param2"]
        },
        ...
      ]
    }
    
  • Execute Tool: Outputs an object with a result field containing the execution result of the specified tool.

    {
      "result": /* tool execution output */
    }
    
  • List Prompts: Outputs an object with a prompts array listing available prompt templates.

    {
      "prompts": [ /* array of prompt names or details */ ]
    }
    
  • Get Prompt: Outputs an object with a prompt field containing the requested prompt template.

    {
      "prompt": { /* prompt template data */ }
    }
    

The node does not output binary data.

Dependencies

  • Requires access to an MCP server via either:
    • A command line client executable with appropriate environment variables set.
    • An SSE endpoint URL with optional custom headers and POST endpoint configuration.
  • Requires credentials configured in n8n for authentication with the MCP server depending on the chosen connection type.
  • Environment variables prefixed with MCP_ can be used to pass additional environment settings to the command line client transport.

Troubleshooting

  • Connection errors: If the node fails to connect to the MCP server, verify that the correct connection type is selected and that credentials (API key or SSE URL) are properly configured.
  • Invalid resource URI: When reading a resource, ensure the URI is correctly formatted 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 invalid JSON objects. Validate tool names against the list of available tools and ensure parameters are well-formed JSON.
  • Transport errors: Issues with the underlying transport (command line or SSE) will throw errors; check logs for detailed messages and confirm network connectivity or command availability.
  • Missing parameters: Required properties like Resource URI for reading resources must be provided; missing these will cause errors.

Links and References

  • MCP protocol and SDK documentation (refer to your MCP server provider)
  • n8n documentation on creating and using custom nodes
  • Node.js child process and event source libraries for understanding transports

Discussion