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 resources, tools, and prompts managed by the MCP system. It supports multiple operations such as listing available resources, resource templates, tools, and prompts; reading specific resources; executing tools; and retrieving prompt templates.

Common scenarios where this node is beneficial include:

  • Automating workflows that require dynamic access to AI model resources or tools.
  • Integrating external AI capabilities into n8n workflows by invoking tools or fetching resource data.
  • Managing and querying available prompts and resource templates for AI-driven processes.

For example, a user might use this node to list all available AI tools on the MCP server and then execute a selected tool with specific parameters within an automation workflow.

Properties

Name Meaning
Connection Type Choose the transport type to connect to MCP server. Options: "Command Line (STDIO)", "Server-Sent Events (SSE)"
Operation The action to perform on the MCP server. Options include:
- Execute Tool: Run a specific tool with parameters
- Get Prompt: Retrieve a specific prompt template
- List Prompts: List all available prompts
- List Resource Templates: List available resource templates
- List Resources: List available resources
- List Tools: List available tools
- Read Resource: Read a specific resource by URI
Resource URI URI of the resource to read (required when operation is "Read Resource")
Tool Name Name of the tool to execute (required when operation is "Execute Tool")
Tool Parameters JSON object specifying parameters to pass to the tool (required when operation is "Execute Tool")
Prompt Name Name of the prompt template to get (required when operation is "Get Prompt")

Output

The output structure varies depending on the selected operation:

  • List Resources: Outputs a JSON object with a resources array containing the list of available resources.

    {
      "resources": [ /* array of resource objects */ ]
    }
    
  • List Resource Templates: Outputs a JSON object with a resourceTemplates array listing resource templates.

  • Read Resource: Outputs a JSON object with a resource field containing the detailed resource data fetched by URI.

  • List Tools: Outputs a JSON object with a tools array. Each tool includes its name, description, and input schema in JSON Schema format.

  • Execute Tool: Outputs a JSON object with a result field containing the execution result of the specified tool.

  • List Prompts: Outputs a JSON object with a prompts array listing available prompt templates.

  • Get Prompt: Outputs a JSON object with a prompt field containing the requested prompt template.

The node does not output binary data.

Dependencies

  • Requires connection to an MCP server via either:

    • Command Line interface using STDIO transport.
    • Server-Sent Events (SSE) transport over HTTP(S).
  • Requires appropriate credentials configured in n8n for the chosen connection type:

    • For "Command Line (STDIO)": credentials providing command and environment variables.
    • For "Server-Sent Events (SSE)": credentials including SSE URL, optional POST endpoint, and headers.
  • Uses environment variables prefixed with MCP_ to set additional environment variables for the command line transport.

  • Depends on several external libraries bundled with the node, including:

    • MCP SDK client modules for communication.
    • Zod for schema validation.
    • n8n-workflow utilities for error handling.

Troubleshooting

  • Connection errors: If the node fails to connect to the MCP server, verify that the credentials are correctly configured and that the MCP server is reachable via the selected transport method.

  • Invalid tool parameters: When executing a tool, ensure that the Tool Parameters property contains valid JSON representing an object. Invalid JSON or incorrect parameter types will cause errors.

  • Tool not found: If the specified tool name does not exist on the MCP server, the node will throw an error listing available tools.

  • Operation not supported: Selecting an unsupported operation will result in an error.

  • Transport errors: Errors during communication with the MCP server (e.g., network issues, invalid headers) will be reported as transport errors.

To resolve these issues:

  • Double-check credentials and connection settings.
  • Validate JSON inputs carefully.
  • Use the "List Tools" operation to confirm available tools before execution.
  • Review logs/debug messages for detailed error information.

Links and References

  • MCP SDK documentation (if publicly available)
  • n8n documentation on creating custom nodes and managing credentials
  • Zod schema validation library: https://github.com/colinhacks/zod

Discussion