Skip to main content
Glama
therealsachin

Langfuse MCP Server

get_trace_detail

Retrieve comprehensive trace data including all observations to analyze performance, costs, and usage patterns for debugging and optimization.

Instructions

Get detailed information about a specific trace including all observations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
traceIdYesThe trace ID to retrieve

Implementation Reference

  • The core handler function that fetches a specific trace by ID, retrieves associated observations, constructs a detailed TraceDetail object, and returns it as formatted JSON. Handles errors by returning error content.
    export async function getTraceDetail(
      client: LangfuseAnalyticsClient,
      args: z.infer<typeof getTraceDetailSchema>
    ) {
      try {
        const [traceResponse, observationsResponse] = await Promise.all([
          client.getTrace(args.traceId),
          client.listObservations({ traceId: args.traceId }),
        ]);
    
        const trace = traceResponse;
        const observations = observationsResponse.data || [];
    
        const detail: TraceDetail = {
          traceId: trace.id,
          name: trace.name || 'Unnamed trace',
          totalCost: trace.totalCost || 0,
          totalTokens: trace.totalTokens || 0,
          timestamp: trace.timestamp,
          userId: trace.userId,
          tags: trace.tags,
          metadata: trace.metadata,
          observations: observations.map((obs: any) => ({
            id: obs.id,
            type: obs.type,
            name: obs.name,
            startTime: obs.startTime,
            endTime: obs.endTime,
            model: obs.model,
            inputTokens: obs.usage?.input,
            outputTokens: obs.usage?.output,
            totalTokens: obs.usage?.total,
            cost: obs.calculatedTotalCost,
          })),
        };
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(detail, null, 2),
            },
          ],
        };
      } catch (error) {
        // Handle case where trace doesn't exist or API error
        const errorMessage = error instanceof Error ? error.message : 'Unknown error';
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify({
                error: `Failed to retrieve trace ${args.traceId}: ${errorMessage}`,
                traceId: args.traceId,
              }, null, 2),
            },
          ],
          isError: true,
        };
      }
    }
  • Zod schema for input validation, requiring a single 'traceId' string parameter.
    export const getTraceDetailSchema = z.object({
      traceId: z.string(),
    });
  • src/index.ts:1025-1028 (registration)
    Registration in the CallToolRequest switch statement: parses arguments using the schema and invokes the handler function.
    case 'get_trace_detail': {
      const args = getTraceDetailSchema.parse(request.params.arguments);
      return await getTraceDetail(this.client, args);
    }
  • src/index.ts:275-288 (registration)
    Tool metadata registration in the ListToolsRequest handler, defining name, description, and input schema for discovery.
      name: 'get_trace_detail',
      description:
        'Get detailed information about a specific trace including all observations.',
      inputSchema: {
        type: 'object',
        properties: {
          traceId: {
            type: 'string',
            description: 'The trace ID to retrieve',
          },
        },
        required: ['traceId'],
      },
    },
  • Inclusion in readonly tools set, allowing the tool in readonly server mode.
    'get_trace_detail',
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 it 'gets' information, implying a read-only operation, but doesn't clarify if it requires authentication, has rate limits, returns paginated results, or what format the 'detailed information' includes. This leaves significant behavioral gaps for a tool with no 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 that directly states the tool's function without unnecessary words. It is appropriately sized and front-loaded, with every word contributing to understanding the purpose.

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 that retrieves 'detailed information'. It doesn't explain what 'detailed information' entails, how observations are included, or the response structure. For a read operation with rich expected output, this lack of detail is a significant gap.

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?

The input schema has 100% description coverage, with the single parameter 'traceId' documented as 'The trace ID to retrieve'. The description adds no additional meaning beyond this, such as format examples or sourcing details. Since schema coverage is high, 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 clearly states the verb ('Get') and resource ('detailed information about a specific trace including all observations'), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'get_traces' (which likely lists traces) or 'get_observation_detail' (which focuses on individual observations), missing full 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 this over 'get_traces' for a list or 'get_observation_detail' for observation-specific details, nor does it specify prerequisites or exclusions for usage.

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/therealsachin/langfuse-mcp'

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