This guide explains how to integrate Loopgate with various AI systems using the Model Context Protocol (MCP).
Loopgate implements MCP 2.0 specification and exposes the following tools:
request_human_input- Request human approval/inputcheck_request_status- Poll request statuslist_pending_requests- List pending requestscancel_request- Cancel a request
# Start as standalone MCP server (stdio)
./loopgate
# Or start as HTTP server with MCP endpoint
make runimport "loopgate/pkg/client"
client := client.NewMCPClient()
err := client.ConnectToServer("./loopgate")
if err != nil {
log.Fatal(err)
}
err = client.Initialize("MyAI", "1.0.0")
if err != nil {
log.Fatal(err)
}tools, err := client.ListTools()
if err != nil {
log.Fatal(err)
}
for _, tool := range tools {
fmt.Printf("Tool: %s - %s\n", tool.Name, tool.Description)
}response, err := client.SendHITLRequest(
"my-session",
"my-ai-agent",
"Should I proceed with deployment?",
[]string{"Yes", "No", "Review First"},
map[string]interface{}{
"environment": "production",
"version": "v1.2.3",
},
)Add to your Claude Desktop MCP configuration:
{
"mcpServers": {
"loopgate": {
"command": "/path/to/loopgate",
"args": []
}
}
}import { MCPClient } from '@modelcontextprotocol/sdk/client';
const client = new MCPClient({
name: "my-ai-agent",
version: "1.0.0"
});
await client.connect({
command: "./loopgate",
args: []
});
// Request human approval
const result = await client.callTool("request_human_input", {
session_id: "my-session",
client_id: "my-ai",
message: "Approve this action?",
options: ["Approve", "Deny"]
});For systems that prefer HTTP:
# POST to /mcp endpoint
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{
"method": "tools/call",
"params": {
"name": "request_human_input",
"arguments": {
"session_id": "test",
"client_id": "test",
"message": "Test message"
}
},
"id": "1"
}'MCP responses include error information:
{
"error": {
"code": -32601,
"message": "Method not found",
"data": null
},
"id": "1"
}Common error codes:
-32700: Parse error-32600: Invalid request-32601: Method not found-32602: Invalid params
- Session Management: Always register sessions before sending requests
- Error Handling: Check for MCP errors in responses
- Timeouts: Set appropriate timeouts for requests
- Cleanup: Close MCP connections properly
- Logging: Log MCP interactions for debugging
- Ensure Loopgate binary is executable
- Check that stdio pipes are working
- Verify process permissions
- Validate tool parameters against schema
- Check session registration status
- Verify Telegram bot configuration
- Use HTTP mode for high-throughput scenarios
- Implement connection pooling for multiple agents
- Monitor memory usage with many concurrent requests