thedotmack/claude-mem · error
observation_context: "query" is required
Error message
observation_context: "query" is required
What it means
Validation error inside the observation_context tool handler. After the server-runtime guard passes, the handler requires args.query to be a non-empty trimmed string and throws this plain Error otherwise. It runs before ServerClient.contextObservations() issues the /v1/context request.
Source
Thrown at src/servers/mcp-server.ts:329
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 d768ba3643)
Solutions
- Supply a non-empty query string describing the context you want assembled.
- If you want project-scoped injection context without a query, use session_start_context with a projects list instead.
- Trim/validate the query client-side before calling.
Example fix
// before
await tools.observation_context({ limit: 5 });
// throws 'observation_context: "query" is required'
// after
await tools.observation_context({ query: 'authentication flow', limit: 5 }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof args?.query !== 'string' || args.query.trim().length === 0) {
return { content: [{ type: 'text', text: 'query is required for observation_context' }], isError: true };
} Type guard
function hasContextQuery(v: unknown): v is { query: string; limit?: number } {
return typeof (v as any)?.query === 'string' && (v as any).query.trim().length > 0;
} Prevention
- Distinguish observation_context (needs query) from session_start_context (needs projects).
- Trim and validate the query before invoking.
- Document the difference in tool descriptions to prevent LLM misuse.
When it happens
Trigger: Calling observation_context with query omitted, null, non-string, or whitespace-only. observation_context shares the same query requirement as observation_search but returns a pre-joined context string rather than a result list.
Common situations: Caller passes only limit/platformSource; an LLM confuses context (needs a query) with session_start_context (needs projects); query sourced from an empty variable.
Related errors
- observation_add: "content" is required
- observation_record_event: "eventType" is required
- observation_search: "query" is required
- observation_generation_status: "jobId" is required
- "${key}" is required
AI-assisted analysis of thedotmack/claude-mem@d768ba3643 (2026-08-12).
Data as JSON: /api/errors/72647f50580879e1.
Report an issue: GitHub.