# Step 05: K-Agent Server Class Structure## Define the KAgentServer ClassAdd the class definition to your `src/index.ts`:
```typescriptclassKAgentServer{// Kubernetes API clientsprivatek8sConfig:k8s.KubeConfig;privatek8sAppsApi:k8s.AppsV1Api;privatek8sCoreApi:k8s.CoreV1Api;// MCP Server instanceprivateserver:Server;constructor(){// Initialize Kubernetes configurationthis.k8sConfig=newk8s.KubeConfig();try{this.k8sConfig.loadFromDefault();}catch(error){console.error("Warning: Could not load Kubernetes configuration.");console.error("Make sure kubectl is configured.");console.error("Error:",errorinstanceofError?error.message:String(error),);}// Create Kubernetes API clientsthis.k8sAppsApi=this.k8sConfig.makeApiClient(k8s.AppsV1Api);this.k8sCoreApi=this.k8sConfig.makeApiClient(k8s.CoreV1Api);// Initialize MCP serverthis.server=newServer({name:"k-agent-logs",version:"1.0.0",},{capabilities:{tools:{},resources:{},},},);// Setup request handlersthis.setupHandlers();}privatesetupHandlers(){// Will be implemented in next steps}asyncrun(){consttransport=newStdioServerTransport();awaitthis.server.connect(transport);console.error("K-Agent MCP server running on stdio");}}// Create and run the serverconstserver=newKAgentServer();server.run().catch(console.error);```
Class Structure Explanation
Properties
Property
Type
Purpose
k8sConfig
KubeConfig
Loads and manages kubeconfig
k8sAppsApi
AppsV1Api
Apps API for deployments
k8sCoreApi
CoreV1Api
Core API for pods/logs
server
Server
MCP server instance
Constructor Flow
Load Configuration - Reads ~/.kube/config or in-cluster config
Create API Clients - Instantiates typed K8s API clients
Initialize MCP Server - Creates server with name and capabilities
Setup Handlers - Registers tool and resource handlers