Skip to main content
Glama

create_or_update_credential

Create or update a credential for a consumer in the APISIX-MCP server, specifying username, credential ID, and configuration details.

Instructions

Create or update a credential for a consumer

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
credentialYescredential configuration object
idYescredential id
usernameYesconsumer username

Implementation Reference

  • Registers the 'create_or_update_credential' tool with its inline handler function that performs a PUT request to create or update a consumer credential via the admin API.
    server.tool("create_or_update_credential", "Create or update a credential for a consumer", CreateCredentialSchema.shape, async (args) => {
      return await makeAdminAPIRequest(`/consumers/${args.username}/credentials/${args.id}`, "PUT", args);
    });
  • The inline handler function for the tool that executes the logic: makes a PUT request to the APISIX admin API endpoint for the consumer's credential.
    server.tool("create_or_update_credential", "Create or update a credential for a consumer", CreateCredentialSchema.shape, async (args) => {
      return await makeAdminAPIRequest(`/consumers/${args.username}/credentials/${args.id}`, "PUT", args);
    });
  • Zod schema defining the input parameters for the create_or_update_credential tool: username, id, and credential object.
    export const CreateCredentialSchema = z.object({
      username: ConsumerSchema.shape.username,
      id: z.string().describe("credential id"),
      credential: CredentialSchema,
    });
  • Shared helper function called by the tool handler to perform HTTP requests to the APISIX admin API, handling success and error responses in MCP format.
    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),
              },
            ],
          };
        }
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states 'create or update' which implies mutation, but doesn't specify permissions required, whether updates are idempotent, error conditions (e.g., invalid consumer), or what happens on success/failure. This is inadequate for a mutation tool with zero annotation coverage.

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

Conciseness5/5

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

The description is a single, efficient sentence with no wasted words. It's appropriately sized and front-loaded with the core action, though it could benefit from additional context 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 mutation tool with no annotations, no output schema, and nested parameters, the description is incomplete. It doesn't explain what a 'credential' entails in this context, what the tool returns, error handling, or security implications. Given the complexity, more guidance is needed for effective use.

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 already documents all three parameters (username, id, credential) with their properties. The description doesn't add any meaning beyond what's in the schema—it doesn't explain the relationship between parameters (e.g., id identifies the credential, username identifies the consumer) or provide usage examples.

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

Purpose4/5

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

The description clearly states the action ('create or update') and resource ('credential for a consumer'), making the purpose understandable. However, it doesn't distinguish this tool from sibling tools like 'create_secret' or 'update_secret' which might handle similar resources, nor does it explain what type of credential this is (e.g., API key, OAuth token).

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 is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., consumer must exist), when to choose create vs. update, or how it differs from sibling tools like 'create_secret' or 'update_secret' that might handle credentials differently.

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