get_shorts_analytics
Retrieve YouTube Analytics data filtered to Shorts content for your authenticated channel. Specify date range and metrics to analyze Shorts performance.
Instructions
Query YouTube Analytics restricted to Shorts for the authenticated channel. Applies filters=creatorContentType==SHORTS on top of the usual start_date/end_date/metrics/dimensions knobs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_date | Yes | YYYY-MM-DD start date (inclusive). | |
| end_date | Yes | YYYY-MM-DD end date (inclusive). | |
| metrics | No | Comma-separated YouTube Analytics metrics. | views,estimatedMinutesWatched,averageViewDuration,subscribersGained |
| dimensions | No | Optional dimensions, e.g. 'day' for a time series. | |
| sort | No | ||
| max_results | No |
Implementation Reference
- src/tools/shorts.ts:98-121 (handler)The tool handler for 'get_shorts_analytics' — calls client.analyticsQuery() with a SHORTS filter and returns the results as JSON.
server.tool( "get_shorts_analytics", "Query YouTube Analytics restricted to Shorts for the authenticated channel. Applies filters=creatorContentType==SHORTS on top of the usual start_date/end_date/metrics/dimensions knobs.", getShortsAnalyticsSchema, async (args) => { const res = await client.analyticsQuery({ startDate: args.start_date, endDate: args.end_date, metrics: args.metrics, dimensions: args.dimensions, filters: "creatorContentType==SHORTS", sort: args.sort, maxResults: args.max_results, }); return { content: [ { type: "text" as const, text: JSON.stringify(res, null, 2), }, ], }; }, ); - src/tools/shorts.ts:32-49 (schema)Input schema for get_shorts_analytics: start_date, end_date, metrics, dimensions, sort, max_results.
const getShortsAnalyticsSchema = { start_date: z .string() .describe("YYYY-MM-DD start date (inclusive)."), end_date: z .string() .describe("YYYY-MM-DD end date (inclusive)."), metrics: z .string() .default("views,estimatedMinutesWatched,averageViewDuration,subscribersGained") .describe("Comma-separated YouTube Analytics metrics."), dimensions: z .string() .optional() .describe("Optional dimensions, e.g. 'day' for a time series."), sort: z.string().optional(), max_results: z.number().int().min(1).max(500).optional(), }; - src/tools/shorts.ts:51-57 (registration)Function registerShortsTools() that calls server.tool('get_shorts_analytics', ...) to register the tool.
export function registerShortsTools( server: McpServer, client: YouTubeClient, ): void { server.tool( "list_my_shorts", "List your recent Shorts — scans the most recent uploads and filters to videos ≤60s. Useful when the Data API doesn't expose a direct Shorts filter.", - src/server.ts:52-52 (registration)Call to registerShortsTools(s, youtube) from the main server setup.
registerShortsTools(s, youtube); - src/youtube/client.ts:298-317 (helper)analyticsQuery() method on YouTubeClient that builds and sends the YouTube Analytics API request.
async analyticsQuery(params: { startDate: string; endDate: string; metrics: string; dimensions?: string; filters?: string; sort?: string; maxResults?: number; }): Promise<AnalyticsResponse> { return this.analyticsGet<AnalyticsResponse>("/reports", { ids: "channel==MINE", "start-date": params.startDate, "end-date": params.endDate, metrics: params.metrics, dimensions: params.dimensions, filters: params.filters, sort: params.sort, maxResults: params.maxResults ? String(params.maxResults) : undefined, }); }