Skip to main content
Glama

search_conversations

Quickly locate past conversations by searching with keywords, file patterns, time ranges, or tags. Helps AI assistants retrieve relevant context and maintain project continuity efficiently.

Instructions

搜索历史对话记录

支持: • 关键词搜索 • 文件名模式搜索 • 时间范围筛选 • 标签过滤

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daysNo最近N天
filePatternNo文件名模式搜索
keywordsNo关键词搜索
limitNo结果数量限制
projectNo项目过滤(默认当前)
tagsNo标签过滤

Implementation Reference

  • Main handler function that validates parameters, searches conversation logs across projects or a specific project using helper methods, formats results as markdown, and handles errors.
    async searchConversations(params: unknown): Promise<{ content: Array<{ type: string; text: string }> }> { try { const validatedParams = validateSearchConversations(params); const { project } = validatedParams; let searchResults = ''; let totalResults = 0; if (project) { const projectResults = await this.searchInProject(project, validatedParams); searchResults += projectResults.content; totalResults += projectResults.count; } else { const projects = await this.fileManager.listProjects(); for (const proj of projects) { if (totalResults >= validatedParams.limit) break; const projectResults = await this.searchInProject(proj, { ...validatedParams, limit: validatedParams.limit - totalResults }); if (projectResults.content) { searchResults += `\n## 项目: ${proj}\n${projectResults.content}`; totalResults += projectResults.count; } } } if (totalResults === 0) { return { content: [ { type: 'text', text: '🔍 未找到匹配的对话记录。\n\n请尝试调整搜索条件:\n- 检查项目名称是否正确\n- 尝试更广泛的关键词\n- 扩大时间范围' } ] }; } return { content: [ { type: 'text', text: `🔍 找到 ${totalResults} 条匹配的对话记录:\n\n${searchResults}` } ] }; } catch (error) { const errorMessage = error instanceof ValidationError ? `参数验证失败: ${error.message}` : error instanceof SearchError ? `搜索失败: ${error.message} (查询: ${error.query})` : `搜索对话时出错: ${String(error)}`; return { content: [ { type: 'text', text: `❌ ${errorMessage}` } ] }; } }
  • Zod schema for input validation of the search_conversations tool parameters including project, keywords, file pattern, platform, tags, and limit.
    export const SearchConversationsSchema = z.object({ project: z.string().optional(), keywords: z.array(z.string()).optional(), filePattern: z.string().optional(), // 文件名模式搜索 days: z.number().int().positive().optional(), platform: PlatformSchema, tags: z.array(z.string()).optional(), limit: z.number().int().positive().max(100).optional() }).transform((data) => ({ ...data, keywords: data.keywords || [], tags: data.tags || [], limit: data.limit || CONSTANTS.DEFAULT_SEARCH_LIMIT }));
  • src/index.ts:80-113 (registration)
    Registers the search_conversations tool in the MCP ListTools response with name, description, and input schema definition.
    name: 'search_conversations', description: '搜索历史对话记录\n\n支持:\n• 关键词搜索\n• 文件名模式搜索\n• 时间范围筛选\n• 标签过滤', inputSchema: { type: 'object', properties: { keywords: { type: 'array', items: { type: 'string' }, description: '关键词搜索' }, filePattern: { type: 'string', description: '文件名模式搜索' }, days: { type: 'number', description: '最近N天' }, project: { type: 'string', description: '项目过滤(默认当前)' }, tags: { type: 'array', items: { type: 'string' }, description: '标签过滤' }, limit: { type: 'number', description: '结果数量限制', default: 10 } } }
  • src/index.ts:164-165 (registration)
    Switch case in CallToolRequest handler that routes search_conversations calls to the ConversationLogger instance.
    case 'search_conversations': return await this.conversationLogger.searchConversations(args || {});
  • Private helper that searches within a specific project's log files (.md), applies search criteria using matchesSearchCriteria, extracts sections, and returns content and count.
    private async searchInProject(project: string, params: SearchConversationsParams): Promise<{ content: string; count: number }> { // Search in the ai-logs directory structure (no daily-logs subdirectory) const projectDir = await this.fileManager.getProjectDir(project); try { const { promises: fs } = await import('fs'); const files = await fs.readdir(projectDir); let content = ''; let count = 0; for (const file of files.slice(0, params.limit)) { if (file.endsWith('.md')) { const filePath = join(projectDir, file); const fileContent = await this.fileManager.readFile(filePath); if (this.matchesSearchCriteria(fileContent, params)) { content += `### ${file.replace('.md', '')}\n`; content += this.extractRelevantSections(fileContent, params); content += '\n'; count++; } } } return { content, count }; } catch (error) { throw new SearchError(`搜索项目 ${project} 失败`, String(error)); } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fablefang/ai-conversation-logger-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server