Cloud Native 10 min read

How Alibaba Cloud Function Compute Cuts MCP Server Idle Costs by Up to 87%

This article explains how Alibaba Cloud Function Compute (FC) provides a serverless, pay‑per‑use environment for MCP Server, introduces the session‑affinity challenges that cause resource idle time, and details the idle‑billing mechanism that can reduce overall MCP Server costs by as much as 87% while preserving performance.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
How Alibaba Cloud Function Compute Cuts MCP Server Idle Costs by Up to 87%

Function Compute (FC) is Alibaba Cloud's fully managed, event‑driven compute service that abstracts away servers; users only upload code or container images and FC handles provisioning, scaling, logging, monitoring, and alerts.

Why MCP Server Needs Idle Billing

MCP Server maintains long‑lived sessions for each client, which leads to sparse and bursty traffic patterns. In many real‑world scenarios a session may stay open for hours while only a few requests are issued, causing the underlying compute resources to remain allocated but largely idle.

FC Enhancements for MCP Server

FC adds two key features for MCP Server:

Community‑maintained Stdio MCP Server can be deployed to FC with one click.

Affinity scheduling resolves the session‑persistence problem, enabling long‑connection idle billing that charges only for active CPU time.

These improvements allow MCP Server to be billed on actual usage, reducing idle cost by up to 87% in sparse‑access scenarios.

MCP Server Communication Flow

The interaction consists of a series of SSE (Server‑Sent Events) and HTTP POST calls:

Client sends a GET request to establish an SSE long‑connection (Connection1).

Server replies with an event: endpoint containing a sessionId (Connection1).

Client uses the sessionId to send the first POST request (Connection2).

Server quickly returns HTTP 202 with no body (Connection2).

Server sends the actual response for the previous request (Connection1).

Client sends further POSTs such as initialized, list tools, call tool, each followed by a 202 response and later the real payload.

This pattern shows that after initialization the connection stays open, but most of the time the server does nothing, leading to idle resources.

Idle‑Billing Mechanism

FC divides the long‑connection lifetime into fixed idle‑checking intervals. If the CPU time consumed in an interval is below a configurable threshold, the interval is considered idle and only memory charges are applied. Active intervals are those that contain real calls like Initialize, List Tools, or Call Tools.

In a typical sparse‑access case (1 hour session, 4 real actions lasting 8 seconds total), 3592 seconds are idle. Assuming a 2‑core 3 GB instance where memory accounts for 18% of cost, the overall cost drops to roughly 13% of the original, i.e., an 87% saving.

Enabling Idle Billing for MCP Server

Idle billing is automatically enabled when session affinity (MCP_SSE) is turned on. It can be activated via the FC console, Function AI console, or programmatically using the CreateFunction or UpdateFunction APIs with the SessionAffinity field set to MCP_SSE. Note that GPU‑based functions do not support this feature.

Additional Scenarios

WebSocket services that require long‑lived connections also benefit from idle billing without extra configuration. Detailed billing breakdowns are available in the “Function Compute – Resource Usage Details” page.

References

Function Compute billing overview: https://www.alibabacloud.com/help/zh/functioncompute/fc-3-0/product-overview/billing-overview-1

MCP affinity scheduling guide: https://help.aliyun.com/zh/functioncompute/fc-3-0/user-guide/mcp-sse-affinity-scheduling

FC console: https://fcnext.console.aliyun.com/overview

CreateFunction API: https://help.aliyun.com/zh/functioncompute/fc-3-0/developer-reference/api-fc-2023-03-30-createfunction

UpdateFunction API: https://help.aliyun.com/zh/functioncompute/fc-3-0/developer-reference/api-fc-2023-03-30-updatefunction

Resource usage details: https://fcnext.console.aliyun.com/billing

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.

ServerlessCost OptimizationFunction ComputeMCP ServerIdle Billing
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

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.