get_copilot_metrics_for_enterprise
Retrieve daily GitHub Copilot usage metrics for enterprise-wide analysis, including code completions, chat activity, active users, and language/editor breakdowns.
Instructions
Get daily Copilot usage metrics for the entire GitHub Enterprise (code completions, chat usage, active users, language/editor breakdown)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| enterprise | No | Enterprise slug (defaults to GITHUB_ENTERPRISE 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/enterprise.ts:16-37 (handler)The async handler function that implements the logic for 'get_copilot_metrics_for_enterprise' tool, including input validation, parameter defaults, and invoking the GitHub client.
async ({ enterprise, since, until, force_refresh }) => { try { const ent = enterprise ?? defaultEnterprise; if (!ent) { return { content: [{ type: "text", text: "Enterprise slug is required. Set GITHUB_ENTERPRISE or pass 'enterprise' 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("enterprise", ent, s, u, force_refresh ?? false, { identifier: ent }); 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/enterprise.ts:7-38 (registration)The registration of 'get_copilot_metrics_for_enterprise' tool using the MCP server's tool registration method.
server.tool( "get_copilot_metrics_for_enterprise", "Get daily Copilot usage metrics for the entire GitHub Enterprise (code completions, chat usage, active users, language/editor breakdown)", { enterprise: z.string().optional().describe("Enterprise slug (defaults to GITHUB_ENTERPRISE 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 ({ enterprise, since, until, force_refresh }) => { try { const ent = enterprise ?? defaultEnterprise; if (!ent) { return { content: [{ type: "text", text: "Enterprise slug is required. Set GITHUB_ENTERPRISE or pass 'enterprise' 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("enterprise", ent, s, u, force_refresh ?? false, { identifier: ent }); 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 }; } } );