Integrate an OpenAPI MCP Server in Model Studio

更新时间:
复制 MD 格式

Integrate an OpenAPI MCP Server in Alibaba Cloud Model Studio to enable applications to manage Alibaba Cloud resources through natural language.

Import an OpenAPI MCP Server

  1. On the MCP Management page of the Alibaba Cloud Model Studio console, click Create MCP Service and select Import from Alibaba Cloud OpenAPI.

  2. On the Create MCP Service page, configure the following parameters.

    Parameter

    Description

    Example

    Service Name

    The name of the OpenAPI MCP service to import.

    mcp-demo

    Role for Accessing Alibaba Cloud OpenAPI

    The role that Alibaba Cloud Model Studio uses to access OpenAPI. You can use an existing role or click Create Role to create a new one.

    ModelStudioMcpRoleDemo

    Permission policy

    If you create a new role, it automatically includes the permissions displayed on the page. If you use an existing role, you must copy the permission policy from the page, create a custom permission policy in the RAM console, and then attach this policy to the role.

    Important

    When you add more APIs to the OpenAPI MCP Server, you must also add their corresponding permissions to the permission policy.

    [Auto-generated]

    After configuring the parameters, click Confirm Import.

  3. After the import completes, you can view the MCP Server and its tools on the MCP Management page.

Test the MCP

  1. On the Application Management page of the Alibaba Cloud Model Studio console, select the application where you want to add the MCP. If you do not have an application, create one first.

  2. On the application configuration page, add your custom MCP service.

    In the Skills section, under MCP Service, click + MCP.

  3. In the text chat, enter a natural language prompt to test the integration. For example, enter "Query ECS instances in the China (Hangzhou) region". If successful, the application calls the Ecs-20140526-DescribeInstances tool from MCP Tools and returns the query results.

Call the MCP programmatically

Publish the application that contains the integrated MCP Server. You can then programmatically manage Alibaba Cloud resources by calling the application.

import os
from http import HTTPStatus
from dashscope import Application

response = Application.call(
    # If the environment variable is not configured, you can replace the next line with api_key="sk-xxx" using your Model Studio API Key. 
    # Avoid hardcoding the API Key in production environments.
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    app_id='xxx',  # Replace with your actual application ID.
    prompt='Query ECS instances in the China (Hangzhou) region')

if response.status_code != HTTPStatus.OK:
    print(f'request_id={response.request_id}')
    print(f'code={response.status_code}')
    print(f'message={response.message}')
    print(f'For more information, see: https://help.aliyun.com/en/model-studio/developer-reference/error-code')
else:
    print(response.output.text)

Publishing to other platforms

Alibaba Cloud Model Studio lets you publish your applications to various platforms to easily integrate AI capabilities into your business. For example, you can publish an application as a DingTalk chatbot or a WeChat Official Account. For more details, see Share Applications.