get_copilot_metrics_for_org
Retrieve daily GitHub Copilot usage metrics for organizations, including code completions, chat activity, active users, and language/editor breakdowns.
Instructions
Get daily Copilot usage metrics for a GitHub Organization (code completions, chat usage, active users, language/editor breakdown)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| org | No | Organization name (defaults to GITHUB_ORG env var) | |
| since | No | Start date in YYYY-MM-DD format (defaults to 28 days ago) | |
| until | No | End date in YYYY-MM-DD format (defaults to today) | |
| force_refresh | No | Ignore cache and fetch fresh data |
Implementation Reference
- src/tools/org.ts:16-37 (handler)The handler function that executes the logic for 'get_copilot_metrics_for_org' tool.
async ({ org, since, until, force_refresh }) => { try { const o = org ?? defaultOrg; if (!o) { return { content: [{ type: "text", text: "Organization name is required. Set GITHUB_ORG or pass 'org' parameter." }], isError: true }; } const today = new Date().toISOString().split("T")[0]; const defaultSince = new Date(); defaultSince.setUTCDate(defaultSince.getUTCDate() - 28); const s = since ?? defaultSince.toISOString().split("T")[0]; const u = until ?? today; validateDateRange(s, u); const metrics = await client.fetchMetrics("org", o, s, u, force_refresh ?? false, { identifier: o }); return { content: [{ type: "text", text: JSON.stringify(metrics, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } - src/tools/org.ts:7-38 (registration)The registration of the 'get_copilot_metrics_for_org' tool using the MCP server instance.
server.tool( "get_copilot_metrics_for_org", "Get daily Copilot usage metrics for a GitHub Organization (code completions, chat usage, active users, language/editor breakdown)", { org: z.string().optional().describe("Organization name (defaults to GITHUB_ORG env var)"), since: z.string().optional().describe("Start date in YYYY-MM-DD format (defaults to 28 days ago)"), until: z.string().optional().describe("End date in YYYY-MM-DD format (defaults to today)"), force_refresh: z.boolean().optional().describe("Ignore cache and fetch fresh data"), }, async ({ org, since, until, force_refresh }) => { try { const o = org ?? defaultOrg; if (!o) { return { content: [{ type: "text", text: "Organization name is required. Set GITHUB_ORG or pass 'org' parameter." }], isError: true }; } const today = new Date().toISOString().split("T")[0]; const defaultSince = new Date(); defaultSince.setUTCDate(defaultSince.getUTCDate() - 28); const s = since ?? defaultSince.toISOString().split("T")[0]; const u = until ?? today; validateDateRange(s, u); const metrics = await client.fetchMetrics("org", o, s, u, force_refresh ?? false, { identifier: o }); return { content: [{ type: "text", text: JSON.stringify(metrics, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );