MCP Client Bearer icon

MCP Client Bearer

Use MCP client with Bearer Token Authentication

Overview

This node provides integration with an MCP (Model Context Protocol) server using a Bearer Token for authentication. It supports two connection types: Command Line (STDIO) and Server-Sent Events (SSE). The node allows users to perform various operations such as listing available resources, resource templates, tools, prompts, reading specific resources, getting prompt templates, and executing tools on the MCP server.

Common scenarios include:

  • Automating retrieval of AI model resources or templates.
  • Executing AI tools remotely with specified parameters.
  • Fetching prompt templates for dynamic prompt generation.
  • Integrating MCP server capabilities into workflows that require authenticated access via bearer tokens.

Practical example:

  • A user wants to list all available AI tools on their MCP server and then execute a specific tool with JSON parameters, all within an n8n workflow.

Properties

Name Meaning
Bearer Token Your API Bearer token for authentication, primarily used for SSE connection type.
Connection Type Choose the transport type to connect to the MCP server. Options: Command Line (STDIO) or Server-Sent Events (SSE).
SSE URL (Required if SSE selected) The full URL for the Server-Sent Events endpoint.
SSE Timeout (Ms) (If SSE) Timeout in milliseconds for SSE requests. Default is 60000 ms.
SSE Messages POST Endpoint (Optional) (If SSE) Optional separate URL endpoint for posting messages if different from the SSE URL.
SSE Additional Headers (JSON) (If SSE) Additional HTTP headers to send with SSE requests, provided as a JSON object (e.g., {"X-Custom-Header": "value"}).
Command (If Command Line selected) The command to execute for the MCP server process (e.g., path or executable name).
Arguments (Space Separated) (If Command Line) Arguments to pass to the command, separated by spaces.
Environment Variables (Key=value Pairs, One per Line) (If Command Line) Additional environment variables for the command process, each on a new line in KEY=VALUE format.
Operation 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 (If Read Resource operation) URI of the resource to read.
Tool Name (If Execute Tool operation) Name of the tool to execute.
Tool Parameters (If Execute Tool) Parameters to pass to the tool in JSON format.
Prompt Name (If Get Prompt operation) Name of the prompt template to retrieve.

Output

The output JSON structure depends on the selected operation:

  • List Resources:

    {
      "resources": [ /* array of resource objects */ ]
    }
    
  • List Resource Templates:

    {
      "resourceTemplates": [ /* array of resource template objects */ ]
    }
    
  • Read Resource:

    {
      "resource": { /* resource object matching the requested URI */ }
    }
    
  • List Tools:

    {
      "tools": [
        {
          "name": "toolName",
          "description": "tool description",
          "schema": { /* JSON schema of tool input parameters */ }
        },
        ...
      ]
    }
    
  • Execute Tool:

    {
      "result": { /* result returned by the executed tool, can be any JSON value */ }
    }
    
  • List Prompts:

    {
      "prompts": [ /* array of prompt templates */ ]
    }
    
  • Get Prompt:

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

If binary data were involved, it would be summarized here, but this node outputs only JSON data.

Dependencies

  • Requires an active MCP server accessible either via:
    • Command Line interface (running a local or remote MCP server process).
    • Server-Sent Events (SSE) endpoint with proper URL and authentication.
  • Requires a valid Bearer Token for authentication when using SSE connection type.
  • Uses external MCP SDK packages for client communication and tool execution.
  • For command line connection, requires the MCP server executable or command available on the system running n8n.
  • For SSE connection, requires network access to the SSE endpoint and optionally a POST endpoint for sending messages.
  • No internal credential names are exposed; users must provide their own API Bearer token or command details.

Troubleshooting

  • Missing Required Parameters:
    Errors will occur if required parameters like Bearer Token (for SSE), SSE URL, or Command (for cmd connection) are missing. Ensure these are correctly set.

  • Invalid JSON in Additional Headers or Tool Parameters:
    If JSON inputs are malformed, the node throws errors indicating invalid JSON. Validate JSON syntax before input.

  • Connection Failures:
    Errors connecting to MCP server may indicate wrong URLs, network issues, or incorrect command paths. Check connectivity and command correctness.

  • Tool Not Found:
    When executing a tool, if the specified tool name does not exist on the MCP server, an error lists available tools. Verify tool names carefully.

  • Timeouts:
    SSE connections have configurable timeouts. Increase timeout if operations take longer than expected.

  • Environment Variable Parsing:
    For command line connection, environment variables must be in KEY=VALUE format, one per line. Incorrect formatting may cause unexpected behavior.

  • Transport Errors:
    Transport layer errors are caught and reported. Review logs for detailed error messages.

Links and References


This summary covers the static analysis of the node's execute() method and its properties related to the "Default" resource and "List Resources" operation context.

Discussion