search_logs
Filter and search confirmation history logs by keyword, type, date range, success, timeout, and response time. Supports pagination for efficient log retrieval and analysis within MCP-Confirm.
Instructions
Search confirmation history logs with various filters and pagination
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| confirmationType | No | Filter by confirmation type (confirmation, rating, clarification, verification, yes_no, custom) | |
| endDate | No | End date filter (ISO 8601 format) | |
| keyword | No | Search keyword in message content | |
| maxResponseTime | No | Maximum response time in milliseconds | |
| minResponseTime | No | Minimum response time in milliseconds | |
| page | No | Page number for pagination (1-based) | |
| pageSize | No | Number of entries per page | |
| startDate | No | Start date filter (ISO 8601 format) | |
| success | No | Filter by success status | |
| timedOut | No | Filter by timeout status |
Implementation Reference
- src/index.ts:1183-1248 (handler)The primary handler for the 'search_logs' tool. Parses tool call arguments into LogSearchParams, invokes the searchLogs method, formats the results into a readable text response with pagination info, and handles errors.private async handleSearchLogs(args: Record<string, unknown>) { try { const searchParams: LogSearchParams = { keyword: typeof args.keyword === "string" ? args.keyword : undefined, confirmationType: typeof args.confirmationType === "string" ? args.confirmationType : undefined, startDate: typeof args.startDate === "string" ? args.startDate : undefined, endDate: typeof args.endDate === "string" ? args.endDate : undefined, success: typeof args.success === "boolean" ? args.success : undefined, timedOut: typeof args.timedOut === "boolean" ? args.timedOut : undefined, minResponseTime: typeof args.minResponseTime === "number" ? args.minResponseTime : undefined, maxResponseTime: typeof args.maxResponseTime === "number" ? args.maxResponseTime : undefined, page: typeof args.page === "number" ? args.page : 1, pageSize: typeof args.pageSize === "number" ? Math.min(args.pageSize, 100) : 10, }; const result = await this.searchLogs(searchParams); const formatEntry = (entry: ConfirmationLogEntry, index: number) => { const timestamp = new Date(entry.timestamp).toLocaleString(); const responseTime = `${entry.responseTimeMs}ms`; const status = entry.success ? "✅ Success" : "❌ Failed"; const action = entry.response.action; return `**${index + 1}.** ${timestamp} [${entry.confirmationType}] ${status} - ${action} (${responseTime}) Message: ${entry.request.message.substring(0, 100)}${entry.request.message.length > 100 ? "..." : ""} ${entry.error ? `Error: ${entry.error}` : ""}`; }; const entriesText = result.entries .map((entry, index) => formatEntry(entry, (result.currentPage - 1) * result.pageSize + index) ) .join("\n\n"); const paginationInfo = `\n\n📊 **Search Results** Total: ${result.totalCount} entries Page: ${result.currentPage}/${result.totalPages} Showing: ${result.entries.length} entries`; return { content: [ { type: "text", text: `🔍 **Confirmation Log Search Results**\n\n${entriesText}${paginationInfo}`, }, ], }; } catch (error) { return this.createErrorResponse( `Log search failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:1153-1181 (helper)Core search logic that reads log entries from file, applies filters using filterLogEntries, sorts by timestamp descending, applies pagination, and returns structured LogSearchResult.private async searchLogs(params: LogSearchParams): Promise<LogSearchResult> { const entries = await this.readLogEntries(); // Apply filters const filteredEntries = this.filterLogEntries(entries, params); // Sort by timestamp (newest first) filteredEntries.sort( (a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime() ); // Pagination const page = params.page || 1; const pageSize = params.pageSize || 10; const totalCount = filteredEntries.length; const totalPages = Math.ceil(totalCount / pageSize); const startIndex = (page - 1) * pageSize; const endIndex = startIndex + pageSize; const paginatedEntries = filteredEntries.slice(startIndex, endIndex); return { entries: paginatedEntries, totalCount, currentPage: page, totalPages, pageSize, }; }
- src/index.ts:47-58 (schema)TypeScript interface defining the input parameters for log search, matching the tool's inputSchema. Includes optional filters for keyword, type, dates, status, response times, and pagination.interface LogSearchParams { keyword?: string; confirmationType?: string; startDate?: string; endDate?: string; success?: boolean; timedOut?: boolean; minResponseTime?: number; maxResponseTime?: number; page?: number; pageSize?: number; }
- src/index.ts:395-462 (registration)Tool registration function that defines the 'search_logs' Tool object including name, description, and detailed inputSchema for MCP tool listing.private createSearchLogsTool(): Tool { return { name: "search_logs", description: "Search confirmation history logs with various filters and pagination", inputSchema: { type: "object", properties: { keyword: { type: "string", description: "Search keyword in message content", }, confirmationType: { type: "string", description: "Filter by confirmation type (confirmation, rating, clarification, verification, yes_no, custom)", enum: [ "confirmation", "rating", "clarification", "verification", "yes_no", "custom", ], }, startDate: { type: "string", description: "Start date filter (ISO 8601 format)", format: "date-time", }, endDate: { type: "string", description: "End date filter (ISO 8601 format)", format: "date-time", }, success: { type: "boolean", description: "Filter by success status", }, timedOut: { type: "boolean", description: "Filter by timeout status", }, minResponseTime: { type: "number", description: "Minimum response time in milliseconds", }, maxResponseTime: { type: "number", description: "Maximum response time in milliseconds", }, page: { type: "number", description: "Page number for pagination (1-based)", minimum: 1, default: 1, }, pageSize: { type: "number", description: "Number of entries per page", minimum: 1, maximum: 100, default: 10, }, }, }, }; }
- src/index.ts:231-242 (registration)Tool list registration where search_logs tool creator is included in the array returned for ListTools requests.private getToolDefinitions(): Tool[] { return [ this.createAskYesNoTool(), this.createConfirmActionTool(), this.createClarifyIntentTool(), this.createVerifyUnderstandingTool(), this.createCollectRatingTool(), this.createElicitCustomTool(), this.createSearchLogsTool(), this.createAnalyzeLogsTool(), ]; }
- src/index.ts:516-537 (registration)Tool dispatch switch statement that routes 'search_logs' calls to the handleSearchLogs handler.private async executeToolCall(name: string, args: Record<string, unknown>) { switch (name) { case "ask_yes_no": return await this.handleAskYesNo(args); case "confirm_action": return await this.handleConfirmAction(args); case "clarify_intent": return await this.handleClarifyIntent(args); case "verify_understanding": return await this.handleVerifyUnderstanding(args); case "collect_rating": return await this.handleCollectRating(args); case "elicit_custom": return await this.handleElicitCustom(args); case "search_logs": return await this.handleSearchLogs(args); case "analyze_logs": return await this.handleAnalyzeLogs(args); default: throw new Error(`Unknown tool: ${name}`); } }