@tocharianou/mcp-server-kibana 0.6.1

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 (48) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +530 -0
  3. package/dist/index.d.ts +4 -0
  4. package/dist/index.js +417 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/kibana-openapi-source.yaml +52597 -0
  7. package/dist/src/analysis-tools.d.ts +6 -0
  8. package/dist/src/analysis-tools.js +134 -0
  9. package/dist/src/analysis-tools.js.map +1 -0
  10. package/dist/src/base-tools.d.ts +2 -0
  11. package/dist/src/base-tools.js +349 -0
  12. package/dist/src/base-tools.js.map +1 -0
  13. package/dist/src/dependency-analyzer.d.ts +65 -0
  14. package/dist/src/dependency-analyzer.js +233 -0
  15. package/dist/src/dependency-analyzer.js.map +1 -0
  16. package/dist/src/health-analyzer.d.ts +60 -0
  17. package/dist/src/health-analyzer.js +301 -0
  18. package/dist/src/health-analyzer.js.map +1 -0
  19. package/dist/src/kibana-openapi-source.yaml +52597 -0
  20. package/dist/src/openapi-simplifier.d.ts +33 -0
  21. package/dist/src/openapi-simplifier.js +122 -0
  22. package/dist/src/openapi-simplifier.js.map +1 -0
  23. package/dist/src/prompts.d.ts +2 -0
  24. package/dist/src/prompts.js +91 -0
  25. package/dist/src/prompts.js.map +1 -0
  26. package/dist/src/resources.d.ts +2 -0
  27. package/dist/src/resources.js +125 -0
  28. package/dist/src/resources.js.map +1 -0
  29. package/dist/src/types.d.ts +150 -0
  30. package/dist/src/types.js +38 -0
  31. package/dist/src/types.js.map +1 -0
  32. package/dist/src/vl_create_tools.d.ts +5 -0
  33. package/dist/src/vl_create_tools.js +264 -0
  34. package/dist/src/vl_create_tools.js.map +1 -0
  35. package/dist/src/vl_delete_tools.d.ts +5 -0
  36. package/dist/src/vl_delete_tools.js +158 -0
  37. package/dist/src/vl_delete_tools.js.map +1 -0
  38. package/dist/src/vl_get_tools.d.ts +5 -0
  39. package/dist/src/vl_get_tools.js +201 -0
  40. package/dist/src/vl_get_tools.js.map +1 -0
  41. package/dist/src/vl_search_tools.d.ts +9 -0
  42. package/dist/src/vl_search_tools.js +290 -0
  43. package/dist/src/vl_search_tools.js.map +1 -0
  44. package/dist/src/vl_update_tools.d.ts +5 -0
  45. package/dist/src/vl_update_tools.js +372 -0
  46. package/dist/src/vl_update_tools.js.map +1 -0
  47. package/kibana-openapi-source.yaml +52597 -0
  48. package/package.json +95 -0
