-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added FM Delivery Data API MCP Tool #9393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { z } from "zod"; | ||
| import { tool } from "../../tool"; | ||
| import { mcpError, toContent } from "../../util"; | ||
| import { getAndroidDeliveryData } from "../../../messaging/getDeliveryData"; | ||
|
|
||
| export const get_fcm_delivery_data = tool( | ||
| "messaging", | ||
| { | ||
| name: "get_fcm_delivery_data", | ||
| description: "Gets FCM's delivery data", | ||
| inputSchema: z.object({ | ||
| appId: z.string().describe("appId to fetch data for"), | ||
| pageSize: z.number().optional().describe("How many results to fetch"), | ||
| pageToken: z.string().optional().describe("Next page token"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MCP tools aren't API. If pageSize & pageToken can make LLM work more smooth, a few example prompts can help illustrate that. In practice, I see it struggle with detailed API token, but works better with high-level user intent. For example, get recent delivery data in the past 7 days. Two suggestions:
If the customer intent it to fetch a lot of delivery data, the MCP tool probably should abstract out the paging portion and return all data in one go. |
||
| }), | ||
| annotations: { | ||
| title: "Fetch FCM Delivery Data", | ||
| }, | ||
| _meta: { | ||
| requiresAuth: true, | ||
| requiresProject: true, | ||
| }, | ||
| }, | ||
| async ({ appId, pageSize, pageToken }, { projectId }) => { | ||
| if (!appId.includes(":android:")) { | ||
| return mcpError( | ||
| `Invalid app id provided: ${appId}. Currently fcm delivery data is only available for android apps.`, | ||
| ); | ||
| } | ||
|
|
||
| return toContent(await getAndroidDeliveryData(projectId, appId, { pageSize, pageToken })); | ||
| }, | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { ServerTool } from "../../tool"; | ||
| import { send_message } from "./send_message"; | ||
| import { get_fcm_delivery_data } from "./get_delivery_data"; | ||
|
|
||
| export const messagingTools: ServerTool[] = [send_message]; | ||
| export const messagingTools: ServerTool[] = [send_message, get_fcm_delivery_data]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { messagingDataApiOrigin } from "../api"; | ||
| import { Client } from "../apiv2"; | ||
| import { logger } from "../logger"; | ||
| import { FirebaseError } from "../error"; | ||
| import { ListAndroidDeliveryDataResponse } from "./interfaces"; | ||
|
|
||
| const TIMEOUT = 10000; | ||
|
|
||
| const apiClient = new Client({ | ||
| urlPrefix: messagingDataApiOrigin(), | ||
| apiVersion: "v1beta1", | ||
| }); | ||
|
|
||
| export async function getAndroidDeliveryData( | ||
| projectId: string, | ||
| androidAppId: string, | ||
| options: { | ||
| pageSize?: number; | ||
| pageToken?: string; | ||
| }, | ||
| ): Promise<ListAndroidDeliveryDataResponse> { | ||
| try { | ||
| // API docs for fetching Android delivery data are here: | ||
| // https://firebase.google.com/docs/reference/fcmdata/rest/v1beta1/projects.androidApps.deliveryData/list#http-request | ||
|
|
||
| const customHeaders = { | ||
| "Content-Type": "application/json", | ||
| "x-goog-user-project": projectId, | ||
| }; | ||
|
|
||
| // set up query params | ||
| const params = new URLSearchParams(); | ||
| if (options.pageSize) { | ||
| params.set("pageSize", String(options.pageSize)); | ||
| } | ||
| if (options.pageToken) { | ||
| params.set("pageToken", options.pageToken); | ||
| } | ||
|
|
||
| logger.debug(`requesting android delivery data for ${projectId}, ${androidAppId}`); | ||
|
|
||
| const res = await apiClient.request<null, ListAndroidDeliveryDataResponse>({ | ||
| method: "GET", | ||
| path: `/projects/${projectId}/androidApps/${androidAppId}/deliveryData`, | ||
| queryParams: params, | ||
| headers: customHeaders, | ||
| timeout: TIMEOUT, | ||
| }); | ||
|
|
||
| logger.debug(`${res.status}, ${res.response}, ${res.body}`); | ||
| return res.body; | ||
| } catch (err: any) { | ||
| logger.debug(err.message); | ||
| throw new FirebaseError( | ||
| `Failed to fetch delivery data for project ${projectId} and ${androidAppId}, ${err}.`, | ||
| { original: err }, | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested it with GCLI?
The MCP description here should make it clear to LLM what this tool can do, when to use it, etc.
A good description should be validated with some sample prompts.