Skip to main content

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

Metadata

Release files for llama-index-tools-mcp-discovery 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-tools-mcp-discovery 0.3.0
File Size Uploaded Provenance
llama_index_tools_mcp_discovery-0.3.0.tar.gz 5.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-tools-mcp-discovery 0.3.0
File Interpreter ABI Platform
llama_index_tools_mcp_discovery-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / llama_index_tools_mcp_discovery-0.3.0.tar.gz

Download URL llama_index_tools_mcp_discovery-0.3.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a7f1ccb63de67225bfe455e1df609cce944c9bf51c8f9fca7e22ab831056fc42
BLAKE2b-256 checksum
How to use checksums
718f328feb6efc14dff98b6649a04a038c7a4727af32946bdaff4f0c350a8bd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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}

Release files / llama_index_tools_mcp_discovery-0.3.0-py3-none-any.whl

Download URL llama_index_tools_mcp_discovery-0.3.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e2c3ac2218e24fb2b89b5f0842b79784a82918268802a58f6a70c442de75f29
BLAKE2b-256 checksum
How to use checksums
fa81df9e17c461f17a8f258beda713a364d514a0b9a74fb020c54813b8a7820a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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}

Security for llama-index-tools-mcp-discovery 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page