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 exposed by the server. It supports multiple operations such as listing available resources, reading specific resources, listing and executing tools, and managing prompt templates.

Common scenarios where this node is beneficial include:

  • Automating workflows that require dynamic access to external model resources or tools.
  • Integrating AI or model-driven capabilities into n8n workflows by invoking tools or fetching resource data.
  • Managing and utilizing prompt templates for language models within automation pipelines.

For example, a user can list all available tools on the MCP server, execute a selected tool with custom parameters, or retrieve a specific resource by its URI to incorporate its data downstream in the 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 prompt templates
- List Resources: List all available resources
- List Tools: List all 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 JSON structure varies depending on the selected operation:

  • List Resources:

    {
      "resources": [ /* array of resource objects */ ]
    }
    

    Contains an array of available resources from the MCP server.

  • Read Resource:

    {
      "resource": { /* resource object data */ }
    }
    

    Contains the data of the requested resource identified by its URI.

  • List Tools:

    {
      "tools": [
        {
          "name": "toolName",
          "description": "tool description",
          "schema": ["inputProperty1", "inputProperty2", "..."]
        },
        ...
      ]
    }
    

    Lists available tools with their names, descriptions, and input parameter keys.

  • Execute Tool:

    {
      "result": /* result returned by the executed tool */
    }
    

    Contains the output from running the specified tool with given parameters.

  • List Prompts:

    {
      "prompts": [ /* array of prompt template objects */ ]
    }
    

    Lists all available prompt templates.

  • Get Prompt:

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

    Returns the details of a specific 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.
  • Requires appropriate credentials for the chosen connection type (an API key or authentication token).
  • Environment variables prefixed with MCP_ can be used to configure the command line environment.
  • Uses several external libraries including:
    • @modelcontextprotocol/sdk for MCP client functionality.
    • zod for schema validation.
    • n8n-workflow for error handling and logging.

Troubleshooting

  • Connection Issues:
    Errors connecting to the MCP server may occur if the command or SSE URL is incorrect, or if required credentials are missing or invalid. Verify connection settings and credentials.

  • Operation Failures:
    If an operation fails (e.g., listing resources, executing a tool), the node throws descriptive errors indicating the failure reason. Common causes include:

    • Invalid or malformed tool parameters (must be valid JSON object).
    • Specified tool or prompt name does not exist on the MCP server.
    • Network or server-side issues preventing communication.
  • Parameter Parsing Errors:
    When executing a tool, ensure the "Tool Parameters" field contains valid JSON. Invalid JSON or wrong types will cause parsing errors.

  • No Tools Found:
    If no tools are returned from the MCP server during listing, verify the server configuration and availability of tools.

Links and References

Discussion