Skip to main content
Glama
AgentOps-AI

AgentOps MCP

Official
by AgentOps-AI

auth

Authorize access to AgentOps MCP server by validating API keys for observability and tracing data during AI agent debugging.

Instructions

Authorize using the AGENTOPS_API_KEY. If the API key is not provided and cannot be found in the directory, ask the user for the API key.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
api_keyNoAgentOps project API key (optional if AGENTOPS_API_KEY environment variable is set)

Implementation Reference

  • Handler logic for the 'auth' tool: authenticates using provided or env API key, stores JWT token in server state, fetches project name for confirmation.
    case "auth": {
      const { api_key } = args as { api_key?: string };
    
      // Check if already authenticated
      if (serverState.isAuthenticated() && !api_key) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  success: true,
                  message: "Already authenticated",
                  source:
                    "Previously authenticated (likely from environment variable on startup)",
                },
                null,
                2,
              ),
            },
          ],
        };
      }
    
      // Try to get API key from environment first, then from parameter
      const actualApiKey = api_key || process.env["AGENTOPS_API_KEY"];
      if (!actualApiKey) {
        throw new Error(
          "No project API key available. Please provide a project API key.",
        );
      }
    
      const authResult = await authWithApiKey(actualApiKey);
      if (typeof authResult === "object" && "error" in authResult) {
        throw new Error(`Authentication failed: ${authResult.error}`);
      }
    
      // Store the JWT token in server state
      serverState.setJwtToken(authResult);
    
      const result = await makeAuthenticatedRequest(`/public/v1/project`);
      const name = result.name;
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                success: true,
                message: "Authentication successful",
                project: name,
              },
              null,
              2,
            ),
          },
        ],
      };
    }
  • Input schema definition for the 'auth' tool, as returned in ListTools response.
    {
      name: "auth",
      description:
        "Authorize using the AGENTOPS_API_KEY. If the API key is not provided and cannot be found in the directory, ask the user for the API key.",
      inputSchema: {
        type: "object",
        properties: {
          api_key: {
            type: "string",
            description:
              "AgentOps project API key (optional if AGENTOPS_API_KEY environment variable is set)",
          },
        },
        required: [],
      },
    },
  • src/index.ts:162-226 (registration)
    Registration of the 'auth' tool via the ListToolsRequestSchema handler, including it in the tools list.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "auth",
            description:
              "Authorize using the AGENTOPS_API_KEY. If the API key is not provided and cannot be found in the directory, ask the user for the API key.",
            inputSchema: {
              type: "object",
              properties: {
                api_key: {
                  type: "string",
                  description:
                    "AgentOps project API key (optional if AGENTOPS_API_KEY environment variable is set)",
                },
              },
              required: [],
            },
          },
          {
            name: "get_trace",
            description: "Get trace information and metrics by trace_id.",
            inputSchema: {
              type: "object",
              properties: {
                trace_id: {
                  type: "string",
                  description: "Trace ID",
                },
              },
              required: ["trace_id"],
            },
          },
          {
            name: "get_span",
            description: "Get span information and metrics by span_id.",
            inputSchema: {
              type: "object",
              properties: {
                span_id: {
                  type: "string",
                  description: "Span ID",
                },
              },
              required: ["span_id"],
            },
          },
          {
            name: "get_complete_trace",
            description:
              "Reserved for explicit requests for COMPLETE or ALL data. Get complete trace information and metrics by trace_id.",
            inputSchema: {
              type: "object",
              properties: {
                trace_id: {
                  type: "string",
                  description: "Trace ID",
                },
              },
              required: ["trace_id"],
            },
          },
        ],
      };
    });
  • Helper function authWithApiKey that performs the actual API call to obtain JWT token from AgentOps.
    async function authWithApiKey(apiKey: string): Promise<string | ErrorResponse> {
      const data = { api_key: apiKey };
    
      try {
        const response: AxiosResponse = await axios.post(
          `${HOST}/public/v1/auth/access_token`,
          data,
        );
        const bearer = response.data?.bearer;
        if (!bearer) {
          throw new Error("No bearer token received from auth endpoint");
        }
        return bearer;
      } catch (error) {
        return { error: error instanceof Error ? error.message : String(error) };
      }
    }
  • ServerState class that manages the JWT token and provides auth headers and auth status checks.
    class ServerState {
      private jwtToken: string | null = null;
    
      setJwtToken(token: string): void {
        this.jwtToken = token;
      }
    
      getAuthHeaders(): AuthHeaders | null {
        if (!this.jwtToken) {
          return null;
        }
        return {
          Authorization: `Bearer ${this.jwtToken}`,
          "User-Agent": "agentops-mcp/0.3.5",
        };
      }
    
      isAuthenticated(): boolean {
        return this.jwtToken !== null;
      }
    
      clearAuth(): void {
        this.jwtToken = null;
      }
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool handles authorization with an API key, including fallback to user input if missing, which is useful behavioral context. However, it doesn't mention what happens after authorization (e.g., does it return a token, set a session, or enable other tools?), rate limits, or error handling, leaving gaps in transparency for a security-related tool.

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 two sentences that are front-loaded and waste-free. The first sentence states the core purpose, and the second provides critical usage guidance. Every word contributes to understanding the tool's role and invocation logic, making it highly efficient and well-structured.

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

Completeness3/5

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

Given the tool's complexity (authorization with security implications), lack of annotations, and no output schema, the description is moderately complete. It covers the basic purpose and usage but omits details like what authorization enables, return values, or error cases. For a tool named 'auth' with siblings focused on data retrieval, more context on its role in the workflow would improve completeness.

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

Parameters4/5

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

The schema description coverage is 100%, with the parameter 'api_key' well-documented in the schema as optional if an environment variable is set. The description adds value by explaining the fallback behavior ('ask the user for the API key') and implying a directory lookup, which provides context beyond the schema's technical details. With only one parameter and high schema coverage, this earns a strong score.

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's purpose is to 'Authorize using the AGENTOPS_API_KEY,' which is a clear verb+resource combination. However, it doesn't distinguish this from potential sibling tools (like get_complete_trace, get_span, get_trace) or explain what authorization enables. The purpose is understandable but lacks context about what system or capabilities authorization unlocks.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool: 'If the API key is not provided and cannot be found in the directory, ask the user for the API key.' This clearly outlines the fallback behavior and conditions for invocation, making it easy for an agent to decide when this tool is necessary versus relying on environment variables or other methods.

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/AgentOps-AI/agentops-mcp'

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