All Products
Search
Document Center

Alibaba Cloud Model Studio:MCP

Last Updated:Mar 21, 2026

Model Context Protocol (MCP) memungkinkan Large Language Model (LLM) berinteraksi dengan tool dan data eksternal. Dibandingkan Function Calling, MCP lebih fleksibel dan mudah digunakan. Topik ini menjelaskan cara menghubungkan ke MCP melalui Responses API.

Cara kerja

Untuk menggunakan Responses API, konfigurasikan informasi server MCP Anda dalam parameter tools.

Anda dapat memperoleh titik akhir Server-Sent Events (SSE) dan informasi autentikasi layanan MCP dari platform seperti ModelScope.
Catatan: Hanya server MCP yang menggunakan protokol SSE yang didukung.
Catatan: Anda dapat menambahkan maksimal 10 server MCP dalam satu permintaan.
# Impor dependensi dan buat client...
mcp_tool = {
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "my-mcp-service",
    "server_description": "Menjelaskan fitur server untuk membantu model menentukan kapan harus menggunakannya.",
    "server_url": "https://your-mcp-server-endpoint/sse",
    "headers": {
        "Authorization": "Bearer YOUR_TOKEN"
    }
}

response = client.responses.create(
    model="qwen3.5-plus",
    input="Your question...",
    tools=[mcp_tool]
)

print(response.output_text)

Model yang didukung

Singapore

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

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

  • Qwen Open-Source: qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, dan qwen3.5-35b-a3b

Global

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

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

  • Qwen Open-Source: qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, dan qwen3.5-35b-a3b

China (Beijing)

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

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

  • Qwen Open-Source: qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, dan qwen3.5-35b-a3b

European Union

Qwen Flash: qwen3.5-flash dan qwen3.5-flash-2026-02-23

Anda hanya dapat memanggil model-model ini melalui Responses API.

Memulai

Contoh ini menunjukkan cara menghubungkan ke layanan MCP Fetch web scraping dari ModelScope. Dari bagian Service configuration di sebelah kanan, ambil titik akhir SSE dan informasi autentikasi layanan tersebut.

Sebelum memulai, pastikan Anda memiliki Kunci API dan telah mengonfigurasinya sebagai Variabel lingkungan.

Pada kode contoh, ganti server_url dengan titik akhir SSE dan headers dengan informasi autentikasi dari penyedia layanan MCP Anda.
import os
from openai import OpenAI

client = OpenAI(
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan api_key="sk-xxx" (tidak disarankan).
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
)

# Konfigurasi tool MCP
# Ganti server_url dengan titik akhir SSE yang Anda peroleh dari platform seperti ModelScope.
# Jika diperlukan autentikasi, tambahkan token dari platform terkait ke headers.
mcp_tool = {
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "fetch",
    "server_description": "Fetch MCP Server, which provides web scraping capabilities to fetch the content of a specified URL and return it as text.",
    "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse",
}

