Use this advanced n8n workflow to dynamically select and rank Model Context Protocol (MCP) servers using an OpenAI LLM for initial decision making and Contextual AI for highly relevant reranking. Explore n8n templates for tool calling.
Download this n8n workflow template and start using it instantly.
When dealing with thousands of dynamic tools, such as Model Context Protocol (MCP) servers, traditional LLMs struggle with selection and context. This powerful n8n workflow solves this by introducing a two-stage AI process.
First, an OpenAI LLM (GPT-4.1 mini) acts as a high-level decision agent, analyzing the user's query and determining if an external MCP server is needed. If needed, the LLM generates a precise reranking instruction.
Second, the automation fetches a large list of up to 5000 servers from the PulseMCP directory. It then uses the Contextual AI Reranker service to score every potential server based on the user's query and the instruction generated by the initial AI agent. This specialized reranker identifies the most contextually relevant servers, eliminating the complexity of manual setup or generic tool lists. This advanced n8n workflow provides a robust solution for dynamic, scalable tool orchestration.
This n8n workflow executes the following steps:
User-Query chat trigger initiates the flow when a user sends a message. This is a common starting point for interactive n8n templates.LLM Agent for Decision-Making n8n node, powered by the OpenAI Chat Model (GPT-4.1-mini), analyzes the input query. It determines if an MCP server is necessary (usemcp: true/false) and generates a specific instruction text for contextual reranking.If n8n node checks the LLM output. If usemcp is false, the flow terminates and provides the LLM's reason in Final Response1.use_mcp is true, the PulseMCP Fetch MCP Servers HTTP Request n8n node fetches up to 5000 server records from the external PulseMCP API.Parse MCP Server list into documents w metadata custom n8n node formats the thousands of server records into arrays of documents and metadata, combining them with the user's query and the AI-generated instruction. This is critical for the reranker API.ContextualAI Reranker HTTP Request n8n node calls the Contextual AI service, passing the query, instruction, and all 5000 documents. The reranker model scores the relevance of each server.Format the top 5 results custom n8n node processes the scores, identifies the top 5 ranked servers, and generates a structured, user-friendly message containing the server name, description, GitHub stars, downloads, and the relevance score.Final Response2 n8n node displays the highly relevant, contextually ranked list of MCP servers back to the user.To set up this dynamic server selection n8n workflow, follow these steps:
OpenAI Chat Model n8n node.CONTEXTUALAIAPIKEY and paste your API key from Contextual AI.User-Query n8n trigger will immediately be available for testing.PulseMCP Fetch MCP Servers and ContextualAI Reranker n8n nodes, respectively. User-Query (Chat Trigger): Function: The initial n8n trigger. Starts the workflow upon receiving a chat input. Key Configuration: Set to public with a starting message encouraging users to try the MCP Reranker.
OpenAI Chat Model (LangChain Node): Function: Provides the language model (GPT-4.1-mini) used by the LLM Agent. Key Configuration: Response format set to jsonobject for reliable parsing.
LLM Agent for Decision-Making (LangChain Agent n8n node): Function: Analyzes the user query using the system prompt to decide if external MCP servers are necessary and generates contextual reranking instructions. Key Configuration: System message explicitly demands a JSON output containing usemcp, reason, and instruction.
If (n8n node): Function: Controls the workflow path based on the LLM's decision, checking if the parsed JSON output for usemcp is true. This is a crucial n8n node for flow control.
PulseMCP Fetch MCP Servers (HTTP Request n8n node): Function: Retrieves the list of available MCP servers. Key Configuration: Query parameter countperpage is set to 5000 to fetch a large batch.
Parse MCP Server list into documents w metadata (Code n8n node): Function: A custom JavaScript n8n node that transforms the raw server list into structured documents and metadata arrays required by the Contextual AI Reranker API, ensuring optimal data transmission.
ContextualAI Reranker (HTTP Request n8n node): Function: Sends the query, instruction, and documents to the Contextual AI API for scoring. Key Configuration: Uses Bearer {{$vars.CONTEXTUALAIAPI_KEY}} for authorization and utilizes the ctxl-rerank-v2-instruct-multilingual reranker model.
Format the top 5 results (Code n8n node): Function: Sorts the results based on relevance score, extracts the top 5 servers, and formats the data into a clean text message for the final chat response. This n8n node completes the processing.
Use this advanced n8n workflow to automate lead routing based on AI qualification. Triggered by HubSpot, it uses GPT-4 and Airtable capacity data to assign leads and send instant notifications via Slack and Gmail.

Generate highly structured research data and export to CSV using this advanced n8n workflow. Utilizes GPT-4/5 for dynamic planning and Linkup for deep web extraction.

A sophisticated n8n workflow that dynamically updates form dropdowns with available AI models using the n8n node for self-configuration, enabling compliant AI chat interfaces.

Use this advanced n8n workflow to manage your media library, creating dummy files for instant Plex access and triggering on-demand downloads via Radarr, Sonarr, Tautulli, and Overseerr integration. Get these n8n templates today!

Deploy a scalable, context-aware AI chatbot using this advanced n8n workflow. Integrates OpenAI and uses MongoDB for real-time knowledge retrieval. Start automating today.









































