Actions7
Overview
This node connects to an MCP (Model Context Protocol) server using a Bearer Token for authentication and supports two connection types: Command Line (STDIO) or Server-Sent Events (SSE). It allows users to perform various operations such as retrieving prompt templates, listing available prompts, tools, resources, reading specific resources, and executing tools on the MCP server.
The Get Prompt operation fetches a specific prompt template by its name from the MCP server. This is useful when you want to dynamically retrieve and use predefined prompt templates stored on the server for further processing or integration in your workflows.
Common scenarios:
- Fetching a prompt template to customize or review before sending it to an AI model.
- Dynamically loading prompt templates based on workflow conditions.
- Integrating with MCP servers that manage prompt templates centrally.
Example:
You want to get a prompt named "customerSupportResponse" from the MCP server to feed it into a language model node later in your workflow.
Properties
| Name | Meaning |
|---|---|
| Bearer Token | Your API Bearer token used for authenticating requests, primarily required for SSE connection type. |
| Connection Type | The transport method to connect to the MCP server. Options: - Command Line (STDIO): Runs a local command/process. - Server-Sent Events (SSE): Connects via HTTP SSE endpoint. |
| SSE URL | Full URL of the Server-Sent Events endpoint (required if Connection Type is SSE). |
| SSE Timeout (Ms) | Timeout in milliseconds for SSE requests (minimum 1000 ms). Default is 60000 ms. |
| SSE Messages POST Endpoint | Optional separate URL endpoint for posting messages if different from the SSE URL. |
| SSE Additional Headers (JSON) | Additional HTTP headers to send with SSE requests, provided as a JSON object (e.g., {"X-Custom-Header": "value"}). |
| Command | The command to execute for the MCP server process (required if Connection Type is Command Line). |
| Arguments (Space Separated) | Arguments to pass to the command, separated by spaces (optional). |
| Environment Variables | Additional environment variables for the command process, specified as key=value pairs, one per line (optional). |
| Prompt Name | The name of the prompt template to retrieve (required for Get Prompt operation). |
Output
The output JSON contains a single field:
{
"prompt": {
/* prompt template object */
}
}
- The
promptfield holds the retrieved prompt template object fetched from the MCP server by the given prompt name. - The structure of the prompt template depends on the MCP server's schema but typically includes fields like prompt text, variables, metadata, etc.
- No binary data output is produced by this operation.
Dependencies
- Requires an active MCP server accessible either via:
- A local command-line executable (STDIO transport), or
- An HTTP Server-Sent Events (SSE) endpoint.
- Requires a valid Bearer Token for authentication, especially mandatory for SSE connections.
- Uses the MCP SDK client libraries internally to communicate with the MCP server.
- For SSE connection, additional configuration such as SSE URL, optional POST endpoint, and custom headers may be needed.
- If using Command Line connection, the MCP server command, arguments, and environment variables must be correctly configured.
Troubleshooting
Missing Required Parameters:
Errors will occur if required parameters like Bearer Token (for SSE), Command (for STDIO), or Prompt Name are missing. Ensure all required inputs are provided.Invalid JSON in Additional Headers:
If the SSE Additional Headers JSON is malformed, the node throws an error indicating invalid JSON. Validate JSON syntax carefully.Connection Failures:
- For SSE, verify the SSE URL is correct and reachable, and the Bearer Token is valid.
- For Command Line, ensure the command path is correct, executable permissions are set, and environment variables are properly formatted.
Operation Not Supported:
If an unsupported operation is selected, the node will throw an error. Confirm the operation name matches supported options.Tool Execution Errors:
When executing tools (not applicable for Get Prompt), errors may indicate invalid tool names or parameter issues.Timeouts:
SSE connections have configurable timeouts; increase the timeout if requests take longer than expected.
Links and References
- MCP Protocol Documentation (hypothetical link)
- Server-Sent Events (SSE) MDN Docs
- n8n Custom Node Development
- Zod Validation Library (used internally for schema validation)