get_notifications
Retrieve user notifications with pagination. Optionally filter to show only unread notifications.
Instructions
Get user notifications with pagination
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_notifications"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number (default: 1) | |
| limit | No | Notifications per page (default: 20) | |
| unreadOnly | No | Show only unread notifications |
Implementation Reference
- src/tools/users/index.js:229-265 (handler)The getNotifications method - the actual handler that executes the tool logic. It takes pagination/filter args, calls the /notifications API, and formats the response with notification list, pagination info, and action hints.
async getNotifications(args) { const { page = 1, limit = 20, unreadOnly = false } = args; try { const params = new URLSearchParams(); params.append('page', page.toString()); params.append('limit', Math.min(limit, 50).toString()); if (unreadOnly) params.append('unreadOnly', 'true'); const response = await this.baseUtils.makeApiRequest(`/notifications?${params.toString()}`); const { notifications, totalCount, unreadCount, totalPages } = response.data; if (!notifications || notifications.length === 0) { return this.baseUtils.formatResponse( `🔔 **No Notifications**\n\n` + `You have no ${unreadOnly ? 'unread ' : ''}notifications at this time.` ); } const notificationsList = notifications.map((notif, index) => `${index + 1}. ${notif.isRead ? '📖' : '🔔'} **${notif.title}**\n` + ` ${notif.message}\n` + ` ${new Date(notif.createdAt).toLocaleString()} • ID: ${notif.id}` ).join('\n\n'); return this.baseUtils.formatResponse( `🔔 **Notifications** (${totalCount} total, ${unreadCount} unread, Page ${page}/${totalPages})\n\n` + notificationsList + '\n\n' + `**Actions Available:**\n` + `• Use \`mark_notification_read\` to mark specific notifications as read\n` + `• Use \`mark_all_read\` to mark all notifications as read\n` + this.baseUtils.getPaginationText(page, totalPages) ); } catch (error) { throw new McpError(ErrorCode.InternalError, `Failed to get notifications: ${error.message}`); } } - src/tools/users/index.js:59-70 (schema)The get_notifications tool definition/schema, declaring the tool name, description, and input schema with page, limit, and unreadOnly parameters.
{ name: "get_notifications", description: "Get user notifications with pagination", inputSchema: { type: "object", properties: { page: { type: "number", description: "Page number (default: 1)" }, limit: { type: "number", description: "Notifications per page (default: 20)" }, unreadOnly: { type: "boolean", description: "Show only unread notifications" } } } }, - src/tools/users/index.js:102-112 (registration)Registration of the get_notifications handler in getToolHandlers(), mapping the tool name to the bound getNotifications method.
getToolHandlers() { return { "get_user_profile": this.getUserProfile.bind(this), "update_user_profile": this.updateUserProfile.bind(this), "change_password": this.changePassword.bind(this), "get_user_storage": this.getUserStorage.bind(this), "get_notifications": this.getNotifications.bind(this), "get_unread_count": this.getUnreadCount.bind(this), "mark_notification_read": this.markNotificationRead.bind(this), "mark_all_read": this.markAllRead.bind(this) }; - src/tools/users/index.js:14-84 (registration)The getToolDefinitions() registration returning all tool definitions including get_notifications, called by the tool loader to register tools with the MCP server.
getToolDefinitions() { return [ { name: "get_user_profile", description: "Get current user's complete profile and statistics", inputSchema: { type: "object", properties: {} } }, { name: "update_user_profile", description: "Update user profile information", inputSchema: { type: "object", properties: { firstName: { type: "string", description: "First name" }, lastName: { type: "string", description: "Last name" }, position: { type: "string", description: "Job title/position" }, department: { type: "string", description: "Department within institution" }, organizationType: { type: "string", description: "Type of organization" }, bio: { type: "string", description: "Professional biography" } } } }, { name: "change_password", description: "Change user password", inputSchema: { type: "object", properties: { currentPassword: { type: "string", description: "Current password" }, newPassword: { type: "string", description: "New password" } }, required: ["currentPassword", "newPassword"] } }, { name: "get_user_storage", description: "Check storage usage and quota information", inputSchema: { type: "object", properties: {} } }, { name: "get_notifications", description: "Get user notifications with pagination", inputSchema: { type: "object", properties: { page: { type: "number", description: "Page number (default: 1)" }, limit: { type: "number", description: "Notifications per page (default: 20)" }, unreadOnly: { type: "boolean", description: "Show only unread notifications" } } } }, { name: "get_unread_count", description: "Get count of unread notifications", inputSchema: { type: "object", properties: {} } }, { name: "mark_notification_read", description: "Mark a specific notification as read", inputSchema: { type: "object", properties: { - src/utils/baseServer.js:412-426 (helper)The formatResponse and getPaginationText helper utilities used by getNotifications to format output and pagination hints.
formatResponse(text) { return { content: [ { type: "text", text: text } ] }; } // Helper for pagination display getPaginationText(page, totalPages) { return totalPages > page ? `• Add \`page: ${page + 1}\` to see more results` : ''; }