|
| 1 | +# TCP Server for AI Services |
| 2 | + |
| 3 | +The Gallagher MCP server now supports running as a TCP server, making it accessible to AI services like ChatGPT, Claude, and other external applications that can connect via HTTP. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The TCP server mode allows the Gallagher MCP server to: |
| 8 | + |
| 9 | +- Run on a network port instead of stdio |
| 10 | +- Accept connections from external AI services |
| 11 | +- Provide the same cardholder querying functionality over HTTP |
| 12 | +- Work with services that don't support subprocess-based MCP servers |
| 13 | + |
| 14 | +## Quick Start |
| 15 | + |
| 16 | +### 1. Set your API key |
| 17 | + |
| 18 | +```bash |
| 19 | +export GACC_API_KEY="your-gallagher-api-key-here" |
| 20 | +``` |
| 21 | + |
| 22 | +### 2. Start the TCP server |
| 23 | + |
| 24 | +```bash |
| 25 | +# Using the CLI |
| 26 | +gala mcp serve --port 8080 --host 0.0.0.0 |
| 27 | + |
| 28 | +# Or directly with Python |
| 29 | +python -m gallagher.mcp.server --port 8080 --host 0.0.0.0 |
| 30 | +``` |
| 31 | + |
| 32 | +### 3. Connect from your AI service |
| 33 | + |
| 34 | +Configure your AI service to connect to: |
| 35 | + |
| 36 | +- **URL**: `http://your-server-ip:8080` |
| 37 | +- **Protocol**: MCP over HTTP |
| 38 | + |
| 39 | +## Configuration Options |
| 40 | + |
| 41 | +### Host Binding |
| 42 | + |
| 43 | +- `--host localhost` (default): Only accessible from the local machine |
| 44 | +- `--host 0.0.0.0`: Accessible from any network interface |
| 45 | +- `--host 192.168.1.100`: Bind to a specific IP address |
| 46 | + |
| 47 | +### Port Selection |
| 48 | + |
| 49 | +- Choose any available port (e.g., 8080, 3000, 5000) |
| 50 | +- Avoid using privileged ports (below 1024) |
| 51 | +- Ensure the port is not already in use |
| 52 | + |
| 53 | +## Usage Examples |
| 54 | + |
| 55 | +### Local Development |
| 56 | + |
| 57 | +```bash |
| 58 | +# Start server for local testing |
| 59 | +gala mcp serve --port 8080 --host localhost |
| 60 | +``` |
| 61 | + |
| 62 | +### Production Deployment |
| 63 | + |
| 64 | +```bash |
| 65 | +# Start server accessible from network |
| 66 | +gala mcp serve --port 8080 --host 0.0.0.0 |
| 67 | +``` |
| 68 | + |
| 69 | +### Docker Deployment |
| 70 | + |
| 71 | +```dockerfile |
| 72 | +FROM python:3.10-slim |
| 73 | + |
| 74 | +RUN pip install gallagher |
| 75 | + |
| 76 | +EXPOSE 8080 |
| 77 | + |
| 78 | +CMD ["python", "-m", "gallagher.mcp.server", "--port", "8080", "--host", "0.0.0.0"] |
| 79 | +``` |
| 80 | + |
| 81 | +## Available Tools |
| 82 | + |
| 83 | +The TCP server provides the same tools as the stdio server: |
| 84 | + |
| 85 | +- **list_cardholders** - List all cardholders in the system |
| 86 | +- **search_cardholders** - Search for cardholders by name or criteria |
| 87 | +- **get_cardholder** - Get detailed information about a specific cardholder |
| 88 | +- **get_cardholder_cards** - Get all cards assigned to a cardholder |
| 89 | +- **get_cardholder_access_groups** - Get all access groups assigned to a cardholder |
| 90 | + |
| 91 | +## Testing the Server |
| 92 | + |
| 93 | +### Using curl |
| 94 | + |
| 95 | +```bash |
| 96 | +# Test server connectivity |
| 97 | +curl http://localhost:8080/health |
| 98 | + |
| 99 | +# List available tools |
| 100 | +curl -X POST http://localhost:8080/ \ |
| 101 | + -H "Content-Type: application/json" \ |
| 102 | + -d '{ |
| 103 | + "jsonrpc": "2.0", |
| 104 | + "id": 1, |
| 105 | + "method": "tools/list", |
| 106 | + "params": {} |
| 107 | + }' |
| 108 | +``` |
| 109 | + |
| 110 | +### Using the test script |
| 111 | + |
| 112 | +```bash |
| 113 | +python examples/tcp_server_test.py |
| 114 | +``` |
| 115 | + |
| 116 | +## Security Considerations |
| 117 | + |
| 118 | +### Network Security |
| 119 | + |
| 120 | +- **Firewall**: Restrict access to the server port |
| 121 | +- **Localhost only**: Use `--host localhost` for local-only access |
| 122 | +- **VPN**: Use VPN for remote access |
| 123 | +- **Reverse proxy**: Use nginx/apache with SSL termination |
| 124 | + |
| 125 | +### Authentication |
| 126 | + |
| 127 | +The current implementation relies on network-level security. For production use, consider: |
| 128 | + |
| 129 | +- Implementing API key authentication |
| 130 | +- Using HTTPS/TLS |
| 131 | +- Adding rate limiting |
| 132 | +- Implementing request validation |
| 133 | + |
| 134 | +### Environment Variables |
| 135 | + |
| 136 | +- Keep your `GACC_API_KEY` secure |
| 137 | +- Use environment-specific configuration |
| 138 | +- Consider using a secrets manager |
| 139 | + |
| 140 | +## Troubleshooting |
| 141 | + |
| 142 | +### Common Issues |
| 143 | + |
| 144 | +1. **Port already in use** |
| 145 | + |
| 146 | + ```bash |
| 147 | + # Check what's using the port |
| 148 | + lsof -i :8080 |
| 149 | + |
| 150 | + # Use a different port |
| 151 | + gala mcp serve --port 8081 |
| 152 | + ``` |
| 153 | + |
| 154 | +2. **Connection refused** |
| 155 | + |
| 156 | + - Check if the server is running |
| 157 | + - Verify the host and port settings |
| 158 | + - Check firewall settings |
| 159 | + |
| 160 | +3. **Authentication errors** |
| 161 | + - Verify `GACC_API_KEY` is set correctly |
| 162 | + - Check Gallagher Command Centre connectivity |
| 163 | + - Test with the stdio server first |
| 164 | + |
| 165 | +### Debug Mode |
| 166 | + |
| 167 | +```bash |
| 168 | +# Run with verbose logging |
| 169 | +python -m gallagher.mcp.server --port 8080 --host localhost |
| 170 | +``` |
| 171 | + |
| 172 | +## Integration Examples |
| 173 | + |
| 174 | +### ChatGPT Plugin |
| 175 | + |
| 176 | +```json |
| 177 | +{ |
| 178 | + "name": "gallagher-mcp", |
| 179 | + "description": "Gallagher Command Centre integration", |
| 180 | + "endpoint": "http://localhost:8080", |
| 181 | + "protocol": "mcp" |
| 182 | +} |
| 183 | +``` |
| 184 | + |
| 185 | +### Custom AI Service |
| 186 | + |
| 187 | +```python |
| 188 | +import requests |
| 189 | + |
| 190 | +# Connect to Gallagher MCP server |
| 191 | +response = requests.post( |
| 192 | + "http://localhost:8080/", |
| 193 | + json={ |
| 194 | + "jsonrpc": "2.0", |
| 195 | + "id": 1, |
| 196 | + "method": "tools/call", |
| 197 | + "params": { |
| 198 | + "name": "list_cardholders", |
| 199 | + "arguments": {"limit": 10} |
| 200 | + } |
| 201 | + }, |
| 202 | + headers={"Content-Type": "application/json"} |
| 203 | +) |
| 204 | + |
| 205 | +print(response.json()) |
| 206 | +``` |
| 207 | + |
| 208 | +## Performance Considerations |
| 209 | + |
| 210 | +- The server handles one request at a time by default |
| 211 | +- For high-load scenarios, consider running multiple instances |
| 212 | +- Monitor memory usage with large cardholder datasets |
| 213 | +- Use connection pooling for external Gallagher API calls |
| 214 | + |
| 215 | +## Monitoring |
| 216 | + |
| 217 | +### Health Check |
| 218 | + |
| 219 | +```bash |
| 220 | +curl http://localhost:8080/health |
| 221 | +``` |
| 222 | + |
| 223 | +### Logs |
| 224 | + |
| 225 | +Monitor server logs for: |
| 226 | + |
| 227 | +- Connection attempts |
| 228 | +- API call results |
| 229 | +- Error messages |
| 230 | +- Performance metrics |
| 231 | + |
| 232 | +## Support |
| 233 | + |
| 234 | +For issues with the TCP server: |
| 235 | + |
| 236 | +1. Check the troubleshooting section above |
| 237 | +2. Test with the stdio server first |
| 238 | +3. Review the main MCP documentation |
| 239 | +4. Check Gallagher Command Centre connectivity |
0 commit comments