github_classroom_get_an_assignment
Retrieve details of a specific assignment in GitHub Classroom by providing its ID.
Instructions
Get an assignment
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| assignment_id | Yes | assignment_id |
Implementation Reference
- src/tools/classroom.ts:12-14 (handler)The handler function that executes the 'github_classroom_get_an_assignment' tool. It makes a GET request to /assignments/{assignment_id} using the githubRequest client.
handler: async (args: Record<string, any>) => { return githubRequest("GET", `/assignments/${args.assignment_id}`, undefined, undefined); }, - src/tools/classroom.ts:9-11 (schema)Input schema for the tool, defined using Zod. Accepts a single required string parameter 'assignment_id'.
inputSchema: z.object({ assignment_id: z.string().describe("assignment_id") }), - src/tools/classroom.ts:5-15 (registration)The tool is defined as part of the 'classroomTools' array in src/tools/classroom.ts, with name 'github_classroom_get_an_assignment' and description 'Get an assignment'.
export const classroomTools = [ { name: "github_classroom_get_an_assignment", description: "Get an assignment", inputSchema: z.object({ assignment_id: z.string().describe("assignment_id") }), handler: async (args: Record<string, any>) => { return githubRequest("GET", `/assignments/${args.assignment_id}`, undefined, undefined); }, }, - src/index.ts:110-130 (registration)Tools are registered with the MCP server in src/index.ts via server.tool() calls, iterating over all tool objects from combined tool modules.
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) }], }; } catch (err) { const message = err instanceof Error ? err.message : String(err); return { content: [{ type: "text" as const, text: `Error: ${message}` }], isError: true, }; } } ); } - src/client.ts:9-59 (helper)The githubRequest helper function that performs the actual HTTP request to the GitHub API, used by the tool handler.
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>; }