invite_user
Add users to your Portkey organization with controlled workspace access and API key permissions. Specify roles, workspaces, and API scopes during invitation.
Instructions
Invite a new user to your Portkey organization with specific workspace access and API key permissions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes | Email address of the user to invite | ||
| role | Yes | Organization-level role: 'admin' for full access, 'member' for limited access | |
| first_name | No | User's first name | |
| last_name | No | User's last name | |
| workspaces | Yes | List of workspaces and corresponding roles to grant to the user | |
| workspace_api_key_details | No | Optional API key to be created for the user |
Implementation Reference
- src/index.ts:33-74 (registration)MCP server.tool registration for 'invite_user' tool, including Zod input schema definition and async handler function that delegates to PortkeyService.inviteUser and formats the MCP responseserver.tool( "invite_user", "Invite a new user to your Portkey organization with specific workspace access and API key permissions", { email: z.string().email().describe("Email address of the user to invite"), role: z.enum(['admin', 'member']).describe("Organization-level role: 'admin' for full access, 'member' for limited access"), first_name: z.string().optional().describe("User's first name"), last_name: z.string().optional().describe("User's last name"), workspaces: z.array(z.object({ id: z.string().describe("Workspace ID/slug where the user will be granted access"), role: z.enum(['admin', 'member', 'manager']).describe("Workspace-level role: 'admin' for full access, 'manager' for workspace management, 'member' for basic access") })).describe("List of workspaces and corresponding roles to grant to the user"), workspace_api_key_details: z.object({ name: z.string().optional().describe("Name of the API key to be created"), expiry: z.string().optional().describe("Expiration date for the API key (ISO8601 format)"), metadata: z.record(z.string()).optional().describe("Additional metadata key-value pairs for the API key"), scopes: z.array(z.string()).describe("List of permission scopes for the API key") }).optional().describe("Optional API key to be created for the user") }, async (params) => { try { const result = await portkeyService.inviteUser(params); return { content: [{ type: "text", text: JSON.stringify({ message: `Successfully invited ${params.email} as ${params.role}`, invite_id: result.id, invite_link: result.invite_link }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error inviting user: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } } );
- src/services/portkey.service.ts:307-340 (handler)Core handler function in PortkeyService that performs the HTTP POST to Portkey API to invite a user, handles response and errorsasync inviteUser(data: InviteUserRequest): Promise<InviteUserResponse> { try { const response = await fetch(`${this.baseUrl}/admin/users/invites`, { // Fixed URL method: 'POST', headers: { 'x-portkey-api-key': this.apiKey, 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify({ email: data.email, role: data.role, first_name: data.first_name, last_name: data.last_name, workspaces: data.workspaces, workspace_api_key_details: data.workspace_api_key_details }) }); if (!response.ok) { const error = await response.json(); throw new Error(error.message || `Failed to invite user: ${response.status}`); } const result = await response.json(); return { id: result.id, invite_link: result.invite_link }; } catch (error) { console.error('PortkeyService Error:', error); throw new Error('Failed to invite user to Portkey'); } }
- TypeScript interface for input parameters to inviteUser functioninterface InviteUserRequest { email: string; role: 'admin' | 'member'; first_name?: string; last_name?: string; workspaces: WorkspaceDetails[]; workspace_api_key_details?: WorkspaceApiKeyDetails; }
- TypeScript interface for output of inviteUser functioninterface InviteUserResponse { id: string; // Changed to match API response invite_link: string; // Changed to match API response }