|
| 1 | +# Managed Notifications Search MCP Server |
| 2 | + |
| 3 | +An MCP (Model Context Protocol) server that enables AI agents to search through |
| 4 | +OpenShift service notification logs using semantic search powered by ChromaDB and |
| 5 | +sentence transformers. |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +This server provides semantic search capabilities over OpenShift service |
| 10 | +notification JSON files, allowing AI agents to find relevant notifications based |
| 11 | +on problem descriptions. The system uses vector embeddings to enable semantic |
| 12 | +matching rather than just keyword search. |
| 13 | + |
| 14 | +## Features |
| 15 | + |
| 16 | +- **Semantic Search**: Find notifications based on problem descriptions using |
| 17 | + vector similarity |
| 18 | +- **Metadata Enrichment**: Results include folder categories (hcp, osd, rosa, |
| 19 | + etc.), severity levels, and full notification data |
| 20 | +- **Efficient Container Deployment**: Multi-stage Docker build with optimized |
| 21 | + layering for embedding regeneration |
| 22 | +- **Database Statistics**: Get insights into available notifications and categories |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +### Prerequisites |
| 27 | + |
| 28 | +- Python 3.13+ |
| 29 | +- uv (Python package manager) |
| 30 | +- Git |
| 31 | +- Podman or Docker (for containerized deployment) |
| 32 | + |
| 33 | +### Local Development |
| 34 | + |
| 35 | +1. **Clone and setup the repository:** |
| 36 | + |
| 37 | + ```bash |
| 38 | + git clone <repository-url> |
| 39 | + cd managed-notifications |
| 40 | + ``` |
| 41 | + |
| 42 | +2. **Install dependencies:** |
| 43 | + |
| 44 | + ```bash |
| 45 | + uv sync |
| 46 | + ``` |
| 47 | + |
| 48 | +3. **Build the embeddings database:** |
| 49 | + |
| 50 | + ```bash |
| 51 | + uv run build-embeddings |
| 52 | + ``` |
| 53 | + |
| 54 | +4. **Run the MCP server:** |
| 55 | + |
| 56 | + ```bash |
| 57 | + uv run serve |
| 58 | + ``` |
| 59 | + |
| 60 | +### Container Deployment |
| 61 | + |
| 62 | +1. **Build the container:** |
| 63 | + |
| 64 | + ```bash |
| 65 | + podman build -t managed-notifications-search . |
| 66 | + ``` |
| 67 | + |
| 68 | +2. **Run the container:** |
| 69 | + |
| 70 | + ```bash |
| 71 | + podman run -p 8000:8000 managed-notifications-search |
| 72 | + ``` |
| 73 | + |
| 74 | +### MCP Client Configuration |
| 75 | + |
| 76 | +To connect to the server from an MCP client, use the provided configuration file: |
| 77 | + |
| 78 | +**File: `mcp-config.json`** |
| 79 | + |
| 80 | +```json |
| 81 | +{ |
| 82 | + "mcpServers": { |
| 83 | + "service-logs": { |
| 84 | + "type": "http", |
| 85 | + "url": "http://localhost:8000/mcp", |
| 86 | + "auth": {} |
| 87 | + } |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +This configuration enables MCP clients (like Claude Desktop) to connect to the |
| 93 | +running server on localhost port 8000. |
| 94 | + |
| 95 | +## Usage |
| 96 | + |
| 97 | +The server provides two main MCP tools: |
| 98 | + |
| 99 | +### `search_service_logs` |
| 100 | + |
| 101 | +Search for notifications matching a problem statement. |
| 102 | + |
| 103 | +**Parameters:** |
| 104 | + |
| 105 | +- `problem_statement` (required): Description of the issue to search for |
| 106 | +- `max_results` (optional, default: 5): Maximum number of results to return |
| 107 | + |
| 108 | +**Example:** |
| 109 | + |
| 110 | +```python |
| 111 | +# Search for pod scheduling issues |
| 112 | +results = search_service_logs( |
| 113 | + problem_statement="pods stuck in pending state unable to schedule", |
| 114 | + max_results=3 |
| 115 | +) |
| 116 | +``` |
| 117 | + |
| 118 | +**Important Note on Variable Interpolation:** |
| 119 | +Many service notifications contain variable placeholders like `${TIME}`, |
| 120 | +`${REASON}`, `${POD}`, `${NAMESPACE}` that need to be replaced with actual values. |
| 121 | +When using this tool: |
| 122 | + |
| 123 | +1. **Check the `variables` field** in each result to see what variables need interpolation |
| 124 | +2. **Ask users for specific values** for each variable when presenting a notification |
| 125 | +3. **Help interpolate variables** into the notification text before sending to customers |
| 126 | + |
| 127 | +Common variables include: |
| 128 | + |
| 129 | +- `${TIME}`: Timestamp when the issue occurred |
| 130 | +- `${REASON}`: Specific reason for the failure |
| 131 | +- `${POD}`: Name of the affected pod |
| 132 | +- `${NAMESPACE}`: Kubernetes namespace |
| 133 | +- `${CLUSTER_ID}`: Cluster identifier |
| 134 | +- `${NUM_OF_WORKERS}`: Number of worker nodes |
| 135 | + |
| 136 | +### `get_database_stats` |
| 137 | + |
| 138 | +Get statistics about the notification database. |
| 139 | + |
| 140 | +**Returns:** |
| 141 | + |
| 142 | +- Total number of notifications |
| 143 | +- Available folder categories |
| 144 | +- Severity levels |
| 145 | +- Service names |
| 146 | +- Database path |
| 147 | + |
| 148 | +## Architecture |
| 149 | + |
| 150 | +### Components |
| 151 | + |
| 152 | +1. **Embedding Script** (`scripts/build_embeddings.py`): |
| 153 | + - Processes all JSON files in the managed-notifications directory |
| 154 | + - Extracts searchable text from notification fields |
| 155 | + - Creates vector embeddings using sentence-transformers |
| 156 | + - Stores embeddings in ChromaDB with metadata |
| 157 | + |
| 158 | +2. **MCP Server** (`main.py`): |
| 159 | + - FastMCP-based server with search tools |
| 160 | + - Loads pre-built ChromaDB database on startup |
| 161 | + - Provides semantic search and database statistics |
| 162 | + |
| 163 | +3. **Container Configuration**: |
| 164 | + - Multi-stage build separating embedding creation from runtime |
| 165 | + - Optimized layering to minimize rebuilds |
| 166 | + - Non-root user for security |
| 167 | + |
| 168 | +### Data Flow |
| 169 | + |
| 170 | +1. **Build Phase**: JSON files � Text extraction � Vector embeddings � |
| 171 | + ChromaDB |
| 172 | +2. **Runtime Phase**: Problem statement � Query embedding � Similarity search |
| 173 | + � Formatted results |
| 174 | + |
| 175 | +## Notification Categories |
| 176 | + |
| 177 | +The system organizes notifications by folder structure: |
| 178 | + |
| 179 | +- **hcp**: Hosted Control Plane notifications |
| 180 | +- **osd**: OpenShift Dedicated notifications |
| 181 | +- **rosa**: Red Hat OpenShift Service on AWS notifications |
| 182 | +- **cluster**: General cluster notifications |
| 183 | +- **ocm**: OpenShift Cluster Manager notifications |
| 184 | + |
| 185 | +## Development |
| 186 | + |
| 187 | +### Project Structure |
| 188 | + |
| 189 | +```text |
| 190 | +├── main.py # MCP server implementation |
| 191 | +├── scripts/ |
| 192 | +│ └── build_embeddings.py # Embedding creation script |
| 193 | +├── managed-notifications/ # Directory with notification JSONs |
| 194 | +├── Containerfile # Multi-stage container build |
| 195 | +├── .containerignore # Container build exclusions |
| 196 | +└── pyproject.toml # Python dependencies |
| 197 | +``` |
| 198 | + |
| 199 | +### Embedding Model |
| 200 | + |
| 201 | +The system uses the `all-MiniLM-L6-v2` sentence transformer model by default. |
| 202 | +You can override this by setting the `EMBEDDING_MODEL` environment variable in |
| 203 | +the embedding script. |
| 204 | + |
| 205 | +### Database Structure |
| 206 | + |
| 207 | +Each notification is stored with: |
| 208 | + |
| 209 | +- **Document**: Concatenated searchable text (summary, description, tags, etc.) |
| 210 | +- **Metadata**: File path, folder category, severity, service name, variables |
| 211 | + list, full JSON |
| 212 | +- **Embedding**: 384-dimensional vector (for default model) |
| 213 | +- **Variables**: Extracted variable placeholders (e.g., |
| 214 | + `["TIME", "REASON", "POD"]`) for interpolation |
| 215 | + |
| 216 | +## Contributing |
| 217 | + |
| 218 | +1. Ensure the managed-notifications directory is up to date |
| 219 | +2. Run the embedding script after notification changes |
| 220 | +3. Test both local and containerized deployments |
| 221 | +4. Validate search results for accuracy and relevance |
0 commit comments