Skip to main content
Glama

cortex_renew_user_key

Generate a new API key for a user, invalidating the previous key. Requires superadmin privileges.

Instructions

Generate a new API key for a user (invalidates the previous key). Requires superadmin API key.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userIdYesThe user login/ID to renew the key for

Implementation Reference

  • Tool handler for 'cortex_renew_user_key'. Checks superadmin availability, calls client.renewUserKey(userId), and returns the new API key in JSON response with a warning to store it securely. Handles errors gracefully.
    server.tool(
      "cortex_renew_user_key",
      "Generate a new API key for a user (invalidates the previous key). Requires superadmin API key.",
      {
        userId: z.string().describe("The user login/ID to renew the key for"),
      },
      async ({ userId }) => {
        try {
          if (!client.superadminAvailable) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: "User key management requires CORTEX_SUPERADMIN_KEY environment variable to be set.",
                },
              ],
              isError: true,
            };
          }
    
          const newKey = await client.renewUserKey(userId);
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(
                  {
                    userId,
                    apiKey: newKey,
                    message: `New API key generated for user "${userId}". The previous key is now invalid.`,
                    warning: "Store this key securely. It will not be shown again.",
                  },
                  null,
                  2,
                ),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error renewing user key: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      },
    );
  • Input schema for cortex_renew_user_key: requires 'userId' (string) described as 'The user login/ID to renew the key for'.
    {
      userId: z.string().describe("The user login/ID to renew the key for"),
    },
  • src/index.ts:44-44 (registration)
    Registration of the user tools module (which includes cortex_renew_user_key) via registerUserTools(server, client).
    registerUserTools(server, client);
  • Client helper method renewUserKey(userId) that sends POST to /user/{userId}/key/renew with superadmin auth and returns the plain text response (the new API key).
    async renewUserKey(userId: string): Promise<string> {
      return this.requestText(
        `/user/${encodeURIComponent(userId)}/key/renew`,
        { method: "POST" },
        true,
      );
    }
  • Private requestText utility used by renewUserKey to make an HTTP request and return the response body as plain text with superadmin bearer auth.
    private async requestText(
      path: string,
      options: RequestInit = {},
      useSuperadmin = false,
    ): Promise<string> {
      const url = `${this.baseUrl}${path}`;
      const controller = new AbortController();
      const timeoutId = setTimeout(() => controller.abort(), this.timeout);
      const authKey = useSuperadmin
        ? (this.config.superadminKey ?? this.config.apiKey)
        : this.config.apiKey;
    
      const headers: Record<string, string> = {
        Authorization: `Bearer ${authKey}`,
      };
      if (options.body) {
        headers["Content-Type"] = "application/json";
      }
    
      try {
        const response = await fetch(url, {
          ...options,
          headers: { ...headers, ...(options.headers as Record<string, string>) },
          signal: controller.signal,
        });
    
        if (!response.ok) {
          const body = await response.text().catch(() => "");
          throw new Error(`Cortex API error: HTTP ${response.status}${body ? ` - ${body}` : ""}`);
        }
    
        return response.text();
      } catch (error) {
        if (error instanceof Error && error.name === "AbortError") {
          throw new Error(`Cortex API timeout after ${this.timeout}ms`);
        }
        throw error;
      } finally {
        clearTimeout(timeoutId);
      }
    }
Behavior4/5

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

Discloses the destructive side effect: 'invalidates the previous key,' which is crucial for an agent to understand the impact. No annotations provided, so the description carries the full burden. Could mention if the invalidation is immediate or affects active sessions.

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?

Two concise sentences with no wasted words. Every sentence adds value: purpose, side effect, and authorization requirement.

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

Completeness4/5

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

For a simple tool with one parameter and no output schema, the description covers purpose, side effect, and prerequisite. Lacks details on response format or error conditions, but acceptable for its simplicity.

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 already describes 'userId' as 'The user login/ID to renew the key for' with 100% coverage. Description adds no further meaning beyond the schema, resulting in a baseline score of 3.

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

Purpose5/5

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

Description clearly states 'Generate a new API key for a user' with the specific verb 'renew' and resource 'user key'. It explicitly notes that it invalidates the previous key, distinguishing it from retrieval tools like 'cortex_get_user_key'.

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

Usage Guidelines4/5

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

States 'Requires superadmin API key,' providing a clear prerequisite. Does not explicitly exclude non-superadmin usage but implies it. No alternatives or when-not-to-use guidance given.

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

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/solomonneas/cortex-mcp'

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