execute_kb_api
Run custom API requests in Kibana with multi-space support, enabling flexible data interactions via specified methods, paths, and parameters.
Instructions
Execute a custom API request for Kibana with multi-space support
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | No | ||
| method | Yes | ||
| params | No | ||
| path | Yes | ||
| space | No | Target Kibana space (optional, defaults to configured space) |
Implementation Reference
- src/base-tools.ts:177-226 (handler)Handler function that performs the actual API execution using kibanaClient methods (get, post, put, delete) based on input parameters, constructs query strings if params provided, handles multi-space support, and returns formatted ToolResponse with JSON response or error.async ({ method, path, body, params, space }): Promise<ToolResponse> => { try { const targetSpace = space || defaultSpace; let url = path; if (params) { const queryString = new URLSearchParams( Object.entries(params).map(([key, value]) => [key, String(value)]) ).toString(); url += `?${queryString}`; } let response; switch (method.toLowerCase()) { case 'get': response = await kibanaClient.get(url, { space }); break; case 'post': response = await kibanaClient.post(url, body, { space }); break; case 'put': response = await kibanaClient.put(url, body, { space }); break; case 'delete': response = await kibanaClient.delete(url, { space }); break; default: throw new Error(`Unsupported HTTP method: ${method}`); } return { content: [ { type: "text", text: `[Space: ${targetSpace}] API response: ${JSON.stringify(response, null, 2)}` } ] }; } catch (error) { console.error(`API request failed: ${error}`); return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
- src/base-tools.ts:170-176 (schema)Zod validation schema for tool inputs: method (required enum), path (required string), body (optional any), params (optional record of string/number/boolean), space (optional string).z.object({ method: z.enum(['GET', 'POST', 'PUT', 'DELETE']), path: z.string(), body: z.any().optional(), params: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(), space: z.string().optional().describe("Target Kibana space (optional, defaults to configured space)") }),
- src/base-tools.ts:168-227 (registration)Registration of the 'execute_kb_api' tool via server.tool() call, including name, description, schema, and handler function. Called within registerBaseTools function."execute_kb_api", `Execute a custom API request for Kibana with multi-space support`, z.object({ method: z.enum(['GET', 'POST', 'PUT', 'DELETE']), path: z.string(), body: z.any().optional(), params: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(), space: z.string().optional().describe("Target Kibana space (optional, defaults to configured space)") }), async ({ method, path, body, params, space }): Promise<ToolResponse> => { try { const targetSpace = space || defaultSpace; let url = path; if (params) { const queryString = new URLSearchParams( Object.entries(params).map(([key, value]) => [key, String(value)]) ).toString(); url += `?${queryString}`; } let response; switch (method.toLowerCase()) { case 'get': response = await kibanaClient.get(url, { space }); break; case 'post': response = await kibanaClient.post(url, body, { space }); break; case 'put': response = await kibanaClient.put(url, body, { space }); break; case 'delete': response = await kibanaClient.delete(url, { space }); break; default: throw new Error(`Unsupported HTTP method: ${method}`); } return { content: [ { type: "text", text: `[Space: ${targetSpace}] API response: ${JSON.stringify(response, null, 2)}` } ] }; } catch (error) { console.error(`API request failed: ${error}`); return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );