External Invocation

更新时间:
复制 MD 格式

Alibaba Cloud Model Studio provides end-to-end MCP services. You can configure these services within the platform (such as in agent applications or workflows) or invoke them externally from third-party applications or your own projects. To invoke them externally, choose one of the following options:

  • Integrate with a third-party application: One-click automatic configuration lets you quickly enable external invocation.

  • Integrate with your own project: You can use the MCP SDK for flexible coding and deep customization.

Demo

You can call the Amap Maps MCP service from Alibaba Cloud Model Studio within Cherry Studio to build a route-planning agent application.

image

Prerequisites

1. Activate Alibaba Cloud Model Studio

  1. Create an account: If you do not have an Alibaba Cloud account, first register.

    If you encounter issues, see Create an Alibaba Cloud Account.
  2. Activate Alibaba Cloud Model Studio: Sign in with your Alibaba Cloud account and go to Alibaba Cloud Model Studio. Read and accept the Terms of Service to automatically activate the service. If the Terms of Service do not appear, the service is already activated.

    If you see the message “You have not completed identity verification” when activating the service, you must complete identity verification first.
After your first activation of Model Studio, you receive a free quota for new users (valid for 90 days from activation). You can use it for model inference. For details and instructions on claiming the free quota, see the Free Quota for New Users page.
Note

You incur charges if you exceed the free quota or after its validity period expires. You can enable the spending limit feature to prevent unexpected charges. Actual pricing and final bills are displayed in the console.

2. Get an Alibaba Cloud Model Studio API key

  1. Open the API Key (China (Beijing)), API Key (Singapore), or API Key (US (Virginia)) page and click Create API Key.

  2. Configure the following settings and click OK:

    • Owner Account: Select the Alibaba Cloud account (digit-only ID in the Account column).

    • Workspace: Select the default workspace.

  3. Click image next to the API key to copy it.

    Root accounts can view all API keys. RAM users can only view keys they created.

    2026-02-11_11-56-27

Enable an MCP service

Note

The Alibaba Cloud Model Studio MCP service has been upgraded from the legacy Server-Sent Events (SSE) protocol to the new Streamable HTTP protocol. Choose the steps that match your situation:

First-time setup (new users)

  1. Go to the Alibaba Cloud Model Studio MCP Marketplace and select an MCP service. For example, you can click the Amap Maps card.

    截屏2026-03-16 15

  2. Click Enable Now and then Confirm activation to enable the Amap Maps MCP service.

    image

    Note

    The Amap Maps MCP service is hosted on Alibaba Cloud Model Studio. For trial use, you do not need to provide an AMAP_MAPS_API_KEY. For commercial customization, you can use your own AMAP_MAPS_API_KEY.

    To enter sensitive information, encrypt it using a KMS credential.

    image

Protocol upgrade (existing users)

  1. Go to the Alibaba Cloud Model Studio MCP Marketplace and select an MCP service. For example, you can click the Amap Maps card.

    截屏2026-03-16 15

  2. Click Disable on the right. Then click Enable Now and Confirm activation to update the Amap Maps MCP service.

Invoke an MCP service externally

Integrate into a third-party application

Alibaba Cloud Model Studio supports configuring MCP services in Cherry Studio and Cursor. Both automatic and manual configuration methods are supported. The following example uses the Amap Maps service.

Cherry Studio

  1. Install Cherry Studio.

  2. Go to the Amap Maps MCP service page. In the External Call section, select Cherry Studio.

    image

  3. Click One-Click Configuration for Cherry Studio. Select an API key and click OK.

    imageThe Cherry Studio window displays the detailed configuration of the MCP service.image

  4. You can also configure the MCP service manually. Click the image icon in the top-right corner. In the dialog box, select an API Key and copy the configuration file. In Cherry Studio, go to the MCP Settings page. Click Add Server > Import from JSON. Paste the configuration and click OK.image

  5. Use the MCP service in Cherry Studio. Create a new topic. Click image below the input field and select the AliyunBailianMCP_amap-maps service.

    image

  6. In the dialog box, enter Start now. Provide three public transportation routes from Hangzhou Xiaoshan International Airport to West Lake Scenic Area. The Large Language Model (LLM) successfully calls the MCP tool for route planning.

    If the model fails to call the MCP tool, refer to the FAQ.

    image

