thedotmack/claude-mem · error

observation_context: "query" is required

Error message

observation_context: "query" is required

What it means

The observation_context tool handler requires a non-empty 'query' string and throws this error otherwise. Context assembly matches observations against the query, so an absent or blank query cannot produce a meaningful context request.

Solutions

  1. Pass the current task or prompt text as query, e.g. { query: 'fix login timeout bug' }
  2. Skip the context call when no query text is available instead of sending an empty string
  3. Default the query from the conversation's latest user message before invoking
  4. Confirm the tool schema marks query as required and your client validates arguments

Example fix

// before
await callTool('observation_context', { query: '', limit: 5 });
// after
await callTool('observation_context', { query: 'memory leak in worker pool', limit: 5 });
Defensive patterns

Strategy: validation

Validate before calling

function canBuildContext(args) {
  return typeof args?.query === 'string' && args.query.trim().length > 0;
}
if (!canBuildContext(args)) return null; // no context to assemble

Type guard

function hasContextQuery(args: unknown): args is { query: string } & Record<string, unknown> {
  return typeof (args as any)?.query === 'string' && (args as any).query.trim().length > 0;
}

Try / catch

try {
  return await callTool('observation_context', { query: taskText, limit: 5 });
} catch (e) {
  if (e instanceof Error && e.message.includes('"query" is required')) {
    return fallbackContext;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling observation_context with args missing query, or query = undefined / null / non-string / '' / ' ' (check: typeof args?.query !== 'string' || args.query.trim().length === 0).

Common situations: Automated context-injection hooks firing before any task text exists; empty prompt placeholders; callers confusing this tool with a no-argument context summary tool; query key accidentally nested inside another object.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/72647f50580879e1. Report an issue: GitHub.

Appendix: source

Thrown at src/servers/mcp-server.ts:334

    query: args.query,
    ...(args.limit !== undefined ? { limit: args.limit } : {}),
    ...(args.platformSource !== undefined ? { platformSource: normalizeMcpPlatformSource(args.platformSource) } : {}),
  };
  const response = await ctx.client.searchObservations(request);
  return formatJsonResult(response);
});

interface ObservationContextArgs {
  projectId?: string;
  query: string;
  limit?: number;
  platformSource?: string | null;
}

const handleObservationContext = wrapHandler('observation_context', async (args: ObservationContextArgs) => {
  const ctx = requireServerForObservationTool('observation_context');
  if (typeof args?.query !== 'string' || args.query.trim().length === 0) {
    throw new Error('observation_context: "query" is required');
  }
  const projectId = args.projectId && args.projectId.trim().length > 0 ? args.projectId : ctx.projectId;
  const request: ServerContextObservationsRequest = {
    projectId,
    query: args.query,
    ...(args.limit !== undefined ? { limit: args.limit } : {}),
    ...(args.platformSource !== undefined ? { platformSource: normalizeMcpPlatformSource(args.platformSource) } : {}),
  };
  const response = await ctx.client.contextObservations(request);
  return formatJsonResult(response);
});

interface ObservationGenerationStatusArgs {
  jobId?: string;
  job_id?: string;
}

interface SessionStartContextArgs {

View on GitHub (pinned to d8bc9755e7)