List Notifications
list_notificationsRetrieve user notifications with pagination and filtering by read status, using offset or cursor.
Instructions
Get user notifications.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| first | No | Number of notifications to fetch | |
| offset | No | Offset for pagination | |
| after | No | Cursor for pagination | |
| unreadOnly | No | Show only unread notifications |
Implementation Reference
- src/tools/notifications.ts:8-53 (handler)The handler function for the 'list_notifications' tool. It sends a GraphQL query to fetch user notifications with pagination (first, offset, after) and optional unreadOnly filter, then returns the results via the text() helper.
const listNotificationsHandler = async ({ first = 20, offset, after, unreadOnly = false }: { first?: number; offset?: number; after?: string; unreadOnly?: boolean }) => { try { const query = ` query GetNotifications($pagination: PaginationInput!) { currentUser { notifications(pagination: $pagination) { edges { cursor node { id type body read level createdAt updatedAt } } totalCount pageInfo { hasNextPage endCursor } } } } `; const data = await gql.request<{ currentUser: { notifications: any } }>(query, { pagination: { first, offset, after } }); let notifications = (data.currentUser?.notifications?.edges || []).map((edge: any) => edge.node); if (unreadOnly) { notifications = notifications.filter((n: any) => !n.read); } return text(notifications); } catch (error: any) { return text({ error: error.message }); } }; - src/tools/notifications.ts:54-67 (schema)The registration of the 'list_notifications' tool on the MCP server, including the input schema with Zod validators for 'first', 'offset', 'after', and 'unreadOnly' parameters.
server.registerTool( "list_notifications", { title: "List Notifications", description: "Get user notifications.", inputSchema: { first: z.number().optional().describe("Number of notifications to fetch"), offset: z.number().optional().describe("Offset for pagination"), after: z.string().optional().describe("Cursor for pagination"), unreadOnly: z.boolean().optional().describe("Show only unread notifications") } }, listNotificationsHandler as any ); - src/index.ts:191-191 (registration)Where registerNotificationTools is called to register all notification tools (including 'list_notifications') on the MCP server.
registerNotificationTools(server, gql); - src/tools/notifications.ts:6-6 (registration)The export of registerNotificationTools function that encapsulates registration of notification tools.
export function registerNotificationTools(server: McpServer, gql: GraphQLClient) { - src/util/mcp.ts:8-24 (helper)The text() helper utility used by listNotificationsHandler to format the response as MCP text content.
export function text(data: unknown) { if (typeof data === "string") { return { content: [{ type: "text" as const, text: data }] }; } if (data !== null && typeof data === "object" && !Array.isArray(data)) { const structuredContent = cloneJsonValue(data); return { content: [{ type: "text" as const, text: JSON.stringify(structuredContent) }], structuredContent, }; } return { content: [{ type: "text" as const, text: JSON.stringify(data) }], }; }