MCP Client icon

MCP Client

Use MCP client

Overview

This node acts as a client interface to an MCP (Model Context Protocol) server, enabling interaction with various MCP resources, tools, and prompts. It supports multiple connection types for communication, including command line (STDIO), HTTP streamable protocol, and deprecated Server-Sent Events (SSE). The node is useful in scenarios where you want to programmatically list, read, or execute resources and tools managed by an MCP server, such as integrating AI model tools, fetching prompt templates, or managing resource templates.

Practical examples:

  • Listing all available AI tools on the MCP server to dynamically select one for execution.
  • Reading a specific resource by its URI to retrieve detailed information.
  • Executing a tool with custom parameters to perform a task like text generation or data processing.
  • Fetching prompt templates to use in subsequent operations or workflows.

Properties

Name Meaning
Connection Type Choose the transport type to connect to the MCP server. Options:
- Command Line (STDIO)
- Server-Sent Events (SSE) (Deprecated)
- HTTP Streamable (recommended for real-time communication)
Operation Select the operation to perform on the MCP server. Options include:
- Execute Tool
- Get Prompt
- List Prompts
- List Resource Templates
- List Resources
- List Tools
- Read Resource
Resource URI (Required for "Read Resource" operation) The URI of the resource to read.
Tool Name or ID (Required for "Execute Tool" operation) Select a tool from the list or specify a custom name.
Tool Parameters (Required for "Execute Tool" operation) JSON object specifying parameters to pass to the tool.
Prompt Name (Required for "Get Prompt" operation) Name of the prompt template to retrieve.

Output

The output JSON structure depends on the selected operation:

  • List Resources: Outputs { resources: [...] } — an array of available resources from the MCP server.
  • List Resource Templates: Outputs { resourceTemplates: [...] } — an array of resource templates.
  • Read Resource: Outputs { resource: {...} } — details of the specified resource.
  • List Tools: Outputs { tools: [...] } — an array of tools with their names, descriptions, and input schemas.
  • Execute Tool: Outputs { result: ... } — the result returned by executing the specified tool, which can be any JSON-serializable data.
  • List Prompts: Outputs { prompts: [...] } — an array of available prompt templates.
  • Get Prompt: Outputs { prompt: {...} } — details of the specified prompt template.

The node does not output binary data; all outputs are JSON objects representing the requested data or results.

Dependencies

  • Requires an MCP server accessible via one of the supported connection types.
  • Needs appropriate credentials configured in n8n for the chosen connection type:
    • For Command Line (STDIO): command, arguments, and environment variables.
    • For HTTP Streamable: URL endpoint and optional headers.
    • For SSE (deprecated): URL endpoint and optional headers.
  • Uses internal MCP SDK clients and transports for communication.
  • Environment variables prefixed with MCP_ can be passed to the command line transport environment.

Troubleshooting

  • Connection errors: If the node fails to connect to the MCP server, verify that the credentials and connection parameters (command, URLs, headers) are correct and that the MCP server is reachable.
  • No transport available: This error indicates missing or misconfigured credentials for the selected connection type.
  • Tool not found: When executing a tool, if the specified tool name does not exist, ensure the tool name matches exactly one of the listed tools.
  • Invalid tool parameters: Tool parameters must be valid JSON objects. Errors parsing parameters usually mean malformed JSON or incorrect parameter structure.
  • Timeouts: The node uses configurable timeouts for HTTP and SSE connections; increase these if operations take longer than expected.
  • Deprecated SSE transport: SSE connection type is deprecated; prefer using HTTP Streamable for real-time communication.
  • General operation failure: The node wraps errors with descriptive messages; check logs for details and verify inputs.

Links and References

  • n8n Documentation on Expressions
  • MCP SDK repository and documentation (not linked here due to internal references)
  • General info on Server-Sent Events and HTTP streaming protocols for real-time data transfer

Discussion