Cursor

  1. Install Cursor.

  2. Go to the Amap Maps MCP service page. In the External Call section, select Cursor.

    image

  3. Click One-Click Configuration for Cursor. Select an API key and click OK. In the Cursor window, click Install.

    image

    A green status indicator appears in the bottom-right corner of your profile picture after successful installation.

    image

Develop integration using the SDK

You can use the MCP SDK to call Alibaba Cloud Model Studio MCP services. This provides full coding flexibility.

The following example builds an agent application that uses the Qwen Agent framework to call the Amap Maps MCP service and query today’s weather in Hangzhou.

  1. Install the Qwen Agent framework.

    pip install -U "qwen-agent[gui,rag,code_interpreter,mcp]"
  2. You can set your Alibaba Cloud Model Studio API key as an environment variable.

  3. You can create a file named hangzhou_weather.py and use this sample code:

    Python

    # -*- coding: utf-8 -*-
    # Use the amap-maps tool to query Hangzhou weather
    
    import os
    from qwen_agent.agents import Assistant
    
    
    def query_hangzhou_weather():
        """Query today's weather in Hangzhou"""
        # Check environment variable
        api_key = os.getenv('DASHSCOPE_API_KEY')
        if not api_key:
            print("Error: Set the DASHSCOPE_API_KEY environment variable")
            print("Example: export DASHSCOPE_API_KEY=your_api_key")
            return
        
        llm_cfg = {'model': 'qwen-max'}
        system = (
            'You are a weather-query agent. You will use the amap-maps MCP service to get weather data.'
            'Always call the tool first to get structured weather data. Then give a brief summary.'
        )
        
        # Configure the MCP tool (Streamable HTTP protocol)
        tools = [{
            "mcpServers": {
                "amap-maps": {
                    "type": "streamable-http",
                    "url": "https://dashscope.aliyuncs.com/api/v1/mcps/amap-maps/mcp",
                    "headers": {
                        "Authorization": f"Bearer {api_key}"
                    }
                }
            }
        }]
        
        # Create the agent
        bot = Assistant(
            llm=llm_cfg,
            name='Weather Query Agent',
            description='Weather information lookup',
            system_message=system,
            function_list=tools,
        )
    
        # Query Hangzhou weather
        messages = []
        query = "What is today's date? What is the weather in Hangzhou today?"
        messages.append({'role': 'user', 'content': query})
    
        print("Querying today's weather in Hangzhou...")
        print("=" * 50)
        
        # Run the query and collect all responses
        all_responses = []
        for response in bot.run(messages):
            all_responses.append(response)
        
        # Extract the final assistant reply
        final_content = ""
        if all_responses:
            last_response = all_responses[-1]
            if isinstance(last_response, list):
                for item in last_response:
                    if isinstance(item, dict) and item.get('role') == 'assistant' and 'content' in item:
                        final_content = item['content']
            elif isinstance(last_response, dict) and 'content' in last_response:
                final_content = last_response['content']
        
        # Output the result
        if final_content:
            print(final_content)
        else:
            print("Failed to retrieve weather information")
    
    
    if __name__ == '__main__':
        query_hangzhou_weather()
  4. You can run the code. The output appears as follows:

    image

    If you run the code and receive the error message npx is not recognized as an internal or external command, first install <a href="https://nodejs.org/zh-cn" id="f9c77c8d95wkf">Node.js</a>.

FAQ

What do I do if I cannot connect to an MCP service?

  1. MCP service not enabled or not upgraded: Ensure the MCP service is enabled or upgraded in the Model Studio MCP Marketplace. See Enable an MCP service.

  2. Invalid API key: Confirm that you are using a valid Alibaba Cloud Model Studio API key.

  3. Quota exhausted: Some MCP services, such as web search, have monthly quotas. They stop automatically when the quota is exhausted.

For answers to common questions and information about other errors, see the FAQ.

The model responds normally and no MCP errors appear, but the MCP tool still does not run. What do I do?

The Large Language Model needs clear instructions to correctly call an MCP service. Specify the tool name and its capabilities in your prompt. For example, call the Alibaba Cloud Model Studio Amap Maps MCP service to plan a driving route from Hangzhou to Shanghai.