github_campaigns_list_org_campaigns
Retrieve a paginated list of campaigns for a GitHub organization, with options to filter by state, sort by date fields, and control page size.
Instructions
List campaigns for an organization
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| org | Yes | org | |
| page | No | The page number of the results to fetch. For more information, see "[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api)." | |
| per_page | No | The number of results per page (max 100). For more information, see "[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api)." | |
| direction | No | The direction to sort the results by. | |
| state | No | If specified, only campaigns with this state will be returned. | |
| sort | No | The property by which to sort the results. |
Implementation Reference
- src/tools/campaigns.ts:17-19 (handler)The handler function that executes the tool logic. It calls githubRequest to make a GET request to /orgs/{org}/campaigns with optional query parameters (page, per_page, direction, state, sort).
handler: async (args: Record<string, any>) => { return githubRequest("GET", `/orgs/${args.org}/campaigns`, undefined, { page: args.page, per_page: args.per_page, direction: args.direction, state: args.state, sort: args.sort }); }, - src/tools/campaigns.ts:9-16 (schema)Input schema definition using Zod, defining parameters: org (required string), page, per_page, direction (asc/desc), state (unknown), and sort (created/updated/ends_at/published).
inputSchema: z.object({ org: z.string().describe("org"), page: z.number().optional().describe("The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\""), per_page: z.number().optional().describe("The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\""), direction: z.enum(["asc", "desc"]).optional().describe("The direction to sort the results by."), state: z.unknown().optional().describe("If specified, only campaigns with this state will be returned."), sort: z.enum(["created", "updated", "ends_at", "published"]).optional().describe("The property by which to sort the results.") }), - src/tools/campaigns.ts:5-20 (registration)The tool is defined as an object in the campaignsTools array with name 'github_campaigns_list_org_campaigns', along with its description, inputSchema, and handler.
export const campaignsTools = [ { name: "github_campaigns_list_org_campaigns", description: "List campaigns for an organization", inputSchema: z.object({ org: z.string().describe("org"), page: z.number().optional().describe("The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\""), per_page: z.number().optional().describe("The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\""), direction: z.enum(["asc", "desc"]).optional().describe("The direction to sort the results by."), state: z.unknown().optional().describe("If specified, only campaigns with this state will be returned."), sort: z.enum(["created", "updated", "ends_at", "published"]).optional().describe("The property by which to sort the results.") }), handler: async (args: Record<string, any>) => { return githubRequest("GET", `/orgs/${args.org}/campaigns`, undefined, { page: args.page, per_page: args.per_page, direction: args.direction, state: args.state, sort: args.sort }); }, }, - src/index.ts:110-130 (registration)The MCP server registration loop where all tools (including campaigns) are registered via server.tool() with name, description, schema, and execution handler.
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 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>; }