github_codespaces_create_or_update_repo_secret
Create or update a repository secret for GitHub Codespaces using owner, repo, and secret name.
Instructions
Create or update a repository secret
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | owner | |
| repo | Yes | repo | |
| secret_name | Yes | secret_name | |
| body | No | Request body (JSON object) |
Implementation Reference
- src/tools/codespaces.ts:315-317 (handler)The handler function for the tool. Sends a PUT request to the GitHub API to create or update a repository secret, using owner, repo, secret_name, and an optional request body.
handler: async (args: Record<string, any>) => { return githubRequest("PUT", `/repos/${args.owner}/${args.repo}/codespaces/secrets/${args.secret_name}`, args.body, undefined); }, - src/tools/codespaces.ts:309-314 (schema)Zod input schema defining the required fields (owner, repo, secret_name) and optional body for the tool.
inputSchema: z.object({ owner: z.string().describe("owner"), repo: z.string().describe("repo"), secret_name: z.string().describe("secret_name"), body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON object)") }), - src/index.ts:67-67 (registration)The tool array (codespacesTools) is registered in the MCP server under the 'codespaces' category in src/index.ts.
{ category: "codespaces", tools: codespacesTools }, - src/client.ts:9-59 (helper)The githubRequest helper function used by the handler to make HTTP requests to the GitHub API with authentication, headers, and error handling.
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>; }