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#
Learn how you can deploy an MCP server in a Kubernetes cluster. Choose between the following options:
- Option 1: Deploy an MCP server with
npx
oruvx
: Use an existing npm package to spin up an MCP server instance withnpx
oruvx
. - Option 2: Build and deploy an MCP server: Build a Docker image for your MCP server project. Then, load this image to your Kubernetes cluster and deploy an MCP server from it.
Option 1: Deploy an MCP server with npx
or uvx
#
Deploy an instance of the server-everything
MCP server by using the npx
or uvx
command. This server provides simple tools, such as an echo tool, that you can use for testing.
Choose between using the kmcp CLI or creating the MCPServer resource yourself.
-
Deploy the MCP server.
kmcp deploy package --deployment-name my-mcp-server \--manager npx --args @modelcontextprotocol/server-everything -
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
-
Create the MCPServer resource.
kubectl apply -f- <<EOFapiVersion: kagent.dev/v1alpha1kind: MCPServermetadata:name: my-mcp-servernamespace: defaultspec:deployment:args:- '@modelcontextprotocol/server-everything'cmd: npxport: 3000stdioTransport: {}transportType: stdioEOF -
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
Option 2: Build and deploy an MCP server#
Learn how to use the kmcp CLI to build an image for your MCP server and to deploy the server to your Kubernetes cluster.
The following example assumes that you created a FastMCP or MCP Go project with a sample MCP server and tool, and that your kind cluster is named kind
.
-
Build a Docker image for your MCP server and load it to your kind cluster.
kmcp build --project-dir my-mcp-server -t my-mcp-server:latest --kind-load-cluster kind -
Deploy your MCP server. Choose between the kmcp CLI or manually creating an MCPServer resource.
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:latestYou 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.