Skip to main content
Glama

trace_usage

Analyze how client code uses MCP tools by finding callTool() invocations and tracking result property access to detect schema mismatches.

Instructions

Trace how client code uses MCP tools. Finds callTool() invocations and tracks which properties are accessed on results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rootDirYesRoot directory of consumer source code
includeNoGlob patterns to include
excludeNoGlob patterns to exclude

Implementation Reference

  • MCP tool handler case for 'trace_usage': parses input with TraceUsageInput, invokes traceConsumerUsage on consumer directory, logs results, and returns JSON-formatted usage data.
    case 'trace_usage': { const input = TraceUsageInput.parse(args); log(`Tracing usage in: ${input.rootDir}`); const usage = await traceConsumerUsage({ rootDir: input.rootDir, include: input.include, exclude: input.exclude, }); log(`Found ${usage.length} tool calls`); return { content: [ { type: 'text', text: JSON.stringify({ success: true, count: usage.length, usage, }, null, 2), }, ], }; }
  • Zod input schema for trace_usage tool defining rootDir (required), optional include/exclude globs.
    const TraceUsageInput = z.object({ rootDir: z.string().describe('Root directory of consumer/client source code'), include: z.array(z.string()).optional().describe('Glob patterns to include'), exclude: z.array(z.string()).optional().describe('Glob patterns to exclude'), });
  • src/index.ts:154-166 (registration)
    Registration of 'trace_usage' tool in ListTools response, including name, description, and inputSchema matching the Zod schema.
    { name: 'trace_usage', description: 'Trace how client code uses MCP tools. Finds callTool() invocations and tracks which properties are accessed on results.', inputSchema: { type: 'object', properties: { rootDir: { type: 'string', description: 'Root directory of consumer source code' }, include: { type: 'array', items: { type: 'string' }, description: 'Glob patterns to include' }, exclude: { type: 'array', items: { type: 'string' }, description: 'Glob patterns to exclude' }, }, required: ['rootDir'], }, },
  • Core execution logic for trace_usage: selects language parser (default typescript) and delegates to parser.traceUsage to scan consumer code for MCP tool calls.
    export async function traceConsumerUsage( options: TracerOptions ): Promise<ConsumerSchema[]> { // For backward compatibility, default to TypeScript const language = options.language || 'typescript'; // Get parser from registry if (!hasParser(language)) { throw new Error( `No parser available for language: ${language}. Make sure to call bootstrapLanguageParsers() at startup.` ); } const parser = getParser(language); return parser.traceUsage({ rootDir: options.rootDir, callPatterns: options.callPatterns, include: options.include, exclude: options.exclude, }); }
  • TypeScript-specific parser implementation of traceUsage method, invoked for default language, containing the AST traversal logic to find MCP callTool invocations and property accesses.
    async traceUsage(options: TraceOptions): Promise<ConsumerSchema[]> {

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/Mnehmos/mnehmos.trace.mcp'

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