Skip to main content
Glama
comet-ml

Opik MCP Server

by comet-ml

get-trace-by-id

Retrieve a specific trace by its ID to analyze or debug workflows in the Opik MCP Server. Supports optional workspace customization for targeted trace fetching.

Instructions

Get a single trace by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
traceIdYesID of the trace to fetch
workspaceNameNoWorkspace name to use instead of the default

Implementation Reference

  • Handler function that makes API request to fetch the specific trace by ID, formats the input/output fields as JSON strings if they are objects, and returns a formatted response with details.
    async (args: any) => {
      const { traceId, workspaceName } = args;
      const response = await makeApiRequest<SingleTraceResponse>(
        `/v1/private/traces/${traceId}`,
        {},
        workspaceName
      );
    
      if (!response.data) {
        return {
          content: [{ type: 'text', text: response.error || 'Failed to fetch trace' }],
        };
      }
    
      // Format the response for better readability
      const formattedResponse: any = { ...response.data };
    
      // Format input/output if they're large
      if (
        formattedResponse.input &&
        typeof formattedResponse.input === 'object' &&
        Object.keys(formattedResponse.input).length > 0
      ) {
        formattedResponse.input = JSON.stringify(formattedResponse.input, null, 2);
      }
    
      if (
        formattedResponse.output &&
        typeof formattedResponse.output === 'object' &&
        Object.keys(formattedResponse.output).length > 0
      ) {
        formattedResponse.output = JSON.stringify(formattedResponse.output, null, 2);
      }
    
      return {
        content: [
          {
            type: 'text',
            text: `Trace Details for ID: ${traceId}`,
          },
          {
            type: 'text',
            text: JSON.stringify(formattedResponse, null, 2),
          },
        ],
      };
    }
  • Input schema for the get-trace-by-id tool using Zod validation: requires traceId (string, UUID), optional workspaceName (string).
      traceId: z
        .string()
        .describe(
          'ID of the trace to fetch (UUID format, e.g. "123e4567-e89b-12d3-a456-426614174000")'
        ),
      workspaceName: z
        .string()
        .optional()
        .describe('Workspace name to use instead of the default workspace'),
    },
  • Registration of the 'get-trace-by-id' tool within the loadTraceTools function, including name, description, input schema, and inline handler.
    server.tool(
      'get-trace-by-id',
      'Get detailed information about a specific trace including input, output, metadata, and timing information',
      {
        traceId: z
          .string()
          .describe(
            'ID of the trace to fetch (UUID format, e.g. "123e4567-e89b-12d3-a456-426614174000")'
          ),
        workspaceName: z
          .string()
          .optional()
          .describe('Workspace name to use instead of the default workspace'),
      },
      async (args: any) => {
        const { traceId, workspaceName } = args;
        const response = await makeApiRequest<SingleTraceResponse>(
          `/v1/private/traces/${traceId}`,
          {},
          workspaceName
        );
    
        if (!response.data) {
          return {
            content: [{ type: 'text', text: response.error || 'Failed to fetch trace' }],
          };
        }
    
        // Format the response for better readability
        const formattedResponse: any = { ...response.data };
    
        // Format input/output if they're large
        if (
          formattedResponse.input &&
          typeof formattedResponse.input === 'object' &&
          Object.keys(formattedResponse.input).length > 0
        ) {
          formattedResponse.input = JSON.stringify(formattedResponse.input, null, 2);
        }
    
        if (
          formattedResponse.output &&
          typeof formattedResponse.output === 'object' &&
          Object.keys(formattedResponse.output).length > 0
        ) {
          formattedResponse.output = JSON.stringify(formattedResponse.output, null, 2);
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `Trace Details for ID: ${traceId}`,
            },
            {
              type: 'text',
              text: JSON.stringify(formattedResponse, null, 2),
            },
          ],
        };
      }
    );
  • src/index.ts:91-93 (registration)
    Conditional registration of the trace tools module (including get-trace-by-id) by calling loadTraceTools(server) when 'traces' toolset is enabled.
    if (config.enabledToolsets.includes('traces')) {
      server = loadTraceTools(server);
      logToFile('Loaded traces toolset');
Behavior2/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 of behavioral disclosure. It states it's a read operation ('get'), but doesn't cover aspects like error handling (e.g., what happens if the trace ID doesn't exist), rate limits, authentication requirements, or response format. For a tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

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 zero wasted words. It's front-loaded with the core purpose ('Get a single trace by ID'), making it immediately understandable. Every part of the sentence contributes directly to clarifying the tool's function.

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?

Given no annotations and no output schema, the description is incomplete for a tool with 2 parameters. It lacks details on behavioral traits (e.g., error cases, permissions), return values, and usage context. While the schema covers parameters well, the overall context for safe and effective use is insufficient, especially for a read operation that might involve workspace-specific data.

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%, with clear descriptions for both parameters: 'traceId' as the ID to fetch and 'workspaceName' as an optional override. The description adds no additional parameter semantics beyond what the schema provides, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate.

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 'Get a single trace by ID' clearly states the action (get) and resource (trace), with specificity about retrieving by ID. It distinguishes from siblings like 'list-traces' (multiple) and 'get-trace-stats' (statistics), though it doesn't explicitly name them. The purpose is unambiguous but lacks explicit sibling differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose it over 'list-traces' for multiple traces or 'get-trace-stats' for aggregated data, nor does it specify prerequisites like authentication or workspace context. Usage is implied by the name but not explicitly stated.

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/comet-ml/opik-mcp'

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