list_workspaces
Retrieve all workspaces in your Portkey organization to view configurations and metadata for managing AI settings and API usage.
Instructions
Retrieve all workspaces in your Portkey organization, including their configurations and metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | Number of workspaces to return per page (default varies by endpoint) | |
| current_page | No | Page number to retrieve when results are paginated |
Implementation Reference
- src/index.ts:119-136 (handler)The MCP tool handler function for 'list_workspaces' that calls the Portkey service method and formats the response as text content or handles errors.async (params) => { try { const workspaces = await portkeyService.listWorkspaces(params); return { content: [{ type: "text", text: JSON.stringify(workspaces, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error fetching workspaces: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } }
- src/index.ts:116-118 (schema)Zod input schema defining optional pagination parameters for the list_workspaces tool.page_size: z.number().positive().optional().describe("Number of workspaces to return per page (default varies by endpoint)"), current_page: z.number().positive().optional().describe("Page number to retrieve when results are paginated") },
- src/index.ts:112-137 (registration)MCP server registration of the 'list_workspaces' tool, specifying name, description, input schema, and handler function.server.tool( "list_workspaces", "Retrieve all workspaces in your Portkey organization, including their configurations and metadata", { page_size: z.number().positive().optional().describe("Number of workspaces to return per page (default varies by endpoint)"), current_page: z.number().positive().optional().describe("Page number to retrieve when results are paginated") }, async (params) => { try { const workspaces = await portkeyService.listWorkspaces(params); return { content: [{ type: "text", text: JSON.stringify(workspaces, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error fetching workspaces: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } } );
- Helper method in PortkeyService that performs the actual API request to list workspaces with optional pagination and error handling.async listWorkspaces(params?: ListWorkspacesParams): Promise<ListWorkspacesResponse> { try { const queryParams = new URLSearchParams(); if (params?.page_size) { queryParams.append('page_size', params.page_size.toString()); } if (params?.current_page) { queryParams.append('current_page', params.current_page.toString()); } const url = `${this.baseUrl}/admin/workspaces${queryParams.toString() ? '?' + queryParams.toString() : ''}`; const response = await fetch(url, { method: 'GET', headers: { 'x-portkey-api-key': this.apiKey, 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json() as ListWorkspacesResponse; } catch (error) { console.error('PortkeyService Error:', error); throw new Error('Failed to fetch workspaces from Portkey API'); } }
- TypeScript interface defining input parameters for the listWorkspaces service method.interface ListWorkspacesParams { page_size?: number; current_page?: number; }