|
| 1 | +# MCP (Model Context Protocol) Server |
| 2 | + |
| 3 | +The Gallagher Command Centre toolkit includes an MCP server that exposes cardholder querying functionality through the Model Context Protocol. This allows AI assistants to query Gallagher Command Centre data directly. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The MCP server provides tools for: |
| 8 | + |
| 9 | +- Listing all cardholders in the system |
| 10 | +- Searching for cardholders by name or other criteria |
| 11 | +- Getting detailed information about specific cardholders |
| 12 | +- Retrieving cards assigned to cardholders |
| 13 | +- Getting access groups assigned to cardholders |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +The MCP dependencies are included in the main package. No additional installation is required. |
| 18 | + |
| 19 | +## Configuration |
| 20 | + |
| 21 | +### Environment Variables |
| 22 | + |
| 23 | +The MCP server requires the following environment variable: |
| 24 | + |
| 25 | +- `GACC_API_KEY`: Your Gallagher Command Centre API key |
| 26 | + |
| 27 | +### Setting up the API Key |
| 28 | + |
| 29 | +```bash |
| 30 | +export GACC_API_KEY="your-gallagher-api-key-here" |
| 31 | +``` |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +### Running the MCP Server |
| 36 | + |
| 37 | +#### Via CLI |
| 38 | + |
| 39 | +```bash |
| 40 | +# Start the MCP server |
| 41 | +gala mcp serve |
| 42 | + |
| 43 | +# Show configuration information |
| 44 | +gala mcp config |
| 45 | + |
| 46 | +# Test the server functionality |
| 47 | +gala mcp test |
| 48 | +``` |
| 49 | + |
| 50 | +#### Direct Module Execution |
| 51 | + |
| 52 | +```bash |
| 53 | +python -m gallagher.mcp |
| 54 | +``` |
| 55 | + |
| 56 | +### Claude Desktop Configuration |
| 57 | + |
| 58 | +Add the following to your Claude Desktop MCP configuration: |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "mcpServers": { |
| 63 | + "gallagher": { |
| 64 | + "command": "python", |
| 65 | + "args": ["-m", "gallagher.mcp.server"], |
| 66 | + "env": { |
| 67 | + "GACC_API_KEY": "your-gallagher-api-key-here" |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### Other MCP Clients |
| 75 | + |
| 76 | +For other MCP clients, you can run the server directly: |
| 77 | + |
| 78 | +```bash |
| 79 | +export GACC_API_KEY="your-gallagher-api-key-here" |
| 80 | +python -m gallagher.mcp.server |
| 81 | +``` |
| 82 | + |
| 83 | +## Available Tools |
| 84 | + |
| 85 | +### list_cardholders |
| 86 | + |
| 87 | +Lists all cardholders in the system. |
| 88 | + |
| 89 | +**Parameters:** |
| 90 | + |
| 91 | +- `limit` (integer, optional): Maximum number of cardholders to return (default: 100) |
| 92 | +- `skip` (integer, optional): Number of cardholders to skip for pagination (default: 0) |
| 93 | + |
| 94 | +**Example:** |
| 95 | + |
| 96 | +```json |
| 97 | +{ |
| 98 | + "name": "list_cardholders", |
| 99 | + "arguments": { |
| 100 | + "limit": 10 |
| 101 | + } |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +### search_cardholders |
| 106 | + |
| 107 | +Searches for cardholders by name or other criteria. |
| 108 | + |
| 109 | +**Parameters:** |
| 110 | + |
| 111 | +- `name` (string, required): First or last name to search for |
| 112 | +- `description` (string, optional): Keywords to search in description |
| 113 | +- `division` (integer, optional): Division ID for hierarchical search |
| 114 | +- `authorised_only` (boolean, optional): Only return authorised cardholders (default: false) |
| 115 | +- `limit` (integer, optional): Maximum number of results to return (default: 100) |
| 116 | +- `sort` (string, optional): Sort order - "id", "name", "-id", or "-name" (default: "name") |
| 117 | + |
| 118 | +**Example:** |
| 119 | + |
| 120 | +```json |
| 121 | +{ |
| 122 | + "name": "search_cardholders", |
| 123 | + "arguments": { |
| 124 | + "name": "John", |
| 125 | + "authorised_only": true, |
| 126 | + "limit": 5 |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +### get_cardholder |
| 132 | + |
| 133 | +Gets detailed information about a specific cardholder. |
| 134 | + |
| 135 | +**Parameters:** |
| 136 | + |
| 137 | +- `id` (integer, required): Cardholder ID |
| 138 | + |
| 139 | +**Example:** |
| 140 | + |
| 141 | +```json |
| 142 | +{ |
| 143 | + "name": "get_cardholder", |
| 144 | + "arguments": { |
| 145 | + "id": 123 |
| 146 | + } |
| 147 | +} |
| 148 | +``` |
| 149 | + |
| 150 | +### get_cardholder_cards |
| 151 | + |
| 152 | +Gets all cards assigned to a specific cardholder. |
| 153 | + |
| 154 | +**Parameters:** |
| 155 | + |
| 156 | +- `id` (integer, required): Cardholder ID |
| 157 | + |
| 158 | +**Example:** |
| 159 | + |
| 160 | +```json |
| 161 | +{ |
| 162 | + "name": "get_cardholder_cards", |
| 163 | + "arguments": { |
| 164 | + "id": 123 |
| 165 | + } |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +### get_cardholder_access_groups |
| 170 | + |
| 171 | +Gets all access groups assigned to a specific cardholder. |
| 172 | + |
| 173 | +**Parameters:** |
| 174 | + |
| 175 | +- `id` (integer, required): Cardholder ID |
| 176 | + |
| 177 | +**Example:** |
| 178 | + |
| 179 | +```json |
| 180 | +{ |
| 181 | + "name": "get_cardholder_access_groups", |
| 182 | + "arguments": { |
| 183 | + "id": 123 |
| 184 | + } |
| 185 | +} |
| 186 | +``` |
| 187 | + |
| 188 | +## Example Usage |
| 189 | + |
| 190 | +Here's an example of how to use the MCP server programmatically: |
| 191 | + |
| 192 | +```python |
| 193 | +import asyncio |
| 194 | +from gallagher.mcp.server import GallagherMCPServer |
| 195 | + |
| 196 | +async def main(): |
| 197 | + server = GallagherMCPServer() |
| 198 | + |
| 199 | + # List cardholders |
| 200 | + result = await server._list_cardholders({"limit": 5}) |
| 201 | + print(result.content[0].text) |
| 202 | + |
| 203 | + # Search for cardholders |
| 204 | + result = await server._search_cardholders({ |
| 205 | + "name": "John", |
| 206 | + "authorised_only": True |
| 207 | + }) |
| 208 | + print(result.content[0].text) |
| 209 | + |
| 210 | +asyncio.run(main()) |
| 211 | +``` |
| 212 | + |
| 213 | +## Error Handling |
| 214 | + |
| 215 | +The MCP server handles various error conditions: |
| 216 | + |
| 217 | +- **Authentication Error**: Occurs when the API key is invalid or missing |
| 218 | +- **Not Found Error**: Occurs when a requested resource doesn't exist |
| 219 | +- **Network Error**: Occurs when there are connectivity issues |
| 220 | + |
| 221 | +All errors are returned as structured error responses with descriptive messages. |
| 222 | + |
| 223 | +## Security Considerations |
| 224 | + |
| 225 | +- The API key should be kept secure and not shared |
| 226 | +- The server runs on stdio by default, which is secure for local use |
| 227 | +- Consider using environment variables for API key storage |
| 228 | +- The server only provides read access to cardholder data |
| 229 | + |
| 230 | +## Troubleshooting |
| 231 | + |
| 232 | +### Common Issues |
| 233 | + |
| 234 | +1. **Authentication Error**: Ensure the `GACC_API_KEY` environment variable is set correctly |
| 235 | +2. **Import Error**: Make sure all dependencies are installed |
| 236 | +3. **Network Error**: Check your network connection and Gallagher Command Centre accessibility |
| 237 | + |
| 238 | +### Testing |
| 239 | + |
| 240 | +Use the built-in test command to verify functionality: |
| 241 | + |
| 242 | +```bash |
| 243 | +gala mcp test |
| 244 | +``` |
| 245 | + |
| 246 | +This will test basic connectivity and cardholder operations. |
| 247 | + |
| 248 | +## Development |
| 249 | + |
| 250 | +The MCP server is built using the official MCP Python SDK and integrates with the existing Gallagher Command Centre API client. The server follows the MCP specification and provides a clean interface for AI assistants to query cardholder data. |
0 commit comments