iflow-mcp_splunk_splunk-mcp-server 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/PKG-INFO +391 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/README.md +381 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/guardrails.py +307 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/helpers.py +117 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/iflow_mcp_splunk_splunk_mcp_server.egg-info/PKG-INFO +391 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/iflow_mcp_splunk_splunk_mcp_server.egg-info/SOURCES.txt +14 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/iflow_mcp_splunk_splunk_mcp_server.egg-info/dependency_links.txt +1 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/iflow_mcp_splunk_splunk_mcp_server.egg-info/entry_points.txt +2 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/iflow_mcp_splunk_splunk_mcp_server.egg-info/requires.txt +3 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/iflow_mcp_splunk_splunk_mcp_server.egg-info/top_level.txt +4 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/pyproject.toml +21 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/server.py +637 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/setup.cfg +4 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/splunk_client.py +336 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/tests/test_sse_transport.py +243 -0
- iflow_mcp_splunk_splunk_mcp_server-0.1.0/tests/test_stdio_transport.py +267 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iflow-mcp_splunk_splunk-mcp-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server for retrieving data from Splunk
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: mcp[cli]>=1.3.0
|
|
8
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
9
|
+
Requires-Dist: httpx>=0.25.0
|
|
10
|
+
|
|
11
|
+
# Splunk MCP Server
|
|
12
|
+
|
|
13
|
+
An MCP (Model Context Protocol) server for retrieving data from Splunk Enterprise or Splunk Cloud.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **FastMCP Framework**: Simplified server implementation
|
|
18
|
+
- **Splunk Integration**: Direct REST API integration (no SDK dependency)
|
|
19
|
+
- **Multiple Transports**: Supports both stdio and SSE
|
|
20
|
+
- **Docker Support**: Ready for containerized deployment
|
|
21
|
+
- **SPL Query Validation**: Built-in guardrails to detect risky, inefficient, or destructive queries
|
|
22
|
+
- **Output Sanitization**: Automatic masking of sensitive data (credit cards, SSNs)
|
|
23
|
+
- **Multiple Output Formats**: JSON, Markdown, CSV, and Summary formats
|
|
24
|
+
- **Essential Tools**:
|
|
25
|
+
- `validate_spl`: Validate SPL queries for risks and inefficiencies
|
|
26
|
+
- `search_oneshot`: Run blocking search queries
|
|
27
|
+
- `search_export`: Stream search results immediately
|
|
28
|
+
- `get_indexes`: List available Splunk indexes
|
|
29
|
+
- `get_saved_searches`: List saved searches
|
|
30
|
+
- `run_saved_search`: Execute saved searches
|
|
31
|
+
- `get_config`: Get server configuration
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
### 1. Setup Environment
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
cd /path/to/splunk-mcp-server/python
|
|
39
|
+
cp .env.example .env
|
|
40
|
+
# Edit .env with your Splunk connection details
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Install Dependencies
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install -e .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 3. Run the Server
|
|
50
|
+
|
|
51
|
+
**SSE Mode (default):**
|
|
52
|
+
```bash
|
|
53
|
+
python server.py
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Stdio Mode:**
|
|
57
|
+
Configure via environment or let the client spawn the server.
|
|
58
|
+
|
|
59
|
+
### 4. Test with Example Clients
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cd tests
|
|
63
|
+
|
|
64
|
+
# For SSE transport
|
|
65
|
+
python test_sse_transport.py
|
|
66
|
+
|
|
67
|
+
# For stdio transport
|
|
68
|
+
python test_stdio_transport.py
|
|
69
|
+
|
|
70
|
+
# Test SPL validation interactively
|
|
71
|
+
python validate_spl_test.py
|
|
72
|
+
|
|
73
|
+
# Interactive SPL search
|
|
74
|
+
python splunk_sse_search.py
|
|
75
|
+
|
|
76
|
+
# Or use the comprehensive test menu
|
|
77
|
+
./testall
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Docker Deployment
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Using the dock script for common operations:
|
|
84
|
+
|
|
85
|
+
# Build and start containers
|
|
86
|
+
./dock rebuild
|
|
87
|
+
|
|
88
|
+
# Start containers
|
|
89
|
+
./dock up # or ./dock start
|
|
90
|
+
|
|
91
|
+
# Stop containers
|
|
92
|
+
./dock down # or ./dock stop
|
|
93
|
+
|
|
94
|
+
# Restart containers
|
|
95
|
+
./dock restart
|
|
96
|
+
|
|
97
|
+
# Manual docker commands:
|
|
98
|
+
sudo docker compose build --no-cache
|
|
99
|
+
sudo docker compose up -d
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Client Configuration
|
|
103
|
+
|
|
104
|
+
### Claude Desktop
|
|
105
|
+
|
|
106
|
+
**SSE Mode Configuration:**
|
|
107
|
+
|
|
108
|
+
Edit your Claude Desktop configuration file:
|
|
109
|
+
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
110
|
+
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
111
|
+
- Linux: `~/.config/claude/claude_desktop_config.json`
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"mcpServers": {
|
|
116
|
+
"splunk-mcp": {
|
|
117
|
+
"url": "http://localhost:8050/sse"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Stdio Mode Configuration:**
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"mcpServers": {
|
|
128
|
+
"splunk-mcp": {
|
|
129
|
+
"command": "python",
|
|
130
|
+
"args": ["/path/to/splunk-mcp-server/python/server.py"],
|
|
131
|
+
"env": {
|
|
132
|
+
"TRANSPORT": "stdio",
|
|
133
|
+
"SPLUNK_HOST": "your-splunk-host",
|
|
134
|
+
"SPLUNK_USERNAME": "your-username",
|
|
135
|
+
"SPLUNK_PASSWORD": "your-password"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Claude Code
|
|
143
|
+
|
|
144
|
+
**SSE Mode Configuration:**
|
|
145
|
+
|
|
146
|
+
Start the server:
|
|
147
|
+
```bash
|
|
148
|
+
cd /path/to/splunk-mcp-server/python
|
|
149
|
+
python server.py
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Add to Claude Code:
|
|
153
|
+
```bash
|
|
154
|
+
claude mcp add --transport sse --scope project splunk-mcp-server http://localhost:8050/sse
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Stdio Mode Configuration:**
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
cd /path/to/splunk-mcp-server/python
|
|
161
|
+
claude mcp add splunk-mcp-server -e TRANSPORT=stdio --scope project -e SPLUNK_HOST=your-host -e SPLUNK_USERNAME=your-user -e SPLUNK_PASSWORD=your-pass -- python server.py
|
|
162
|
+
|
|
163
|
+
# claude mcp remove splunk-mcp-server [--scope project]
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Available Tools
|
|
167
|
+
|
|
168
|
+
### validate_spl
|
|
169
|
+
Validate an SPL query for potential risks and inefficiencies before execution.
|
|
170
|
+
|
|
171
|
+
Parameters:
|
|
172
|
+
- `query`: The SPL query to validate
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
- `risk_score`: Risk score from 0-100
|
|
176
|
+
- `risk_message`: Detailed explanation of risks found with suggestions
|
|
177
|
+
- `risk_tolerance`: Current risk tolerance setting
|
|
178
|
+
- `would_execute`: Whether this query would execute or be blocked
|
|
179
|
+
- `execution_note`: Clear message about execution status
|
|
180
|
+
|
|
181
|
+
Example:
|
|
182
|
+
```
|
|
183
|
+
validate_spl("index=* | delete")
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### search_oneshot
|
|
187
|
+
Run a blocking search query and return results.
|
|
188
|
+
|
|
189
|
+
Parameters:
|
|
190
|
+
- `query`: Splunk search query (e.g., "index=main | head 10")
|
|
191
|
+
- `earliest_time`: Start time (default: "-24h")
|
|
192
|
+
- `latest_time`: End time (default: "now")
|
|
193
|
+
- `max_count`: Maximum results (default: 100 or SPL_MAX_EVENTS_COUNT)
|
|
194
|
+
- `output_format`: Format for results - json, markdown/md, csv, or summary (default: "json")
|
|
195
|
+
- `risk_tolerance`: Override risk tolerance level (default: SPL_RISK_TOLERANCE)
|
|
196
|
+
- `sanitize_output`: Override output sanitization (default: SPL_SANITIZE_OUTPUT)
|
|
197
|
+
|
|
198
|
+
Example:
|
|
199
|
+
```
|
|
200
|
+
search_oneshot("index=_internal | head 5", earliest_time="-1h", output_format="markdown")
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### search_export
|
|
204
|
+
Stream search results immediately without creating a job.
|
|
205
|
+
|
|
206
|
+
Parameters:
|
|
207
|
+
- `query`: Splunk search query
|
|
208
|
+
- `earliest_time`: Start time (default: "-24h")
|
|
209
|
+
- `latest_time`: End time (default: "now")
|
|
210
|
+
- `max_count`: Maximum results (default: 100 or SPL_MAX_EVENTS_COUNT)
|
|
211
|
+
- `output_format`: Format for results - json, markdown/md, csv, or summary (default: "json")
|
|
212
|
+
- `risk_tolerance`: Override risk tolerance level (default: SPL_RISK_TOLERANCE)
|
|
213
|
+
- `sanitize_output`: Override output sanitization (default: SPL_SANITIZE_OUTPUT)
|
|
214
|
+
|
|
215
|
+
### get_indexes
|
|
216
|
+
List all available Splunk indexes with properties.
|
|
217
|
+
|
|
218
|
+
### get_saved_searches
|
|
219
|
+
List all saved searches with their queries and descriptions.
|
|
220
|
+
|
|
221
|
+
### run_saved_search
|
|
222
|
+
Execute a saved search by name.
|
|
223
|
+
|
|
224
|
+
Parameters:
|
|
225
|
+
- `search_name`: Name of the saved search
|
|
226
|
+
- `trigger_actions`: Whether to trigger actions (default: False)
|
|
227
|
+
|
|
228
|
+
### get_config
|
|
229
|
+
Get current server configuration (excludes sensitive data).
|
|
230
|
+
|
|
231
|
+
## Configuration
|
|
232
|
+
|
|
233
|
+
Edit `.env` file to customize:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# Server Configuration
|
|
237
|
+
SERVER_NAME=Splunk MCP
|
|
238
|
+
SERVER_DESCRIPTION=MCP server for retrieving data from Splunk
|
|
239
|
+
HOST=0.0.0.0
|
|
240
|
+
PORT=8050
|
|
241
|
+
TRANSPORT=sse
|
|
242
|
+
LOG_LEVEL=INFO
|
|
243
|
+
|
|
244
|
+
# Splunk Configuration
|
|
245
|
+
SPLUNK_HOST=localhost
|
|
246
|
+
SPLUNK_PORT=8089
|
|
247
|
+
SPLUNK_USERNAME=admin
|
|
248
|
+
SPLUNK_PASSWORD=changeme
|
|
249
|
+
# Optional: Use token instead of username/password
|
|
250
|
+
SPLUNK_TOKEN=
|
|
251
|
+
# SSL verification
|
|
252
|
+
VERIFY_SSL=false
|
|
253
|
+
|
|
254
|
+
# Search Configuration
|
|
255
|
+
# Maximum number of events to return from searches (0 = unlimited)
|
|
256
|
+
SPL_MAX_EVENTS_COUNT=100000
|
|
257
|
+
|
|
258
|
+
# Risk tolerance level for SPL query validation (0 = reject all risky queries, 100 = allow all)
|
|
259
|
+
SPL_RISK_TOLERANCE=75
|
|
260
|
+
|
|
261
|
+
# Safe time range for searches - queries within this range get no time penalty
|
|
262
|
+
SPL_SAFE_TIMERANGE=24h
|
|
263
|
+
|
|
264
|
+
# Enable output sanitization to mask sensitive data (credit cards, SSNs)
|
|
265
|
+
SPL_SANITIZE_OUTPUT=false
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Common Splunk Search Patterns
|
|
269
|
+
|
|
270
|
+
### Get recent errors:
|
|
271
|
+
```
|
|
272
|
+
index=main level=ERROR | head 20
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Get statistics by source:
|
|
276
|
+
```
|
|
277
|
+
index=_internal | stats count by source
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Time-based searches:
|
|
281
|
+
```
|
|
282
|
+
index=main earliest=-1h latest=now | timechart count
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Field extraction:
|
|
286
|
+
```
|
|
287
|
+
index=web_logs | rex field=_raw "status=(?<status_code>\d+)" | stats count by status_code
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## SPL Query Validation (Guardrails)
|
|
291
|
+
|
|
292
|
+
The server includes built-in validation to detect potentially risky or inefficient SPL queries before execution. This helps prevent:
|
|
293
|
+
|
|
294
|
+
- **Destructive Operations**: Commands like `delete` that permanently remove data
|
|
295
|
+
- **Performance Issues**: Unbounded searches, expensive commands, or missing time ranges
|
|
296
|
+
- **Resource Consumption**: Queries that could overwhelm system resources
|
|
297
|
+
- **Security Risks**: External script execution or unsafe operations
|
|
298
|
+
|
|
299
|
+
### Risk Scoring
|
|
300
|
+
|
|
301
|
+
Each query is analyzed and assigned a risk score from 0-100:
|
|
302
|
+
- **0-30**: Low risk - Query is generally safe
|
|
303
|
+
- **31-60**: Medium risk - Query may have performance implications
|
|
304
|
+
- **61-100**: High risk - Query could be destructive or severely impact performance
|
|
305
|
+
|
|
306
|
+
### Common Risk Factors
|
|
307
|
+
|
|
308
|
+
1. **Destructive Commands** (High Risk):
|
|
309
|
+
- `delete` command (+80 points)
|
|
310
|
+
- `collect` with `override=true` (+25 points)
|
|
311
|
+
- `outputlookup` with `override=true` (+20 points)
|
|
312
|
+
|
|
313
|
+
2. **Time Range Issues**:
|
|
314
|
+
- All-time searches or missing time constraints (+50 points)
|
|
315
|
+
- Time ranges exceeding safe threshold (+20 points)
|
|
316
|
+
|
|
317
|
+
3. **Performance Concerns**:
|
|
318
|
+
- `index=*` without constraints (+35 points)
|
|
319
|
+
- Expensive commands like `transaction`, `map`, `join` (+20 points each)
|
|
320
|
+
- Missing index specification (+20 points)
|
|
321
|
+
- Subsearches without limits (+20 points)
|
|
322
|
+
|
|
323
|
+
4. **Security Risks**:
|
|
324
|
+
- External script execution (+40 points)
|
|
325
|
+
|
|
326
|
+
### Configuration
|
|
327
|
+
|
|
328
|
+
Configure validation behavior in your `.env` file:
|
|
329
|
+
- `SPL_RISK_TOLERANCE`: Set threshold for blocking queries (default: 75)
|
|
330
|
+
- `SPL_SAFE_TIMERANGE`: Define safe time range (default: 24h)
|
|
331
|
+
- `SPL_SANITIZE_OUTPUT`: Enable/disable output sanitization
|
|
332
|
+
|
|
333
|
+
### Output Sanitization
|
|
334
|
+
|
|
335
|
+
When `SPL_SANITIZE_OUTPUT=true`, the server automatically masks sensitive data:
|
|
336
|
+
- **Credit Cards**: Shows only last 4 digits (e.g., ****-****-****-1234)
|
|
337
|
+
- **Social Security Numbers**: Completely masked (e.g., ***-**-****)
|
|
338
|
+
|
|
339
|
+
### Testing Validation
|
|
340
|
+
|
|
341
|
+
Use the interactive validation tool to test queries:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
cd tests
|
|
345
|
+
python validate_spl_test.py
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## Security Notes
|
|
349
|
+
|
|
350
|
+
- Store credentials securely in `.env` file
|
|
351
|
+
- Use token authentication when possible
|
|
352
|
+
- Enable SSL verification in production (`VERIFY_SSL=true`)
|
|
353
|
+
- Never commit `.env` file to version control
|
|
354
|
+
|
|
355
|
+
## Troubleshooting
|
|
356
|
+
|
|
357
|
+
### Connection Issues
|
|
358
|
+
- Verify Splunk is running and accessible
|
|
359
|
+
- Check firewall rules for port 8089
|
|
360
|
+
- Ensure credentials are correct
|
|
361
|
+
- Try disabling SSL verification for testing
|
|
362
|
+
|
|
363
|
+
### Search Issues
|
|
364
|
+
- Verify user has search permissions
|
|
365
|
+
- Check index access rights
|
|
366
|
+
- Use `| head` to limit results during testing
|
|
367
|
+
- Check Splunk search job limits
|
|
368
|
+
|
|
369
|
+
## Project Structure
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
python/
|
|
373
|
+
├── .env.example # Environment configuration template
|
|
374
|
+
├── server.py # Main server implementation
|
|
375
|
+
├── splunk_client.py # Splunk REST API client
|
|
376
|
+
├── helpers.py # Formatting utilities
|
|
377
|
+
├── guardrails.py # SPL query validation and sanitization
|
|
378
|
+
├── spl_risk_rules.py # Configurable risk rules for validation
|
|
379
|
+
├── pyproject.toml # Python project configuration
|
|
380
|
+
├── Dockerfile # Docker deployment configuration
|
|
381
|
+
├── docker-compose.yml # Docker compose configuration
|
|
382
|
+
├── dock # Docker management script
|
|
383
|
+
├── README.md # This file
|
|
384
|
+
└── tests/
|
|
385
|
+
├── test_sse_transport.py # SSE transport tests
|
|
386
|
+
├── test_stdio_transport.py # Stdio transport tests
|
|
387
|
+
├── validate_spl_test.py # Interactive validation tool
|
|
388
|
+
├── splunk_sse_search.py # Interactive search tool
|
|
389
|
+
├── testall # Comprehensive test menu
|
|
390
|
+
└── quick_test.py # Quick smoke test
|
|
391
|
+
```
|