# MCP Servers Deployment Fix

## Issue
```
MountVolume.SetUp failed for volume "guidelines" : configmap "agent-guidelines" not found
```

## Root Cause
The `memory-mcp` deployment in `tbi-devops-common` references a ConfigMap named `agent-guidelines` that was not created.

## Solution

### Files Created
1. **agent-guidelines-configmap.yaml** - ConfigMap with deployment guidelines
2. **README.md** - Comprehensive deployment and troubleshooting guide
3. **deploy.sh** - Automated deployment script

### Location
```
tbi-devops-common/app/monitor/apps/mcp-servers/
├── agent-guidelines-configmap.yaml  ← NEW
├── README.md                        ← NEW
├── deploy.sh                        ← NEW
├── custom-elasticsearch-mcp.yaml
├── grafana-mcp.yaml
├── memory-mcp.yaml
├── namespace.yaml
└── secrets.yaml
```

## Quick Fix

### Option 1: Use Deployment Script (Recommended)
```bash
cd /Users/iakpabio/Desktop/git-code/tbi-code/tbi-devops-common/app/monitor/apps/mcp-servers
./deploy.sh
```

### Option 2: Manual Deployment
```bash
cd /Users/iakpabio/Desktop/git-code/tbi-code/tbi-devops-common/app/monitor/apps/mcp-servers

# Apply in order
kubectl apply -f namespace.yaml
kubectl apply -f agent-guidelines-configmap.yaml
kubectl apply -f secrets.yaml
kubectl apply -f memory-mcp.yaml
kubectl apply -f grafana-mcp.yaml
kubectl apply -f custom-elasticsearch-mcp.yaml
```

### Option 3: Fix Existing Deployment
If the deployment already exists and is failing:
```bash
# Apply the missing ConfigMap
kubectl apply -f agent-guidelines-configmap.yaml

# Restart the deployment
kubectl rollout restart deployment memory-mcp -n mcp-servers

# Verify
kubectl get pods -n mcp-servers
kubectl logs -n mcp-servers -l app=memory-mcp
```

## Verification

### Check ConfigMap
```bash
kubectl get configmap agent-guidelines -n mcp-servers
kubectl describe configmap agent-guidelines -n mcp-servers
```

### Check Deployment
```bash
kubectl get deployment memory-mcp -n mcp-servers
kubectl describe deployment memory-mcp -n mcp-servers
```

### Check Pods
```bash
kubectl get pods -n mcp-servers
kubectl describe pod -n mcp-servers -l app=memory-mcp
```

### Test Service
```bash
kubectl port-forward -n mcp-servers svc/memory-mcp 8080:8080

# In another terminal
curl http://localhost:8080
```

## ConfigMap Contents

The `agent-guidelines` ConfigMap includes:

1. **deployment-standards.md** - TBI DevOps deployment standards and practices
2. **mcp-architecture.md** - MCP servers architecture and configuration
3. **troubleshooting.md** - Common issues and solutions
4. **service-migration.md** - Service migration checklist

These guidelines are automatically loaded by the memory-mcp server and made available to AI agents via the MCP protocol.

## Related Documentation

- [MCP Servers README](../tbi-devops-common/app/monitor/apps/mcp-servers/README.md)
- [TBI Agent IAM Setup](../tbi-devops-common/docs/tbi-agent-iam-setup.md)
- [Strand Agent Architecture](../tbi-devops-common/docs/strandagent.md)

## Prevention

To prevent this issue in the future:

1. Always create ConfigMaps before deployments that reference them
2. Use the deployment script which enforces correct ordering
3. Add ConfigMap validation to CI/CD pipeline
4. Document all ConfigMap dependencies in deployment manifests

## Rollback

If needed, remove the MCP servers:
```bash
kubectl delete -f memory-mcp.yaml
kubectl delete -f grafana-mcp.yaml
kubectl delete -f custom-elasticsearch-mcp.yaml
kubectl delete configmap agent-guidelines -n mcp-servers
```
