Skip to content

MCPサーバーを使用してツールを統合する

モデルコンテキストプロトコル(MCP)は、AIエージェントが外部のシステム、ツール、データソースとやりとりするための標準化されたインターフェイスを提供します。 MCPサーバーを使用してエージェントにツールを提供すると、ツールを直接デプロイする場合に比べていくつかの利点があります。

  • ツールの一元管理:すべてのツールが1つのMCPサーバーデプロイで管理されます
  • 標準化されたインターフェイス:ツールはMCPプロトコル標準に準拠しているため、さまざまなエージェントフレームワーク間で互換性があります
  • 動的なツール登録:ツールは、エージェントを再デプロイせずに追加または変更できます
  • 関心の分離を強化:ツールはエージェントとは別にデプロイされるため、個別のスケーリングと更新が可能です。

このガイドでは、DataRobot Agentic Starterのテンプレートで実装されている、MCPサーバーを使用してエージェントワークフローにツールを統合する方法について説明します。 MCP endpoints can come from the Agentic Starter app, a standalone server built with the DataRobot MCP template, or the DataRobot Global MCP; this page focuses on connecting your agent application to the MCP URL your deployment uses.

MCPベースの統合とローカルツールを使用した統合

このドキュメントでは、MCPサーバーベースのツール統合について説明します。 ローカルツール(直接のツールデプロイ)を使用したツール統合の詳細については、エージェントにツールを追加するを参照してください。 To connect MCP clients in Cursor, Claude Desktop, or VS Code—including the DataRobot Global MCP and deployment URLs—see Connect agentic coding environments to MCP servers.

概要

モデルコンテキストプロトコル(MCP)は、エージェントがツールにアクセスする方法を根本的に変えます。 エージェントのコード内でツールロジックを直接定義する代わりに、スタンドアロンの「ツールサーバー」をデプロイします。次に、エージェントはクライアントとしてこのサーバーに接続し、利用可能なツールを要求して、標準化されたプロトコルを介してそれらを実行します。

The DataRobot Agentic Starter template connects MCP tools at runtime: LangGraph workflows receive MCP (and optional workflow) tools as the tools argument to graph_factory, using mcp_tools_context in custompy_adaptor (DRUM) and in register.py (DRAgent). You do not import the MCP server into agent code. エージェントワークフローでのMCPツールの使用方法に関する詳細については、以下のセクションを参照してください。

MCPアーキテクチャ

  • エージェント(クライアント):タスクを計画する推論エンジン(例:LangGraphアプリケーション)。 これにはツールのコードは含まれておらず、利用可能なツールをMCPサーバーに問い合わせる方法のみを認識しています。
  • MCPサーバー:ツール、リソース、およびプロンプトのロジックをホストするWebサービス。 タスクの実際の実行(例:データベースへのクエリー、外部APIの呼び出し)を処理します。
  • プロトコル:基盤となるインフラストラクチャに関係なく、エージェントとMCPサーバーがセキュアに通信できるようにする標準インターフェイス。

統合ワークフロー

To integrate tools using this architecture, follow this high-level process:

  • Deploy or select an MCP endpoint: Create and deploy an MCP server containing your tool logic (using the DataRobot MCP template), use the MCP server bundled with the DataRobot Agentic Starter template, or connect through the DataRobot Global MCP when your environment uses that service.
  • Connect the agent: Configure your agent application to point to the MCP server's URL (for example, a deployment directAccess URL, a gateway URL, or a local dev URL).
  • 実行:エージェントは実行時にツールを自動的に検出します。 新しいツールを追加するためにエージェントを再デプロイする必要はありません。MCPサーバーを更新するだけです。

前提条件

MCPツールを統合する前に、以下が揃っていることを確認してください。

For deploying a standalone MCP server, refer to the MCP template documentation. For URL patterns (local ports, deployment directAccess, gateway), see Connect agentic coding environments to MCP servers.

MCPサーバーのデプロイ

MCPサーバーは、開発用としてローカルにデプロイすることも、本番用としてDataRobotにデプロイすることも可能です。

ローカルデプロイ

ローカル開発の場合は、開発コマンドを使用してMCPサーバーを起動します。

cd mcp_server
dr task run mcp_server:dev 

MCPサーバーは設定されたポート(デフォルト:9000)で起動し、http://localhost:9000/mcp/でアクセス可能になります。

本番デプロイ

