@influxdata/influxdb3-mcp-server 1.3.0

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/Dockerfile +22 -0
  3. package/LICENSE +6 -0
  4. package/LICENSE-APACHE.txt +201 -0
  5. package/LICENSE-MIT.txt +25 -0
  6. package/README.md +318 -0
  7. package/build/config.js +85 -0
  8. package/build/helpers/enums/influx-product-types.enum.js +8 -0
  9. package/build/index.js +33 -0
  10. package/build/prompts/index.js +98 -0
  11. package/build/resources/index.js +223 -0
  12. package/build/server/index.js +104 -0
  13. package/build/services/base-connection.service.js +318 -0
  14. package/build/services/cloud-token-management.service.js +179 -0
  15. package/build/services/context-file.service.js +97 -0
  16. package/build/services/database-management.service.js +549 -0
  17. package/build/services/help.service.js +241 -0
  18. package/build/services/http-client.service.js +109 -0
  19. package/build/services/influxdb-master.service.js +117 -0
  20. package/build/services/query.service.js +499 -0
  21. package/build/services/serverless-schema-management.service.js +266 -0
  22. package/build/services/token-management.service.js +215 -0
  23. package/build/services/write.service.js +153 -0
  24. package/build/tools/categories/cloud-token.tools.js +321 -0
  25. package/build/tools/categories/database.tools.js +299 -0
  26. package/build/tools/categories/health.tools.js +75 -0
  27. package/build/tools/categories/help.tools.js +104 -0
  28. package/build/tools/categories/query.tools.js +180 -0
  29. package/build/tools/categories/schema.tools.js +308 -0
  30. package/build/tools/categories/token.tools.js +378 -0
  31. package/build/tools/categories/write.tools.js +104 -0
  32. package/build/tools/index.js +27 -0
  33. package/env.example +17 -0
  34. package/example-cloud-dedicated.mcp.json +15 -0
  35. package/example-cloud-serverless.mcp.json +13 -0
  36. package/example-clustered.mcp.json +14 -0
  37. package/example-docker.mcp.json +25 -0
  38. package/example-local.mcp.json +13 -0
  39. package/example-npx.mcp.json +13 -0
  40. package/package.json +78 -0
