Skip to main content
Glama
TocharianOU

Kibana MCP Server

by TocharianOU

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
NameRequiredDescriptionDefault
bodyNo
methodYes
paramsNo
pathYes
spaceNoTarget Kibana space (optional, defaults to configured space)

Implementation Reference

  • 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
        };
      }
    }
  • 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)")
    }),
  • 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
          };
        }
      }
    );

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TocharianOU/mcp-server-kibana'

If you have feedback or need assistance with the MCP directory API, please join our Discord server