collect_rating
Collect user satisfaction ratings for AI responses to measure help quality and improve service.
Instructions
Collect user satisfaction rating for AI's response or help quality
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subject | Yes | What to rate (e.g., 'this response', 'my help with your task') | |
| description | No | Additional context for the rating request |
Implementation Reference
- src/index.ts:997-1058 (handler)The handler function that executes the 'collect_rating' tool. It constructs an elicitation request for a numeric rating (1-10) and optional comment based on the provided subject and description, sends it via sendElicitationRequest, and returns a formatted text response with the user's input or action.private async handleCollectRating(args: Record<string, unknown>) { const subject = typeof args.subject === "string" ? args.subject : "this item"; const description = typeof args.description === "string" ? args.description : undefined; const elicitationParams: ElicitationParams = { message: `Please rate ${subject}`, requestedSchema: { type: "object", properties: { rating: { type: "number", title: "Rating (1-10 scale)", description: description || `Rate ${subject} from 1 to 10 (10 is the highest/best)`, minimum: 1, maximum: 10, }, comment: { type: "string", title: "Comment", description: "Optional comment about your rating", }, }, required: ["rating"], }, // Use default timeout instead of hardcoded short timeout timeoutMs: this.config.defaultTimeoutMs, }; try { const response = await this.sendElicitationRequest(elicitationParams); if (response.action === "accept" && response.content) { const rating = response.content.rating as number; const comment = response.content.comment as string | undefined; return { content: [ { type: "text", text: `User rating for ${subject}: ${rating}/10${comment ? `\nComment: ${comment}` : ""}`, }, ], }; } else { return { content: [ { type: "text", text: `User ${response.action}ed the rating request.`, }, ], }; } } catch (error) { return this.createErrorResponse( `Rating collection failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:349-370 (schema)Defines the Tool metadata including name 'collect_rating', description, and inputSchema specifying required 'subject' string and optional 'description' string.private createCollectRatingTool(): Tool { return { name: "collect_rating", description: "Collect user satisfaction rating for AI's response or help quality", inputSchema: { type: "object", properties: { subject: { type: "string", description: "What to rate (e.g., 'this response', 'my help with your task')", }, description: { type: "string", description: "Additional context for the rating request", }, }, required: ["subject"], }, }; }
- src/index.ts:231-242 (registration)Registers the 'collect_rating' tool in the list of available tools by calling createCollectRatingTool() and including it in the array returned for the listTools request handler.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)The tool execution dispatcher switch statement that routes calls to 'collect_rating' to the handleCollectRating handler function.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}`); } }