MCP

Discover and Integrate External Tools

LlamaIndex tool to query an MCP Discovery server for dynamic tool retrieval.

Works with openaisupabase

91
Spark score
out of 100
Updated 3 months ago
Version 1.0.0

Add to Favorites

Why it matters

Dynamically discover and integrate external tools into your LlamaIndex agents by querying a Model Context Protocol (MCP) Discovery server. Enables agents to find and utilize new functionalities autonomously.

Outcomes

What it gets done

01

Query MCP Discovery servers for available tools.

02

Retrieve tool metadata and descriptions.

03

Integrate discovered tools into LlamaIndex agents.

04

Enable agents to find tools based on natural language queries.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-tool-tools-mcp-discovery | bash

Capabilities

Tools your agent gets

discover_tools

Query MCP servers to discover available tools based on natural language descriptions

Overview

LlamaIndex Tool: MCP Discovery

What it does

A LlamaIndex BaseToolSpec client that queries MCP Discovery servers to find tools matching natural language descriptions. Returns structured recommendations with server names, npm packages, install commands, and confidence scores. Built with async aiohttp for performance and includes graceful error handling.

How it connects

Use this when you want LlamaIndex agents to query for available MCP tools at runtime based on task requirements, rather than configuring a fixed set of tools upfront. Requires Python ≥3.9, llama-index-core ≥0.13.0, and a separately deployed MCP Discovery server (self-hosted or cloud-deployed).

Source README

LlamaIndex Tool: MCP Discovery

This tool allows LlamaIndex agents to query a Model Context Protocol (MCP) Discovery server to find and retrieve other tools dynamically.

⚠️ Important Note

This MCP Discovery integration does not work out of the box.
It requires a separately deployed MCP Discovery server, which you must self-host locally or deploy to your own cloud.

This tool acts only as a client and assumes an existing, reachable MCP Discovery server.


Required Environment Variables

SUPABASE_URL=your-supabase-url
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
OPENAI_API_KEY=your-openai-api-key

Deploying the MCP Discovery Server

  git clone https://github.com/yksanjo/mcp-discovery.git
  cd mcp-discovery
  npm install

Features

  • 🔍 Autonomous Tool Discovery: Query MCP servers to discover available tools based on natural language descriptions
  • Async Operations: Built with aiohttp for high-performance async operations
  • 🤖 Seamless Integration: Works directly with LlamaIndex agents via BaseToolSpec
  • 🛡️ Error Handling: Graceful error handling with informative messages

Requirements

  • Python >= 3.9
  • llama-index-core >= 0.13.0
  • aiohttp >= 3.8.0

Installation

pip install llama-index-tools-mcp-discovery

Usage

from llama_index.tools.mcp_discovery import MCPDiscoveryTool
from llama_index.core.agent import ReActAgent

### Initialize the tool with the MCP Discovery API
tool_spec = MCPDiscoveryTool(
    api_url="https://mcp-discovery-two.vercel.app/api/v1/discover"
)

### Convert the spec to a list of FunctionTools
tools = tool_spec.to_tool_list()

### Create an agent with the discovery tool
agent = ReActAgent.from_tools(tools, verbose=True)

### The agent can now use the 'discover_tools' function to find MCP servers it needs
agent.chat("Find me a server that can send Slack notifications")

API Response Format

This tool uses the standard MCP Discovery response schema as defined in the MCP Discovery. The API should return responses following this format:

{
  "recommendations": [
    {
      "server": "filesystem-server",
      "name": "Filesystem Server",
      "npm_package": "@modelcontextprotocol/server-filesystem",
      "install_command": "npx -y @modelcontextprotocol/server-filesystem",
      "confidence": 0.85,
      "description": "Secure file operations for MCP...",
      "category": "development",
      "github_url": "https://github.com/modelcontextprotocol/servers"
    }
  ],
  "total_found": 10,
  "query_time_ms": 52
}

Note: To optimize context window usage, the tool summarizes the raw JSON into a concise string containing only the name, server, and category. This allows the LLM to efficiently evaluate and select the best tool without being overwhelmed by installation metadata.

Examples

See the examples directory for more usage examples.

Development

Run tests:

make test

Run linters:

make lint

Format code:

make format

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.