Skip to main content
MCP

External Invocation

Alibaba Cloud Bailian provides end-to-end MCP (Model Context Protocol) services — supporting both in-platform configuration (e.g., agents, workflows) and external invocation for integration into third-party applications or personal projects.

  • Integration into third-party applications: One-click automatic configuration enables rapid external invocation.
  • Integration into personal projects: Use the MCP SDK for flexible coding and deep customization.

Enable MCP Services

Bailian’s MCP service has been upgraded from the legacy SSE protocol to the new Streamable HTTP protocol. Please follow the appropriate steps below based on your situation.
1. Go to the Alibaba Cloud Bailian MCP Plaza and select an MCP service. For example, click the Amap Maps service card.
2. Click **Enable Now**, then confirm by clicking **Confirm Enablement** to activate the Amap Maps MCP service.

> Alibaba Cloud Bailian has deployed the Amap Maps MCP service in the cloud. No AMAP_MAPS_API_KEY is required for trial usage.
> For commercial customization, you may optionally provide your own AMAP_MAPS_API_KEY.

If sensitive inputs are involved, encrypt them using KMS credentials.

Externally Invoking MCP Services

Integration into Third-Party Applications

Alibaba Cloud Bailian supports configuring MCP services into Cherry Studio and Cursor, with both automatic and manual configuration options. The following uses Amap Maps as an example.
1. Install Cherry Studio (https://www.cherry-ai.com/).

2. Navigate to the Amap Maps MCP service page and select **Cherry Studio** under the **External Invocation** tab.
   Two configuration methods appear: Method 1 (automatic) — click the **Configure to Cherry Studio with One Click** button; Method 2 (manual) — retrieve your DASHSCOPE_API_KEY and replace the corresponding variable in your configuration file.

3. Click **Configure to Cherry Studio with One Click**, select an API Key, and click **OK**.
   A dialog appears prompting you to choose an API Key and configure it in Cherry Studio. Select the desired API Key from the list and click OK. In the newly opened Cherry Studio interface, you’ll see detailed information about the configured MCP service: name `AliyunBailianMCP_amap-maps`, type `server-sent events (sse)`, URL (the MCP service endpoint), and status toggled ON.

4. Alternatively, manually configure the MCP service: copy your `DASHSCOPE_API_KEY` from the **External Invocation** tab and paste it into your configuration file. In Cherry Studio’s MCP Settings page, click **Add Server > Import from JSON**, paste the configuration, and click OK.

5. Use the MCP service in Cherry Studio: create a new chat topic and select `AliyunBailianMCP_amap-maps` from the dropdown below.

6. Enter the following prompt in the chat window:  
   “I’m departing now from Hangzhou Xiaoshan International Airport to West Lake Scenic Area in Hangzhou. Please provide three public transportation route options.”  
   You’ll observe that the large language model successfully invokes the MCP tool to plan routes.
If the model fails to invoke MCP tools, refer to the troubleshooting section below.

Development Integration via SDK

Invoke Alibaba Cloud Bailian MCP services programmatically using the MCP SDK for maximum flexibility. The example below demonstrates invoking Bailian’s WebSearch MCP service using both the OpenAI SDK and the MCP SDK to perform web searches.
1

Install dependencies

pip install openai mcp
2

Configure Bailian API Key as environment variable

Refer to the Configure Bailian API Key documentation to complete setup.
3

Write code

# -*- coding: utf-8 -*-
# Using OpenAI SDK + MCP SDK to invoke Bailian WebSearch MCP service
import os
import asyncio
import json
from openai import OpenAI
from mcp.client.streamable_http import streamablehttp_client
from mcp import ClientSession

async def main():
    api_key = os.getenv("DASHSCOPE_API_KEY")
    if not api_key:
        print("Error: Please set the DASHSCOPE_API_KEY environment variable")
        return
    mcp_url = "https://dashscope.aliyuncs.com/api/v1/mcps/WebSearch/mcp"
    headers = {"Authorization": f"Bearer {api_key}"}
    # 1. Connect to MCP Server and fetch available tools list
    async with streamablehttp_client(mcp_url, headers=headers) as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()
            tools_result = await session.list_tools()
            # Convert to OpenAI function-calling format
            openai_tools = []
            for tool in tools_result.tools:
                openai_tools.append({
                    "type": "function",
                    "function": {
                        "name": tool.name,
                        "description": tool.description or "",
                        "parameters": tool.inputSchema or {"type": "object", "properties": {}},
                    },
                })
            # 2. Call DashScope (OpenAI-compatible endpoint)
            client = OpenAI(
                api_key=api_key,
                base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
            )
            messages = [{"role": "user", "content": "Search for the latest developments regarding Alibaba Cloud Bailian MCP"}]
            print("Performing web search...")
            print("=" * 50)
            # 3. Multi-turn tool-calling loop
            while True:
                response = client.chat.completions.create(
                    model="qwen-max",
                    messages=messages,
                    tools=openai_tools or None,
                )
                choice = response.choices[0]
                msg = choice.message
                if not msg.tool_calls:
                    print(msg.content)
                    break
                messages.append(msg)
                for tc in msg.tool_calls:
                    args = json.loads(tc.function.arguments)
                    result = await session.call_tool(tc.function.name, args)
                    tool_content = ""
                    for block in result.content:
                        if hasattr(block, "text"):
                            tool_content += block.text
                    messages.append({
                        "role": "tool",
                        "tool_call_id": tc.id,
                        "content": tool_content,
                    })

if __name__ == "__main__":
    asyncio.run(main())
4

Run the code

Running the script yields the following output:
Performing web search...
==================================================
Alibaba Cloud Bailian MCP (Model Context Protocol) is a newly launched service enabling unified access and management of MCP services on the Bailian platform. Recent updates include:
1. One-click enablement of multiple MCP services (e.g., Amap Maps, WebSearch) via the MCP Plaza.
2. Adoption of the Streamable HTTP protocol, enabling standard HTTP-based external invocations.
3. Native integrations with mainstream tools such as Cherry Studio and Cursor, supporting automatic configuration.
4. Flexible SDK-based integration for developers building custom applications.

Frequently Asked Questions (FAQ)

What should I do if I cannot connect to the MCP service?

  1. MCP service not enabled or not upgraded: Confirm that you have enabled or upgraded the MCP service in the Bailian MCP Plaza.
  2. Invalid API Key: Ensure you’re using a valid, active Bailian universal API Key.
  3. Quota exhausted: Some MCP services (e.g., WebSearch) enforce monthly usage quotas. Once exceeded, invocation automatically stops.
For other errors and common issues, see the MCP FAQ.

The model responds normally and no MCP errors occur, yet MCP tools still fail to invoke — why?

Large language models require explicit instructions to correctly invoke MCP tools. Be sure to clearly specify the tool name and its capabilities in your prompt. Example:
“Use the Alibaba Cloud Bailian Amap Maps MCP service to plan a self-driving route from Hangzhou to Shanghai.”