Skip to content
LlamaIndex Framework
Component Guides
MCP

Converting Existing LlamaIndex Workflows & Tools to MCP

Convert your LlamaIndex tools and workflows into MCP servers for broader ecosystem compatibility.

Use workflow_as_mcp to convert any LlamaIndex Workflow into an FastMCP server:

from workflows import Context, Workflow, step
from workflows.events import StartEvent, StopEvent
from llama_index.tools.mcp.utils import workflow_as_mcp
class QueryEvent(StartEvent):
query: str
class SimpleWorkflow(Workflow):
@step
def process_query(self, ctx: Context, ev: QueryEvent) -> StopEvent:
result = f"Processed: {ev.query}"
return StopEvent(result=result)
# Convert to MCP server
workflow = SimpleWorkflow()
mcp = workflow_as_mcp(workflow, start_event_model=QueryEvent)

If you were using FastMCP directly, it would look something like this:

from fastmcp import FastMCP
# Workflow definition
...
mcp = FastMCP("Demo 🚀")
workflow = SimpleWorkflow()
@mcp.tool
async def run_my_workflow(input_args: QueryEvent) -> str:
"""Add two numbers"""
if isintance(input_args, dict):
input_args = QueryEvent.model_validate(input_args)
result = await workflow.run(start_event=input_args)
return str(result)
if __name__ == "__main__":
mcp.run()

We can also use FastMCP to directly convert existing functions and tools input MCP endpoints:

from fastmcp import FastMCP
from llama_index.tools.notion import NotionToolSpec
# Get tools from ToolSpec
tool_spec = NotionToolSpec(integration_token="your_token")
tools = tool_spec.to_tool_list()
# Create MCP server
mcp_server = FastMCP("Tool Server")
# Register tools
for tool in tools:
mcp_server.tool(
name=tool.metadata.name, description=tool.metadata.description
)(tool.real_fn)

You can launch your server from the CLI (which is also great for debugging!):

Terminal window
# Install MCP CLI
pip install "mcp[cli]"
# Run server
mcp run your-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/