Skip to main content
Glama
DynamicEndpoints

Microsoft 365 Core MCP Server

manage_defender_policies

Destructive

Configure and manage Microsoft Defender for Office 365 security policies including Safe Attachments, Safe Links, anti-phishing, and anti-malware settings to protect email communications.

Instructions

Manage Microsoft Defender for Office 365 policies including Safe Attachments, Safe Links, anti-phishing, and anti-malware.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform on Defender policy
policyTypeYesType of Defender policy
policyIdNoDefender policy ID for specific operations
displayNameNoDisplay name for the policy
descriptionNoDescription of the policy
isEnabledNoWhether the policy is enabled
settingsNoPolicy settings
appliedToNoPolicy application scope

Implementation Reference

  • The core handler function `handleDefenderPolicies` that implements the logic for managing Microsoft Defender policies. It handles actions like list, get, create, update, delete for different policy types (safeAttachments, safeLinks, antiPhishing, etc.) using Microsoft Graph API endpoints.
    export async function handleDefenderPolicies(
      graphClient: Client,
      args: DefenderPolicyArgs
    ): Promise<{ content: { type: string; text: string }[] }> {
      let apiPath = '';
      let result: any;
    
      // Map policy types to API endpoints
      const policyEndpoints = {
        safeAttachments: '/security/attackSimulation/safeAttachmentPolicies',
        safeLinks: '/security/attackSimulation/safeLinksPolicies',
        antiPhishing: '/security/antiPhishingPolicies',
        antiMalware: '/security/antiMalwarePolicies',
        antiSpam: '/security/antiSpamPolicies'
      };
    
      const endpoint = policyEndpoints[args.policyType];
      if (!endpoint) {
        throw new McpError(ErrorCode.InvalidParams, `Unsupported policy type: ${args.policyType}`);
      }
    
      switch (args.action) {
        case 'list':
          apiPath = endpoint;
          result = await graphClient.api(apiPath).get();
          break;
    
        case 'get':
          if (!args.policyId) {
            throw new McpError(ErrorCode.InvalidParams, 'policyId is required for get action');
          }
          apiPath = `${endpoint}/${args.policyId}`;
          result = await graphClient.api(apiPath).get();
          break;
    
        case 'create':
          if (!args.displayName) {
            throw new McpError(ErrorCode.InvalidParams, 'displayName is required for create action');
          }
          
          const defenderPolicyPayload: any = {
            displayName: args.displayName,
            description: args.description || '',
            isEnabled: args.isEnabled !== undefined ? args.isEnabled : true,
            settings: args.settings || {},
            appliedTo: args.appliedTo || {}
          };
    
          apiPath = endpoint;
          result = await graphClient.api(apiPath).post(defenderPolicyPayload);
          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.settings) updatePayload.settings = args.settings;
          if (args.appliedTo) updatePayload.appliedTo = args.appliedTo;
    
          apiPath = `${endpoint}/${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 = `${endpoint}/${args.policyId}`;
          await graphClient.api(apiPath).delete();
          result = { message: `${args.policyType} policy ${args.policyId} deleted successfully` };
          break;
    
        default:
          throw new McpError(ErrorCode.InvalidParams, `Unknown action: ${args.action}`);
      }
    
      return {
        content: [{
          type: 'text',
          text: `Defender ${args.policyType} Policy ${args.action} operation completed:\n\n${JSON.stringify(result, null, 2)}`
        }]
      };
    }
  • Zod schema `defenderPolicyArgsSchema` defining the input parameters for the manage_defender_policies tool, including action, policyType, policyId, settings, etc.
    export const defenderPolicyArgsSchema = z.object({
      action: z.enum(['list', 'get', 'create', 'update', 'delete']).describe('Action to perform on Defender policy'),
      policyType: z.enum(['safeAttachments', 'safeLinks', 'antiPhishing', 'antiMalware', 'antiSpam']).describe('Type of Defender policy'),
      policyId: z.string().optional().describe('Defender policy ID for specific operations'),
      displayName: z.string().optional().describe('Display name for the policy'),
      description: z.string().optional().describe('Description of the policy'),
      isEnabled: z.boolean().optional().describe('Whether the policy is enabled'),
      settings: z.object({
        action: z.enum(['Block', 'Replace', 'Allow', 'DynamicDelivery']).optional().describe('Safe Attachments action'),
        redirectToRecipients: z.array(z.string()).optional().describe('Redirect recipients for Safe Attachments'),
        actionOnError: z.boolean().optional().describe('Action on error for Safe Attachments'),
        scanUrls: z.boolean().optional().describe('Scan URLs for Safe Links'),
        enableForInternalSenders: z.boolean().optional().describe('Enable Safe Links for internal senders'),
        trackClicks: z.boolean().optional().describe('Track clicks for Safe Links'),
        allowClickThrough: z.boolean().optional().describe('Allow click through for Safe Links'),
        enableMailboxIntelligence: z.boolean().optional().describe('Enable mailbox intelligence for anti-phishing'),
        enableSpoofIntelligence: z.boolean().optional().describe('Enable spoof intelligence'),
        enableUnauthenticatedSender: z.boolean().optional().describe('Enable unauthenticated sender indicators'),
        enableViaTag: z.boolean().optional().describe('Enable via tag'),
        enableFileFilter: z.boolean().optional().describe('Enable file filter for anti-malware'),
        fileTypes: z.array(z.string()).optional().describe('File types to filter'),
        zap: z.boolean().optional().describe('Enable Zero-hour Auto Purge'),
        bulkThreshold: z.number().optional().describe('Bulk email threshold'),
        quarantineRetentionPeriod: z.number().optional().describe('Quarantine retention period in days'),
        enableEndUserSpamNotifications: z.boolean().optional().describe('Enable end user spam notifications'),
      }).optional().describe('Policy settings'),
      appliedTo: z.object({
        recipientDomains: z.array(z.string()).optional().describe('Recipient domains'),
        recipientGroups: z.array(z.string()).optional().describe('Recipient groups'),
        recipients: z.array(z.string()).optional().describe('Individual recipients'),
      }).optional().describe('Policy application scope'),
    });
  • Tool registration in the MCP server: registers 'manage_defender_policies' tool with schema, annotations, and handler `handleDefenderPolicies` wrapped with error handling.
    this.server.tool(
      "manage_defender_policies",
      "Manage Microsoft Defender for Office 365 policies including Safe Attachments, Safe Links, anti-phishing, and anti-malware.",
      defenderPolicyArgsSchema.shape,
      {"readOnlyHint":false,"destructiveHint":true,"idempotentHint":false},
      wrapToolHandler(async (args: DefenderPolicyArgs) => {
        this.validateCredentials();
        try {
          return await handleDefenderPolicies(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'}`
          );
        }
      })
    );
  • Tool metadata definition providing description, title, and annotations for the manage_defender_policies tool, used for MCP discovery.
    manage_defender_policies: {
      description: "Manage Microsoft Defender for Office 365 policies including Safe Attachments, Safe Links, anti-phishing, and anti-malware.",
      title: "Defender Policy Manager",
      annotations: { title: "Defender Policy Manager", readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description doesn't contradict the annotations (destructiveHint=true, readOnlyHint=false, idempotentHint=false). While the annotations already indicate this is a destructive, non-idempotent write operation, the description adds context by specifying the policy types managed. However, it doesn't elaborate on what 'destructive' means in this context (e.g., policy deletion consequences) or mention authentication requirements or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. Every word earns its place by specifying the resource (Microsoft Defender for Office 365 policies) and enumerating the policy types managed. There's zero waste or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 8 parameters, nested objects, destructive operations, and no output schema, the description is adequate but has clear gaps. It covers what policy types are managed but doesn't explain the multi-action nature (list/get/create/update/delete), expected outputs, or important behavioral considerations beyond what annotations provide. The combination of good annotations and thorough schema helps compensate somewhat.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the input schema already documents all 8 parameters thoroughly. The description mentions policy types that map to the policyType enum but doesn't add meaningful semantic context beyond what's in the schema. The baseline of 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool manages Microsoft Defender for Office 365 policies and lists specific policy types (Safe Attachments, Safe Links, anti-phishing, anti-malware). It provides a specific verb ('manage') and resource ('policies'), but doesn't explicitly distinguish this tool from its many sibling tools on the server, which mostly manage different Microsoft 365 resources.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, appropriate contexts, or when other tools might be more suitable. With many sibling tools managing different Microsoft 365 components, this lack of differentiation is a significant gap.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/DynamicEndpoints/m365-core-mcp'

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