すべてのプロダクト
Search
ドキュメントセンター

Alibaba Cloud Model Studio:MCP

最終更新日:Feb 25, 2026

Model Context Protocol (MCP) は、大規模言語モデル (LLM) が外部のツールやデータを使用できるようにするプロトコルです。関数呼び出しと比較して、MCP はより柔軟で使いやすいです。このトピックでは、Responses API を使用して MCP に接続する方法について説明します。

使用方法

Responses API を使用して、tools パラメーターに MCP サーバーの情報を設定します。

ModelScope などのプラットフォームから、MCP サービスの Server-Sent Events (SSE) エンドポイントと認証情報を取得できます。
SSE プロトコルを使用する MCP サーバーのみがサポートされています。
最大 10 個の MCP サーバーを追加できます。
# 依存関係をインポートし、クライアントを作成します...
mcp_tool = {
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "my-mcp-service",
    "server_description": "モデルがユースケースを理解するのに役立つ MCP サーバーの機能の説明。",
    "server_url": "https://your-mcp-server-endpoint/sse",
    "headers": {
        "Authorization": "Bearer YOUR_TOKEN"
    }
}

response = client.responses.create(
    model="qwen3.5-plus",
    input="ご質問内容...",
    tools=[mcp_tool]
)

print(response.output_text)

サポート対象モデル

  • Qwen-Plus: qwen3.5-plusqwen3.5-plus-2026-02-15

  • Qwen-Flash: qwen3.5-flashqwen3.5-flash-2026-02-23

  • オープンソース Qwen: qwen3.5-397b-a17bqwen3.5-122b-a10bqwen3.5-27bqwen3.5-35b-a3b

Responses API を通じてのみ呼び出すことができます。

クイックスタート

この例では、ModelScope の Fetch Web スクレイピング MCP サービスを使用します。サービスの SSE エンドポイントと認証情報は、右側のサービス構成セクションから取得できます。

API キーを取得し、環境変数として設定する必要があります。

サンプルコード内の server_url を、MCP サービスプラットフォームから取得した SSE エンドポイントに置き換えてください。headers 内の認証情報を、そのプラットフォームから提供されたトークンに置き換えてください。
import os
from openai import OpenAI

client = OpenAI(
    # 環境変数を設定していない場合は、次の行を api_key="sk-xxx" に置き換えてください (非推奨)。
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
)

# MCP ツール構成
# server_url を ModelScope などのプラットフォームから取得した SSE エンドポイントに置き換えます
# 認証が必要な場合は、対応するプラットフォームのトークンをヘッダーに追加します
mcp_tool = {
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "fetch",
    "server_description": "Web スクレイピング機能を提供する Fetch MCP サーバー。指定された URL のコンテンツをスクレイピングし、テキストとして返すことができます。",
    "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse",
}

response = client.responses.create(
    model="qwen3.5-plus",
    input="https://news.aibase.com/zh/news、今日の AI ニュースは何ですか?",
    tools=[mcp_tool]
)

print("[Model Response]")
print(response.output_text)
print(f"\n[Token Usage] Input: {response.usage.input_tokens}, Output: {response.usage.output_tokens}, Total: {response.usage.total_tokens}")
import OpenAI from "openai";
import process from 'process';

const openai = new OpenAI({
    // 環境変数を設定していない場合は、次の行を apiKey: "sk-xxx" に置き換えます。
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});

async function main() {
    // MCP ツールの構成
    // server_url を ModelScope などのプラットフォームから取得した SSE エンドポイントに置き換えます。
    // 認証が必要な場合は、対応するプラットフォームのトークンをヘッダーに追加します。
    const mcpTool = {
        type: "mcp",
        server_protocol: "sse",
        server_label: "fetch",
        server_description: "Fetch MCP Server that provides web scraping capabilities. It can scrape the content of a specified URL and return it as text.",
        server_url: "https://mcp.api-inference.modelscope.net/xxx/sse",
    };

    const response = await openai.responses.create({
        model: "qwen3.5-plus",
        input: "https://news.aibase.com/zh/news, what is the AI news today?",
        tools: [mcpTool]
    });

    console.log("[Model Response]");
    console.log(response.output_text);
    console.log(`\n[Token Usage] Input: ${response.usage.input_tokens}, Output: ${response.usage.output_tokens}, Total: ${response.usage.total_tokens}`);
}

main();
# server_url を ModelScope などのプラットフォームから取得した SSE エンドポイントに置き換えます
# 認証が必要な場合は、対応するプラットフォームのトークンをヘッダーに追加します
curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.5-plus",
    "input": "https://news.aibase.com/zh/news、今日の AI ニュースは何ですか?",
    "tools": [
        {
            "type": "mcp",
            "server_protocol": "sse",
            "server_label": "fetch",
            "server_description": "Web スクレイピング機能を提供する Fetch MCP サーバー。指定された URL のコンテンツをスクレイピングし、テキストとして返すことができます。",
            "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse"
        }
    ]
}'

コードを実行すると、次の応答が返されます:

[モデルの応答]
北京から上海まで車で行くには、次のいずれかのルートを選択できます:

1. 推奨ルート (G2 北京-上海高速道路)
   - G2 北京-上海高速道路を南下し、河北省、天津市、山東省、江蘇省などの省や市を通過します。
   - 総距離は約 1,200 km で、推定所要時間は 13〜15 時間です。

2. 代替ルート (G3 北京-台北高速道路から G60 上海-昆明高速道路へ)
   - G3 北京-台北高速道路を南下します。安徽省に入った後、G60 上海-昆明高速道路に乗り換えて上海に向かいます。
   - 総距離は約 1,250 km で、推定所要時間は 14〜16 時間です。

