All Products
Search
Document Center

Container Service for Kubernetes:Deploy an MCP server in Knative

最終更新日:Dec 10, 2025

Hosting the Model Context Protocol (MCP) server in Knative allows you to use serverless advantages, such as on-demand auto-scaling and event-driven processing for AI workloads.

How it works

The following workflow outlines how an AI application running on Knative interacts with external tools via the MCP protocol.

image
  1. 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 using the Server-Sent Events (SSE) or HTTP protocol.

    Knative does not support MCP servers that use the stdio transport protocol.
  2. Request handling and execution: The Knative Service receives the HTTP request, routes it to an available MCP server instance, and automatically scales based on the load.

    To develop your own MCP server, see the MCP Server SDK or FastMCP. For existing implementations, see the MCP Server GitHub repository.
  3. Result response: The MCP server returns the task result to the AI agent, which then forwards the final response to the user.

Prerequisites

Knative is deployed in the cluster. For more information, see Deploy and manage Knative.

Step 1: Deploy the MCP server

This section deploys a sample MCP server for Hangzhou trip planning. The server packages functions for trip planning, flight booking, hotel reservation, and weather forecasting into standardized tools for an AI agent.

  1. Create a file named 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 path with the actual region, such as cn-hangzhou.
              image: >-
                registry-{region}-vpc.ack.aliyuncs.com/acs/knative-samples-mcp-trip:v1.0-6b9fc59
              name: user-container
  2. Create the Knative Service.

    kubectl apply -f mcp-server.yaml

Step 2: Access the server

After deploying the server, send an MCP request to verify that it is working correctly.

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, find the cluster you want and click its name. In the left navigation pane, choose Applications > Knative.

  3. Click the Services tab, obtain the Gateway and Default Domain of the Knative Service.

    image

  4. Access the helloworld-go Service.

    Replace helloworld-go.default.example.com with your domain name. Replace <GATEWAY_IP> with your gateway IP address.

    This command sends a tools/list request to the Service to retrieve the list of 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 expected output is a formatted JSON response that contains the list of tools provided by the MCP server.

    Expand to view the expected output

    {
      "jsonrpc": "2.0",
      "id": "1",
      "result": {
        "tools": [
          {
            "annotations": {
              "readOnlyHint": false,
              "destructiveHint": true,
              "idempotentHint": false,
              "openWorldHint": true
            },
            "description": "Book a hotel near West Lake in Hangzhou",
            "inputSchema": {
              "type": "object",
              "properties": {
                "check_in": {
                  "description": "Check-in date (YYYY-MM-DD)",
                  "type": "string"
                },
                "guests": {
                  "description": "Number of guests",
                  "type": "number"
                },
                "nights": {
                  "description": "Number of nights",
                  "type": "number"
                }
              },
              "required": [
                "check_in",
                "guests",
                "nights"
              ]
            },
            "name": "book_hotel"
          },
          {
            "annotations": {
              "readOnlyHint": false,
              "destructiveHint": true,
              "idempotentHint": false,
              "openWorldHint": true
            },
            "description": "Get the weather forecast for the next few days in Hangzhou for trip preparation",
            "inputSchema": {
              "type": "object",
              "properties": {
                "date_start": {
                  "description": "Start date (YYYY-MM-DD)",
                  "type": "string"
                },
                "days": {
                  "description": "Number of forecast days",
                  "type": "number"
                }
              },
              "required": [
                "date_start",
                "days"
              ]
            },
            "name": "get_weather_forecast"
          },
          {
            "annotations": {
              "readOnlyHint": false,
              "destructiveHint": true,
              "idempotentHint": false,
              "openWorldHint": true
            },
            "description": "Generate a multi-day in-depth travel itinerary for Hangzhou, including daily attractions, food, and cultural experiences",
            "inputSchema": {
              "type": "object",
              "properties": {
                "days": {
                  "description": "Number of travel days (1-7)",
                  "maximum": 7,
                  "minimum": 1,
                  "type": "number"
                }
              },
              "required": [
                "days"
              ]
            },
            "name": "plan_hangzhou_trip"
          },
          {
            "annotations": {
              "readOnlyHint": false,
              "destructiveHint": true,
              "idempotentHint": false,
              "openWorldHint": true
            },
            "description": "Search for flight information to Hangzhou",
            "inputSchema": {
              "type": "object",
              "properties": {
                "date": {
                  "description": "Departure date (YYYY-MM-DD)",
                  "type": "string"
                },
                "origin": {
                  "description": "Departure city (such as Beijing, Shanghai)",
                  "type": "string"
                }
              },
              "required": [
                "origin",
                "date"
              ]
            },
            "name": "search_flights"
          }
        ]
      }
    }

Billing

There is no additional cost for Knative itself. However, you are responsible for the costs of any underlying cloud resources that are provisioned while using Knative, such as compute resources (Elastic Compute Service instances) and network resources (Application Load Balancer). These resources are billed separately by each respective cloud service. For detailed pricing information, see Cloud resource fee.