Deploy MCP servers
Use the kmcp controller to automatically spin up your MCP server in a Kubernetes environment.
Prerequisites
- Create a FastMCP or MCP Go project with a sample MCP server and tool.
- Install the KMCP controller in a local kind cluster to manage the lifecycle of MCP servers in your cluster.
Deploy the MCP server
-
Build a Docker image for your MCP server and load it to your kind cluster. The following command assumes that your kind cluster is named
kind
.kmcp build --project-dir my-mcp-server -t my-mcp-server:latest --kind-load-cluster kind -
Deploy your MCP server. Choose between the following options:
-
Option 1: Use the kmcp deploy command
The
kmcp deploy
command automatically creates an MCPServer resource in your cluster that contains the MCP server configuration that is defined in thekmcp.yaml
file in your MCP project. The kmcp controller then uses this resource to spin up and manage the lifecycle of your MCP server. After the MCP server is deployed, the command automatically starts the MCP inspector tool so that you can test your server.Tip: If you do not want to start the MCP inspector tool, add the
--no-inspector
flag to the command.kmcp deploy --file my-mcp-server/kmcp.yaml --image my-mcp-server:latest -
Option 2: Create an MCPServer resource
You can manually create an MCPServer resource yourself as shown in the following examples.
- FastMCP example
kubectl apply -f- <<EOFapiVersion: kagent.dev/v1alpha1kind: MCPServermetadata:name: my-mcp-serverspec:deployment:image: "my-mcp-server:latest"port: 3000cmd: "python"args: ["src/main.py"]transportType: "stdio"EOF- MCP Go example:
kubectl apply -f- <<EOFapiVersion: kagent.dev/v1alpha1kind: MCPServermetadata:name: my-mcp-serverspec:deployment:image: "my-mcp-server:latest"port: 3000cmd: "./server"transportType: "stdio"EOF
-
-
Verify that the MCP server is up and running.
kubectl get podsExample output:
NAME READY STATUS RESTARTS AGEmy-mcp-server-669bcb5d6f-zv5dn 1/1 Running 0 27h
Test access to the MCP server
-
Run the MCP inspector tool. Note that if you used the
kmcp deploy
command to spin up your MCP server, the MCP inspector tool is already running. You can skip to the next step.-
Port-forward the MCP server that you deployed.
kubectl port-forward deploy/my-mcp-server 3000 -
Run the MCP inspector tool. In your CLI output, find the URL that the MCP inspector tool is exposed on.
npx @modelcontextprotocol/inspectorExample output:
🚀 MCP Inspector is up and running at:http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=8aca1a7088efc984e433fd750ed042b1881fbda3734282e3f0e524b00fc3e69f
-
-
In your MCP inspector tool, click Connect to connect to your MCP server. Note that it might take a few seconds for the MCP inspector tool to successfully connect to your MCP server. If the connection fails, make sure the following fields are set in the MCP inspector tool.
- Select Streamable HTTP from the Transport Type drop down.
- Enter
http://127.0.0.1:3000/mcp
in the URL field. - Expand the Configuration section and make sure that the Proxy Session Token is set to the value of the
PROXY_AUTH_TOKEN
that was shown in the CLI output when you opened the MCP inspector tool.
Connect to FastMCP server with MCP inspector tool -
Try out the built-in
echo
MCP tool.- Go to the Tools tab and click List Tools.
- Select the
echo
tool. - Enter any string in the message field, such as
Hello world
and click Run Tool. - Verify that you see your message echoed in the Tool result card.
Successful run of the echo tool
Next
Learn how to manage secrets for your MCP servers.