...

[トークン使用量] 入力: 55, 出力: 195, 合計: 250

ストリーミング出力

MCP ツールの呼び出しには、外部サービスとの複数回のやり取りが含まれる場合があります。ストリーミング出力を有効にすると、ツールの呼び出しプロシージャと応答内容をリアルタイムで取得できます。

import os
from openai import OpenAI

client = OpenAI(
    # 環境変数を設定していない場合は、次の行を api_key="sk-xxx" に置き換えてください (非推奨)。
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
)

# server_url を ModelScope などのプラットフォームから取得した SSE エンドポイントに置き換えます
# 認証が必要な場合は、対応するプラットフォームのトークンをヘッダーに追加します
mcp_tool = {
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "fetch",
    "server_description": "Web スクレイピング機能を提供する Fetch MCP サーバー。指定された URL のコンテンツをスクレイピングし、テキストとして返すことができます。",
    "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse",
}

stream = client.responses.create(
    model="qwen3.5-plus",
    input="https://news.aibase.com/zh/news、今日の AI ニュースは何ですか?",
    tools=[mcp_tool],
    stream=True
)

for event in stream:
    # モデルの応答開始
    if event.type == "response.content_part.added":
        print("[Model Response]")
    # テキストのストリーミング出力
    elif event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)
    # 応答完了、使用量を出力
    elif event.type == "response.completed":
        usage = event.response.usage
        print(f"\n\n[Token Usage] Input: {usage.input_tokens}, Output: {usage.output_tokens}, Total: {usage.total_tokens}")
import OpenAI from "openai";
import process from 'process';

const openai = new OpenAI({
    // 環境変数を設定していない場合は、次の行を apiKey: "sk-xxx" に置き換えてください (非推奨)。
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});

async function main() {
    // server_url を ModelScope などのプラットフォームから取得した SSE エンドポイントに置き換えます
    // 認証が必要な場合は、対応するプラットフォームのトークンをヘッダーに追加します
    const mcpTool = {
        type: "mcp",
        server_protocol: "sse",
        server_label": "fetch",
        server_description": "Web スクレイピング機能を提供する Fetch MCP サーバー。指定された URL のコンテンツをスクレイピングし、テキストとして返すことができます。",
        server_url": "https://mcp.api-inference.modelscope.net/xxx/sse",
    };

    const stream = await openai.responses.create({
        model: "qwen3.5-plus",
        input: "https://news.aibase.com/zh/news、今日の AI ニュースは何ですか?",
        tools: [mcpTool],
        stream: true
    });

    for await (const event of stream) {
        // モデルの応答開始
        if (event.type === "response.content_part.added") {
            console.log("[Model Response]");
        }
        // テキストのストリーミング出力
        else if (event.type === "response.output_text.delta") {
            process.stdout.write(event.delta);
        }
        // 応答完了、使用量を出力
        else if (event.type === "response.completed") {
            const usage = event.response.usage;
            console.log(`\n\n[Token Usage] Input: ${usage.input_tokens}, Output: ${usage.output_tokens}, Total: ${usage.total_tokens}`);
        }
    }
}

main();
# server_url を、ModelScope などのプラットフォームから取得した SSE エンドポイントに置き換えます。
# 認証が必要な場合は、対応するプラットフォームのトークンをヘッダーに追加します。
curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.5-plus",
    "input": "https://news.aibase.com/zh/news, what is the AI news today?",
    "tools": [
        {
            "type": "mcp",
            "server_protocol": "sse",
            "server_label": "fetch",
            "server_description": "Web スクレイピング機能を提供するフェッチ MCP サーバーです。指定された URL のコンテンツをスクレイピングし、テキストとして返すことができます。",
            "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse"
        }
    ],
    "stream": true
}'

コードを実行すると、次の応答が返されます:

[モデルの応答]
北京から上海まで車で行くには、次のいずれかのルートを選択できます:

1. 推奨ルート (G2 北京-上海高速道路)
   - G2 北京-上海高速道路を南下し、河北省、天津市、山東省、江蘇省などの省や市を通過します。
   - 総距離は約 1,200 km で、推定所要時間は 13〜15 時間です。

...

[トークン使用量] 入力: 55, 出力: 195, 合計: 250

パラメーター

mcp ツールは、次のパラメーターをサポートしています:

パラメーター

必須

説明

type

はい

"mcp" に設定します。

server_protocol

はい

MCP サーバーとの通信プロトコル。現在、サポートされているのは "sse" のみです。

server_label

はい

MCP サーバーのラベル名。サービスを識別するために使用されます。

server_description

いいえ

MCP サーバーの機能の説明。これにより、モデルがサービスの機能とシナリオを理解しやすくなります。モデル呼び出しの精度を向上させるために、このパラメーターを入力することを推奨します。

server_url

はい

MCP サーバーのエンドポイント URL。

headers

いいえ

MCP サーバーに接続する際に含めるリクエストヘッダー。Authorization などの認証情報が含まれます。

例:

{
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "fetch",
    "server_description": "Web スクレイピング機能を提供する Fetch MCP サーバー。指定された URL のコンテンツをスクレイピングし、テキストとして返すことができます。",
    "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse"
}

課金

課金には、次の項目が含まれます:

  • モデル推論料金: これらの料金は、モデルのトークン使用量に基づいて課金されます。

  • MCP サーバー料金: これらの料金は、各 MCP サーバーの課金ルールに従います。