Skip to main content
Glama
r-huijts
by r-huijts

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
NameRequiredDescriptionDefault
emailYesEmail address of the user to invite
roleYesOrganization-level role: 'admin' for full access, 'member' for limited access
first_nameNoUser's first name
last_nameNoUser's last name
workspacesYesList of workspaces and corresponding roles to grant to the user
workspace_api_key_detailsNoOptional 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 response
    server.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'}`
            }]
          };
        }
      }
    );
  • Core handler function in PortkeyService that performs the HTTP POST to Portkey API to invite a user, handles response and errors
    async 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 function
    interface 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 function
    interface InviteUserResponse {
      id: string;        // Changed to match API response
      invite_link: string;  // Changed to match API response
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/r-huijts/portkey-admin-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server