response = client.responses.create(
    model="qwen3.5-plus",
    input="https://news.aibase.com/en/news, what is the AI news today?",
    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({
    // Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan apiKey: "sk-xxx" (tidak disarankan).
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});

async function main() {
    // Konfigurasi tool MCP
    // Ganti server_url dengan titik akhir SSE yang Anda peroleh dari platform seperti ModelScope.
    // Jika diperlukan autentikasi, tambahkan token dari platform terkait ke headers.
    const mcpTool = {
        type: "mcp",
        server_protocol": "sse",
        server_label: "fetch",
        server_description: "Fetch MCP Server, which provides web scraping capabilities to fetch 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/en/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();
# Ganti server_url dengan titik akhir SSE yang Anda peroleh dari platform seperti ModelScope.
# Jika diperlukan autentikasi, tambahkan token dari platform terkait ke headers.
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/en/news, what is the AI news today?",
    "tools": [
        {
            "type": "mcp",
            "server_protocol": "sse",
            "server_label": "fetch",
            "server_description": "Fetch MCP Server, which provides web scraping capabilities to fetch the content of a specified URL and return it as text.",
            "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse"
        }
    ]
}'

Menjalankan kode di atas menghasilkan respons yang mirip dengan berikut:

[Model Response]
To drive from Beijing to Shanghai, you can choose from the following routes:

1. Recommended Route (G2 Beijing-Shanghai Expressway)
   - Drive south along the G2 Beijing-Shanghai Expressway, passing through provinces and cities such as Hebei, Tianjin, Shandong, and Jiangsu.
   - Total distance: approximately 1,200 km. Estimated driving time: 13–15 hours.

2. Alternative Route (G3 Beijing-Taipei Expressway to G60 Shanghai-Kunming Expressway)
   - Drive south on the G3 Beijing-Taipei Expressway. After you enter Anhui, switch to the G60 Shanghai-Kunming Expressway to reach Shanghai.
   - Total distance: approximately 1,250 km. Estimated driving time: 14–16 hours.

...

[Token Usage] Input: 55, Output: 195, Total: 250

Keluaran streaming

Pemanggilan tool MCP mungkin melibatkan beberapa interaksi dengan layanan eksternal. Untuk menerima pembaruan real-time mengenai progres dan respons tool, aktifkan keluaran streaming.

import os
from openai import OpenAI

client = OpenAI(
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan api_key="sk-xxx" (tidak disarankan).
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
)

# Ganti server_url dengan titik akhir SSE yang Anda peroleh dari platform seperti ModelScope.
# Jika diperlukan autentikasi, tambahkan token dari platform terkait ke headers.
mcp_tool = {
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "fetch",
    "server_description": "Fetch MCP Server, which provides web scraping capabilities to fetch the content of a specified URL and return it as text.",
    "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse",
}

stream = client.responses.create(
    model="qwen3.5-plus",
    input="https://news.aibase.com/en/news, what is the AI news today?",
    tools=[mcp_tool],
    stream=True
)

for event in stream:
    # Respons model dimulai.
    if event.type == "response.content_part.added":
        print("[Model Response]")
    # Keluaran teks streaming.
    elif event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)
    # Respons selesai. Penggunaan token dicetak.
    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({
    // Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan apiKey: "sk-xxx" (tidak disarankan).
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});

async function main() {
    // Ganti server_url dengan titik akhir SSE yang Anda peroleh dari platform seperti ModelScope.
    // Jika diperlukan autentikasi, tambahkan token dari platform terkait ke headers.
    const mcpTool = {
        type: "mcp",
        server_protocol": "sse",
        server_label: "fetch",
        server_description: "Fetch MCP Server, which provides web scraping capabilities to fetch the content of a specified URL and return it as text.",
        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/en/news, what is the AI news today?",
        tools: [mcpTool],
        stream: true
    });

    for await (const event of stream) {
        // Respons model dimulai.
        if (event.type === "response.content_part.added") {
            console.log("[Model Response]");
        }
        // Keluaran teks streaming.
        else if (event.type === "response.output_text.delta") {
            process.stdout.write(event.delta);
        }
        // Respons selesai. Penggunaan token dicetak.
        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();
# Ganti server_url dengan titik akhir SSE yang Anda peroleh dari platform seperti ModelScope.
# Jika diperlukan autentikasi, tambahkan token dari platform terkait ke headers.
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/en/news, what is the AI news today?",
    "tools": [
        {
            "type": "mcp",
            "server_protocol": "sse",
            "server_label": "fetch",
            "server_description": "Fetch MCP Server, which provides web scraping capabilities to fetch the content of a specified URL and return it as text.",
            "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse"
        }
    ],
    "stream": true
}'

Menjalankan kode di atas menghasilkan respons yang mirip dengan berikut:

[Model Response]
To drive from Beijing to Shanghai, you can choose from the following routes:

1. Recommended Route (G2 Beijing-Shanghai Expressway)
   - Drive south along the G2 Beijing-Shanghai Expressway, passing through provinces and cities such as Hebei, Tianjin, Shandong, and Jiangsu.
   - Total distance: approximately 1,200 km. Estimated driving time: 13–15 hours.

...

[Token Usage] Input: 55, Output: 195, Total: 250

Parameter

Tool mcp mendukung parameter berikut:

Parameter

Wajib

Deskripsi

type

Ya

Harus diatur ke "mcp".

server_protocol

Ya

Protokol komunikasi untuk layanan MCP. Saat ini, hanya "sse" yang didukung.

server_label

Ya

Nama label yang mengidentifikasi layanan MCP.

server_description

Tidak

Deskripsi fitur server untuk membantu model menentukan kapan harus menggunakan layanan tersebut. Menyediakan deskripsi ini direkomendasikan untuk meningkatkan akurasi pemanggilan.

server_url

Ya

URL titik akhir layanan MCP.

headers

Tidak

Header permintaan yang dikirim ke layanan MCP, seperti Authorization untuk autentikasi.

Contoh:

{
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "fetch",
    "server_description": "Fetch MCP Server, which provides web scraping capabilities to fetch the content of a specified URL and return it as text.",
    "server_url": "https://mcp.api-inference.modelscope.net/xxx/sse"
}

Penagihan

Biaya mencakup komponen berikut:

  • Biaya inferensi model: Ditagih berdasarkan Penggunaan Token model.

  • Biaya server MCP: Ditagih sesuai aturan penagihan masing-masing server MCP.