Using MCP Tools with LlamaIndex
LlamaIndex provides robust support for consuming MCP servers through the llama-index-tools-mcp package.
Installation
Section titled “Installation”pip install llama-index-tools-mcpBasic Usage
Section titled “Basic Usage”The most common usage will be converting an MCP server into a list of llama-index tool definitions:
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec
# Connect to MCP servermcp_client = BasicMCPClient("http://127.0.0.1:8000/sse")mcp_tool_spec = McpToolSpec(client=mcp_client)
# Get toolstools = await mcp_tool_spec.to_tool_list_async()Using with Agents
Section titled “Using with Agents”Once you have a list of tools, you can plug this into any existing agent:
from llama_index.core.agent.workflow import FunctionAgentfrom llama_index.llms.openai import OpenAI
agent = FunctionAgent( tools=tools, llm=OpenAI(model="gpt-5-mini"), system_prompt="You are a helpful assistant.",)
response = await agent.run("Your query here")You can read more about agents in the Agents Guide.
Connection Types
Section titled “Connection Types”The BasicMCPClient supports multiple transport methods:
# Server-Sent Eventssse_client = BasicMCPClient("https://example.com/sse")
# Streamable HTTPhttp_client = BasicMCPClient("https://example.com/mcp")
# Local processlocal_client = BasicMCPClient("python", args=["server.py"])Note for AI agents: this documentation is built for programmatic access.
- Overview of all docs: https://developers.llamaindex.ai/llms.txt
- Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md
- Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters.
- A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/python/shared/mcp/