get_notifications
Retrieve unread notifications from Habitica to stay updated on tasks, rewards, and account activity.
Instructions
Get unread notifications.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:462-462 (handler)The handler function that executes the get_notifications tool logic - makes a GET request to the Habitica API /notifications endpoint and returns the data as JSON.
get_notifications: async () => json((await api("GET", "/notifications")).data), - index.js:346-350 (schema)The tool schema/definition for get_notifications - no input parameters required, returns unread notifications.
{ name: "get_notifications", description: "Get unread notifications.", inputSchema: { type: "object", properties: {} }, }, - index.js:482-492 (registration)Generic tool registration handler - dispatches tool calls by name to the handlers object. When 'get_notifications' is called, it looks up handlers['get_notifications'].
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 that makes HTTP requests to the Habitica API - used by the get_notifications handler to call GET /notifications.
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; }