MCPサーバーをDataRobotにデプロイするには:

  1. Configure deployment settings: Update your Pulumi configuration or deployment settings.
  2. Deploy the server: Use the deployment command:

    dr run deploy 
    

    You can also use dr task run deploy, which is equivalent. For more on these commands, see the CLI task and run commands.

  3. Get the deployment endpoint: After deployment, note the deployment ID and construct the MCP endpoint URL:

    https://{DATAROBOT_URL}/api/v2/deployments/{DEPLOYMENT_ID}/directAccess/mcp 
    

    Some environments use the DataRobot Global MCP instead of a per-deployment directAccess URL:

    https://{DATAROBOT_URL}/api/v2/genai/globalmcp/mcp 
    

    See Using the DataRobot Global MCP for how Global MCP URLs fit alongside deployment endpoints.

  4. Configure the agent: Update your agent's configuration to use the production MCP endpoint (whichever URL your deployment provides).

For detailed deployment instructions, refer to the MCP template README.

MCPサーバー接続の設定

エージェントをMCPサーバーに接続するには、エージェントの環境変数または設定でMCPサーバーのエンドポイントと認証を設定する必要があります。

ローカル開発

ローカル開発の場合は、.envファイルでMCPサーバー接続を設定します。

.env
# MCP Server Configuration
MCP_SERVER_PORT=9000 

MCPサーバーは、デフォルトで次の2つのポートのいずれかを使用します。

エージェントを設定するときは、必ず正しいポートを使用してください。

本番環境の設定

本番環境にデプロイする場合は、環境変数を使用してMCPサーバーを設定します。 このプロセスはテンプレートによって自動的に処理されます。

MCPサーバー認証

MCPサーバーで認証が必要な場合は、環境にDATAROBOT_API_TOKENが設定されていることを確認してください。MCPクライアントは、認証されたリクエストにこれを自動的に使用します。 HTTP MCP endpoints often expect both Authorization: Bearer and x-datarobot-api-token headers; the client typically supplies these from your DataRobot API credentials. For the same headers in Cursor, Claude Desktop, and VS Code, see Connect agentic coding environments to MCP servers.

エージェントでのMCPツールの使用

In the current DataRobot Agentic Starter template (LangGraph), MCP tools are passed into your graph_factory(llm, tools, verbose) as the tools list. The template merges MCP discovery with any workflow tools before calling MyAgent.

LangGraphエージェント

For LangGraph agents, pass the tools argument through to each create_agent node:

agent/agent/myagent.py (excerpt)
from datarobot_genai.core.agents import make_system_prompt
from langchain.agents import create_agent

def graph_factory(llm, tools, verbose=False):
    planner = create_agent(
        llm,
        tools=tools,
        system_prompt=make_system_prompt(
            "You are a content planner. Use available tools to gather information and plan content."
        ),
        name="planner_agent",
        debug=verbose,
    )
    ... 