@@ -0,0 +1,264 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Implementation function for creating a Kibana saved object.
4
+ *
5
+ * @param kibanaClient - The Kibana client instance
6
+ * @param type - The saved object type
7
+ * @param attributes - The object attributes
8
+ * @param id - Optional: specific ID for the object (if not provided, auto-generated)
9
+ * @param overwrite - Whether to overwrite existing object with same ID
10
+ * @param references - Array of references to other saved objects
11
+ * @param initialNamespaces - Array of initial namespaces for the object
12
+ * @param space - The Kibana space (optional)
13
+ * @returns Promise<ToolResponse> - The tool response containing the created object data
14
+ */
15
+ async function vl_create_saved_object_impl(kibanaClient, type, attributes, id, overwrite, references, initialNamespaces, space) {
16
+ try {
17
+ // Validate required parameters
18
+ if (!type) {
19
+ return {
20
+ content: [
21
+ {
22
+ type: "text",
23
+ text: "Error: 'type' parameter is required. Please specify the saved object type (e.g., 'dashboard', 'visualization', 'index-pattern')."
24
+ }
25
+ ],
26
+ isError: true
27
+ };
28
+ }
29
+ if (!attributes || typeof attributes !== 'object') {
30
+ return {
31
+ content: [
32
+ {
33
+ type: "text",
34
+ text: "Error: 'attributes' parameter is required and must be an object containing the saved object properties."
35
+ }
36
+ ],
37
+ isError: true
38
+ };
39
+ }
40
+ // Validate attributes based on type
41
+ const validationResult = validateAttributesByType(type, attributes);
42
+ if (!validationResult.valid) {
43
+ return {
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: `Error: Invalid attributes for type '${type}': ${validationResult.error}`
48
+ }
49
+ ],
50
+ isError: true
51
+ };
52
+ }
53
+ // Prepare request body
54
+ const requestBody = {
55
+ attributes
56
+ };
57
+ if (references && references.length > 0) {
58
+ requestBody.references = references;
59
+ }
60
+ if (initialNamespaces && initialNamespaces.length > 0) {
61
+ requestBody.initialNamespaces = initialNamespaces;
62
+ }
63
+ // Prepare URL and query parameters
64
+ const params = new URLSearchParams();
65
+ if (overwrite) {
66
+ params.append('overwrite', 'true');
67
+ }
68
+ // Choose API endpoint based on whether ID is specified
69
+ let url;
70
+ if (id) {
71
+ // Create with specific ID
72
+ url = `/api/saved_objects/${encodeURIComponent(type)}/${encodeURIComponent(id)}${params.toString() ? '?' + params.toString() : ''}`;
73
+ }
74
+ else {
75
+ // Create with auto-generated ID
76
+ url = `/api/saved_objects/${encodeURIComponent(type)}${params.toString() ? '?' + params.toString() : ''}`;
77
+ }
78
+ // Make the API call
79
+ const response = await kibanaClient.post(url, requestBody, { space });
80
+ // Format the response
81
+ const result = {
82
+ id: response.id,
83
+ type: response.type,
84
+ version: response.version,
85
+ updated_at: response.updated_at,
86
+ created_at: response.created_at,
87
+ namespaces: response.namespaces || [],
88
+ };
89
+ // Add attributes information
90
+ if (response.attributes) {
91
+ result.attributes = response.attributes;
92
+ // Add common fields for easier access
93
+ if (response.attributes.title) {
94
+ result.title = response.attributes.title;
95
+ }
96
+ if (response.attributes.description) {
97
+ result.description = response.attributes.description;
98
+ }
99
+ }
100
+ // Add references if present
101
+ if (response.references && response.references.length > 0) {
102
+ result.references = response.references;
103
+ }
104
+ // Add migration information if present
105
+ if (response.migrationVersion) {
106
+ result.migrationVersion = response.migrationVersion;
107
+ }
108
+ if (response.coreMigrationVersion) {
109
+ result.coreMigrationVersion = response.coreMigrationVersion;
110
+ }
111
+ return {
112
+ content: [
113
+ {
114
+ type: "text",
115
+ text: `Successfully created ${type} saved object:\n\n${JSON.stringify(result, null, 2)}`
116
+ }
117
+ ]
118
+ };
119
+ }
120
+ catch (error) {
121
+ const errorMessage = error instanceof Error ? error.message : String(error);
122
+ // Handle common error cases
123
+ if (errorMessage.includes('409') || errorMessage.includes('conflict')) {
124
+ return {
125
+ content: [
126
+ {
127
+ type: "text",
128
+ text: `Conflict error: A saved object with type '${type}' and id '${id}' already exists. Use 'overwrite: true' to replace it, or omit the 'id' parameter to create with auto-generated ID.`
129
+ }
130
+ ],
131
+ isError: true
132
+ };
133
+ }
134
+ if (errorMessage.includes('400')) {
135
+ return {
136
+ content: [
137
+ {
138
+ type: "text",
139
+ text: `Bad request error: ${errorMessage}\n\nPossible causes:\n- Invalid object type '${type}'\n- Invalid attributes structure\n- Missing required fields\n- Invalid references format`
140
+ }
141
+ ],
142
+ isError: true
143
+ };
144
+ }
145
+ return {
146
+ content: [
147
+ {
148
+ type: "text",
149
+ text: `Failed to create saved object: ${errorMessage}`
150
+ }
151
+ ],
152
+ isError: true
153
+ };
154
+ }
155
+ }
156
+ /**
157
+ * Validate attributes based on saved object type
158
+ */
159
+ function validateAttributesByType(type, attributes) {
160
+ // Common validation: title is usually required
161
+ if (!attributes.title || typeof attributes.title !== 'string') {
162
+ return { valid: false, error: "Missing required field 'title' (must be a non-empty string)" };
163
+ }
164
+ // Type-specific validation
165
+ switch (type) {
166
+ case 'dashboard':
167
+ // Dashboard-specific validation
168
+ if (attributes.panelsJSON && typeof attributes.panelsJSON !== 'string') {
169
+ return { valid: false, error: "Field 'panelsJSON' must be a JSON string" };
170
+ }
171
+ if (attributes.optionsJSON && typeof attributes.optionsJSON !== 'string') {
172
+ return { valid: false, error: "Field 'optionsJSON' must be a JSON string" };
173
+ }
174
+ if (attributes.timeRestore !== undefined && typeof attributes.timeRestore !== 'boolean') {
175
+ return { valid: false, error: "Field 'timeRestore' must be a boolean" };
176
+ }
177
+ break;
178
+ case 'visualization':
179
+ // Visualization-specific validation
180
+ if (attributes.visState && typeof attributes.visState !== 'string') {
181
+ return { valid: false, error: "Field 'visState' must be a JSON string" };
182
+ }
183
+ if (attributes.uiStateJSON && typeof attributes.uiStateJSON !== 'string') {
184
+ return { valid: false, error: "Field 'uiStateJSON' must be a JSON string" };
185
+ }
186
+ break;
187
+ case 'index-pattern':
188
+ // Index pattern specific validation
189
+ if (!attributes.title) {
190
+ return { valid: false, error: "Index pattern requires 'title' field (index pattern string)" };
191
+ }
192
+ if (attributes.timeFieldName && typeof attributes.timeFieldName !== 'string') {
193
+ return { valid: false, error: "Field 'timeFieldName' must be a string" };
194
+ }
195
+ break;
196
+ case 'search':
197
+ // Saved search validation
198
+ if (attributes.columns && !Array.isArray(attributes.columns)) {
199
+ return { valid: false, error: "Field 'columns' must be an array" };
200
+ }
201
+ break;
202
+ case 'lens':
203
+ // Lens visualization validation
204
+ if (!attributes.state && !attributes.expression) {
205
+ return { valid: false, error: "Lens visualization requires either 'state' or 'expression' field" };
206
+ }
207
+ break;
208
+ case 'map':
209
+ // Map validation
210
+ if (attributes.layerListJSON && typeof attributes.layerListJSON !== 'string') {
211
+ return { valid: false, error: "Field 'layerListJSON' must be a JSON string" };
212
+ }
213
+ break;
214
+ case 'canvas-workpad':
215
+ // Canvas workpad validation
216
+ if (!attributes.name) {
217
+ return { valid: false, error: "Canvas workpad requires 'name' field" };
218
+ }
219
+ if (attributes.pages && !Array.isArray(attributes.pages)) {
220
+ return { valid: false, error: "Field 'pages' must be an array" };
221
+ }
222
+ break;
223
+ default:
224
+ // For unknown types, just check basic structure
225
+ break;
226
+ }
227
+ return { valid: true };
228
+ }
229
+ /**
230
+ * Register VL (Visualization Layer) create tools with the MCP server
231
+ */
232
+ export function registerVLCreateTools(server, kibanaClient) {
233
+ // Tool: Create a Kibana saved object
234
+ server.tool("vl_create_saved_object", "Create a new Kibana saved object (dashboard, visualization, index-pattern, search, config, lens, map, tag, canvas-workpad, canvas-element, etc.). This is a universal tool that can create any type of saved object by specifying the type and attributes. Each object type has specific attribute requirements. IMPORTANT: The 'title' field is required for most object types. Complex fields like panelsJSON, visState should be JSON strings.", z.object({
235
+ type: z.union([z.string(), z.array(z.string())]).transform(val => {
236
+ if (Array.isArray(val))
237
+ return val[0]; // Take first type for single object creation
238
+ if (typeof val === 'string') {
239
+ try {
240
+ const parsed = JSON.parse(val);
241
+ return Array.isArray(parsed) ? parsed[0] : parsed;
242
+ }
243
+ catch {
244
+ const types = val.split(',').map(s => s.trim()).filter(s => s);
245
+ return types[0]; // Take first type
246
+ }
247
+ }
248
+ return val;
249
+ }).describe("REQUIRED: The saved object type. Common types: 'dashboard', 'visualization', 'index-pattern', 'search', 'config', 'lens', 'map', 'tag', 'canvas-workpad', 'canvas-element'. Supports multiple formats but will use first type for single object creation."),
250
+ attributes: z.record(z.any()).describe("REQUIRED: Object containing the saved object attributes. Structure varies by type. Common fields: 'title' (required for most types), 'description'. Dashboard: 'panelsJSON', 'timeRestore'. Visualization: 'visState', 'uiStateJSON'. Index-pattern: 'timeFieldName'. All JSON fields should be strings."),
251
+ id: z.string().optional().describe("OPTIONAL: Specific ID for the saved object. If not provided, Kibana will auto-generate a unique ID. Use this when you need a predictable ID or when recreating objects."),
252
+ overwrite: z.boolean().optional().describe("OPTIONAL: Whether to overwrite an existing object with the same ID. Only relevant when 'id' is specified. Default: false. Set to true to replace existing objects."),
253
+ references: z.array(z.object({
254
+ id: z.string().describe("ID of the referenced object"),
255
+ type: z.string().describe("Type of the referenced object"),
256
+ name: z.string().describe("Reference name used in the object")
257
+ })).optional().describe("OPTIONAL: Array of references to other saved objects. Used to link objects together (e.g., dashboard panels referencing visualizations). Each reference needs id, type, and name."),
258
+ initialNamespaces: z.array(z.string()).optional().describe("OPTIONAL: Array of initial namespaces for the object. Used for multi-tenant setups. If not specified, object will be created in the default namespace."),
259
+ space: z.string().optional().describe("Target Kibana space (optional, defaults to configured space)")
260
+ }), async (params) => {
261
+ return await vl_create_saved_object_impl(kibanaClient, params.type, params.attributes, params.id, params.overwrite, params.references, params.initialNamespaces, params.space);
262
+ });
263
+ }
264
+ //# sourceMappingURL=vl_create_tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vl_create_tools.js","sourceRoot":"","sources":["../../src/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B,CAAC;YAC1D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;SAC/D,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mLAAmL,CAAC;QAC5M,iBAAiB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wJAAwJ,CAAC;QACpN,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,8DAA8D,CAAC;KACtG,CAAC,EACF,KAAK,EAAE,MAQN,EAAyB,EAAE;QAC1B,OAAO,MAAM,2BAA2B,CACtC,YAAY,EACZ,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,EAAE,EACT,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,KAAK,CACb,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ServerBase, KibanaClient } from './types.js';
2
+ /**
3
+ * Register VL (Visualization Layer) delete tools with the MCP server
4
+ */
5
+ export declare function registerVLDeleteTools(server: ServerBase, kibanaClient: KibanaClient): void;
@@ -0,0 +1,158 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Implementation function for bulk deleting Kibana saved objects.
4
+ *
5
+ * @param kibanaClient - The Kibana client instance
6
+ * @param objects - Array of objects to delete, each containing type and id
7
+ * @param force - Force deletion of objects that exist in multiple namespaces
8
+ * @param space - The Kibana space (optional)
9
+ * @returns Promise<ToolResponse> - The tool response containing the bulk delete results
10
+ */
11
+ async function vl_bulk_delete_saved_objects_impl(kibanaClient, objects, force, space) {
12
+ try {
13
+ // Validate input
14
+ if (!objects || objects.length === 0) {
15
+ return {
16
+ content: [
17
+ {
18
+ type: "text",
19
+ text: "Error: No objects specified for deletion. Please provide at least one object with type and id."
20
+ }
21
+ ],
22
+ isError: true
23
+ };
24
+ }
25
+ // Validate each object has required fields
26
+ for (let i = 0; i < objects.length; i++) {
27
+ const obj = objects[i];
28
+ if (!obj.type || !obj.id) {
29
+ return {
30
+ content: [
31
+ {
32
+ type: "text",
33
+ text: `Error: Object at index ${i} is missing required 'type' or 'id' field. Each object must have both 'type' and 'id'.`
34
+ }
35
+ ],
36
+ isError: true
37
+ };
38
+ }
39
+ }
40
+ // Prepare request body
41
+ const requestBody = objects.map(obj => ({
42
+ type: obj.type,
43
+ id: obj.id
44
+ }));
45
+ // Prepare URL with query parameters
46
+ const params = new URLSearchParams();
47
+ if (force) {
48
+ params.append('force', 'true');
49
+ }
50
+ const url = `/api/saved_objects/_bulk_delete${params.toString() ? '?' + params.toString() : ''}`;
51
+ // Make the API call
52
+ const response = await kibanaClient.post(url, requestBody, { space });
53
+ // Process the response
54
+ const statuses = response.statuses || [];
55
+ // Count results
56
+ const successCount = statuses.filter((status) => status.success).length;
57
+ const errorCount = statuses.filter((status) => !status.success).length;
58
+ // Format detailed results
59
+ const results = statuses.map((status) => {
60
+ const result = {
61
+ type: status.type,
62
+ id: status.id,
63
+ success: status.success
64
+ };
65
+ if (status.error) {
66
+ result.error = {
67
+ statusCode: status.error.statusCode,
68
+ error: status.error.error,
69
+ message: status.error.message
70
+ };
71
+ }
72
+ return result;
73
+ });
74
+ // Create summary
75
+ const summary = `Bulk delete operation completed. ${successCount} objects deleted successfully, ${errorCount} errors occurred.`;
76
+ const responseText = [
77
+ summary,
78
+ '',
79
+ 'Detailed Results:',
80
+ JSON.stringify(results, null, 2)
81
+ ].join('\n');
82
+ return {
83
+ content: [
84
+ {
85
+ type: "text",
86
+ text: responseText
87
+ }
88
+ ],
89
+ isError: errorCount > 0
90
+ };
91
+ }
92
+ catch (error) {
93
+ const errorMessage = error instanceof Error ? error.message : String(error);
94
+ // Handle common error cases
95
+ if (errorMessage.includes('400')) {
96
+ return {
97
+ content: [
98
+ {
99
+ type: "text",
100
+ text: `Bad request error during bulk delete: ${errorMessage}\n\nPossible causes:\n- Invalid object type or ID format\n- Objects exist in multiple namespaces (try using force=true)\n- Missing required parameters`
101
+ }
102
+ ],
103
+ isError: true
104
+ };
105
+ }
106
+ if (errorMessage.includes('404')) {
107
+ return {
108
+ content: [
109
+ {
110
+ type: "text",
111
+ text: `Some objects not found during bulk delete: ${errorMessage}\n\nThis may indicate that one or more objects have already been deleted or never existed.`
112
+ }
113
+ ],
114
+ isError: true
115
+ };
116
+ }
117
+ return {
118
+ content: [
119
+ {
120
+ type: "text",
121
+ text: `Failed to bulk delete saved objects: ${errorMessage}`
122
+ }
123
+ ],
124
+ isError: true
125
+ };
126
+ }
127
+ }
128
+ /**
129
+ * Register VL (Visualization Layer) delete tools with the MCP server
130
+ */
131
+ export function registerVLDeleteTools(server, kibanaClient) {
132
+ // Tool: Bulk delete Kibana saved objects
133
+ server.tool("vl_bulk_delete_saved_objects", "Bulk delete multiple Kibana saved objects by type and ID. This is a destructive operation that permanently removes saved objects (dashboard, visualization, index-pattern, search, config, lens, map, tag, canvas-workpad, canvas-element, etc.). WARNING: Deleted objects cannot be recovered. Use with caution. IMPORTANT: Objects that exist in multiple namespaces require the 'force' parameter to be deleted.", z.object({
134
+ objects: z.array(z.object({
135
+ type: z.union([z.string(), z.array(z.string())]).transform(val => {
136
+ if (Array.isArray(val))
137
+ return val[0]; // Take first type for single object deletion
138
+ if (typeof val === 'string') {
139
+ try {
140
+ const parsed = JSON.parse(val);
141
+ return Array.isArray(parsed) ? parsed[0] : parsed;
142
+ }
143
+ catch {
144
+ const types = val.split(',').map(s => s.trim()).filter(s => s);
145
+ return types[0]; // Take first type
146
+ }
147
+ }
148
+ return val;
149
+ }).describe("REQUIRED: The saved object type. Common types: 'dashboard', 'visualization', 'index-pattern', 'search', 'config', 'lens', 'map', 'tag', 'canvas-workpad', 'canvas-element'. Supports multiple formats: single string 'dashboard', array ['dashboard'], JSON string '[\"dashboard\"]', or comma-separated 'dashboard,visualization' (will use first type for single object deletion)."),
150
+ id: z.string().describe("REQUIRED: The saved object ID. This is the unique identifier for the specific object you want to delete.")
151
+ })).min(1).describe("REQUIRED: Array of objects to delete. Each object must have 'type' and 'id' fields. Minimum 1 object required."),
152
+ force: z.boolean().optional().describe("Force deletion of objects that exist in multiple namespaces. Set to true if you get an error about objects existing in multiple namespaces. WARNING: This also deletes legacy URL aliases and can place heavy load on Kibana. Default: false."),
153
+ space: z.string().optional().describe("Target Kibana space (optional, defaults to configured space)")
154
+ }), async (params) => {
155
+ return await vl_bulk_delete_saved_objects_impl(kibanaClient, params.objects, params.force, params.space);
156
+ });
157
+ }
158
+ //# sourceMappingURL=vl_delete_tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vl_delete_tools.js","sourceRoot":"","sources":["../../src/vl_delete_tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;GAQG;AACH,KAAK,UAAU,iCAAiC,CAC9C,YAA0B,EAC1B,OAA4C,EAC5C,KAAe,EACf,KAAc;IAEd,IAAI,CAAC;QACH,iBAAiB;QACjB,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,gGAAgG;qBACvG;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAED,2CAA2C;QAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACvB,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACzB,OAAO;oBACL,OAAO,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AAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;wBAC/D,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB;oBACrC,CAAC;gBACH,CAAC;gBACD,OAAO,GAAG,CAAC;YACb,CAAC,CAAC,CAAC,QAAQ,CAAC,sXAAsX,CAAC;YACnY,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0GAA0G,CAAC;SACpI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gHAAgH,CAAC;QACrI,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+OAA+O,CAAC;QACvR,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,8DAA8D,CAAC;KACtG,CAAC,EACF,KAAK,EAAE,MAAyF,EAAyB,EAAE;QACzH,OAAO,MAAM,iCAAiC,CAC5C,YAAY,EACZ,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,KAAK,CACb,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ServerBase, KibanaClient } from './types.js';
2
+ /**
3
+ * Register VL (Visualization Layer) get tools with the MCP server
4
+ */
5
+ export declare function registerVLGetTools(server: ServerBase, kibanaClient: KibanaClient): void;
@@ -0,0 +1,201 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Implementation function for getting a single Kibana saved object by type and ID.
4
+ *
5
+ * @param kibanaClient - The Kibana client instance
6
+ * @param type - The saved object type (e.g., 'dashboard', 'visualization', 'index-pattern')
7
+ * @param id - The saved object ID
8
+ * @param useResolve - Whether to use resolve API (handles legacy URL aliases)
9
+ * @param space - The Kibana space (optional)
10
+ * @returns Promise<ToolResponse> - The tool response containing the saved object data
11
+ */
12
+ async function vl_get_saved_object_impl(kibanaClient, type, id, useResolve, space) {
13
+ try {
14
+ // Choose API endpoint based on useResolve flag
15
+ const endpoint = useResolve
16
+ ? `/api/saved_objects/resolve/${encodeURIComponent(type)}/${encodeURIComponent(id)}`
17
+ : `/api/saved_objects/${encodeURIComponent(type)}/${encodeURIComponent(id)}`;
18
+ const response = await kibanaClient.get(endpoint, { space });
19
+ // Format the response data
20
+ const savedObject = response;
21
+ if (!savedObject) {
22
+ return {
23
+ content: [
24
+ {
25
+ type: "text",
26
+ text: `No saved object found with type '${type}' and id '${id}'`
27
+ }
28
+ ],
29
+ isError: true
30
+ };
31
+ }
32
+ // Create formatted result with essential information
33
+ const result = {
34
+ id: savedObject.id,
35
+ type: savedObject.type,
36
+ updated_at: savedObject.updated_at,
37
+ created_at: savedObject.created_at,
38
+ version: savedObject.version,
39
+ managed: savedObject.managed || false,
40
+ namespaces: savedObject.namespaces || [],
41
+ };
42
+ // Add attributes if they exist
43
+ if (savedObject.attributes) {
44
+ if (savedObject.attributes.title !== undefined) {
45
+ result.title = savedObject.attributes.title;
46
+ }
47
+ if (savedObject.attributes.description !== undefined) {
48
+ result.description = savedObject.attributes.description;
49
+ }
50
+ // Type-specific attributes
51
+ if (savedObject.type === 'dashboard') {
52
+ if (savedObject.attributes.panelsJSON !== undefined) {
53
+ try {
54
+ const panels = JSON.parse(savedObject.attributes.panelsJSON);
55
+ result.panelCount = panels.length;
56
+ result.panels = panels.map((panel) => ({
57
+ id: panel.panelIndex,
58
+ type: panel.type,
59
+ title: panel.title || 'Untitled Panel'
60
+ }));
61
+ }
62
+ catch {
63
+ // Ignore parsing errors
64
+ }
65
+ }
66
+ if (savedObject.attributes.timeRestore !== undefined) {
67
+ result.timeRestore = savedObject.attributes.timeRestore;
68
+ }
69
+ if (savedObject.attributes.timeTo !== undefined) {
70
+ result.timeTo = savedObject.attributes.timeTo;
71
+ }
72
+ if (savedObject.attributes.timeFrom !== undefined) {
73
+ result.timeFrom = savedObject.attributes.timeFrom;
74
+ }
75
+ }
76
+ if (savedObject.type === 'visualization') {
77
+ if (savedObject.attributes.visState !== undefined) {
78
+ try {
79
+ const visState = JSON.parse(savedObject.attributes.visState);
80
+ result.visualizationType = visState.type;
81
+ result.visualizationTitle = visState.title;
82
+ }
83
+ catch {
84
+ // Ignore parsing errors
85
+ }
86
+ }
87
+ if (savedObject.attributes.kibanaSavedObjectMeta !== undefined) {
88
+ try {
89
+ const meta = JSON.parse(savedObject.attributes.kibanaSavedObjectMeta.searchSourceJSON);
90
+ if (meta.index) {
91
+ result.indexPattern = meta.index;
92
+ }
93
+ }
94
+ catch {
95
+ // Ignore parsing errors
96
+ }
97
+ }
98
+ }
99
+ if (savedObject.type === 'index-pattern') {
100
+ if (savedObject.attributes.title !== undefined) {
101
+ result.indexPatternTitle = savedObject.attributes.title;
102
+ }
103
+ if (savedObject.attributes.timeFieldName !== undefined) {
104
+ result.timeFieldName = savedObject.attributes.timeFieldName;
105
+ }
106
+ if (savedObject.attributes.fieldCount !== undefined) {
107
+ result.fieldCount = savedObject.attributes.fieldCount;
108
+ }
109
+ }
110
+ if (savedObject.type === 'search') {
111
+ if (savedObject.attributes.columns !== undefined) {
112
+ result.columns = savedObject.attributes.columns;
113
+ }
114
+ if (savedObject.attributes.sort !== undefined) {
115
+ result.sort = savedObject.attributes.sort;
116
+ }
117
+ }
118
+ // Include full attributes for completeness (can be large)
119
+ result.attributes = savedObject.attributes;
120
+ }
121
+ // Add references if they exist
122
+ if (savedObject.references && savedObject.references.length > 0) {
123
+ result.references = savedObject.references.map((ref) => ({
124
+ id: ref.id,
125
+ type: ref.type,
126
+ name: ref.name
127
+ }));
128
+ }
129
+ // Add resolve-specific information if using resolve API
130
+ if (useResolve && savedObject.outcome) {
131
+ result.outcome = savedObject.outcome;
132
+ if (savedObject.alias_target_id) {
133
+ result.alias_target_id = savedObject.alias_target_id;
134
+ }
135
+ if (savedObject.alias_purpose) {
136
+ result.alias_purpose = savedObject.alias_purpose;
137
+ }
138
+ }
139
+ return {
140
+ content: [
141
+ {
142
+ type: "text",
143
+ text: `Successfully retrieved saved object:\n\n${JSON.stringify(result, null, 2)}`
144
+ }
145
+ ]
146
+ };
147
+ }
148
+ catch (error) {
149
+ const errorMessage = error instanceof Error ? error.message : String(error);
150
+ // Handle common error cases
151
+ if (errorMessage.includes('404') || errorMessage.includes('Not Found')) {
152
+ return {
153
+ content: [
154
+ {
155
+ type: "text",
156
+ text: `Saved object not found: type '${type}', id '${id}'. Please verify the type and ID are correct.`
157
+ }
158
+ ],
159
+ isError: true
160
+ };
161
+ }
162
+ return {
163
+ content: [
164
+ {
165
+ type: "text",
166
+ text: `Failed to retrieve saved object: ${errorMessage}`
167
+ }
168
+ ],
169
+ isError: true
170
+ };
171
+ }
172
+ }
173
+ /**
174
+ * Register VL (Visualization Layer) get tools with the MCP server
175
+ */
176
+ export function registerVLGetTools(server, kibanaClient) {
177
+ // Tool: Get a single Kibana saved object by type and ID
178
+ server.tool("vl_get_saved_object", "Get a single Kibana saved object by type and ID. This is a universal tool that can retrieve any type of saved object (dashboard, visualization, index-pattern, search, config, lens, map, tag, canvas-workpad, canvas-element, etc.) by its exact type and ID. Use this when you know the specific object you want to retrieve. PERFORMANCE: This is much faster than searching when you have the exact type and ID.", z.object({
179
+ type: z.union([z.string(), z.array(z.string())]).transform(val => {
180
+ if (Array.isArray(val))
181
+ return val[0]; // Take first type for single object retrieval
182
+ if (typeof val === 'string') {
183
+ try {
184
+ const parsed = JSON.parse(val);
185
+ return Array.isArray(parsed) ? parsed[0] : parsed;
186
+ }
187
+ catch {
188
+ const types = val.split(',').map(s => s.trim()).filter(s => s);
189
+ return types[0]; // Take first type
190
+ }
191
+ }
192
+ return val;
193
+ }).describe("REQUIRED: The saved object type. Common types: 'dashboard', 'visualization', 'index-pattern', 'search', 'config', 'lens', 'map', 'tag', 'canvas-workpad', 'canvas-element'. Supports multiple formats: single string 'dashboard', array ['dashboard'], JSON string '[\"dashboard\"]', or comma-separated 'dashboard,visualization' (will use first type for single object retrieval)."),
194
+ id: z.string().describe("REQUIRED: The saved object ID. This is the unique identifier for the specific object you want to retrieve."),
195
+ useResolve: z.boolean().optional().describe("Use resolve API instead of get API. The resolve API can handle legacy URL aliases from object ID migrations. Use this if you're having trouble finding an object that may have had its ID changed during Kibana upgrades. Default: false."),
196
+ space: z.string().optional().describe("Target Kibana space (optional, defaults to configured space)")
197
+ }), async (params) => {
198
+ return await vl_get_saved_object_impl(kibanaClient, params.type, params.id, params.useResolve, params.space);
199
+ });
200
+ }
201
+ //# sourceMappingURL=vl_get_tools.js.map