list-user-orgs
Retrieve a list of organizations associated with a specific GitHub Enterprise user using their username, with options for pagination and results per page.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for pagination | |
| per_page | No | Number of results per page (max 100) | |
| username | Yes | Username of the user whose organizations to list |
Implementation Reference
- server/index.ts:2113-2149 (handler)MCP tool registration, input schema (zod), and handler function for 'list-user-orgs'. Calls UserManagement.listUserOrganizations and formats the response as text content."list-user-orgs", { username: z.string().describe("Username of the user whose organizations to list"), per_page: z.number().optional().describe("Number of results per page (max 100)"), page: z.number().optional().describe("Page number for pagination") }, async ({ username, per_page, page }) => { try { const orgs = await context.users.listUserOrganizations(context.client, { username, per_page, page }); return { content: [ { type: "text", text: `Organizations for user '${username}':\n\n${JSON.stringify(orgs, null, 2)}` } ] }; } catch (error: any) { console.error('Error listing user organizations:', error); return { content: [ { type: "text", text: `An error occurred while listing user organizations: ${error.message}` } ], isError: true }; } } );
- api/users/users.ts:325-362 (helper)Helper function in UserManagement class that performs the actual GitHub API call to retrieve the list of organizations for a given user.async listUserOrganizations(client: any, params: ListUserOrgsParams): Promise<Organization[]> { try { const { baseUrl, token } = client; const { username, per_page, page } = params; if (!username) { throw new Error('Username is required'); } const queryParams = new URLSearchParams(); if (per_page) { queryParams.append('per_page', per_page.toString()); } if (page) { queryParams.append('page', page.toString()); } const queryString = queryParams.toString() ? `?${queryParams.toString()}` : ''; const url = `${baseUrl}/users/${username}/orgs${queryString}`; const response = await axios.get(url, { headers: { Authorization: `token ${token}`, Accept: 'application/vnd.github.v3+json' } }); return response.data; } catch (error: any) { if (error.response?.status === 404) { throw new Error(`User '${params.username}' not found`); } throw new Error(`Failed to list user organizations: ${error.message}`); } }
- api/users/types.ts:189-204 (schema)TypeScript interface defining the input parameters for listing user organizations: username (required), per_page and page (optional). Matches the zod schema in the handler.export interface ListUserOrgsParams { /** * Username of the user whose organizations to list */ username: string; /** * Optional number of results per page (max 100) */ per_page?: number; /** * Optional page number for pagination */ page?: number; }