{"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":329,"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":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/servers/mcp-server.ts#L311-L347","documentation":"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.","triggerScenarios":"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.","commonSituations":"Caller passes only limit/platformSource; an LLM confuses context (needs a query) with session_start_context (needs projects); query sourced from an empty variable.","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."],"exampleFix":"// before\nawait tools.observation_context({ limit: 5 });\n// throws 'observation_context: \"query\" is required'\n\n// after\nawait tools.observation_context({ query: 'authentication flow', limit: 5 });","handlingStrategy":"validation","validationCode":"if (typeof args?.query !== 'string' || args.query.trim().length === 0) {\n  return { content: [{ type: 'text', text: 'query is required for observation_context' }], isError: true };\n}","typeGuard":"function hasContextQuery(v: unknown): v is { query: string; limit?: number } {\n  return typeof (v as any)?.query === 'string' && (v as any).query.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["mcp","validation","observation-tools","context"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}