Claude API + MCP Integration Usage Guide¶
Prerequisites¶
Claude API Key: Get from Anthropic Console
Port-forward running: MCP server accessible at localhost:8090
Python 3.8+ with virtual environment
Setup¶
Create and activate virtual environment:
python3 -m venv claude_env
source claude_env/bin/activate
Install dependencies:
pip install -r toolsforlocal/requirements.txt
Set your Claude API key:
export ANTHROPIC_API_KEY='your-api-key-here'
Start port-forward to MCP server:
kubectl port-forward -n canvas svc/pdb-management-mcp-service 8090:8090
Usage¶
Interactive Mode¶
python toolsforlocal/claude_mcp_integration.py
Commands:
analyze pdb-demo- Claude analyzes the namespacerecommend pdb-demo- Claude recommends policieschat- Free-form conversationAny text - Send directly to Claude
Python Script Usage¶
from claude_mcp_integration import ClaudeMCPIntegration
# Initialize
integration = ClaudeMCPIntegration()
# Ask Claude to analyze
response = integration.analyze_namespace("pdb-demo")
print(response)
# Get recommendations
response = integration.recommend_policies("pdb-demo")
print(response)
# Custom prompt
response = integration.chat_with_tools(
"What deployments in pdb-demo need better availability?"
)
print(response)
Direct API Usage¶
import os
from anthropic import Anthropic
client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
# Define your MCP tools based on what's available
tools = [
{
"name": "analyze_cluster_availability",
"description": "Analyze cluster-wide PDB coverage",
"input_schema": {
"type": "object",
"properties": {
"namespace": {"type": "string"},
"detailed": {"type": "boolean"}
}
}
}
]
# Send message with tools
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[{
"role": "user",
"content": "Analyze the pdb-demo namespace availability"
}],
tools=tools
)
What Claude Can Do¶
With MCP tools, Claude can:
Analyze - Check PDB coverage, identify gaps
Recommend - Suggest optimal availability policies
Create - Generate availability policies (with your approval)
Simulate - Test policy impact before applying
Update - Modify deployment annotations
Pattern Analysis - Identify workload patterns
Example Conversations¶
You: What's the PDB coverage in my pdb-demo namespace?
Claude: [Uses analyze_cluster_availability tool]
Claude: Your pdb-demo namespace has 100% PDB coverage with 15 deployments...
You: Which deployments need better availability settings?
Claude: [Uses recommend_policies tool]
Claude: Based on my analysis, payment-processor and auth-service should be mission-critical...
You: Create a policy for the payment services
Claude: [Uses create_availability_policy tool]
Claude: I'll create a mission-critical policy for your payment services...
Troubleshooting¶
Connection Error: Check port-forward is running
MCP Not Initialized: Verify MCP server health:
curl http://localhost:8090/healthAPI Key Error: Ensure ANTHROPIC_API_KEY is set correctly
Tool Not Found: MCP server may need restart
Cost Optimization¶
Claude 3.5 Sonnet: ~$3 per million input tokens
Use caching for repeated analysis
Batch multiple operations in one conversation
Use specific namespaces instead of cluster-wide analysis