Skip to main content
Glama

get_resource

Retrieve detailed resource information by ID or list all resources in the APISIX ecosystem. Filter results by type, name, labels, or URI, and paginate through large datasets effectively.

Instructions

Get resource details by ID or list all resources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNoresource id
labelsNofilter labels
nameNofilter name
pageNopage number
page_sizeNopage size
typeYesresource type
uriNofilter uri

Implementation Reference

  • Inline asynchronous handler function for the 'get_resource' tool. Retrieves a specific resource by ID or lists resources with optional pagination and filters by constructing the appropriate Admin API path and delegating to makeAdminAPIRequest.
    server.tool("get_resource", "Get resource details by ID or list all resources", GetResourceSchema.shape, async (args) => {
      if (args.id) {
        return await makeAdminAPIRequest(`/${args.type}/${args.id}`);
      } else {
        let query = "";
        if (args.name) {
          query += `&name=${args.name}`;
        }
        if (args.labels) {
          query += `&labels=${args.labels}`;
        }
        if (args.uri) {
          query += `&uri=${args.uri}`;
        }
        return await makeAdminAPIRequest(`/${args.type}?page=${args.page}&page_size=${args.page_size}${query}`);
      }
    });
  • Zod schema defining the input parameters for the get_resource tool: optional 'id' for specific resource, required 'type', pagination ('page', 'page_size'), and filters ('name', 'labels', 'uri'). Composed from PaginationSchema and FilterSchema.
    export const GetResourceSchema = z
      .object({
        id: z.string().optional().describe("resource id"),
        type: ResourceTypeSchema.describe("resource type"),
      })
      .merge(PaginationSchema)
      .merge(FilterSchema);
  • Supporting utility function makeAdminAPIRequest that performs HTTP requests to the APISIX Admin API with authentication, used by the get_resource handler to fetch resource data and handles both success and error responses formatting them as MCP CallToolResult.
    export async function makeAdminAPIRequest(
      path: string,
      method: string = "GET",
      data?: object
    ): Promise<CallToolResult> {
      const baseUrl = `${APISIX_SERVER_HOST}:${APISIX_ADMIN_API_PORT}${APISIX_ADMIN_API_PREFIX}`;
      const url = `${baseUrl}${path}`;
    
      try {
        const response = await axios({
          method,
          url,
          data,
          headers: {
            "X-API-KEY": APISIX_ADMIN_KEY,
            "Content-Type": "application/json",
          },
        });
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(response.data, null, 2),
            },
          ],
        };
      } catch (error) {
        if (axios.isAxiosError(error)) {
          console.error(`Request failed: ${method} ${url}`);
          console.error(
            `Status: ${error.response?.status}, Error: ${error.message}`
          );
    
          if (error.response?.data) {
            try {
              const stringifiedData = JSON.stringify(error.response.data);
              console.error(`Response data: ${stringifiedData}`);
            } catch {
              console.error(`Response data: [Cannot parse as JSON]`);
            }
          }
    
          return {
            isError: true,
            content: [
              {
                type: "text",
                text: JSON.stringify(
                  `Status: ${error.response?.status}\nMessage: ${error.message}
    Data:\n${JSON.stringify(error.response?.data || {}, null, 2)}`,
                  null,
                  2
                ),
              },
            ],
          };
        } else {
          return {
            isError: true,
            content: [
              {
                type: "text",
                text: JSON.stringify(error, null, 2),
              },
            ],
          };
        }
      }
    }
  • Registration of the get_resource tool on the MCP server using server.tool, specifying name, description, input schema, and inline handler function.
    server.tool("get_resource", "Get resource details by ID or list all resources", GetResourceSchema.shape, async (args) => {
      if (args.id) {
        return await makeAdminAPIRequest(`/${args.type}/${args.id}`);
      } else {
        let query = "";
        if (args.name) {
          query += `&name=${args.name}`;
        }
        if (args.labels) {
          query += `&labels=${args.labels}`;
        }
        if (args.uri) {
          query += `&uri=${args.uri}`;
        }
        return await makeAdminAPIRequest(`/${args.type}?page=${args.page}&page_size=${args.page_size}${query}`);
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but provides minimal behavioral context. It doesn't mention pagination behavior (implied by page/page_size parameters), authentication requirements, rate limits, or what happens when no ID is provided. The 'list all resources' phrasing is misleading since parameters allow filtering.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is brief and front-loaded with the core functionality. However, it could be more structured to separate the two modes (get by ID vs list with filters) and might benefit from slightly more detail given the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 7 parameters, no annotations, no output schema, and complex filtering/pagination behavior, the description is inadequate. It doesn't explain the relationship between parameters, the meaning of 'resource' in context, or what the tool returns. Sibling tools suggest this is part of an API gateway system, but this context is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema documents all parameters well. The description adds minimal value beyond the schema - it mentions ID-based lookup and listing, but doesn't explain how parameters interact (e.g., that 'type' is required, or how filtering works with pagination).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool retrieves resource details, but it's vague about what 'resource' means and doesn't distinguish from siblings like 'get_credential' or 'get_secret_by_id'. It mentions two modes (by ID or list all) but lacks specificity about the resource types involved.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like 'get_credential' or 'get_secret_by_id'. The description implies it can list all resources, but doesn't clarify if this is preferred over other listing tools or when filtering is needed.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/api7/apisix-mcp'

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