add_privileges_to_role
Grant specific permissions to security roles by adding privileges with defined access levels for operations like create, read, write, and delete on entities or system functions.
Instructions
Adds specific privileges with defined access levels to a security role. Use this to grant permissions for specific operations (create, read, write, delete, etc.) on entities or system functions. Each privilege can have different access levels (Basic, Local, Deep, Global).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| privileges | Yes | Array of privileges to add to the role | |
| roleId | Yes | ID of the role to add privileges to |
Implementation Reference
- src/tools/role-tools.ts:331-361 (handler)The core handler function that processes the tool input, maps privileges with depth values using getDepthValue helper, calls the Dataverse 'AddPrivilegesRole' action, and returns success or error response.async (params) => { try { const privileges = params.privileges.map(p => ({ PrivilegeId: p.privilegeId, Depth: getDepthValue(p.depth) })); await client.callAction('AddPrivilegesRole', { RoleId: params.roleId, Privileges: privileges }); return { content: [ { type: "text", text: `Successfully added ${privileges.length} privilege(s) to role.` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error adding privileges to role: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; }
- src/tools/role-tools.ts:324-329 (schema)Zod input schema defining the parameters: roleId (string) and privileges (array of objects with privilegeId and depth enum).roleId: z.string().describe("ID of the role to add privileges to"), privileges: z.array(z.object({ privilegeId: z.string().describe("ID of the privilege to add"), depth: z.enum(['Basic', 'Local', 'Deep', 'Global']).describe("Access level for the privilege") })).describe("Array of privileges to add to the role") }
- src/tools/role-tools.ts:317-364 (registration)The exported addPrivilegesToRoleTool function that performs the server.registerTool call for 'add_privileges_to_role', defining title, description, inputSchema, and handler.export function addPrivilegesToRoleTool(server: McpServer, client: DataverseClient) { server.registerTool( "add_privileges_to_role", { title: "Add Privileges to Dataverse Role", description: "Adds specific privileges with defined access levels to a security role. Use this to grant permissions for specific operations (create, read, write, delete, etc.) on entities or system functions. Each privilege can have different access levels (Basic, Local, Deep, Global).", inputSchema: { roleId: z.string().describe("ID of the role to add privileges to"), privileges: z.array(z.object({ privilegeId: z.string().describe("ID of the privilege to add"), depth: z.enum(['Basic', 'Local', 'Deep', 'Global']).describe("Access level for the privilege") })).describe("Array of privileges to add to the role") } }, async (params) => { try { const privileges = params.privileges.map(p => ({ PrivilegeId: p.privilegeId, Depth: getDepthValue(p.depth) })); await client.callAction('AddPrivilegesRole', { RoleId: params.roleId, Privileges: privileges }); return { content: [ { type: "text", text: `Successfully added ${privileges.length} privilege(s) to role.` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error adding privileges to role: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } ); }
- src/index.ts:187-187 (registration)Invocation of addPrivilegesToRoleTool in the main index file to register the tool on the MCP server instance.addPrivilegesToRoleTool(server, dataverseClient);
- src/tools/role-tools.ts:5-12 (helper)Helper utility function that converts the depth enum string to the numeric value required by the Dataverse API (Basic=0, Local=1, Deep=2, Global=3). Used in the handler.function getDepthValue(depth: string): number { switch (depth) { case 'Basic': return 0; case 'Local': return 1; case 'Deep': return 2; case 'Global': return 3; default: return 0; }