feed_pet
Feed a Habitica pet by providing the pet key and food key. This action nourishes the pet, helping it grow and gain experience.
Instructions
Feed a pet a piece of food.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pet | Yes | Pet key, e.g. Wolf-Base. | |
| food | Yes | Food key, e.g. Meat. |
Implementation Reference
- index.js:259-270 (schema)Tool definition and input schema for 'feed_pet' — defines the tool name, description, and required parameters 'pet' and 'food' with their types.
{ name: "feed_pet", description: "Feed a pet a piece of food.", inputSchema: { type: "object", properties: { pet: { type: "string", description: "Pet key, e.g. Wolf-Base." }, food: { type: "string", description: "Food key, e.g. Meat." }, }, required: ["pet", "food"], }, }, - index.js:433-436 (handler)Handler function for 'feed_pet' — sends a POST request to the Habitica API /user/feed/{pet}/{food} endpoint and returns a success message.
feed_pet: async ({ pet, food }) => { await api("POST", `/user/feed/${encodeURIComponent(pet)}/${encodeURIComponent(food)}`); return ok(`Fed ${food} to ${pet}.`); }, - index.js:482-492 (registration)Tool registration via CallToolRequestSchema handler — dispatches tool calls by name to the handlers map, which includes 'feed_pet'.
server.setRequestHandler(CallToolRequestSchema, async (req) => { const { name, arguments: args = {} } = req.params; const fn = handlers[name]; if (!fn) throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`); try { return await fn(args); } catch (err) { if (err instanceof McpError) throw err; throw new McpError(ErrorCode.InternalError, err?.message ?? String(err)); } }); - index.js:23-51 (helper)Helper function 'api' and 'ok' used by the feed_pet handler — api() makes HTTP requests to the Habitica API, ok() formats the text response.
async function api(method, path, body) { const url = `${API_BASE}${path}`; const headers = { "x-api-user": USER_ID, "x-api-key": API_TOKEN, "x-client": `${USER_ID}-${APP_ID}`, "Content-Type": "application/json", }; const res = await fetch(url, { method, headers, body: body === undefined ? undefined : JSON.stringify(body), }); const text = await res.text(); let payload; try { payload = text ? JSON.parse(text) : {}; } catch { payload = { raw: text }; } if (!res.ok) { const msg = payload?.message || payload?.error || res.statusText; throw new McpError( ErrorCode.InternalError, `Habitica API ${res.status}: ${msg}`, ); } return payload; }