Skip to main content

llama-index tools mcp_discovery integration

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_tools_mcp_discovery-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_tools_mcp_discovery-0.1.0.tar.gz.

File metadata

  • Download URL: llama_index_tools_mcp_discovery-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_mcp_discovery-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35191351faced8f3e022172636ffcbe0205d47d8917a1046c8ca6fa5f37e91b6
MD5 9fad0fceb731e972a0790608d8baf0bb
BLAKE2b-256 c8d8be4145c0faca2a7e9f68878f16d32ef4a94f1977110aa0dd3e5384c92dbc

See more details on using hashes here.

File details

Details for the file llama_index_tools_mcp_discovery-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_tools_mcp_discovery-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_mcp_discovery-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b1196d825381b9b642d4e7706c6147db0bca67c3d6586e6fd6105849abb80ef
MD5 06a57b3954163ed994ff636655d28874
BLAKE2b-256 bb33894c7d539e6591046307c57e65a66ebc42914b3ffc00d094c51d8ff98707

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page