Cloud Computing 20 min read

Control Alibaba Cloud Resources with LLMs and MCP Server in Minutes

This article explains how to combine Alibaba Cloud's MCP Server with large language models to enable natural‑language operations on cloud products, covering setup, tool selection, OAuth authentication, code examples, troubleshooting context‑length limits, and future enhancements for more efficient, secure cloud management.

Alibaba Cloud Developer
Alibaba Cloud Developer
Alibaba Cloud Developer
Control Alibaba Cloud Resources with LLMs and MCP Server in Minutes

Preface

For Alibaba Cloud users, managing cloud products traditionally requires the console, OpenAPI SDK, CADT, Terraform, etc., all of which rely on OpenAPI calls. Before MCP Server, natural‑language control meant manually writing FunctionCall descriptions for each request, which is cumbersome and inefficient.

Getting Started

Using CherryStudio as an example, the quick start involves three steps:

Click the OpenAPI MCP service to create an MCP Server for a cloud product (up to 30 per product).

Log in to Alibaba Cloud; CherryStudio authorizes via OAuth2.0 (RAM accounts need a service policy).

Configure CherryStudio, which integrates many ready‑made agents and deep integration with Baolian MCP.

When the top‑right button turns green, configuration is complete.

Note: CherryStudio requires a large‑model API key (obtain from Baolian). The first use will show an authorization dialog; click agree.

Principles Exploration

The architecture uses Qwen‑max, Agno (the LLM framework, also called MCP Host), and the ECS OpenAPI MCP Server.

Background

The model is stateless and memory‑less unless explicitly configured.

It focuses on the context of a single session; each request sends the conversation history within the model’s context window.

The framework performs many behind‑the‑scenes tasks, acting as a black box if not examined.

An Agent is an “expert” that can be a simple system prompt or a complex workflow with memory, RAG, etc.

Overall Framework

The Host (Agno or CherryStudio) creates an MCP Client (1:1) to connect to the MCP Server via Streamable HTTP (preferred) or SSE. The client retrieves all tools (APIs) via the MCP protocol, passes them to the LLM, which selects the needed tools, calls them through the Host, and finally returns the result to the user.

Diagram: MCP Server acts as a lightweight proxy that can be integrated into an AI gateway.

OpenAPI MCP Server connections are remote; the MCP Client also supports local STDIO mode (Node.js or Python).

Code Verification

OAuth2.0 Authorization

from utility import set_key
app = Flask(__name__)
app.secret_key = secrets.token_urlsafe(16)
CLIENT_ID = "40711518457*******"
REDIRECT_URI = "http://127.0.0.1:5000/oauth/callback"
DISCOVERY_URL = "https://openapi-mcp.cn-hangzhou.aliyuncs.com/.well-known/oauth-authorization-server"
... (full code omitted for brevity) ...
if __name__ == "__main__":
    app.run(port=5000, debug=True)

After obtaining the access token, store it in the local config file and use it in the Authorization header for subsequent MCP calls.

First MCP Application

print(f"Current path is {os.getcwd()}")
load_keys()
async def run_agent(message: str) -> None:
    server_params = StreamableHTTPClientParams(
        url="https://openapi-mcp.cn-hangzhou.aliyuncs.com/accounts/.../mcp",
        headers={'Authorization': f'Bearer {os.getenv("ALI_OPENAPI_ACCESS_TOKEN")}'})
    async with MCPTools(server_params=server_params, transport="streamable-http", timeout_seconds=30) as mcp_tools:
        model = OpenAILike(id="qwen-max", api_key=os.getenv("DASHSCOPE_API_KEY"), base_url="https://dashscope.aliyuncs.com/compatible-mode/v1")
        agent = Agent(model=model, tools=[mcp_tools], instructions=dedent("""你是一个阿里云云计算专家,请根据用户的问题,使用MCP服务查询阿里云的云产品信息,给出详细的解释。请使用中文回答"""), markdown=True, show_tool_calls=True)
        await agent.aprint_response(message, stream=True)
if __name__ == "__main__":
    asyncio.run(run_agent("我在上海有哪些ECS实例?"))

The program outputs the queried ECS instances.

Solving "Input length out of range"

When the tool list is large (e.g., 26 tools for ECS), the LLM may exceed its context window. The solution is a two‑step selection: first let the LLM choose needed tools based on name and description, then invoke only those tools.

def get_selected_tools_list(server_url, headers, llm_api_key, user_question):
    # fetch all tools via tools/list
    # summarize name & description
    # let LLM return a JSON list of needed tools
    ...

Subsequent calls include only the selected tools, avoiding context overflow.

Future Outlook

Potential improvements include:

Splitting MCP Servers by operation type (Describe, Get, Modify, Create) to reduce tool count.

Using MultiMCPTools to combine multiple servers.

Better tool‑selection algorithms and workflow‑based UI.

Agent matrices for cross‑product collaboration.

Comprehensive security frameworks for agent actions.

With over 20,000 OpenAPIs, MCP can make cloud interactions as simple as a sentence.

References

Alibaba Cloud OpenAPI MCP Console: https://api.aliyun.com/mcp

Model Context Protocol: https://modelcontextprotocol.io/docs/concepts/architecture

MCP Python SDK: https://github.com/modelcontextprotocol/python-sdk

Agno Framework: https://docs.agno.com/introduction

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

cloud computingPythonMCPlarge language modelapi-integration
Alibaba Cloud Developer
Written by

Alibaba Cloud Developer

Alibaba's official tech channel, featuring all of its technology innovations.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.