github_apps_scope_token
Generate a scoped access token for a GitHub App by providing the client ID and optional request body.
Instructions
Create a scoped access token
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| client_id | Yes | client_id | |
| body | No | Request body (JSON object) |
Implementation Reference
- src/tools/apps.ts:198-200 (handler)The handler for github_apps_scope_token. It makes a POST request to /applications/{client_id}/token/scoped with an optional body.
handler: async (args: Record<string, any>) => { return githubRequest("POST", `/applications/${args.client_id}/token/scoped`, args.body, undefined); }, - src/tools/apps.ts:194-197 (schema)Input schema for github_apps_scope_token: requires client_id (string) and optional body (JSON object).
inputSchema: z.object({ client_id: z.string().describe("client_id"), body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON object)") }), - src/tools/apps.ts:191-201 (registration)The tool definition/registration within the appsTools array in src/tools/apps.ts.
{ name: "github_apps_scope_token", description: "Create a scoped access token", inputSchema: z.object({ client_id: z.string().describe("client_id"), body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON object)") }), handler: async (args: Record<string, any>) => { return githubRequest("POST", `/applications/${args.client_id}/token/scoped`, args.body, undefined); }, }, - src/index.ts:110-120 (registration)Registration of all tools (including github_apps_scope_token) with the MCP server via server.tool().
for (const tool of allTools) { server.tool( tool.name, tool.description, tool.inputSchema.shape as any, async (args: any) => { try { const result = await tool.handler(args as any); return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }], }; - src/client.ts:9-59 (helper)The githubRequest helper function used by the handler to make the actual HTTP request to the GitHub API.
export async function githubRequest<T>( method: string, path: string, body?: Record<string, unknown>, params?: Record<string, string | number | boolean | string[] | undefined> ): Promise<T> { const url = new URL(`${BASE_URL}${path}`); if (params) { for (const [key, value] of Object.entries(params)) { if (value === undefined || value === null || value === "") continue; if (Array.isArray(value)) { url.searchParams.set(key, value.join(",")); } else { url.searchParams.set(key, String(value)); } } } const headers: Record<string, string> = { Authorization: `Bearer ${getToken()}`, Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", "User-Agent": "github-mcp/1.0.0", }; if (body) { headers["Content-Type"] = "application/json"; } const res = await fetch(url.toString(), { method, headers, body: body ? JSON.stringify(body) : undefined, }); if (!res.ok) { const text = await res.text().catch(() => ""); let detail = text; try { const json = JSON.parse(text); detail = json.message || text; if (json.errors) detail += ` -- ${JSON.stringify(json.errors)}`; } catch {} throw new Error(`GitHub API error ${res.status}: ${detail}`); } if (res.status === 204) return {} as T; return res.json() as Promise<T>; }