MCP Server Setup
Configure MCP servers to provide custom tools to AI agents.
Overview
MCP servers expose tools through a standardized API. Configure servers using environment variables.
Environment Variables
MCP servers use prefixed environment variables:
# Format: MCP_{SERVER_NAME}_{PARAMETER}
MCP_ORDER_API_URL=https://order-api.example.com
MCP_ORDER_API_KEY=your-api-key
MCP_ORDER_API_TIMEOUT=30
Configuring Servers
Order API Server
# In .env file
MCP_ORDER_API_URL=https://order-api.example.com/v1
MCP_ORDER_API_KEY=your-order-api-key
MCP_ORDER_API_TIMEOUT=30
Weather Server
# In .env file
MCP_WEATHER_URL=https://weather-api.example.com
MCP_WEATHER_KEY=your-weather-key
MCP_WEATHER_TIMEOUT=10
CRM Server
# In .env file
MCP_CRM_URL=https://crm.example.com/api
MCP_CRM_TOKEN=your-crm-token
MCP_CRM_TIMEOUT=20
Server Configuration Parameters
| Parameter | Type | Description | Default |
|-----------|------|----------|---------|-------------|
| URL | string | API endpoint URL | - |
| API_KEY | string | Authentication key | - |
| TOKEN | string | Bearer token | - |
| TIMEOUT | integer | Request timeout in seconds | 30 |
Example Configurations
E-commerce Integration
# Order API
MCP_ORDER_API_URL=https://orders.shop.com/api/v2
MCP_ORDER_API_KEY=sk_order_xxxxx
# Inventory API
MCP_INVENTORY_URL=https://inventory.shop.com/api
MCP_INVENTORY_KEY=inv_key_xxxxx
# Payment API
MCP_PAYMENT_URL=https://payment.shop.com/gateway
MCP_PAYMENT_SECRET=pay_secret_xxxxx
Business Intelligence
# Analytics API
MCP_ANALYTICS_URL=https://analytics.company.com/v1
MCP_ANALYTICS_KEY=analytics_key_xxxxx
# CRM API
MCP_CRM_URL=https://crm.company.com/api
MCP_CRM_TOKEN=crm_token_xxxxx
# Reporting API
MCP_REPORTING_URL=https://reports.company.com/api
MCP_REPORTING_KEY=report_key_xxxxx
Multi-Environment
# Development
MCP_ORDER_API_URL=https://dev-orders.company.com/api
MCP_ORDER_API_KEY=dev_api_key
# Staging
MCP_ORDER_API_URL=https://staging-orders.company.com/api
MCP_ORDER_API_KEY=staging_api_key
# Production
MCP_ORDER_API_URL=https://orders.company.com/api
MCP_ORDER_API_KEY=prod_api_key
Verifying Configuration
import os
def check_mcp_config():
mcp_vars = {k: v for k, v in os.environ.items() if k.startswith('MCP_')}
if not mcp_vars:
print("No MCP servers configured")
return
print(f"Found {len(mcp_vars)} MCP configuration variables:")
servers = set()
for var in mcp_vars.keys():
parts = var.split('_')
if len(parts) >= 3:
servers.add('_'.join(parts[1:2]))
print(f"\nConfigured servers:")
for server in sorted(servers):
print(f" - MCP_{server}")
check_mcp_config()
Using MCP Servers in Agents
Python
import requests
# Create agent with MCP server
response = requests.post(
"http://localhost/api/v1/agent/configs",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"name": "order_support_agent",
"system_prompt": "Help users with their orders using the order API.",
"model": "gpt-4",
"builtin_tools": [],
"mcp_servers": ["ORDER_API"],
"tool_choice": "auto",
"max_iterations": 5
}
)
agent_id = response.json()["id"]
# Chat with agent
chat_response = requests.post(
"http://localhost/api/v1/agent/chat",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"agent_id": agent_id,
"message": "What's the status of order #12345?"
}
)
print(f"Response: {chat_response.json()['response']}")
JavaScript
const response = await fetch('http://localhost/api/v1/agent/configs', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'order_support_agent',
system_prompt: 'Help users with their orders using the order API.',
model: 'gpt-4',
builtin_tools: [],
mcp_servers: ['ORDER_API'],
tool_choice: 'auto',
max_iterations: 5
})
});
const agent = await response.json();
const chatResponse = await fetch('http://localhost/api/v1/agent/chat', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
agent_id: agent.id,
message: "What's the status of order #12345?"
})
});
const result = await chatResponse.json();
console.log('Response:', result.response);
Security Best Practices
API Keys
- Never commit API keys to version control
- Use environment variables
- Rotate keys regularly
- Use separate keys for different environments
- Monitor key usage
Authentication
# Use strong API keys
MCP_ORDER_API_KEY=sk_live_51character_random_string
# Use tokens with expiration
MCP_CRM_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
# Use separate keys for read/write
MCP_ANALYTICS_READ_KEY=key_xxxxx
MCP_ANALYTICS_WRITE_KEY=key_yyyyy
Troubleshooting
Server Not Found
Problem: Agent can't access MCP server
Solution:
- Verify environment variables are set
- Check server URL is correct
- Restart Enclava service
- Review server logs
Authentication Failed
Problem: MCP server returns authentication error
Solution:
- Verify API key/token is correct
- Check key hasn't expired
- Confirm key has required permissions
- Review server documentation
Timeout Errors
Problem: MCP server calls timeout
Solution:
- Increase
TIMEOUTvalue - Check network connectivity
- Review server performance
- Optimize server response time
Next Steps
- Creating Tools - Build MCP tools
- Examples - See MCP in action
- Agent Documentation - Use MCP in agents