Skip to main content
Glama

LlamaCloud MCP Server

by run-llama

LlamaIndex MCP デモ

このリポジトリでは、LlamaCloud を使用して MCP サーバーを作成する方法と、LlamaIndex を MCP クライアントとして使用する方法の両方を示します。

LlamaCloudをMCPサーバーとして

Claude Desktopのようなクライアントが利用できるローカルMCPサーバーを提供するには、 mcp-server.pyを使用します。これを使用することで、RAGを使用してClaudeに最新の個人情報を提供し、質問に答えるためのツールを提供できます。これらのツールは必要な数だけ提供できます。

LlamaCloudインデックスを設定する

  1. LlamaCloudアカウントを取得する
  2. 任意のデータソースで新しいインデックスを作成してください。今回のケースではGoogleドライブを使用し、LlamaIndexドキュメントのサブセットをソースとして提供しました。テスト目的であれば、ドキュメントを直接インデックスにアップロードすることもできます。
  3. LlamaCloud UIからAPIキーを取得する

MCPサーバーをセットアップする

  1. このリポジトリをクローンする
  2. .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デスクトップの設定

  1. Claude Desktopをインストールする
  2. メニューバーでClaude 」→ SettingsDeveloper 」→ Edit Configを選択します。すると、お好みのテキストエディタで編集できる設定ファイルが表示されます。
  3. 設定は次のようになります ( $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 のクエリボックスの下に、次のように、サーバー名がリストされたツールアイコンが表示されます。

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 インデックスからの質問に回答できるようになりました。

-
security - not tested
A
license - permissive license
-
quality - not tested

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Claude Desktop と統合されたローカル MCP サーバー。RAG 機能により、カスタム LlamaCloud インデックスから最新のプライベート情報を Claude に提供できるようになります。

  1. LlamaCloudをMCPサーバーとして
    1. LlamaCloudインデックスを設定する
    2. MCPサーバーをセットアップする
    3. Claudeデスクトップの設定
  2. MCPクライアントとしてのLlamaIndex
    1. MCPサーバーをセットアップする
    2. MCPサーバーからツールを入手する
    3. エージェントを作成して質問する

Related MCP Servers

  • A
    security
    A
    license
    A
    quality
    A MCP server connecting to a managed index on LlamaCloud. This is a TypeScript-based MCP server that implements a connection to a managed index on LlamaCloud.
    Last updated -
    1
    4
    74
    JavaScript
    MIT License
    • Apple
  • -
    security
    A
    license
    -
    quality
    An MCP server that allows accessing and managing ledger files through Claude by providing account listing, balance checking, and transaction register viewing capabilities.
    Last updated -
    1
    Python
    GPL 3.0
    • Apple
  • -
    security
    A
    license
    -
    quality
    A local MCP server that enables AI applications like Claude Desktop to securely access and work with Obsidian vaults, providing capabilities for reading notes, executing templates, and performing semantic searches.
    Last updated -
    60
    TypeScript
    MIT License
    • Apple
    • Linux
  • -
    security
    F
    license
    -
    quality
    An MCP server for Claude Desktop that allows users to query data from selected Google Cloud datasets by configuring project ID and datasets in the Claude Desktop configuration.
    Last updated -
    Python
    • Apple

View all related MCP servers

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