2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

超シンプルなMCPサーバーを実装してwatsonx Orchestrateから連携してみる

2
Last updated at Posted at 2025-06-24

PythonベースのMCP

MCP(Model Context Protocol)は、実質AgentとTool間のデファクトと言ってよいプロトコルです。これまで、watsonx OrchestrateではnodeベースのMCPサーバーのみサポートしていたのですが、ADKがバージョンアップされ、pythonベースのMCPサーバーがサポートされました。この記事ではシンプルなpythonベースのMCPサーバーを実装し、watsonx Orchestrateに登録するまでの流れを説明します。

MCPサーバーの実装

MCPサーバーの実装にはFastMCPを使ってみます。
https://github.com/jlowin/fastmcp

FastMCPのサイトにサンプルが掲載されているのでそれをそのまま使ってみたいと思います。以下のファイルを作成します。

server.py
# server.py
from fastmcp import FastMCP

mcp = FastMCP("Demo 🚀")

@mcp.tool
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b

if __name__ == "__main__":
    mcp.run()

MCPサーバーのインポート

ADKのマニュアルではパッケージを用いた方法が記載されているのですが、以下のシンプルな構成でインポートをすることができました。

/作業ディレクトリ
├addmcp/
 ├server.py

ポイントは、フォルダを作ることで、以上の構成の場合、作業ディレクトリから以下のコマンドを発行することでインポートできました。

orchestrate toolkits import -k mcp -n add --description "sample mcp" --package-root ./addmcp/ --command "python server.py"

image.png

なお、ファイルのあるディレクトリ(/addmcp)からコマンドを実行した場合、以下のエラーがでました。

raise ClientAPIException(request=e.request, response=e.response)
ibm_watsonx_orchestrate.client.base_api_client.ClientAPIException: ClientAPIException(status_code=500, message={"detail":"Tool deployment failed in TRM:{\"error\":\"failed to download tool zip: no zip file found in \\\"toolkits/ecbd3a19-8d05-4bcb-9680-9bcd942488fb/391a58d6-d784-4310-bc3b-c5a7a5f83cde/\\\"\"} "})

Toolの実行

AgentBuilderからAgentを作成し、Toolを追加します。
先ほどインポートしたToolがadd:addとして表示されているので、チェックします。
Agentが使用するToolを判断するために、Toolの説明文を利用するため、本来は正しく設定しておく必要があります。

image.png

チャットから聞いてみると正しくToolが呼び出されました!利用可能なToolがこのToolのみなのと、Toolの名前から使用するToolを正しく判断できたものと思われます。

image.png

まとめ

この記事ではwatsonx Orchestrateで新しくサポートされた、PythonベースのMCPサーバーの実装方法とインポートの方法について説明しました。今後は様々なMCPサーバーの実装が公開され、より、容易にシステム間の連携が出来るようになると思われます。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?