Host a Model Context Protocol (MCP) Server in Knative to use its serverless architecture, which provides on-demand autoscaling and event-driven processing for AI services.
How it works
The following workflow shows how an AI application in Knative uses MCP to interact with external tools.
-
Request initiation: A user issues a command to an AI agent. The agent's built-in MCP client generates a standardized tool-calling request and sends it over Server-Sent Events (SSE) or HTTP.
Knative does not support MCP Servers that use the stdio transport protocol.
-
Service handling and execution: The Knative Service receives the HTTP request, routes it to an MCP Server instance, and scales automatically based on the load.
To build your own MCP Server, see the MCP Server SDK or FastMCP. You can also find existing implementations in the MCP Server GitHub repository.
-
Result response: The MCP Server returns the task result to the AI agent, which then sends the final response to the user.
Prerequisites
You have deployed Knative in the cluster. For more information, see Deploy and manage Knative components.
Step 1: Deploy the MCP Server
In this section, you deploy an MCP Server for trip planning in China (Hangzhou). The server packages trip planning, flight search, hotel booking, and weather forecasting capabilities into standardized tools that AI agents can call.
-
Create
mcp-server.yaml.The following example defines a Knative Service that pulls the sample MCP Server image.
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: helloworld-go namespace: default spec: template: spec: containers: - env: - name: TARGET value: Knative # Replace {region} in the image address with your actual region ID, such as cn-hangzhou image: >- registry-{region}-vpc.ack.aliyuncs.com/acs/knative-samples-mcp-trip:v1.0-6b9fc59 name: user-container -
Create the Knative Service.
kubectl apply -f mcp-server.yaml
Step 2: Access the service
After you deploy the service, send an MCP request to verify that it works as expected.
-
On the Services page, get the Gateway and Default Domain of the service.
In this example, the Gateway is an Application Load Balancer (ALB) address, such as
alb-xxx.aliyuncsslb.com. The helloworld-go service's Default Domain ishelloworld-go.default.example.com. -
Access the
helloworld-goservice.Replace
helloworld-go.default.example.comwith your actual domain name, and<GATEWAY_IP>with your actual gateway address.This command sends a
tools/listrequest to the service to list all supported tools.curl -H "Host: helloworld-go.default.example.com" http://<GATEWAY_IP>/mcp -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": "1", "method": "tools/list", "params": {} }' | jq .The command returns a formatted JSON response that contains the list of tools provided by the MCP Server.
Billing
The Knative add-on itself does not incur additional charges. However, each cloud product charges for the compute resources, network resources, and other resources that you consume. For more information, see Cloud resource costs.