LlamaCloud MCP Server
LlamaIndex MCP デモ
このリポジトリでは、LlamaCloud を使用して MCP サーバーを作成する方法と、LlamaIndex を MCP クライアントとして使用する方法の両方を示します。
LlamaCloudをMCPサーバーとして
Claude Desktopのようなクライアントが利用できるローカルMCPサーバーを提供するには、 mcp-server.pyを使用します。これを使用することで、RAGを使用してClaudeに最新の個人情報を提供し、質問に答えるためのツールを提供できます。これらのツールは必要な数だけ提供できます。
LlamaCloudインデックスを設定する
LlamaCloudアカウントを取得する
任意のデータソースで新しいインデックスを作成してください。今回のケースではGoogleドライブを使用し、LlamaIndexドキュメントのサブセットをソースとして提供しました。テスト目的であれば、ドキュメントを直接インデックスにアップロードすることもできます。
LlamaCloud UIからAPIキーを取得する
MCPサーバーをセットアップする
このリポジトリをクローンする
.envファイルを作成し、次の 2 つの環境変数を追加します。LLAMA_CLOUD_API_KEY- 前の手順で取得したAPIキーOPENAI_API_KEY- OpenAI APIキー。RAGクエリを実行するために使用されます。OpenAIを使用しない場合は、他のLLMを使用できます。
それではコードを見てみましょう。まずMCPサーバーをインスタンス化します。
mcp = FastMCP('llama-index-server')次に、 @mcp.tool()デコレータを使用してツールを定義します。
@mcp.tool()
def llama_index_documentation(query: str) -> str:
"""Search the llama-index documentation for the given query."""
index = LlamaCloudIndex(
name="mcp-demo-2",
project_name="Rando project",
organization_id="e793a802-cb91-4e6a-bd49-61d0ba2ac5f9",
api_key=os.getenv("LLAMA_CLOUD_API_KEY"),
)
response = index.as_query_engine().query(query + " Be verbose and include code examples.")
return str(response)ここで使用するツールはllama_index_documentationです。このツールはmcp-demo-2というLlamaCloudインデックスをインスタンス化し、それをクエリエンジンとして使用してクエリに回答します。プロンプトには追加の指示も表示されます。LlamaCloudインデックスの設定方法については、次のセクションで説明します。
最後に、サーバーを実行します。
if __name__ == "__main__":
mcp.run(transport="stdio")Claude Desktop との通信に使用されるstdioトランスポートに注意してください。
Claudeデスクトップの設定
Claude Desktopをインストールする
メニューバーで
Claude」→Settings→Developer」→Edit Configを選択します。すると、お好みのテキストエディタで編集できる設定ファイルが表示されます。設定は次のようになります (
$YOURPATHリポジトリへのパスに置き換えてください)。
{
"mcpServers": {
"llama_index_docs_server": {
"command": "poetry",
"args": [
"--directory",
"$YOURPATH/llamacloud-mcp",
"run",
"python",
"$YOURPATH/llamacloud-mcp/mcp-server.py"
]
}
}
}ファイルを構成した後は、必ずClaude Desktop を再起動してください。
これでクエリを実行する準備ができました。Claude Desktop のクエリボックスの下に、次のように、サーバー名がリストされたツールアイコンが表示されます。

Related MCP server: Local Development MCP Server
MCPクライアントとしてのLlamaIndex
LlamaIndex には MCP クライアント統合機能も備わっており、任意の MCP サーバーをエージェントが使用できるツールセットに変換できます。 mcp-client.pyでは、 BasicMCPClientを使用してローカル MCP サーバーに接続しています。
デモを簡素化するため、上記でセットアップしたMCPサーバーと同じサーバーを使用しています。通常、LlamaCloudをLlamaIndexエージェントに接続する際にMCPは使用せず、 QueryEngineToolを使用してエージェントに直接渡します。
MCPサーバーをセットアップする
HTTPクライアントが使用できるローカルMCPサーバーを提供するには、 mcp-server.py少し変更して、 runではなくrun_sse_asyncメソッドを使用する必要があります。このメソッドはmcp-http-server.pyにあります。
mcp = FastMCP('llama-index-server',port=8000)
asyncio.run(mcp.run_sse_async())MCPサーバーからツールを入手する
mcp_client = BasicMCPClient("http://localhost:8000/sse")
mcp_tool_spec = McpToolSpec(
client=mcp_client,
# Optional: Filter the tools by name
# allowed_tools=["tool1", "tool2"],
)
tools = mcp_tool_spec.to_tool_list()エージェントを作成して質問する
llm = OpenAI(model="gpt-4o-mini")
agent = FunctionAgent(
tools=tools,
llm=llm,
system_prompt="You are an agent that knows how to build agents in LlamaIndex.",
)
async def run_agent():
response = await agent.run("How do I instantiate an agent in LlamaIndex?")
print(response)
if __name__ == "__main__":
asyncio.run(run_agent())準備完了です。エージェントを使用して、LlamaCloud インデックスからの質問に回答できるようになりました。
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Hosted MCP server connecting claude.ai, ChatGPT and other AI apps to your own computer
MCP server unifying ERPs, CRMs, APIs and knowledge base for Claude, ChatGPT and Gemini.
Augments MCP Server - A comprehensive framework documentation provider for Claude Code
MCP server giving Claude AI access to 22+ NYC public-record databases for real estate due diligence
Related MCP Servers
- FlicenseDqualityDmaintenanceA server built on mcp-framework that enables integration with Claude Desktop through the Model Context Protocol.11
- AlicenseNot gradedqualityCmaintenanceA local MCP server for Claude Desktop with persistent task management, file operations, document generation, and PDF indexing.2251MIT
- FlicenseNot gradedqualityCmaintenanceMCP server enabling Claude Desktop to answer questions from local Word and PDF documents by searching a vector index built from their contents.
- AlicenseNot gradedqualityAmaintenanceAn MCP server that enables Claude Desktop to search and read local documents via full-text and fuzzy search, providing direct access to indexed files without chunking.MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/run-llama/llamacloud-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server