@@ -0,0 +1,241 @@
1
+ /**
2
+ * InfluxDB Help Service
3
+ *
4
+ * Provides help content for InfluxDB operations. Simple in-memory text content
5
+ * that LLMs can easily navigate and extract relevant information from.
6
+ */
7
+ export class HelpService {
8
+ /**
9
+ * Get InfluxDB help content
10
+ */
11
+ getHelp() {
12
+ return INFLUXDB_HELP_CONTENT;
13
+ }
14
+ }
15
+ const INFLUXDB_HELP_CONTENT = `
16
+ INFLUXDB MCP SERVER HELP
17
+
18
+ === LINE PROTOCOL WRITING ===
19
+
20
+ Line Protocol Format:
21
+ measurement,tag1=value1,tag2=value2 field1=value1,field2=value2 timestamp
22
+
23
+ Examples:
24
+ - temperature,location=office value=23.5 1640995200000000000
25
+ - sensor_data,device=sensor1,location=room1 temperature=22.5,humidity=45.2,status="ok"
26
+ - cpu_usage,host=server1,region=us-east cpu_percent=85.2,memory_percent=67.1 1640995200000000000
27
+
28
+ Rules:
29
+ - Tags are indexed metadata (strings only), fields contain actual data
30
+ - Tag values cannot contain spaces, use quotes for field string values
31
+ - Timestamp is optional (nanoseconds since Unix epoch)
32
+ - Escape special characters in tag values: spaces, commas, equals signs
33
+ - Multiple measurements can be written in one call (separate by newlines)
34
+
35
+ Common Errors:
36
+ - Missing field (at least one field required)
37
+ - Invalid timestamp format
38
+ - Unescaped special characters in tag values
39
+ - Retention period violations (Cloud instances): Writing data outside retention window
40
+
41
+ === QUERYING DATA ===
42
+
43
+ SQL Syntax for InfluxDB v3:
44
+ SELECT field1, field2 FROM measurement WHERE time >= 'timestamp' AND tag1 = 'value'
45
+
46
+ Time Filtering:
47
+ - WHERE time >= '2024-01-01T00:00:00Z'
48
+ - WHERE time >= now() - interval '1 hour'
49
+ - WHERE time BETWEEN '2024-01-01' AND '2024-01-02'
50
+
51
+ Common Queries:
52
+ - List measurements: SELECT DISTINCT table_name FROM information_schema.measurements
53
+ - Get schema: DESCRIBE measurement_name
54
+ - Recent data: SELECT * FROM measurement ORDER BY time DESC LIMIT 10
55
+ - Aggregates: SELECT AVG(field1), MAX(field2) FROM measurement WHERE time >= now() - interval '1 day'
56
+
57
+ Cloud Dedicated & Cloud Serverless Additional Requirements:
58
+ - CAST aggregations: Use CAST(COUNT(*) AS DOUBLE), CAST(AVG(field) AS DOUBLE), etc.
59
+ - GROUP BY compliance: Include all grouped columns in SELECT clause
60
+ - Information schema: Use SELECT DISTINCT table_name FROM information_schema.columns WHERE table_schema = 'iox'
61
+ - Schema queries: SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'measurement' AND table_schema = 'iox'
62
+ - Required for: COUNT, SUM, AVG, MIN, MAX aggregation functions
63
+ - Without CAST: Aggregations may return empty results or be missing from response
64
+
65
+ Cloud Examples with CAST:
66
+ - Count records: SELECT building, CAST(COUNT(*) AS DOUBLE) AS count FROM sensors GROUP BY building
67
+ - Averages: SELECT region, CAST(AVG(cpu_usage) AS DOUBLE) AS avg_cpu FROM metrics GROUP BY region
68
+ - Mixed aggregations: SELECT service, CAST(SUM(requests) AS DOUBLE) AS total_requests, CAST(AVG(response_time) AS DOUBLE) AS avg_response FROM app_metrics GROUP BY service
69
+
70
+ Performance Tips:
71
+ - Always include time filters for better performance
72
+ - Use specific field names instead of SELECT *
73
+ - Index on tags for filtering, not fields
74
+ - Use LIMIT for large datasets to avoid memory issues
75
+ - Test with COUNT(*) first to check data size before complex queries
76
+
77
+ === TOKEN MANAGEMENT ===
78
+
79
+ Token Types:
80
+ 1. Operator Token: Super admin with full system access (only one per instance)
81
+ 2. Named Admin Tokens: Administrative access, can manage resource tokens but not other admin tokens
82
+ 3. Resource Tokens: Limited to specific databases with read/write permissions
83
+
84
+ Available Operations:
85
+ - Create named admin tokens: create_admin_token tool
86
+ - Create resource tokens: create_resource_token tool
87
+ - List admin tokens: list_admin_tokens tool (filter by name)
88
+ - List resource tokens: list_resource_tokens tool (filter by name, database, order by various fields)
89
+ - Delete any token: delete_token tool (provide exact token name)
90
+ - Regenerate operator token: regenerate_operator_token tool (⚠️ DANGEROUS - see admin tokens section)
91
+
92
+ Security Best Practices:
93
+ - Use resource tokens for applications (principle of least privilege)
94
+ - Named admin tokens for administrative tasks including resource token management
95
+ - Operator token only for critical system operations and admin token management
96
+ - Set expiration times when possible (resource tokens support expiry_secs)
97
+ - Rotate tokens regularly
98
+ - Store tokens securely (environment variables, not in code)
99
+
100
+ Token Permissions Format:
101
+ - Operator: "*:*:*" (all permissions including admin token management)
102
+ - Named Admin: "*:*:*" (all permissions except managing other admin tokens)
103
+ - Resource: "database1:read,write" or "database1:read" etc.
104
+
105
+ === ADMIN TOKENS ===
106
+
107
+ Admin Token Types:
108
+ 1. Operator Token: Super admin with full permissions including admin token management
109
+ 2. Named Admin Tokens: Administrative permissions, can manage resource tokens but not other admin tokens
110
+
111
+ Named Admin Token Operations:
112
+ - Create: Use create_admin_token tool (optionally provide name)
113
+ - List: Use list_admin_tokens tool (can filter by token name - partial match)
114
+ - Delete: Use delete_token tool (provide exact token name)
115
+
116
+ Operator Token Operations:
117
+ - Regenerate: Use regenerate_operator_token tool (⚠️ USE WITH EXTREME CAUTION)
118
+
119
+ Key Differences:
120
+ - Operator token: Can create/delete/manage ALL tokens (admin and resource tokens)
121
+ - Named admin tokens: Full database and system access, can manage resource tokens but cannot manage other admin tokens
122
+ - Both have "*:*:*" permissions but operator has additional admin token management capabilities
123
+
124
+ Use Cases for Named Admin Tokens:
125
+ - Database management
126
+ - User administration
127
+ - Resource token management (create, list, delete resource tokens)
128
+ - System configuration
129
+ - Backup operations
130
+ - Dedicated token management role (create a named admin specifically for managing resource tokens)
131
+
132
+ ⚠️ OPERATOR TOKEN REGENERATION WARNING:
133
+ The regenerate_operator_token tool will:
134
+ - Invalidate the current operator token immediately
135
+ - Generate a new operator token
136
+ - Require updating INFLUX_TOKEN environment variable
137
+ - Require restarting the MCP server
138
+ - Cannot be undone (irreversible operation)
139
+ Use only when absolutely necessary and ensure you can update the environment!
140
+
141
+ === RESOURCE TOKENS ===
142
+
143
+ Resource Token Operations:
144
+ - Create: Use create_resource_token tool with specific databases and actions
145
+ - List: Use list_resource_tokens tool with filtering options:
146
+ * Filter by database name (partial match)
147
+ * Filter by token name (partial match)
148
+ * Order by: created_at, token_id, or name
149
+ * Order direction: ASC or DESC (default ASC)
150
+ - Delete: Use delete_token tool (provide exact token name)
151
+
152
+ Scope to specific databases with limited permissions.
153
+
154
+ Permission Examples:
155
+ - Read-only: databases=["mydb"], actions=["read"]
156
+ - Write-only: databases=["mydb"], actions=["write"]
157
+ - Full access: databases=["mydb"], actions=["read", "write"]
158
+ - Multi-database: databases=["db1", "db2"], actions=["read", "write"]
159
+
160
+ Best Practices:
161
+ - Use separate tokens for different applications
162
+ - Grant minimal required permissions
163
+ - Set expiration times for temporary access (expiry_secs parameter)
164
+ - Use descriptive names for token identification
165
+
166
+ === DATABASE MANAGEMENT ===
167
+
168
+ Database Operations:
169
+ - Create: Use create_database tool (provide database name, optional configuration parameters)
170
+ - Update: Use update_database tool (Cloud Dedicated and Cloud Serverless only - see parameters below)
171
+ - List: Use list_databases tool (no parameters - shows all databases)
172
+ - Delete: Use delete_database tool (provide exact database name - PERMANENT, no recovery)
173
+
174
+ Cloud Dedicated Parameters (create_database and update_database):
175
+ - maxTables: Maximum number of tables (default: 500)
176
+ - maxColumnsPerTable: Maximum columns per table (default: 200)
177
+ - retentionPeriod: Retention period in nanoseconds (default: 0 = no expiration)
178
+
179
+ Cloud Serverless Parameters (create_database and update_database):
180
+ - description: Bucket description for documentation
181
+ - retentionPeriod: Retention period in nanoseconds (default: 30 days)
182
+ - newName: New bucket name (update_database only - for renaming buckets)
183
+
184
+ Naming Rules:
185
+ - Alphanumeric characters, dashes (-), underscores (_), forward slashes (/)
186
+ - Must start with letter or number
187
+ - Maximum 64 characters
188
+ - Case sensitive
189
+
190
+ Database Structure:
191
+ - Contains measurements (tables)
192
+ - Each measurement has tags (indexed) and fields (data)
193
+ - Schema evolves dynamically with data (all InfluxDB versions)
194
+
195
+ Best Practices:
196
+ - Use descriptive database names
197
+ - Separate different data types into different databases
198
+ - Consider retention policies for large datasets
199
+ - Regular backups before deletion operations
200
+
201
+ Note: The list_databases tool returns all available databases with their details.
202
+ No filtering or querying parameters are supported - it shows the complete list.
203
+
204
+ === TROUBLESHOOTING ===
205
+
206
+ Connection Issues:
207
+ 1. Use health_check tool for comprehensive instance status (flexible assessment based on available endpoints)
208
+ 2. Verify INFLUX_URL environment variable
209
+ 3. Confirm INFLUX_TOKEN has proper permissions
210
+ 4. Test network connectivity to InfluxDB server
211
+
212
+ Health Check Notes:
213
+ - Different InfluxDB product types support different endpoints
214
+ - Cloud Dedicated does not have /health endpoint available
215
+ - Different tokens may have not access to certain endpoints
216
+ - If ANY check passes (connection, /health, /ping), instance is considered operational
217
+
218
+ Authentication Errors:
219
+ - Token expired or invalid
220
+ - Insufficient permissions for operation
221
+ - Token not properly configured for target database
222
+
223
+ Query Errors:
224
+ - Invalid SQL syntax (InfluxDB uses SQL, not InfluxQL)
225
+ - Missing time filters causing performance issues
226
+ - Incorrect measurement or field names
227
+ - Wrong database specified
228
+
229
+ Write Errors:
230
+ - Invalid line protocol format
231
+ - Missing required fields
232
+ - Tag value formatting issues
233
+ - Database doesn't exist
234
+ - Retention period violations (Cloud instances): Data timestamp outside allowed retention window
235
+
236
+ Performance Issues:
237
+ - Add time range filters to queries
238
+ - Use appropriate aggregation functions
239
+ - Index usage (tags vs fields)
240
+ - Consider data retention policies
241
+ `;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * HTTP Client Service
3
+ *
4
+ * Simple axios-based HTTP client for making authenticated requests to InfluxDB API
5
+ */
6
+ import axios from "axios";
7
+ import { InfluxProductType } from "../helpers/enums/influx-product-types.enum.js";
8
+ import { Agent } from "https";
9
+ export class HttpClientService {
10
+ axiosInstance;
11
+ constructor(baseURL, token, influxType) {
12
+ const axiosConfig = {
13
+ baseURL: baseURL?.replace(/\/$/, ""),
14
+ timeout: 30000,
15
+ headers: this.createAuthHeaders(token, influxType),
16
+ };
17
+ if (influxType === InfluxProductType.Clustered) {
18
+ axiosConfig.httpsAgent = new Agent({
19
+ rejectUnauthorized: false,
20
+ });
21
+ }
22
+ this.axiosInstance = axios.create(axiosConfig);
23
+ this.axiosInstance.interceptors.response.use((response) => {
24
+ return response;
25
+ }, (error) => {
26
+ return Promise.reject(error);
27
+ });
28
+ }
29
+ /**
30
+ * Create authentication headers with appropriate format for InfluxDB type
31
+ */
32
+ createAuthHeaders(token, influxType) {
33
+ const headers = {
34
+ "Content-Type": "application/json",
35
+ Accept: "application/json",
36
+ };
37
+ if (token?.trim()) {
38
+ if (influxType === InfluxProductType.CloudServerless) {
39
+ headers["Authorization"] = `Token ${token}`;
40
+ }
41
+ else {
42
+ headers["Authorization"] = `Bearer ${token}`;
43
+ }
44
+ }
45
+ return headers;
46
+ }
47
+ /**
48
+ * Make a GET request
49
+ */
50
+ async get(url, config) {
51
+ const response = await this.axiosInstance.get(url, config);
52
+ return response.data;
53
+ }
54
+ /**
55
+ * Make a POST request
56
+ */
57
+ async post(url, data, config) {
58
+ const response = await this.axiosInstance.post(url, data, config);
59
+ return response.data;
60
+ }
61
+ /**
62
+ * Make a PUT request
63
+ */
64
+ async put(url, data, config) {
65
+ const response = await this.axiosInstance.put(url, data, config);
66
+ return response.data;
67
+ }
68
+ /**
69
+ * Make a DELETE request
70
+ */
71
+ async delete(url, config) {
72
+ const deleteConfig = {
73
+ ...config,
74
+ headers: {
75
+ ...config?.headers,
76
+ Connection: "close",
77
+ },
78
+ };
79
+ try {
80
+ const response = await this.axiosInstance.delete(url, deleteConfig);
81
+ return response.data;
82
+ }
83
+ catch (error) {
84
+ if (error.message?.includes("aborted")) {
85
+ return {};
86
+ }
87
+ throw error;
88
+ }
89
+ }
90
+ /**
91
+ * Make a PATCH request
92
+ */
93
+ async patch(url, data, config) {
94
+ const response = await this.axiosInstance.patch(url, data, config);
95
+ return response.data;
96
+ }
97
+ /**
98
+ * Get the underlying axios instance for advanced usage
99
+ */
100
+ getAxiosInstance() {
101
+ return this.axiosInstance;
102
+ }
103
+ /**
104
+ * Create a configured instance for InfluxDB API calls
105
+ */
106
+ static createInfluxClient(baseUrl, token, influxType) {
107
+ return new HttpClientService(baseUrl, token, influxType);
108
+ }
109
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Master InfluxDB Service
3
+ *
4
+ * Orchestrates all specialized InfluxDB services and provides a unified interface
5
+ */
6
+ import { BaseConnectionService, } from "./base-connection.service.js";
7
+ import { QueryService } from "./query.service.js";
8
+ import { WriteService } from "./write.service.js";
9
+ import { DatabaseManagementService } from "./database-management.service.js";
10
+ import { TokenManagementService } from "./token-management.service.js";
11
+ import { CloudTokenManagementService } from "./cloud-token-management.service.js";
12
+ import { SchemaManagementService } from "./serverless-schema-management.service.js";
13
+ import { HelpService } from "./help.service.js";
14
+ import { ContextFileService } from "./context-file.service.js";
15
+ export class InfluxDBMasterService {
16
+ baseConnection;
17
+ queryService;
18
+ writeService;
19
+ databaseService;
20
+ tokenService;
21
+ cloudTokenService;
22
+ schemaService;
23
+ helpService;
24
+ contextFileService;
25
+ constructor(config) {
26
+ this.baseConnection = new BaseConnectionService(config);
27
+ this.queryService = new QueryService(this.baseConnection);
28
+ this.writeService = new WriteService(this.baseConnection);
29
+ this.databaseService = new DatabaseManagementService(this.baseConnection);
30
+ this.tokenService = new TokenManagementService(this.baseConnection);
31
+ this.cloudTokenService = new CloudTokenManagementService(this.baseConnection);
32
+ this.schemaService = new SchemaManagementService(this.baseConnection);
33
+ this.helpService = new HelpService();
34
+ this.contextFileService = new ContextFileService();
35
+ }
36
+ // ===== Connection & Health Methods =====
37
+ /**
38
+ * Get connection information
39
+ */
40
+ getConnectionInfo() {
41
+ return this.baseConnection.getConnectionInfo();
42
+ }
43
+ /**
44
+ * Ping InfluxDB instance and return version/type info
45
+ */
46
+ async ping() {
47
+ return this.baseConnection.ping();
48
+ }
49
+ /**
50
+ * Get health status
51
+ */
52
+ async getHealthStatus() {
53
+ return this.baseConnection.getHealthStatus();
54
+ }
55
+ // ===== Query Service Access =====
56
+ get query() {
57
+ return this.queryService;
58
+ }
59
+ // ===== Write Service Access =====
60
+ get write() {
61
+ return this.writeService;
62
+ }
63
+ // ===== Database Management Service Access =====
64
+ get database() {
65
+ return this.databaseService;
66
+ }
67
+ // ===== Token Management Service Access =====
68
+ get token() {
69
+ return this.tokenService;
70
+ }
71
+ /**
72
+ * Get the token management service instance
73
+ */
74
+ getTokenManagementService() {
75
+ return this.tokenService;
76
+ }
77
+ // ===== Cloud Token Management Service Access =====
78
+ get cloudToken() {
79
+ return this.cloudTokenService;
80
+ }
81
+ /**
82
+ * Get the cloud token management service instance
83
+ */
84
+ getCloudTokenManagementService() {
85
+ return this.cloudTokenService;
86
+ }
87
+ // ===== Schema Management Service Access =====
88
+ get schema() {
89
+ return this.schemaService;
90
+ }
91
+ /**
92
+ * Get the schema management service instance
93
+ */
94
+ getSchemaManagementService() {
95
+ return this.schemaService;
96
+ }
97
+ // ===== Help Service Access =====
98
+ get help() {
99
+ return this.helpService;
100
+ }
101
+ // ===== Context File Service Access =====
102
+ get contextFile() {
103
+ return this.contextFileService;
104
+ }
105
+ /**
106
+ * Get the context file service instance
107
+ */
108
+ getContextFileService() {
109
+ return this.contextFileService;
110
+ }
111
+ /**
112
+ * Get the main client instance (for advanced operations)
113
+ */
114
+ getClient() {
115
+ return this.baseConnection.getClient();
116
+ }
117
+ }