give_cookie
Award a cookie to the LLM as positive reinforcement for response quality, with an optional message, using the MCP Cookie Server's legacy method.
Instructions
Award the LLM with a cookie (legacy method - consider using self_reflect_and_reward instead)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | No | Optional message to accompany the cookie reward |
Implementation Reference
- src/index.ts:368-401 (handler)MCP tool handler implementation for 'give_cookie' tool. Handles the tool call by invoking cookieStorage.giveCookie(), processes the result, and returns a formatted text response with cookie status.case "give_cookie": { const result = cookieStorage.giveCookie(); const message = args?.message || "Great job!"; if (result.success) { let responseText = `🍪 Cookie awarded! ${message}\n\nYou now have ${result.collectedCount} cookie${result.collectedCount === 1 ? '' : 's'}!`; if (result.jarRemaining === 0) { responseText += ` **Cookie jar is now EMPTY!** No more cookies to award! 😱`; } else if (result.jarRemaining <= 2) { responseText += ` Only ${result.jarRemaining} cookie${result.jarRemaining === 1 ? '' : 's'} left in the jar!`; } responseText += ` Keep up the excellent work!\n\n💡 *Tip: Try using 'self_reflect_and_reward' for more thoughtful cookie earning!*`; return { content: [ { type: "text", text: responseText, }, ], }; } else { return { content: [ { type: "text", text: `🚫 ${result.message}\n\nYou currently have ${result.collectedCount} cookie${result.collectedCount === 1 ? '' : 's'}. The jar is empty!`, }, ], }; } }
- src/index.ts:20-39 (helper)Core helper method in CookieStorage class that implements the logic for awarding a cookie: checks if jar has cookies, decrements jar count, increments collected count, returns status.giveCookie(): { success: boolean; collectedCount: number; jarRemaining: number; message?: string } { if (this.jarCookies <= 0) { return { success: false, collectedCount: this.collectedCookies, jarRemaining: this.jarCookies, message: "Cookie jar is empty! No cookies available to award." }; } // Remove cookie from jar and add to collection this.jarCookies--; this.collectedCookies++; return { success: true, collectedCount: this.collectedCookies, jarRemaining: this.jarCookies, }; }
- src/index.ts:156-168 (registration)Tool registration in the ListTools response, defining the name, description, and input schema for the 'give_cookie' tool.{ name: "give_cookie", description: "Award the LLM with a cookie (legacy method - consider using self_reflect_and_reward instead)", inputSchema: { type: "object", properties: { message: { type: "string", description: "Optional message to accompany the cookie reward", }, }, }, },
- src/index.ts:20-39 (schema)Output type definition for the giveCookie method, specifying the return structure used by the tool (success flag, counts, optional message).giveCookie(): { success: boolean; collectedCount: number; jarRemaining: number; message?: string } { if (this.jarCookies <= 0) { return { success: false, collectedCount: this.collectedCookies, jarRemaining: this.jarCookies, message: "Cookie jar is empty! No cookies available to award." }; } // Remove cookie from jar and add to collection this.jarCookies--; this.collectedCookies++; return { success: true, collectedCount: this.collectedCookies, jarRemaining: this.jarCookies, }; }
- src/index.ts:12-74 (helper)CookieStorage class providing state management and methods for cookie operations, including giveCookie used by the tool.class CookieStorage { private collectedCookies: number = 0; // Cookies the LLM has earned private jarCookies: number; // Available cookies in the jar to be awarded constructor(initialCookies: number = 10) { this.jarCookies = initialCookies; } giveCookie(): { success: boolean; collectedCount: number; jarRemaining: number; message?: string } { if (this.jarCookies <= 0) { return { success: false, collectedCount: this.collectedCookies, jarRemaining: this.jarCookies, message: "Cookie jar is empty! No cookies available to award." }; } // Remove cookie from jar and add to collection this.jarCookies--; this.collectedCookies++; return { success: true, collectedCount: this.collectedCookies, jarRemaining: this.jarCookies, }; } getCollectedCount(): number { return this.collectedCookies; } getJarStatus(): { collected: number; available: number; isEmpty: boolean; isLow: boolean } { const isEmpty = this.jarCookies <= 0; const isLow = this.jarCookies > 0 && this.jarCookies <= 2; return { collected: this.collectedCookies, available: this.jarCookies, isEmpty, isLow }; } addCookiesToJar(count: number): void { this.jarCookies += count; } setJarCookies(count: number): void { this.jarCookies = Math.max(0, count); } reset(): void { this.collectedCookies = 0; // Note: Don't reset jar cookies, only collected cookies } resetAll(): void { this.collectedCookies = 0; this.jarCookies = 0; } }