Skip to content

Commit 0b3070a

Browse files
committed
feat: Add TCP server support for external AI services
- Implement dual transport mode (stdio/TCP) for MCP server - Add StreamableHTTPServerTransport for network accessibility - Support command-line arguments for host and port configuration - Update CLI with --host and --port options for TCP mode - Add comprehensive TCP server documentation and examples - Create test script for TCP server validation - Maintain backward compatibility with stdio mode - Add security considerations and best practices This enables integration with ChatGPT and other AI services that require HTTP-based MCP server connections rather than subprocess spawning. The server can now run on network ports while preserving the original stdio functionality for traditional MCP clients. Closes #70
1 parent e50b753 commit 0b3070a

File tree

6 files changed

+525
-16
lines changed

6 files changed

+525
-16
lines changed

docs/docs/mcp.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ export GACC_API_KEY="your-gallagher-api-key-here"
3737
#### Via CLI
3838

3939
```bash
40-
# Start the MCP server
40+
# Start the MCP server (stdio mode)
4141
gala mcp serve
4242

43+
# Start the MCP server (TCP mode)
44+
gala mcp serve --port 8080 --host 0.0.0.0
45+
4346
# Show configuration information
4447
gala mcp config
4548

@@ -50,9 +53,33 @@ gala mcp test
5053
#### Direct Module Execution
5154

5255
```bash
56+
# Stdio mode (default)
5357
python -m gallagher.mcp
58+
59+
# TCP mode
60+
python -m gallagher.mcp.server --port 8080 --host 0.0.0.0
5461
```
5562

63+
### Transport Modes
64+
65+
The MCP server supports two transport modes:
66+
67+
#### Stdio Mode (Default)
68+
69+
- Runs on standard input/output
70+
- Used by MCP clients that spawn subprocesses
71+
- Secure for local use
72+
- No network exposure
73+
74+
#### TCP Mode
75+
76+
- Runs on a network port
77+
- Accessible via HTTP
78+
- Suitable for external AI services like ChatGPT
79+
- Requires network security considerations
80+
81+
For detailed TCP server documentation, see [TCP Server Guide](tcp-server.md).
82+
5683
### Claude Desktop Configuration
5784

5885
Add the following to your Claude Desktop MCP configuration:
@@ -71,6 +98,20 @@ Add the following to your Claude Desktop MCP configuration:
7198
}
7299
```
73100

101+
### ChatGPT and External AI Services
102+
103+
For services that don't support subprocess-based MCP servers:
104+
105+
```bash
106+
# Start TCP server
107+
gala mcp serve --port 8080 --host 0.0.0.0
108+
```
109+
110+
Then configure your AI service to connect to:
111+
112+
- **URL**: `http://your-server-ip:8080`
113+
- **Protocol**: MCP over HTTP
114+
74115
### Other MCP Clients
75116

76117
For other MCP clients, you can run the server directly:

docs/docs/tcp-server.md

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
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

Comments
 (0)