github_codespaces_get_public_key_for_authenticated_user
Retrieve the public key for the authenticated user, enabling encrypted data operations in GitHub Codespaces.
Instructions
Get public key for the authenticated user
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/codespaces.ts:377-384 (handler)Handler function for 'github_codespaces_get_public_key_for_authenticated_user' tool. Makes a GET request to `/user/codespaces/secrets/public-key` with no body or query parameters.
{ name: "github_codespaces_get_public_key_for_authenticated_user", description: "Get public key for the authenticated user", inputSchema: z.object({}), handler: async (args: Record<string, any>) => { return githubRequest("GET", `/user/codespaces/secrets/public-key`, undefined, undefined); }, }, - src/tools/codespaces.ts:378-380 (schema)Input schema for the tool - empty object (z.object({})), meaning no input parameters are required.
name: "github_codespaces_get_public_key_for_authenticated_user", description: "Get public key for the authenticated user", inputSchema: z.object({}), - src/tools/codespaces.ts:5-5 (registration)The tool is part of the exported `codespacesTools` array, which is imported and registered in src/index.ts via `server.tool()` on line 111.
export const codespacesTools = [ - src/client.ts:9-58 (helper)The `githubRequest` helper function that performs the actual HTTP request to the GitHub API. Used by the handler to make a GET request to the GitHub API endpoint.
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>;