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 MCP 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 retrieval of metadata or content from MCP resources.
  • Executing specialized tools hosted on the MCP server with dynamic parameters.
  • Fetching and using prompt templates for AI or language model workflows.
  • Integrating MCP server capabilities into broader n8n automation pipelines.

For example, a user might list all available resources to discover what data can be accessed, then read a particular resource by its URI, or execute a tool that performs a specific transformation or analysis.

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
- Get Prompt
- List Prompts
- List Resources
- List Tools
- Read Resource
Resource URI (Required for "Read Resource" operation) The URI of the resource to read
Tool Name (Required for "Execute Tool" operation) The name of the tool to execute
Tool Parameters (Required for "Execute Tool" operation) JSON object specifying parameters to pass to the tool
Prompt Name (Required for "Get Prompt" operation) The name of the prompt template to retrieve

Output

The output JSON structure varies depending on the selected operation:

  • List Resources: Outputs { "resources": [...] } where the array contains available resource descriptors.
  • Read Resource: Outputs { "resource": { ... } } containing the detailed data of the specified resource.
  • List Tools: Outputs { "tools": [...] } where each tool includes its name, description, and input schema keys.
  • Execute Tool: Outputs { "result": ... } which is the execution result returned by the tool; can be any JSON-serializable value.
  • List Prompts: Outputs { "prompts": [...] } listing available prompt templates.
  • Get Prompt: Outputs { "prompt": { ... } } containing the details of the requested prompt template.

The node does not output binary data.

Dependencies

  • Requires connection to an MCP server via either:

    • A command line interface using STDIO transport, configured with a command and optional arguments.
    • A Server-Sent Events (SSE) transport, configured with an SSE URL and optional headers and POST endpoint.
  • Requires appropriate credentials for the chosen connection type, including API URLs, commands, environment variables, and headers.

  • Uses external libraries:

    • @modelcontextprotocol/sdk for MCP client functionality.
    • zod for input schema validation.
    • n8n-workflow utilities for error handling.
  • Environment variables starting with MCP_ are injected into the command line environment when using the STDIO 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 (command, URLs, headers) are properly configured.

  • 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: Attempting to execute a non-existent tool will result in an error listing available tools.

  • No tools found: If the MCP server returns no tools, the node throws an error indicating none were found.

  • Transport errors: Errors during communication with the MCP server are caught and reported with messages prefixed by "Transport error".

  • Unsupported operation: Selecting an operation not implemented by the node results in an explicit error.

Links and References

Discussion