search_project
Search your project knowledge base for solutions, patterns, and architecture decisions using your private entries and public community knowledge.
Instructions
Search project hive for knowledge. TRIGGERS: 'search my hive for [topic]', 'search hive [query]', 'find in hive [topic]', 'what does my hive know about [topic]'. Searches your private entries + optionally public entries. Returns relevant solutions, patterns, architecture decisions, etc.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | No | Optional: User ID (auto-detected from .user_id in cwd if not provided) | |
| query | Yes | Search query | |
| project_id | No | Optional: limit to specific project | |
| include_public | No | Include public entries in results (default: true) | |
| project_path | No | Optional: Project directory path (required for local storage) |
Implementation Reference
- src/api.ts:385-447 (handler)Core implementation of the search_project tool handler. Performs local keyword search on .hive.json for local storage or forwards to cloud Supabase API for cloud storage.export async function searchProject( userId: string | null, query: string, projectId?: string, includePublic: boolean = true, projectPath?: string ): Promise<SearchProjectResult> { // Auto-detect user_id if not provided if (!userId) { userId = await getUserId(projectPath); if (!userId) { throw new Error('No .user_id file found. Run init_hive first.'); } } // Check if local storage if (userId.startsWith('local-') && projectPath) { const hive = await readLocalHive(projectPath); if (!hive) { return { query, results: [], count: 0, source: 'local (not found)' }; } // Simple search: filter entries by query keywords const queryLower = query.toLowerCase(); const results = hive.entries.filter(entry => entry.query.toLowerCase().includes(queryLower) || entry.solution.toLowerCase().includes(queryLower) || entry.category.toLowerCase().includes(queryLower) ).map(entry => ({ query: entry.query, solution: entry.solution, category: entry.category, created_at: entry.created_at })); return { query, results, count: results.length, source: `local:${projectId}` }; } // Cloud storage - use API const response = await fetch(`${API_BASE}/search-project`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: userId, query, project_id: projectId, include_public: includePublic }), }); if (!response.ok) { throw new Error(`Search project failed: ${response.statusText}`); } return response.json(); }
- src/index.ts:187-217 (schema)Input schema and metadata definition for the search_project tool, registered in the MCP ListTools response.{ name: "search_project", description: "Search project hive for knowledge. TRIGGERS: 'search my hive for [topic]', 'search hive [query]', 'find in hive [topic]', 'what does my hive know about [topic]'. Searches your private entries + optionally public entries. Returns relevant solutions, patterns, architecture decisions, etc.", inputSchema: { type: "object", properties: { user_id: { type: "string", description: "Optional: User ID (auto-detected from .user_id in cwd if not provided)", }, query: { type: "string", description: "Search query", }, project_id: { type: "string", description: "Optional: limit to specific project", }, include_public: { type: "boolean", description: "Include public entries in results (default: true)", }, project_path: { type: "string", description: "Optional: Project directory path (required for local storage)", }, }, required: ["query"], }, },
- src/index.ts:434-445 (registration)Tool dispatch registration in the MCP CallToolRequestSchema handler switch statement.case "search_project": { const result = await searchProject( args?.user_id as string, args?.query as string, args?.project_id as string | undefined, args?.include_public as boolean | undefined, args?.project_path as string | undefined ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }
- src/api.ts:280-284 (schema)TypeScript interface defining the output structure of the search_project tool.interface SearchProjectResult { query: string; results: any[]; count: number; source: string;
- src/api.ts:26-37 (helper)Helper function to read local hive data from .hive.json file, used in local storage search.async function readLocalHive(projectPath: string): Promise<LocalHive | null> { const fs = await import('fs/promises'); const path = await import('path'); try { const hivePath = path.join(projectPath, '.hive.json'); const content = await fs.readFile(hivePath, 'utf-8'); return JSON.parse(content); } catch { return null; } }