MCPs
Connect to external services and tools via Model Context Protocol (MCP).
π What are MCPs?
Model Context Protocol (MCP) is a standard way for AI agents to connect to external services and tools. Think of it as a universal adapter for different APIs and services.
MCP Benefits
Standardized Interface: Consistent way to connect to any service
Tool Discovery: Agents can automatically discover available tools
Secure Access: Controlled access to external resources
Extensibility: Easy to add new services and capabilities
π Create an MCP
From Configuration File
from glaip_sdk import Client
client = Client()
# Create MCP from configuration file
# Note: SDK doesn't support config_file parameter directly
# You need to read the file and pass the content as config
import json
with open("weather-mcp-config.json") as f:
config_data = json.load(f)
mcp = client.create_mcp(
name="weather-service",
description="Weather API service",
transport="http",
config=config_data
)
From Inline Configuration
# Create MCP with inline config
mcp = client.create_mcp(
name="simple-mcp",
description="Simple MCP server",
transport="http",
config={
"url": "http://localhost:8080",
"auth_token": "your-token",
"version": "1.0.0"
}
)
Security Best Practice: Avoid committing auth_token
directly in JSON files. Instead, use environment variables or secret management services (Secret Manager, Key Vault) for sensitive credentials.
π Test MCP Connection
# Note: SDK doesn't currently support MCP connection testing
# Use the CLI command instead for reliable connection validation
# Alternative: If your deployment exposes get_mcp_tools, you can attempt a fetch
try:
tools = client.mcps.get_mcp_tools(mcp_id)
print(f"β
MCP connection successful, found {len(tools)} tools")
except Exception as e:
print(f"β MCP connection failed: {e}")
print("π‘ Use 'aip mcps test-connection' for reliable testing")
π List MCP Tools
# Get tools from MCP
mcp = client.get_mcp_by_id("mcp-id")
tools = mcp.get_tools()
# List available tools
for tool in tools:
print(f"Tool: {tool['name']} - {tool['description']}")
π Update an MCP
# Update MCP attributes
updated_mcp = client.update_mcp(
"mcp-id",
description="Updated description",
config={"new_config": "value"}
)
# Or use the MCP object
mcp = client.get_mcp_by_id("mcp-id")
mcp.update(
description="Updated description",
config={"new_config": "value"}
)
ποΈ Delete an MCP
# Delete by ID
client.delete_mcp("mcp-id")
# Or use the MCP object
mcp = client.get_mcp_by_id("mcp-id")
mcp.delete()
π List and Find MCPs
# List all MCPs
all_mcps = client.list_mcps()
# Find MCPs by name
mcps = client.find_mcps("weather")
# Get MCP by ID
mcp = client.get_mcp_by_id("mcp-id")
π MCP Configuration Files
Basic Configuration
{
"url": "https://api.external-service.com",
"auth_token": "your-authentication-token",
"version": "1.0.0",
"transport": "http",
"timeout": 30,
"retry_attempts": 3
}
Advanced Configuration
{
"url": "https://api.external-service.com",
"auth_token": "your-authentication-token",
"version": "1.0.0",
"transport": "http",
"timeout": 30,
"retry_attempts": 3,
"headers": {
"User-Agent": "AIP-SDK/1.0.0",
"Accept": "application/json"
},
"authentication": {
"type": "bearer",
"token": "your-authentication-token"
},
"metadata": {
"description": "External API service for weather data",
"provider": "WeatherAPI",
"capabilities": [
"current_weather",
"forecast",
"historical_data"
],
"rate_limit": "1000 requests per hour",
"supported_locations": [
"cities",
"coordinates",
"zip_codes"
]
},
"tools": [
{
"name": "get_current_weather",
"description": "Get current weather for a location",
"parameters": {
"location": {
"type": "string",
"description": "City name, coordinates, or ZIP code",
"required": true
},
"units": {
"type": "string",
"description": "Temperature units (metric, imperial)",
"default": "metric",
"enum": ["metric", "imperial"]
}
}
},
{
"name": "get_forecast",
"description": "Get weather forecast for a location",
"parameters": {
"location": {
"type": "string",
"description": "City name, coordinates, or ZIP code",
"required": true
},
"days": {
"type": "integer",
"description": "Number of days for forecast (1-7)",
"default": 3,
"minimum": 1,
"maximum": 7
}
}
}
]
}
π§ MCP Configuration
Basic Parameters
name
Unique MCP name
-
Yes
description
Human-readable description
None
No
transport
Transport protocol
"http"
No
config
Configuration dictionary
{}
No
config_file
Path to config file
None
No
Transport Types
HTTP: Standard HTTP/HTTPS connections
SSE: Server-Sent Events for streaming
WebSocket: Real-time bidirectional communication
Authentication Types
Bearer Token: Simple token-based authentication
API Key: API key in headers or query parameters
OAuth2: OAuth 2.0 flow for secure access
Custom: Custom authentication schemes
π― Best Practices
MCP Design
Clear Documentation: Document all available tools and parameters
Error Handling: Provide meaningful error messages
Rate Limiting: Respect API rate limits and implement backoff
Security: Use secure authentication and HTTPS
Configuration Management
Environment Variables: Use environment variables for sensitive data
Configuration Files: Keep configurations in version-controlled files
Validation: Validate configuration before creating MCPs
Testing: Test connections before production use
Performance
Connection Pooling: Reuse connections when possible
Timeout Settings: Set appropriate timeouts for different operations
Caching: Cache responses when appropriate
Monitoring: Track MCP performance and availability
π MCP Lifecycle
1. Planning
Identify external services you want to connect to
Review API documentation and capabilities
Plan authentication and security requirements
2. Configuration
Create configuration file with service details
Set up authentication credentials
Define tool schemas and parameters
3. Testing
Test connection using the test command
Verify tool discovery and functionality
Check error handling and edge cases
4. Integration
Create MCP on the platform
Attach to agents that need external capabilities
Monitor performance and usage
5. Maintenance
Update configurations as services evolve
Monitor for errors and performance issues
Rotate credentials regularly
π Next Steps
Streaming: Use Streaming & Renderers for real-time MCP output
File Uploads: Handle files with File Uploads
Output & Scripting: Automate MCP workflows with Output & Scripting
Build Agents: Create agents that use Tools from MCPs
π‘ Pro Tips
Start Simple: Begin with basic HTTP MCPs and gradually add complexity
Test Thoroughly: Always test connections before production use
Document Everything: Keep detailed records of MCP configurations
Monitor Performance: Track response times and error rates
Plan for Scale: Design configurations that can handle growth
Security First: Use secure authentication and validate all inputs
Ready to connect to external services? Start with simple APIs and gradually build more complex integrations!