At runtime, tools includes MCP tools resolved via mcp_tools_context (see the template's custompy_adaptor and register.py). That flow:

  • 設定済みのMCPサーバーに接続する
  • 利用可能なツールを検出する
  • Exposes LangChain-compatible tools to the graph
  • Applies authentication headers and authorization context when required

MCPツールとローカルツールの組み合わせ

Add local tools inside graph_factory by extending the list (MCP tools are already in tools):

agent/agent/myagent.py (excerpt)
from langchain_core.tools import Tool

class DateTimeTool(Tool):
    """Local datetime tool."""
    name = "datetime_tool"
    description = "Returns the current date and time."

    def run(self, query: str = "") -> str:
        from datetime import datetime
        return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

def graph_factory(llm, tools, verbose=False):
    local_tools = [DateTimeTool()]
    all_tools = list(tools) + local_tools
    planner = create_agent(
        llm,
        tools=all_tools,
        system_prompt=make_system_prompt("You are a content planner..."),
        name="planner_agent",
        debug=verbose,
    )
    ... 

カスタムMCPツールの作成

To add custom tools to your MCP server, use the DataRobot MCP template. このテンプレートは、ツール、リソース、およびプロンプトを作成するための構造化されたアプローチを提供します。

ツールの構造

カスタムMCPツールは、@dr_mcp_toolデコレーターを使用して定義されます。

dr_mcp/app/recipe/tools/my_custom_tool.py
from app.base.core.mcp_instance import dr_mcp_tool
from app.base.core.common import get_sdk_client

@dr_mcp_tool(tags={"custom", "recipe", "your-domain"})
async def my_custom_tool(input_param: str, optional_param: int = 10) -> str:
    """
    Brief description of what your tool does.

    This description helps LLMs understand when and how to use your tool.
    Be specific about the tool's purpose and behavior.

    Args:
        input_param: Description of the required parameter
        optional_param: Description of the optional parameter

    Returns:
        Description of what the tool returns
    """
    # Use the DataRobot SDK client for API operations
    client = get_sdk_client()

    # Your custom logic here
    result = f"Processed {input_param} with {optional_param}"

    return result 

MCPテンプレートリポジトリ

The path and imports above refer to the DataRobot MCP template repository structure.

ツールのベストプラクティス

MCPツールを作成するときは、以下のベストプラクティスに従ってください。

  • 明確な説明:詳細なdocstringを提供します。LLMはこれを使用してツールの機能を理解します
  • 型ヒント:常にパラメーターと戻り値に型ヒントを使用します
  • エラーハンドリング:適切なエラーハンドリングを実装し、意味のあるエラーメッセージを返します
  • 非同期関数:パフォーマンスを向上させるために、ツールは非同期関数にする必要があります
  • タグ:わかりやすいタグを使用してツールを分類します(ツールのフィルターに役立ちます)
  • SDKクライアント:DataRobot APIへのアクセスにはget_sdk_client()を使用します

For more information on creating custom MCP tools, see the MCP template custom tools documentation.

比較:MCPとToolClient

特徴量 MCPサーバー ToolClient(直接デプロイ)
ツールの管理 1つのサーバーで一元化 各ツールを個別にデプロイ
プロトコル MCP標準プロトコル DataRobotカスタムプロトコル
ツール検出 MCPによる自動検出 ツールごとの手動設定
動的な更新 エージェントを再デプロイせずにツールを追加または変更可能 新しいツールのためにエージェントの再デプロイが必要
フレームワークの互換性 あらゆるMCP互換フレームワークで動作 DataRobot固有
デプロイの複雑さ 単一のMCPサーバーのデプロイ 複数のツールのデプロイ
スケーリング MCPサーバーを個別にスケール 各ツールを個別にスケール

以下の場合には、MCPサーバー統合を選択してください。

  • ツール管理を一元化したい場合
  • 動的なツール登録が必要な場合
  • ツールを共有する複数のエージェントを使用している場合
  • 標準プロトコルへの準拠を求めている場合

以下の場合には、ToolClient統合を選択してください。

  • 個々のツールデプロイに対してきめ細かな制御が必要な場合
  • ツールごとにスケーリング要件が大きく異なる場合
  • DataRobot固有のツール管理機能を使用したい場合

トラブルシューティング

エージェントがMCPサーバーに接続できない

症状:エージェントのエラーに、MCP接続の失敗またはツールが利用不可であることが示される。

解決方法

  1. Verify MCP server is running:

    # For local development
    curl -i http://localhost:9000/mcp
    
    # For production (deployment MCP endpoint)
    curl -i https://{DATAROBOT_URL}/api/v2/deployments/{DEPLOYMENT_ID}/directAccess/mcp
    
    # If your environment uses the DataRobot Global MCP
    curl -i https://{DATAROBOT_URL}/api/v2/genai/globalmcp/mcp 
    
  2. Check environment variables:

    • Verify MCP_SERVER_PORT matches the server configuration (for local development).
    • Check that DATAROBOT_API_TOKEN is set (for authenticated connections).
  3. Verify network connectivity:

    • Ensure the agent can reach the MCP server endpoint.
    • Check firewall settings if deploying across networks.
    • Verify SSL certificates for HTTPS endpoints.

ツールが表示されない

Symptoms: MCP server is connected, but the agent cannot use tools.

解決方法

  1. Check tool registration: Verify that tools are properly registered in the MCP server.
  2. Review tool metadata: Ensure tool descriptions and schemas are correctly defined.
  3. Check server logs: Review MCP server logs for tool registration errors.
  4. Verify agent configuration: Confirm that the mcp_tools property is being used correctly.

認証に関する問題

症状:MCPサーバーのリクエストが認証エラーで失敗する。

解決方法

  1. Verify API token: Ensure DATAROBOT_API_TOKEN is set and valid.
  2. Check token permissions: Verify the token has necessary permissions for MCP server access.
  3. Review server configuration: Check that the MCP server is configured to accept the authentication method used.

その他のリソース