github_codespaces_stop_for_authenticated_user
Stop a running GitHub Codespace for the authenticated user by specifying its name.
Instructions
Stop a codespace for the authenticated user
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| codespace_name | Yes | codespace_name |
Implementation Reference
- src/tools/codespaces.ts:548-550 (handler)The handler function that executes the tool logic: sends a POST request to /user/codespaces/{codespace_name}/stop to stop a codespace for the authenticated user.
handler: async (args: Record<string, any>) => { return githubRequest("POST", `/user/codespaces/${args.codespace_name}/stop`, undefined, undefined); }, - src/tools/codespaces.ts:545-547 (schema)Input schema using Zod, validating a single required string parameter 'codespace_name'.
inputSchema: z.object({ codespace_name: z.string().describe("codespace_name") }), - src/tools/codespaces.ts:542-552 (registration)The tool is defined as one entry in the exported 'codespacesTools' array, registered in src/index.ts where it is iterated and registered via server.tool().
{ name: "github_codespaces_stop_for_authenticated_user", description: "Stop a codespace for the authenticated user", inputSchema: z.object({ codespace_name: z.string().describe("codespace_name") }), handler: async (args: Record<string, any>) => { return githubRequest("POST", `/user/codespaces/${args.codespace_name}/stop`, undefined, undefined); }, }, ]; - src/client.ts:9-59 (helper)The githubRequest helper function used by the handler to make authenticated HTTP requests to the GitHub REST 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>; }