LangChain / Python を使用した MCP クライアント
このシンプルなモデル コンテキスト プロトコル (MCP)クライアントは、LangChain ReAct Agent による MCP サーバー ツールの使用方法を示します。
これは、 langchain_mcp_toolsのユーティリティ関数convert_mcp_to_langchain_tools()を活用します。
この関数は、指定された複数の MCP サーバーの並列初期化を処理し、使用可能なツールを LangChain 互換ツールのリスト ( List[BaseTool] ) に変換します。
現在、Anthropic、OpenAI、Groq の LLM がサポートされています。
このMCPクライアントのTypescriptバージョンはここから入手できます。
前提条件
Python 3.11以上
[オプション] PythonパッケージベースのMCPサーバーを実行するために
uvがインストールされている[オプション] Node.js パッケージベースの MCP サーバーを実行するためのnpm 7+ (
設定
依存関係をインストールします:
make installAPI キーの設定:
cp .env.template .env必要に応じて
.envを更新します。.gitignoreは、資格情報の誤ったコミットを防ぐために.env無視するように設定されています。
必要に応じて、LLM および MCP サーバーの設定
llm_mcp_config.json5を構成します。MCP サーバーの構成ファイル形式は、 Claude for Desktopと同じ構造に従いますが、1 つの違いがあります。キー名
mcpServersは、JSON 構成ファイルで一般的に使用される snake_case 規則に従うためにmcp_serversに変更されています。ファイル形式はJSON5で、コメントと末尾のコンマが許可されます。
形式はさらに拡張され、
${...}表記が対応する環境変数の値に置き換えられます。すべての資格情報と個人情報を
.envファイルに保存し、必要に応じて${...}表記で参照します。
使用法
アプリを実行します:
初回実行時には多少時間がかかります。
詳細モードで実行:
コマンドラインオプションを参照してください:
プロンプトで Enter キーを押すだけで、MCP サーバー ツールの呼び出しを実行するサンプル クエリを使用できます。
クエリの例はllm_mcp_config.json5で設定できます。
This server cannot be installed
このサーバーは、Anthropic、OpenAI、Groq などのプロバイダーからの AI モデルの呼び出しを容易にし、ユーザーが大規模な言語モデルのインタラクションをシームレスに管理および構成できるようにします。
Related Resources
Related MCP Servers
- -security-license-qualityThis server provides an API to query Large Language Models using context from local files, supporting various models and file types for context-aware responses.Last updated -1
- -security-license-qualityA server that enables Large Language Models to discover and interact with REST APIs defined by OpenAPI specifications through the Model Context Protocol.Last updated -705178MIT License
- -security-license-qualityA server that provides rich UI context and interaction capabilities to AI models, enabling deep understanding of user interfaces through visual analysis and precise interaction via Model Context Protocol.Last updated -60
- -security-license-qualityA server that allows AI agents to consult multiple large language models (like Grok, Gemini, Claude, GPT-4o) through Model Context Protocol for assistance and information.Last updated -4