Skip to main content

Dynamic MCP server selection with OpenAI GPT-4.1 and contextual AI reranker

Workflow preview

Workflow preview
100%
Dynamic MCP server selection with OpenAI GPT-4.1 and contextual AI reranker preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

PROBLEM Thousands of MCP Servers exist and many are updated daily, making server selection difficult for LLMs. Current approaches require manually downloading and configuring servers, limiting flex...

Best for

  • Engineering automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.lmchatopenai, n8n-nodes-base.if, n8n-nodes-base.merge, n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.agent, n8n-nodes-base.httprequest, @n8n/n8n-nodes-langchain.chat

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Jinash Rouniyar.

Original n8n.io source

1.1 Workflow description

Title
Dynamic MCP server selection with OpenAI GPT-4.1 and contextual AI reranker
Workflow name
Dynamic MCP server selection with OpenAI GPT-4.1 and contextual AI reranker

PROBLEM

Thousands of MCP Servers exist and many are updated daily, making server selection difficult for LLMs.

  • Current approaches require manually downloading and configuring servers, limiting flexibility.
  • When multiple servers are pre-configured, LLMs get overwhelmed and confused about which server to use for specific tasks.

This template enables dynamic server selection from a live PulseMCP directory of 5000+ servers.

How it works

  • A user query goes to an LLM that decides whether to use MCP servers to fulfill a given query and provides reasoning for its decision.
  • Next, we fetch MCP Servers from Pulse MCP API and format them as documents for reranking
  • Now, we use Contextual AI's Reranker to score and rank all MCP Servers based on our query and instructions

How to set up

  • Sign up for a free trial of Contextual AI here to find CONTEXTUALAI_API_KEY.
  • Click on variables option in left panel and add a new environment variable CONTEXTUALAI_API_KEY.
  • For the baseline model, we have used GPT 4.1 mini, you can find your OpenAI API key here

How to customize the workflow

  • We use chat trigger to initate the workflow. Feel free to replace it with a webhook or other trigger as required.
  • We use OpenAI's GPT 4.1 mini as the baseline model and reranker prompt generator. You can swap out this section to use the LLM of your choice.
  • We fetch 5000 MCP Servers from the PulseMCP directory as a baseline number, feel free to adjust this parameter as required.
  • We are using Contextual AI's ctxl-rerank-v2-instruct-multilingual reranker model, which can be swapped with any one of the following rerankers:
    1. ctxl-rerank-v2-instruct-multilingual
    2. ctxl-rerank-v2-instruct-multilingual-mini
    3. ctxl-rerank-v1-instruct
  • You can checkout this blog for more information about rerankers to learn more about them.

Good to know:

  • Contextual AI Reranker (with full MCP docs): ~$0.035/query Includes 0.035 for reranking + ~$0.0001 for OpenAI instruction generation.
  • OpenAI Baseline: ~$0.017/query

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 2 - If

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 3 - Merge

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.2

Block 4 - Merge1

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.2

Block 5 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 6 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 8 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - User-Query

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.3

Block 10 - LLM Agent for Decision-Making

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2.2

Block 11 - PulseMCP Fetch MCP Servers

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 12 - Final Response1

Type / Role
@n8n/n8n-nodes-langchain.chat - chat
Config choices
Version 1

Block 13 - Parse MCP Server list into documents w metadata

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 14 - Format the top 5 results

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 15 - Final Response2

Type / Role
@n8n/n8n-nodes-langchain.chat - chat
Config choices
Version 1

Block 16 - Rerank documents

Type / Role
n8n-nodes-contextualai.contextualAi - contextualAi
Config choices
Version 1

3. Summary Table

Workflow Dynamic MCP server selection with OpenAI GPT-4.1 and contextual AI reranker
Complexity advanced
Nodes 16
Categories Engineering, AI RAG
Author Jinash Rouniyar
Published 05 Sept 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/8272/8272.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Dynamic MCP server selection with OpenAI GPT-4.1 and contextual AI reranker do?

PROBLEM Thousands of MCP Servers exist and many are updated daily, making server selection difficult for LLMs. Current approaches require manually downloading and configuring servers, limiting flex...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI RAG use case.