For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Manage secrets
Configure your MCP server to read additional environment variables from a Kubernetes secret.
You can bootstrap your MCP server with additional environment variables that the MCP server needs to run properly. These environment variables are typically defined in an .env file.
You can use the kmcp secret command to store these environment variables in a Kubernetes secret and to automatically configure the MCP server to mount that secret during the MCP server deployment.
The name and namespace of the Kubernetes secret that you want to create is defined in the kmcp.yaml file of your project.
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.
Store environment variables in a Kubernetes secret
Review the
kmcp.yamlconfiguration of your MCP project. The defaultkmcp.yamlfile includes asecretssection that defines multiple environments, such asstaging,production, andlocal. Each environment defines the name and the namespace of the Kubernetes secret that you want to use. Note that all environments are currently disabled.cat my-mcp-server/kmcp.yamlExample output:
name: my-mcp-server framework: fastmcp-python version: 0.1.0 description: MCP server built with fastmcp-python secrets: local: enabled: false provider: env file: .env.local production: enabled: false provider: kubernetes secretName: my-mcp-server-secrets-production namespace: default staging: enabled: false provider: kubernetes secretName: my-mcp-server-secrets-staging namespace: defaultEnable the staging environment by setting the
secret.staging.enabledfield totrue. You can optionally change the name and namespace of the Kubernetes secret that you want to use with your MCP server. However, keep in mind that the secret must be in the same namespace where the MCP server is deployed.... secrets: local: enabled: false provider: env file: .env.local production: enabled: false provider: kubernetes secretName: my-mcp-server-secrets-production namespace: default staging: enabled: true provider: kubernetes secretName: my-mcp-server-secrets-staging namespace: defaultCreate an
.env.stagingfile in your MCP project that defines additional environment variables that you want to provide to your MCP server.cat << EOF > my-mcp-server/.env.staging # .env.staging API_KEY=your-api-key-here DATABASE_URL=postgresql://user:pass@host:5432/db EOFCreate the Kubernetes secret in your kind cluster by using the secret defintion from the
kmcp.yamlfile and the environment variables from the.env.stagingfile. Note that this step is not required when you plan to run your MCP server locally only.kmcp secrets sync staging --from-file my-mcp-server/.env.staging --project-dir my-mcp-serverVerify that the Kubernetes secret is created and that you can see the base64-encoded environment variables that you defined earlier.
kubectl get secret my-mcp-server-secrets-staging -o yamlExample output:
apiVersion: v1 data: API_KEY: eW91ci1hcGkta2V5LWhlcmU= DATABASE_URL: cG9zdGdyZXNxbDovL3VzZXI6cGFzc0Bob3N0OjU0MzIvZGI= kind: Secret metadata: name: my-mcp-server-secrets-staging namespace: default resourceVersion: "10819" uid: 85... type: Opaque
Deploy the MCP server with your secret
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 kindDeploy your MCP server and bootstrap it with the Kubernetes secret of the staging environment.
kmcp deploy --environment staging --file my-mcp-server/kmcp.yaml --no-inspector --image my-mcp-server:latestVerify that your server is up and running.
kubectl get podsGet the details of the
my-mcp-serverdeployment. Verify that you see the reference to your Kubernetes secret in thespec.containers.envFromsection.kubectl get deployment my-mcp-server -o yamlExample output:
... template: metadata: creationTimestamp: null labels: app.kubernetes.io/instance: my-mcp-server app.kubernetes.io/managed-by: kmcp app.kubernetes.io/name: my-mcp-server spec: containers: ... envFrom: - secretRef: name: my-mcp-server-secrets-staging image: my-mcp-server:latest ...