All Products
Search
Document Center

Container Service for Kubernetes:Deploy an MCP server in Knative

Last Updated:Mar 26, 2026

Host an MCP server on Knative to use its serverless architecture, enabling event-driven capabilities and auto-scaling for your AI services.

In this topic, you:

  • Deploy a sample MCP server as a Knative Service

  • Access the service and verify it responds correctly to tool-call requests

How it works

This workflow shows how an AI application in Knative interacts with external tools using the Model Context Protocol (MCP).

image
  1. Request initiation: A user issues a command to an AI agent. The agent's built-in MCP client generates a standardized tool-call request and sends it using Server-Sent Events (SSE) or HTTP.

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

    To build 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 result to the AI agent, which forwards the final response to the user.

Prerequisites

Before you begin, ensure that you have:

Step 1: Deploy the MCP server

This example deploys an MCP service for trip planning in China (Hangzhou). The service packages itinerary planning, flight search, hotel booking, and weather forecast functions as standardized tools that an AI agent can call.

  1. Create a file named mcp-server.yaml. The following YAML defines a Knative Service that pulls a sample MCP server image. Replace {region} in the image path with your target region, such as cn-hangzhou.

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-go
      namespace: default
    spec:
      template:
        spec:
          containers:
            - env:
                - name: TARGET
                  value: Knative
              image: registry-{region}-vpc.ack.aliyuncs.com/acs/knative-samples-mcp-trip:v1.0-6b9fc59
              name: user-container
  2. Apply the manifest to create the Knative Service.

    kubectl apply -f mcp-server.yaml

Step 2: Access the service

After the service is running, send a test request to verify it responds correctly.

  1. On the Services page, get the Gateway and Default Domain of the service.

    image

  2. Send a tools/list request to list all tools exposed by the MCP server. Replace helloworld-go.default.example.com with your domain and <GATEWAY_IP> with your gateway IP address.

    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 lists all tools from the MCP server:

    {
      "jsonrpc": "2.0",
      "id": "1",
      "result": {
        "tools": [
          {
            "annotations": {
              "readOnlyHint": false,
              "destructiveHint": true,
              "idempotentHint": false,
              "openWorldHint": true
            },
            "description": "Book a hotel near West Lake in China (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 a multi-day weather forecast for China (Hangzhou) to help plan your trip",
            "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 China (Hangzhou), including daily attractions, dining, and cultural experiences",
            "inputSchema": {
              "type": "object",
              "properties": {
                "days": {
                  "description": "Number of travel days (1 to 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 flights to China (Hangzhou)",
            "inputSchema": {
              "type": "object",
              "properties": {
                "date": {
                  "description": "Departure date (YYYY-MM-DD)",
                  "type": "string"
                },
                "origin": {
                  "description": "Departure city (for example, Beijing or Shanghai)",
                  "type": "string"
                }
              },
              "required": [
                "origin",
                "date"
              ]
            },
            "name": "search_flights"
          }
        ]
      }
    }

Going live

Security considerations

The example in this topic uses an unauthenticated MCP server. Before deploying an MCP server in production, review the following:

  • Authentication: Add Ingress-level authentication in Knative to restrict who can call your MCP server.

  • Input validation: Validate all tool parameters to prevent malformed or malicious inputs, including prompt injection attacks.

  • Least privilege: Expose only the tools your use case requires. Avoid exposing tools that perform destructive or irreversible operations without additional confirmation.

  • Logging and monitoring: Log MCP tool invocations for auditing and anomaly detection.

Billing

Knative itself has no additional cost. However, the underlying cloud resources provisioned while using Knative are billed separately, including compute resources (ECS) and network resources (Application Load Balancer (ALB)). For pricing details, see Cloud resource fees.