Skip to main content
Glama

search_conversations

Search historical conversation logs using keywords, file patterns, time ranges, or tags to retrieve relevant project discussions and maintain context across AI sessions.

Instructions

搜索历史对话记录

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

Input Schema

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

Implementation Reference

  • Main handler function for search_conversations tool. Validates input, searches conversations in specified or all projects, aggregates results, 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 definition for SearchConversations input validation and transformation.
    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-114 (registration)
    Tool registration in MCP listTools handler, defining name, description, and inputSchema.
      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)
    Dispatch handler in MCP callTool that routes to the conversationLogger.searchConversations method.
    case 'search_conversations':
      return await this.conversationLogger.searchConversations(args || {});
  • Core helper method that searches within a specific project directory for matching conversation log files.
    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));
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While it lists search capabilities, it doesn't describe important behavioral aspects: whether this is a read-only operation, what permissions are needed, how results are returned (format, pagination), whether there are rate limits, or what happens with no matches. For a search tool with 6 parameters and no annotations, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with a clear purpose statement followed by bullet points of capabilities. Every sentence earns its place, though the bullet points could be more efficiently integrated into the main description. The structure is front-loaded with the core purpose first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a search tool with 6 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the search returns (conversation objects? summaries? IDs?), how results are ordered, whether there's pagination, or error conditions. The lack of output schema means the description should compensate by explaining return values, which it doesn't.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 6 parameters thoroughly. The description's bullet points (关键词搜索, 文件名模式搜索, 时间范围筛选, 标签过滤) map to 4 of the 6 parameters but don't add meaningful semantic context beyond what the schema provides. The baseline of 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool searches historical conversation records, which is a specific verb+resource combination. However, it doesn't distinguish this tool from potential sibling tools like 'get_context_suggestions' or 'log_conversation' - we can't tell if those tools also search conversations or perform different functions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of sibling tools like 'get_context_suggestions' or 'log_conversation', nor any context about when search is appropriate versus listing or logging conversations. The bullet points describe capabilities but not usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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