cortex_get_user
Retrieve details of a specific user in the Cortex platform using a superadmin API key, enabling security investigations and access control management.
Instructions
Get details about a specific user (requires superadmin API key)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| userId | Yes | The user login/ID |
Implementation Reference
- src/tools/users.ts:60-101 (handler)MCP tool handler for 'cortex_get_user' - receives a userId, checks superadmin availability, calls client.getUser(), and returns the user details as JSON.
server.tool( "cortex_get_user", "Get details about a specific user (requires superadmin API key)", { userId: z.string().describe("The user login/ID"), }, async ({ userId }) => { try { if (!client.superadminAvailable) { return { content: [ { type: "text" as const, text: "User management requires CORTEX_SUPERADMIN_KEY environment variable to be set.", }, ], isError: true, }; } const user = await client.getUser(userId); return { content: [ { type: "text" as const, text: JSON.stringify(user, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error getting user: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }, ); - src/client.ts:398-404 (helper)Client method getUser() - makes a GET request to /user/{userId} using superadmin auth, returns a CortexUser object. This is the API call backing the handler.
async getUser(userId: string): Promise<CortexUser> { return this.request<CortexUser>( `/user/${encodeURIComponent(userId)}`, {}, true, ); } - src/types.ts:190-203 (schema)CortexUser interface - defines the shape of a user object returned by the API, including id, name, organization, roles, status, hasKey, hasPassword, and timestamps.
export interface CortexUser { id: string; name: string; organization: string; roles: string[]; status: string; hasKey?: boolean; hasPassword?: boolean; createdAt?: number; createdBy?: string; updatedAt?: number; updatedBy?: string; _type?: string; } - src/index.ts:44-44 (registration)Registration of the user tools module - calls registerUserTools(server, client) to register all user tools including cortex_get_user on the MCP server.
registerUserTools(server, client); - src/tools/users.ts:5-273 (registration)registerUserTools function - registers all user-related MCP tools (list, get, create, renew key, get key) on the server instance.
export function registerUserTools( server: McpServer, client: CortexClient, ): void { server.tool( "cortex_list_users", "List all users across organizations (requires superadmin API key via CORTEX_SUPERADMIN_KEY)", {}, async () => { try { if (!client.superadminAvailable) { return { content: [ { type: "text" as const, text: "User listing across organizations requires CORTEX_SUPERADMIN_KEY environment variable to be set.", }, ], isError: true, }; } const users = await client.listUsers(); const summary = users.map((u) => ({ id: u.id, name: u.name, organization: u.organization, roles: u.roles, status: u.status, hasKey: u.hasKey, hasPassword: u.hasPassword, })); return { content: [ { type: "text" as const, text: JSON.stringify(summary, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error listing users: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }, ); server.tool( "cortex_get_user", "Get details about a specific user (requires superadmin API key)", { userId: z.string().describe("The user login/ID"), }, async ({ userId }) => { try { if (!client.superadminAvailable) { return { content: [ { type: "text" as const, text: "User management requires CORTEX_SUPERADMIN_KEY environment variable to be set.", }, ], isError: true, }; } const user = await client.getUser(userId); return { content: [ { type: "text" as const, text: JSON.stringify(user, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error getting user: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }, ); server.tool( "cortex_create_user", "Create a new user in an organization (requires superadmin API key)", { login: z.string().describe("User login (used as ID)"), name: z.string().describe("User display name"), organization: z.string().describe("Organization to assign the user to"), roles: z .array(z.string()) .describe( 'User roles: "read", "analyze", "orgadmin", or "superadmin"', ), password: z.string().optional().describe("Optional initial password"), }, async ({ login, name, organization, roles, password }) => { try { if (!client.superadminAvailable) { return { content: [ { type: "text" as const, text: "User creation requires CORTEX_SUPERADMIN_KEY environment variable to be set.", }, ], isError: true, }; } const user = await client.createUser({ login, name, roles, organization, password, }); return { content: [ { type: "text" as const, text: JSON.stringify( { id: user.id, name: user.name, organization: user.organization, roles: user.roles, status: user.status, message: `User "${user.name}" (${user.id}) created in org "${user.organization}".`, }, null, 2, ), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error creating user: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }, ); server.tool( "cortex_renew_user_key", "Generate a new API key for a user (invalidates the previous key). Requires superadmin API key.", { userId: z.string().describe("The user login/ID to renew the key for"), }, async ({ userId }) => { try { if (!client.superadminAvailable) { return { content: [ { type: "text" as const, text: "User key management requires CORTEX_SUPERADMIN_KEY environment variable to be set.", }, ], isError: true, }; } const newKey = await client.renewUserKey(userId); return { content: [ { type: "text" as const, text: JSON.stringify( { userId, apiKey: newKey, message: `New API key generated for user "${userId}". The previous key is now invalid.`, warning: "Store this key securely. It will not be shown again.", }, null, 2, ), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error renewing user key: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }, ); server.tool( "cortex_get_user_key", "Get the current API key for a user. Requires superadmin API key.", { userId: z.string().describe("The user login/ID"), }, async ({ userId }) => { try { if (!client.superadminAvailable) { return { content: [ { type: "text" as const, text: "User key management requires CORTEX_SUPERADMIN_KEY environment variable to be set.", }, ], isError: true, }; } const key = await client.getUserKey(userId); return { content: [ { type: "text" as const, text: JSON.stringify( { userId, apiKey: key, }, null, 2, ), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error getting user key: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }, ); }