{"record":{"id":"72647f50580879e1","repo":"thedotmack/claude-mem","slug":"observation-context-query-is-required","errorCode":null,"errorMessage":"observation_context: \"query\" is required","messagePattern":"observation_context: \"query\" is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/servers/mcp-server.ts","lineNumber":334,"sourceCode":"    query: args.query,\n    ...(args.limit !== undefined ? { limit: args.limit } : {}),\n    ...(args.platformSource !== undefined ? { platformSource: normalizeMcpPlatformSource(args.platformSource) } : {}),\n  };\n  const response = await ctx.client.searchObservations(request);\n  return formatJsonResult(response);\n});\n\ninterface ObservationContextArgs {\n  projectId?: string;\n  query: string;\n  limit?: number;\n  platformSource?: string | null;\n}\n\nconst handleObservationContext = wrapHandler('observation_context', async (args: ObservationContextArgs) => {\n  const ctx = requireServerForObservationTool('observation_context');\n  if (typeof args?.query !== 'string' || args.query.trim().length === 0) {\n    throw new Error('observation_context: \"query\" is required');\n  }\n  const projectId = args.projectId && args.projectId.trim().length > 0 ? args.projectId : ctx.projectId;\n  const request: ServerContextObservationsRequest = {\n    projectId,\n    query: args.query,\n    ...(args.limit !== undefined ? { limit: args.limit } : {}),\n    ...(args.platformSource !== undefined ? { platformSource: normalizeMcpPlatformSource(args.platformSource) } : {}),\n  };\n  const response = await ctx.client.contextObservations(request);\n  return formatJsonResult(response);\n});\n\ninterface ObservationGenerationStatusArgs {\n  jobId?: string;\n  job_id?: string;\n}\n\ninterface SessionStartContextArgs {","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/servers/mcp-server.ts#L316-L352","documentation":"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.","triggerScenarios":"Calling observation_context with args missing query, or query = undefined / null / non-string / '' / '   ' (check: typeof args?.query !== 'string' || args.query.trim().length === 0).","commonSituations":"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.","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"],"exampleFix":"// before\nawait callTool('observation_context', { query: '', limit: 5 });\n// after\nawait callTool('observation_context', { query: 'memory leak in worker pool', limit: 5 });","handlingStrategy":"validation","validationCode":"function canBuildContext(args) {\n  return typeof args?.query === 'string' && args.query.trim().length > 0;\n}\nif (!canBuildContext(args)) return null; // no context to assemble","typeGuard":"function hasContextQuery(args: unknown): args is { query: string } & Record<string, unknown> {\n  return typeof (args as any)?.query === 'string' && (args as any).query.trim().length > 0;\n}","tryCatchPattern":"try {\n  return await callTool('observation_context', { query: taskText, limit: 5 });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('\"query\" is required')) {\n    return fallbackContext;\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["mcp","validation","context","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}