manage_retention_policies
Configure and manage retention policies for content across Exchange, SharePoint, OneDrive, and Teams using lifecycle rules to control data preservation and deletion.
Instructions
Manage retention policies for content across Exchange, SharePoint, OneDrive, and Teams with lifecycle rules.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform on retention policy | |
| policyId | No | Retention policy ID for specific operations | |
| displayName | No | Display name for the retention policy | |
| description | No | Description of the retention policy | |
| isEnabled | No | Whether the policy is enabled | |
| retentionSettings | Yes | Retention policy settings | |
| locations | No | Locations where the policy applies |
Implementation Reference
- The core handler function implementing manage_retention_policies tool logic. Handles CRUD operations on Microsoft Purview retention policies using Microsoft Graph API endpoints under /security/informationProtection/retentionPolicies.export async function handleRetentionPolicies( graphClient: Client, args: RetentionPolicyArgs ): Promise<{ content: { type: string; text: string }[] }> { let apiPath = ''; let result: any; switch (args.action) { case 'list': // List all retention policies apiPath = '/security/informationProtection/retentionPolicies'; result = await graphClient.api(apiPath).get(); break; case 'get': if (!args.policyId) { throw new McpError(ErrorCode.InvalidParams, 'policyId is required for get action'); } apiPath = `/security/informationProtection/retentionPolicies/${args.policyId}`; result = await graphClient.api(apiPath).get(); break; case 'create': if (!args.displayName || !args.retentionSettings) { throw new McpError(ErrorCode.InvalidParams, 'displayName and retentionSettings are required for create action'); } const retentionPolicyPayload = { displayName: args.displayName, description: args.description || '', isEnabled: args.isEnabled !== undefined ? args.isEnabled : true, retentionSettings: args.retentionSettings, locations: args.locations || {} }; apiPath = '/security/informationProtection/retentionPolicies'; result = await graphClient.api(apiPath).post(retentionPolicyPayload); break; case 'update': if (!args.policyId) { throw new McpError(ErrorCode.InvalidParams, 'policyId is required for update action'); } const updatePayload: any = {}; if (args.displayName) updatePayload.displayName = args.displayName; if (args.description) updatePayload.description = args.description; if (args.isEnabled !== undefined) updatePayload.isEnabled = args.isEnabled; if (args.retentionSettings) updatePayload.retentionSettings = args.retentionSettings; if (args.locations) updatePayload.locations = args.locations; apiPath = `/security/informationProtection/retentionPolicies/${args.policyId}`; result = await graphClient.api(apiPath).patch(updatePayload); break; case 'delete': if (!args.policyId) { throw new McpError(ErrorCode.InvalidParams, 'policyId is required for delete action'); } apiPath = `/security/informationProtection/retentionPolicies/${args.policyId}`; await graphClient.api(apiPath).delete(); result = { message: `Retention policy ${args.policyId} deleted successfully` }; break; default: throw new McpError(ErrorCode.InvalidParams, `Unknown action: ${args.action}`); } return { content: [{ type: 'text', text: `Retention Policy ${args.action} operation completed:\n\n${JSON.stringify(result, null, 2)}` }] }; }
- src/schemas/policy-schemas.ts:38-56 (schema)Zod schema defining the input parameters and structure for the manage_retention_policies tool, used for validation and MCP tool discovery.export const retentionPolicyArgsSchema = z.object({ action: z.enum(['list', 'get', 'create', 'update', 'delete']).describe('Action to perform on retention policy'), policyId: z.string().optional().describe('Retention policy ID for specific operations'), displayName: z.string().optional().describe('Display name for the retention policy'), description: z.string().optional().describe('Description of the retention policy'), isEnabled: z.boolean().optional().describe('Whether the policy is enabled'), retentionSettings: z.object({ retentionDuration: z.number().describe('Retention duration in days'), retentionAction: z.enum(['Delete', 'Keep', 'KeepAndDelete']).describe('Action to take after retention period'), deletionType: z.enum(['Immediately', 'AfterRetentionPeriod']).optional().describe('When to delete content'), }).describe('Retention policy settings'), locations: z.object({ sharePointSites: z.array(z.string()).optional().describe('SharePoint sites to include'), exchangeEmail: z.boolean().optional().describe('Include Exchange email'), teamsChannels: z.boolean().optional().describe('Include Teams channels'), teamsChats: z.boolean().optional().describe('Include Teams chats'), oneDriveAccounts: z.array(z.string()).optional().describe('OneDrive accounts to include'), }).optional().describe('Locations where the policy applies'), });
- src/server.ts:1054-1073 (registration)MCP server tool registration for 'manage_retention_policies', linking the schema, metadata annotations, and handler function.this.server.tool( "manage_retention_policies", "Manage retention policies for content across Exchange, SharePoint, OneDrive, and Teams with lifecycle rules.", retentionPolicyArgsSchema.shape, {"readOnlyHint":false,"destructiveHint":true,"idempotentHint":false}, wrapToolHandler(async (args: RetentionPolicyArgs) => { this.validateCredentials(); try { return await handleRetentionPolicies(this.getGraphClient(), args); } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Error executing tool: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }) );
- src/types/policy-types.ts:38-56 (schema)TypeScript interface defining the structure of arguments for retention policy operations, used in handler implementation.export interface RetentionPolicyArgs { action: 'list' | 'get' | 'create' | 'update' | 'delete'; policyId?: string; displayName?: string; description?: string; isEnabled?: boolean; retentionSettings: { retentionDuration: number; // in days retentionAction: 'Delete' | 'Keep' | 'KeepAndDelete'; deletionType?: 'Immediately' | 'AfterRetentionPeriod'; }; locations?: { sharePointSites?: string[]; exchangeEmail?: boolean; teamsChannels?: boolean; teamsChats?: boolean; oneDriveAccounts?: string[]; }; }
- src/tool-metadata.ts:230-233 (registration)Tool metadata providing description, title, and annotations (readOnlyHint, destructiveHint, etc.) for the manage_retention_policies tool, used in MCP server registration.manage_retention_policies: { description: "Manage retention policies for content across Exchange, SharePoint, OneDrive, and Teams with lifecycle rules.", title: "Retention Policy Manager", annotations: { title: "Retention Policy Manager", readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }