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
- Pass the current task or prompt text as query, e.g. { query: 'fix login timeout bug' }
- Skip the context call when no query text is available instead of sending an empty string
- Default the query from the conversation's latest user message before invoking
- 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
- Default query to the current task/prompt text before invoking
- Skip context injection hooks when no task text exists yet
- Trim task text and treat whitespace-only as absent
- Keep tool-arg builders centralized so required fields are enforced in one place
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
- " " is required
- Missing required argument: name
- observation_generation_status: "jobId" is required
- observation_record_event: "eventType" is required
- observation_search: "query" is required
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)