Assign Role to User
assign_role_to_userAssign security roles to users to grant appropriate access permissions for their job functions and responsibilities in Microsoft Dataverse.
Instructions
Assigns a security role to a specific user, granting them all the permissions defined in that role. Use this to provide users with the appropriate access levels for their job functions and responsibilities.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| roleId | Yes | ID of the role to assign | |
| userId | Yes | ID of the user to assign the role to |
Implementation Reference
- src/tools/role-tools.ts:512-537 (handler)The async handler function that performs the core logic: posts to Dataverse API to associate a role with a user and returns success or error response.
async (params) => { try { await client.post(`systemusers(${params.userId})/systemuserroles_association/$ref`, { "@odata.id": `${client['config'].dataverseUrl}/api/data/v9.2/roles(${params.roleId})` }); return { content: [ { type: "text", text: `Successfully assigned role to user.` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error assigning role to user: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } - src/tools/role-tools.ts:507-510 (schema)Zod-based input schema defining required parameters: roleId and userId.
inputSchema: { roleId: z.string().describe("ID of the role to assign"), userId: z.string().describe("ID of the user to assign the role to") } - src/tools/role-tools.ts:502-538 (registration)The server.registerTool call that registers the tool with name, metadata, schema, and handler function.
server.registerTool( "assign_role_to_user", { title: "Assign Role to User", description: "Assigns a security role to a specific user, granting them all the permissions defined in that role. Use this to provide users with the appropriate access levels for their job functions and responsibilities.", inputSchema: { roleId: z.string().describe("ID of the role to assign"), userId: z.string().describe("ID of the user to assign the role to") } }, async (params) => { try { await client.post(`systemusers(${params.userId})/systemuserroles_association/$ref`, { "@odata.id": `${client['config'].dataverseUrl}/api/data/v9.2/roles(${params.roleId})` }); return { content: [ { type: "text", text: `Successfully assigned role to user.` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error assigning role to user: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } ); - src/index.ts:193-193 (registration)Invocation of the registration function in the main server setup.
assignRoleToUserTool(server, dataverseClient);