elasticsearch-mcp-vsee 0.1.4
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.
- package/LICENSE +21 -0
- package/README.md +375 -0
- package/build/config.d.ts +76 -0
- package/build/config.d.ts.map +1 -0
- package/build/config.js +63 -0
- package/build/config.js.map +1 -0
- package/build/elasticsearch/client.d.ts +26 -0
- package/build/elasticsearch/client.d.ts.map +1 -0
- package/build/elasticsearch/client.js +183 -0
- package/build/elasticsearch/client.js.map +1 -0
- package/build/errors/handlers.d.ts +43 -0
- package/build/errors/handlers.d.ts.map +1 -0
- package/build/errors/handlers.js +166 -0
- package/build/errors/handlers.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +28 -0
- package/build/index.js.map +1 -0
- package/build/logger.d.ts +31 -0
- package/build/logger.d.ts.map +1 -0
- package/build/logger.js +81 -0
- package/build/logger.js.map +1 -0
- package/build/server.d.ts +21 -0
- package/build/server.d.ts.map +1 -0
- package/build/server.js +432 -0
- package/build/server.js.map +1 -0
- package/build/tools/create-index.d.ts +24 -0
- package/build/tools/create-index.d.ts.map +1 -0
- package/build/tools/create-index.js +140 -0
- package/build/tools/create-index.js.map +1 -0
- package/build/tools/delete-document.d.ts +32 -0
- package/build/tools/delete-document.d.ts.map +1 -0
- package/build/tools/delete-document.js +164 -0
- package/build/tools/delete-document.js.map +1 -0
- package/build/tools/export-to-csv.d.ts +37 -0
- package/build/tools/export-to-csv.d.ts.map +1 -0
- package/build/tools/export-to-csv.js +304 -0
- package/build/tools/export-to-csv.js.map +1 -0
- package/build/tools/fetch-indices.d.ts +30 -0
- package/build/tools/fetch-indices.d.ts.map +1 -0
- package/build/tools/fetch-indices.js +105 -0
- package/build/tools/fetch-indices.js.map +1 -0
- package/build/tools/index.d.ts +15 -0
- package/build/tools/index.d.ts.map +1 -0
- package/build/tools/index.js +18 -0
- package/build/tools/index.js.map +1 -0
- package/build/tools/insert-data.d.ts +25 -0
- package/build/tools/insert-data.d.ts.map +1 -0
- package/build/tools/insert-data.js +135 -0
- package/build/tools/insert-data.js.map +1 -0
- package/build/tools/search-elasticsearch.d.ts +44 -0
- package/build/tools/search-elasticsearch.d.ts.map +1 -0
- package/build/tools/search-elasticsearch.js +205 -0
- package/build/tools/search-elasticsearch.js.map +1 -0
- package/build/tools/update-document.d.ts +31 -0
- package/build/tools/update-document.d.ts.map +1 -0
- package/build/tools/update-document.js +163 -0
- package/build/tools/update-document.js.map +1 -0
- package/build/validation/schemas.d.ts +242 -0
- package/build/validation/schemas.d.ts.map +1 -0
- package/build/validation/schemas.js +146 -0
- package/build/validation/schemas.js.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 elastic-mcp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# Elasticsearch MCP
|
|
2
|
+
|
|
3
|
+
> **Model Context Protocol server for Elasticsearch integration with comprehensive security and performance features**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/elasticsearch-mcp)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://www.elastic.co/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
**elasticsearch-mcp** is a Model Context Protocol (MCP) server that provides standardized, secure tools for interacting with Elasticsearch clusters. Built with TypeScript and optimized for Elastic Cloud environments, it offers comprehensive data management capabilities with enterprise-grade security features.
|
|
11
|
+
|
|
12
|
+
## 🚀 Features
|
|
13
|
+
|
|
14
|
+
- **🔐 Secure by Design**: Input validation, script sanitization, injection prevention
|
|
15
|
+
- **☁️ Elastic Cloud Ready**: Native support for cloud ID and API key authentication
|
|
16
|
+
- **⚡ High Performance**: Streaming for large datasets, connection pooling, health monitoring
|
|
17
|
+
- **🛠️ Comprehensive Tools**: 7 essential tools covering all major Elasticsearch operations
|
|
18
|
+
- **📊 Advanced Querying**: Full Elasticsearch DSL support with aggregations and highlighting
|
|
19
|
+
- **📁 Data Export**: Stream large datasets to CSV with compression support
|
|
20
|
+
- **🔍 Smart Validation**: Zod-based schemas with security-first validation
|
|
21
|
+
- **📝 Full TypeScript**: Complete type safety with strict null checks
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install elasticsearch-mcp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 🏃♂️ Quick Start
|
|
30
|
+
|
|
31
|
+
### 1. Basic Setup
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Set your Elasticsearch credentials
|
|
35
|
+
export ELASTIC_CLOUD_ID="your-cloud-id"
|
|
36
|
+
export ELASTIC_API_KEY="your-api-key"
|
|
37
|
+
|
|
38
|
+
# Start the MCP server
|
|
39
|
+
npx elasticsearch-mcp
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Using with Claude Desktop
|
|
43
|
+
|
|
44
|
+
Add to your Claude Desktop MCP configuration:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"mcpServers": {
|
|
49
|
+
"elasticsearch-mcp": {
|
|
50
|
+
"command": "npx",
|
|
51
|
+
"args": ["elasticsearch-mcp"],
|
|
52
|
+
"env": {
|
|
53
|
+
"ELASTIC_CLOUD_ID": "your-cloud-id",
|
|
54
|
+
"ELASTIC_API_KEY": "your-api-key"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. Using with any MCP Client
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { ElasticMCPServer } from 'elasticsearch-mcp';
|
|
65
|
+
|
|
66
|
+
const server = new ElasticMCPServer();
|
|
67
|
+
await server.start();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🛠️ Available Tools
|
|
71
|
+
|
|
72
|
+
| Tool | Description | Use Cases |
|
|
73
|
+
|------|-------------|-----------|
|
|
74
|
+
| `fetch_indices` | List and filter Elasticsearch indices | Index management, monitoring |
|
|
75
|
+
| `search_elasticsearch` | Advanced search with aggregations | Data analysis, querying |
|
|
76
|
+
| `create_index` | Create indices with mappings/settings | Schema management |
|
|
77
|
+
| `insert_data` | Insert documents with validation | Data ingestion |
|
|
78
|
+
| `update_document` | Update documents with scripts | Data modification |
|
|
79
|
+
| `delete_document` | Delete by ID or query | Data cleanup |
|
|
80
|
+
| `export_to_csv` | Stream data to CSV files | Reporting, data export |
|
|
81
|
+
|
|
82
|
+
## 📋 Tool Examples
|
|
83
|
+
|
|
84
|
+
### Search with Aggregations
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"tool": "search_elasticsearch",
|
|
89
|
+
"arguments": {
|
|
90
|
+
"index": "sales-data",
|
|
91
|
+
"query": {
|
|
92
|
+
"range": {
|
|
93
|
+
"date": {
|
|
94
|
+
"gte": "2024-01-01",
|
|
95
|
+
"lte": "2024-12-31"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"aggregations": {
|
|
100
|
+
"monthly_sales": {
|
|
101
|
+
"date_histogram": {
|
|
102
|
+
"field": "date",
|
|
103
|
+
"calendar_interval": "month"
|
|
104
|
+
},
|
|
105
|
+
"aggs": {
|
|
106
|
+
"total_revenue": {
|
|
107
|
+
"sum": { "field": "amount" }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Export Large Dataset
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"tool": "export_to_csv",
|
|
121
|
+
"arguments": {
|
|
122
|
+
"index": "user-analytics",
|
|
123
|
+
"query": {
|
|
124
|
+
"bool": {
|
|
125
|
+
"filter": [
|
|
126
|
+
{ "term": { "status": "active" } },
|
|
127
|
+
{ "range": { "last_login": { "gte": "2024-01-01" } } }
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"fields": ["user_id", "email", "last_login", "country"],
|
|
132
|
+
"filename": "active_users_2024.csv",
|
|
133
|
+
"compress": true,
|
|
134
|
+
"maxRows": 100000
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Create Index with Schema
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"tool": "create_index",
|
|
144
|
+
"arguments": {
|
|
145
|
+
"name": "product-catalog",
|
|
146
|
+
"mappings": {
|
|
147
|
+
"properties": {
|
|
148
|
+
"name": { "type": "text", "analyzer": "standard" },
|
|
149
|
+
"price": { "type": "float" },
|
|
150
|
+
"category": { "type": "keyword" },
|
|
151
|
+
"created_at": { "type": "date" },
|
|
152
|
+
"tags": { "type": "keyword" },
|
|
153
|
+
"description": { "type": "text" }
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
"settings": {
|
|
157
|
+
"number_of_shards": 1,
|
|
158
|
+
"number_of_replicas": 1,
|
|
159
|
+
"analysis": {
|
|
160
|
+
"analyzer": {
|
|
161
|
+
"product_analyzer": {
|
|
162
|
+
"type": "standard",
|
|
163
|
+
"stopwords": "_english_"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"aliases": ["products", "catalog"]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## ⚙️ Configuration
|
|
174
|
+
|
|
175
|
+
### Environment Variables
|
|
176
|
+
|
|
177
|
+
| Variable | Description | Required | Example |
|
|
178
|
+
|----------|-------------|----------|---------|
|
|
179
|
+
| `ELASTIC_CLOUD_ID` | Elastic Cloud deployment ID | Yes* | `deployment:dXMtY2VudHJhbDE=` |
|
|
180
|
+
| `ELASTIC_API_KEY` | Elasticsearch API key | Yes* | `VnVhQ2ZHY0JDZGJrU...` |
|
|
181
|
+
| `ELASTIC_NODE` | Self-hosted Elasticsearch URL | Yes* | `https://localhost:9200` |
|
|
182
|
+
| `ELASTIC_USERNAME` | Basic auth username | No | `elastic` |
|
|
183
|
+
| `ELASTIC_PASSWORD` | Basic auth password | No | `changeme` |
|
|
184
|
+
| `LOG_LEVEL` | Logging level | No | `info` |
|
|
185
|
+
| `LOG_FORMAT` | Log output format | No | `text` |
|
|
186
|
+
| `MAX_CONCURRENT_REQUESTS` | Request concurrency limit | No | `10` |
|
|
187
|
+
|
|
188
|
+
*Either `ELASTIC_CLOUD_ID` or `ELASTIC_NODE` is required
|
|
189
|
+
|
|
190
|
+
### Configuration File
|
|
191
|
+
|
|
192
|
+
Create `.env` file:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Elastic Cloud (recommended)
|
|
196
|
+
ELASTIC_CLOUD_ID=your-deployment-id
|
|
197
|
+
ELASTIC_API_KEY=your-api-key
|
|
198
|
+
|
|
199
|
+
# Logging
|
|
200
|
+
LOG_LEVEL=info
|
|
201
|
+
LOG_FORMAT=json
|
|
202
|
+
|
|
203
|
+
# Performance
|
|
204
|
+
MAX_CONCURRENT_REQUESTS=10
|
|
205
|
+
REQUEST_TIMEOUT_MS=30000
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## 🔒 Security Features
|
|
209
|
+
|
|
210
|
+
### Input Validation
|
|
211
|
+
- **Zod Schemas**: Strict type validation for all inputs
|
|
212
|
+
- **Field Name Validation**: Prevents reserved field usage
|
|
213
|
+
- **Size Limits**: Document size, array length, string length limits
|
|
214
|
+
- **Depth Validation**: Prevents deeply nested objects/queries
|
|
215
|
+
|
|
216
|
+
### Script Security
|
|
217
|
+
- **Script Sanitization**: Blocks dangerous script patterns
|
|
218
|
+
- **Parameter Validation**: Validates script parameters
|
|
219
|
+
- **Execution Limits**: Prevents resource exhaustion
|
|
220
|
+
|
|
221
|
+
### Query Security
|
|
222
|
+
- **Injection Prevention**: Sanitizes and validates all queries
|
|
223
|
+
- **Script Query Blocking**: Prevents script-based queries in sensitive operations
|
|
224
|
+
- **Rate Limiting**: Protects against abuse
|
|
225
|
+
|
|
226
|
+
### Data Protection
|
|
227
|
+
- **Credential Masking**: Never logs sensitive information
|
|
228
|
+
- **Secure Connections**: TLS/SSL support
|
|
229
|
+
- **Access Control**: Validates permissions before operations
|
|
230
|
+
|
|
231
|
+
## 🏗️ Architecture
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
|
235
|
+
│ MCP Client │◄──►│Elasticsearch MCP│◄──►│ Elasticsearch │
|
|
236
|
+
│ (Claude, etc.) │ │ Server │ │ Cluster │
|
|
237
|
+
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
|
238
|
+
│
|
|
239
|
+
┌─────────────┐
|
|
240
|
+
│ Tools │
|
|
241
|
+
│ │
|
|
242
|
+
│ • fetch │
|
|
243
|
+
│ • search │
|
|
244
|
+
│ • create │
|
|
245
|
+
│ • insert │
|
|
246
|
+
│ • update │
|
|
247
|
+
│ • delete │
|
|
248
|
+
│ • export │
|
|
249
|
+
└─────────────┘
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## 📊 Performance
|
|
253
|
+
|
|
254
|
+
### Benchmarks
|
|
255
|
+
- **Search**: <500ms average response time
|
|
256
|
+
- **Large Exports**: 10K+ documents/second with streaming
|
|
257
|
+
- **Memory Usage**: <100MB for typical operations
|
|
258
|
+
- **Concurrent Requests**: Up to 10 simultaneous operations
|
|
259
|
+
|
|
260
|
+
### Optimization Features
|
|
261
|
+
- **Connection Pooling**: Reuses Elasticsearch connections
|
|
262
|
+
- **Streaming**: Memory-efficient processing of large datasets
|
|
263
|
+
- **Compression**: Reduces export file sizes by 70%+
|
|
264
|
+
- **Health Monitoring**: Automatic reconnection on failures
|
|
265
|
+
|
|
266
|
+
## 🔧 Development
|
|
267
|
+
|
|
268
|
+
### Setup Development Environment
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Clone repository
|
|
272
|
+
git clone https://github.com/RajwardhanShinde/elk-mcp.git
|
|
273
|
+
cd elk-mcp
|
|
274
|
+
|
|
275
|
+
# Install dependencies
|
|
276
|
+
npm install
|
|
277
|
+
|
|
278
|
+
# Set up environment
|
|
279
|
+
cp .env.example .env
|
|
280
|
+
# Edit .env with your Elasticsearch credentials
|
|
281
|
+
|
|
282
|
+
# Run in development mode
|
|
283
|
+
npm run dev
|
|
284
|
+
|
|
285
|
+
# Run tests
|
|
286
|
+
npm test
|
|
287
|
+
|
|
288
|
+
# Build for production
|
|
289
|
+
npm run build
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Project Structure
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
elasticsearch-mcp/
|
|
296
|
+
├── src/
|
|
297
|
+
│ ├── tools/ # MCP tool implementations
|
|
298
|
+
│ ├── elasticsearch/ # ES client and connection management
|
|
299
|
+
│ ├── validation/ # Input validation schemas
|
|
300
|
+
│ ├── errors/ # Error handling utilities
|
|
301
|
+
│ ├── config.ts # Configuration management
|
|
302
|
+
│ ├── logger.ts # Structured logging
|
|
303
|
+
│ └── server.ts # Main MCP server
|
|
304
|
+
├── tests/ # Comprehensive test suite
|
|
305
|
+
├── docs/ # Documentation
|
|
306
|
+
└── build/ # Compiled output
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## 🤝 Contributing
|
|
310
|
+
|
|
311
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
312
|
+
|
|
313
|
+
### Development Workflow
|
|
314
|
+
1. Fork the repository
|
|
315
|
+
2. Create a feature branch
|
|
316
|
+
3. Make your changes with tests
|
|
317
|
+
4. Ensure all tests pass
|
|
318
|
+
5. Submit a pull request
|
|
319
|
+
|
|
320
|
+
## 📚 Documentation
|
|
321
|
+
|
|
322
|
+
- [Quick Start Guide](docs/guides/quick-start.md)
|
|
323
|
+
- [API Reference](docs/api/tools.md)
|
|
324
|
+
- [Configuration Guide](docs/api/configuration.md)
|
|
325
|
+
- [Elastic Cloud Setup](docs/guides/elastic-cloud-setup.md)
|
|
326
|
+
- [Troubleshooting](docs/guides/troubleshooting.md)
|
|
327
|
+
- [Examples](docs/examples/)
|
|
328
|
+
|
|
329
|
+
## 🐛 Troubleshooting
|
|
330
|
+
|
|
331
|
+
### Common Issues
|
|
332
|
+
|
|
333
|
+
**Connection Failed**
|
|
334
|
+
```bash
|
|
335
|
+
# Check credentials
|
|
336
|
+
echo $ELASTIC_CLOUD_ID
|
|
337
|
+
echo $ELASTIC_API_KEY
|
|
338
|
+
|
|
339
|
+
# Test connection
|
|
340
|
+
curl -H "Authorization: ApiKey $ELASTIC_API_KEY" \\
|
|
341
|
+
"$ELASTIC_NODE/_cluster/health"
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**Permission Denied**
|
|
345
|
+
- Ensure API key has required privileges
|
|
346
|
+
- Check index permissions
|
|
347
|
+
- Verify cluster access
|
|
348
|
+
|
|
349
|
+
**Tool Validation Errors**
|
|
350
|
+
- Check input parameter types
|
|
351
|
+
- Validate required fields
|
|
352
|
+
- Review field name restrictions
|
|
353
|
+
|
|
354
|
+
See [Troubleshooting Guide](docs/guides/troubleshooting.md) for more details.
|
|
355
|
+
|
|
356
|
+
## 📄 License
|
|
357
|
+
|
|
358
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
359
|
+
|
|
360
|
+
## 🏷️ Version History
|
|
361
|
+
|
|
362
|
+
- **v0.1.0** - Initial release with 7 core tools
|
|
363
|
+
- Full changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
364
|
+
|
|
365
|
+
## 🔗 Links
|
|
366
|
+
|
|
367
|
+
- [npm Package](https://www.npmjs.com/package/elasticsearch-mcp)
|
|
368
|
+
- [GitHub Repository](https://github.com/RajwardhanShinde/elk-mcp)
|
|
369
|
+
- [Issue Tracker](https://github.com/RajwardhanShinde/elk-mcp/issues)
|
|
370
|
+
- [Elasticsearch Documentation](https://www.elastic.co/guide/)
|
|
371
|
+
- [Model Context Protocol](https://modelcontextprotocol.io/)
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
**Built with ❤️ for the Elasticsearch and MCP communities**
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ElasticConfigSchema: z.ZodObject<{
|
|
3
|
+
cloudId: z.ZodOptional<z.ZodString>;
|
|
4
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
5
|
+
node: z.ZodOptional<z.ZodString>;
|
|
6
|
+
auth: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
username: z.ZodString;
|
|
8
|
+
password: z.ZodString;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
}, {
|
|
13
|
+
username: string;
|
|
14
|
+
password: string;
|
|
15
|
+
}>>;
|
|
16
|
+
maxRetries: z.ZodDefault<z.ZodNumber>;
|
|
17
|
+
requestTimeout: z.ZodDefault<z.ZodNumber>;
|
|
18
|
+
pingTimeout: z.ZodDefault<z.ZodNumber>;
|
|
19
|
+
sniffOnStart: z.ZodDefault<z.ZodBoolean>;
|
|
20
|
+
sniffInterval: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
ssl: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
rejectUnauthorized: z.ZodDefault<z.ZodBoolean>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
rejectUnauthorized: boolean;
|
|
25
|
+
}, {
|
|
26
|
+
rejectUnauthorized?: boolean | undefined;
|
|
27
|
+
}>>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
maxRetries: number;
|
|
30
|
+
requestTimeout: number;
|
|
31
|
+
pingTimeout: number;
|
|
32
|
+
sniffOnStart: boolean;
|
|
33
|
+
cloudId?: string | undefined;
|
|
34
|
+
apiKey?: string | undefined;
|
|
35
|
+
node?: string | undefined;
|
|
36
|
+
auth?: {
|
|
37
|
+
username: string;
|
|
38
|
+
password: string;
|
|
39
|
+
} | undefined;
|
|
40
|
+
sniffInterval?: number | undefined;
|
|
41
|
+
ssl?: {
|
|
42
|
+
rejectUnauthorized: boolean;
|
|
43
|
+
} | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
cloudId?: string | undefined;
|
|
46
|
+
apiKey?: string | undefined;
|
|
47
|
+
node?: string | undefined;
|
|
48
|
+
auth?: {
|
|
49
|
+
username: string;
|
|
50
|
+
password: string;
|
|
51
|
+
} | undefined;
|
|
52
|
+
maxRetries?: number | undefined;
|
|
53
|
+
requestTimeout?: number | undefined;
|
|
54
|
+
pingTimeout?: number | undefined;
|
|
55
|
+
sniffOnStart?: boolean | undefined;
|
|
56
|
+
sniffInterval?: number | undefined;
|
|
57
|
+
ssl?: {
|
|
58
|
+
rejectUnauthorized?: boolean | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
export type ElasticConfig = z.infer<typeof ElasticConfigSchema>;
|
|
62
|
+
export interface ServerConfig {
|
|
63
|
+
name: string;
|
|
64
|
+
version: string;
|
|
65
|
+
elasticsearch: ElasticConfig;
|
|
66
|
+
logging: {
|
|
67
|
+
level: 'error' | 'warn' | 'info' | 'debug';
|
|
68
|
+
format: 'json' | 'text';
|
|
69
|
+
};
|
|
70
|
+
server: {
|
|
71
|
+
maxConcurrentRequests: number;
|
|
72
|
+
requestTimeoutMs: number;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export declare function loadConfig(): ServerConfig;
|
|
76
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgB9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE;QACP,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;QAC3C,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;KACzB,CAAC;IACF,MAAM,EAAE;QACN,qBAAqB,EAAE,MAAM,CAAC;QAC9B,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH;AAED,wBAAgB,UAAU,IAAI,YAAY,CA4BzC"}
|
package/build/config.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ElasticConfigSchema = void 0;
|
|
4
|
+
exports.loadConfig = loadConfig;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.ElasticConfigSchema = zod_1.z.object({
|
|
7
|
+
cloudId: zod_1.z.string().optional(),
|
|
8
|
+
apiKey: zod_1.z.string().optional(),
|
|
9
|
+
node: zod_1.z.string().optional(),
|
|
10
|
+
auth: zod_1.z.object({
|
|
11
|
+
username: zod_1.z.string(),
|
|
12
|
+
password: zod_1.z.string(),
|
|
13
|
+
}).optional(),
|
|
14
|
+
maxRetries: zod_1.z.number().min(0).max(10).default(3),
|
|
15
|
+
requestTimeout: zod_1.z.number().min(1000).max(300000).default(30000),
|
|
16
|
+
pingTimeout: zod_1.z.number().min(1000).max(30000).default(3000),
|
|
17
|
+
sniffOnStart: zod_1.z.boolean().default(false),
|
|
18
|
+
sniffInterval: zod_1.z.number().positive().optional(),
|
|
19
|
+
ssl: zod_1.z.object({
|
|
20
|
+
rejectUnauthorized: zod_1.z.boolean().default(true),
|
|
21
|
+
}).optional(),
|
|
22
|
+
});
|
|
23
|
+
function loadConfig() {
|
|
24
|
+
const config = {
|
|
25
|
+
name: 'elasticsearch-mcp',
|
|
26
|
+
version: '0.1.3',
|
|
27
|
+
elasticsearch: exports.ElasticConfigSchema.parse({
|
|
28
|
+
cloudId: process.env.ELASTIC_CLOUD_ID,
|
|
29
|
+
apiKey: process.env.ELASTIC_API_KEY,
|
|
30
|
+
node: process.env.ELASTIC_NODE,
|
|
31
|
+
auth: process.env.ELASTIC_USERNAME && process.env.ELASTIC_PASSWORD ? {
|
|
32
|
+
username: process.env.ELASTIC_USERNAME,
|
|
33
|
+
password: process.env.ELASTIC_PASSWORD,
|
|
34
|
+
} : undefined,
|
|
35
|
+
maxRetries: process.env.ELASTIC_MAX_RETRIES ? parseInt(process.env.ELASTIC_MAX_RETRIES, 10) : 3,
|
|
36
|
+
requestTimeout: process.env.ELASTIC_REQUEST_TIMEOUT ? parseInt(process.env.ELASTIC_REQUEST_TIMEOUT, 10) : 30000,
|
|
37
|
+
pingTimeout: process.env.ELASTIC_PING_TIMEOUT ? parseInt(process.env.ELASTIC_PING_TIMEOUT, 10) : 3000,
|
|
38
|
+
}),
|
|
39
|
+
logging: {
|
|
40
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
41
|
+
format: process.env.LOG_FORMAT || 'text',
|
|
42
|
+
},
|
|
43
|
+
server: {
|
|
44
|
+
maxConcurrentRequests: process.env.MAX_CONCURRENT_REQUESTS ? parseInt(process.env.MAX_CONCURRENT_REQUESTS, 10) : 10,
|
|
45
|
+
requestTimeoutMs: process.env.REQUEST_TIMEOUT_MS ? parseInt(process.env.REQUEST_TIMEOUT_MS, 10) : 30000,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
validateConfig(config);
|
|
49
|
+
return config;
|
|
50
|
+
}
|
|
51
|
+
function validateConfig(config) {
|
|
52
|
+
const { elasticsearch } = config;
|
|
53
|
+
if (!elasticsearch.cloudId && !elasticsearch.node) {
|
|
54
|
+
throw new Error('Either ELASTIC_CLOUD_ID or ELASTIC_NODE must be provided');
|
|
55
|
+
}
|
|
56
|
+
if (elasticsearch.cloudId && !elasticsearch.apiKey) {
|
|
57
|
+
throw new Error('ELASTIC_API_KEY is required when using Elastic Cloud');
|
|
58
|
+
}
|
|
59
|
+
if (elasticsearch.node && !elasticsearch.auth && !elasticsearch.apiKey) {
|
|
60
|
+
throw new Error('Authentication (username/password or API key) is required');
|
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ACD,MAAM,EAAE;YACN,qBAAqB,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;YACnH,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK;SACxG;KACF,CAAC;IAEF,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CAAC,MAAoB;IAC1C,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,aAAa,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,aAAa,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Client } from '@elastic/elasticsearch';
|
|
2
|
+
import { ElasticConfig } from '../config.js';
|
|
3
|
+
import { Logger } from '../logger.js';
|
|
4
|
+
export interface ConnectionInfo {
|
|
5
|
+
isConnected: boolean;
|
|
6
|
+
clusterName?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
lastHealthCheck: Date;
|
|
9
|
+
error?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class ElasticsearchManager {
|
|
12
|
+
private client;
|
|
13
|
+
private config;
|
|
14
|
+
private logger;
|
|
15
|
+
private connectionInfo;
|
|
16
|
+
private healthCheckInterval;
|
|
17
|
+
constructor(config: ElasticConfig, logger: Logger);
|
|
18
|
+
initialize(): Promise<void>;
|
|
19
|
+
healthCheck(): Promise<boolean>;
|
|
20
|
+
reconnect(): Promise<void>;
|
|
21
|
+
getClient(): Client;
|
|
22
|
+
getConnectionInfo(): ConnectionInfo;
|
|
23
|
+
private startHealthMonitoring;
|
|
24
|
+
shutdown(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/elasticsearch/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,mBAAmB,CAA+B;gBAE9C,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM;IAS3C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAuD3B,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAiE/B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAUhC,SAAS,IAAI,MAAM;IAYnB,iBAAiB,IAAI,cAAc;IAInC,OAAO,CAAC,qBAAqB;IAiBvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAmBhC"}
|