Skip to main content
Glama
DynamicEndpoints

Microsoft 365 Core MCP Server

manage_security_groups

Destructive

Create, update, and manage Azure AD security groups to control access by adding or removing members and configuring security settings.

Instructions

Manage Azure AD security groups for access control, including group creation, membership, and security settings.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform on security group
groupIdNoSecurity group ID for existing group operations
displayNameNoDisplay name for the security group
descriptionNoDescription of the security group
membersNoList of member email addresses
settingsNoSecurity group settings

Implementation Reference

  • Core handler function implementing manage_security_groups tool logic: handles actions like get, create, update, delete, add_members, remove_members using Microsoft Graph API on /groups endpoint.
    export async function handleSecurityGroups(
      graphClient: Client,
      args: SecurityGroupArgs
    ): Promise<{ content: { type: string; text: string }[] }> {
      let apiPath = '';
      let result: any;
    
      switch (args.action) {
        case 'get':
          if (!args.groupId) {
            throw new McpError(ErrorCode.InvalidParams, 'groupId is required for get action');
          }
          apiPath = `/groups/${args.groupId}`;
          result = await graphClient.api(apiPath).get();
          break;
    
        case 'create':
          if (!args.displayName) {
            throw new McpError(ErrorCode.InvalidParams, 'displayName is required for create action');
          }
          apiPath = '/groups';
          const createPayload = {
            displayName: args.displayName,
            description: args.description || '',
            mailNickname: args.displayName.replace(/\s+/g, '').toLowerCase(),
            mailEnabled: args.settings?.mailEnabled || false,
            securityEnabled: args.settings?.securityEnabled !== false, // Default to true
            groupTypes: []
          };
          result = await graphClient.api(apiPath).post(createPayload);
          break;
    
        case 'update':
          if (!args.groupId) {
            throw new McpError(ErrorCode.InvalidParams, 'groupId is required for update action');
          }
          apiPath = `/groups/${args.groupId}`;
          const updatePayload: any = {};
          if (args.displayName) updatePayload.displayName = args.displayName;
          if (args.description) updatePayload.description = args.description;
          result = await graphClient.api(apiPath).patch(updatePayload);
          break;
    
        case 'delete':
          if (!args.groupId) {
            throw new McpError(ErrorCode.InvalidParams, 'groupId is required for delete action');
          }
          apiPath = `/groups/${args.groupId}`;
          await graphClient.api(apiPath).delete();
          result = { message: 'Security group deleted successfully' };
          break;
    
        case 'add_members':
          if (!args.groupId || !args.members?.length) {
            throw new McpError(ErrorCode.InvalidParams, 'groupId and members are required for add_members action');
          }
          
          for (const member of args.members) {
            await graphClient
              .api(`/groups/${args.groupId}/members/$ref`)
              .post({
                '@odata.id': `https://graph.microsoft.com/v1.0/users/${member}`
              });
          }
          result = { message: `Added ${args.members.length} members to security group` };
          break;
    
        case 'remove_members':
          if (!args.groupId || !args.members?.length) {
            throw new McpError(ErrorCode.InvalidParams, 'groupId and members are required for remove_members action');
          }
          
          for (const member of args.members) {
            await graphClient
              .api(`/groups/${args.groupId}/members/${member}/$ref`)
              .delete();
          }
          result = { message: `Removed ${args.members.length} members from security group` };
          break;
    
        default:
          throw new McpError(ErrorCode.InvalidParams, `Invalid action: ${args.action}`);
      }
    
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
  • src/server.ts:375-394 (registration)
    MCP server registration of the 'manage_security_groups' tool, wiring the handler function, Zod input schema, and tool annotations.
    this.server.tool(
      "manage_security_groups",
      "Manage Azure AD security groups for access control, including group creation, membership, and security settings.",
      securityGroupSchema.shape,
      {"readOnlyHint":false,"destructiveHint":true,"idempotentHint":false},
      wrapToolHandler(async (args: SecurityGroupArgs) => {
        // Validate credentials only when tool is executed (lazy loading)
        this.validateCredentials();        try {
          return await handleSecurityGroups(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'}`
          );
        }
      })
    );    // M365 Groups - Lazy loading enabled for tool discovery
  • Zod schema defining input parameters and validation for the manage_security_groups tool, used in tool registration.
    export const securityGroupSchema = z.object({
      action: z.enum(['get', 'create', 'update', 'delete', 'add_members', 'remove_members']).describe('Action to perform on security group'),
      groupId: z.string().optional().describe('Security group ID for existing group operations'),
      displayName: z.string().optional().describe('Display name for the security group'),
      description: z.string().optional().describe('Description of the security group'),
      members: z.array(z.string()).optional().describe('List of member email addresses'),
      settings: z.object({
        securityEnabled: z.boolean().optional().describe('Whether security is enabled'),
        mailEnabled: z.boolean().optional().describe('Whether mail is enabled'),
      }).optional().describe('Security group settings'),
    });
  • Tool metadata including description, title, and annotations for manage_security_groups, used in capabilities and tool info.
    manage_security_groups: {
      description: "Manage Azure AD security groups for access control, including group creation, membership, and security settings.",
      title: "Security Group Manager",
      annotations: { title: "Security Group Manager", readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }
Behavior3/5

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

Annotations already indicate this is a destructive, non-idempotent, non-read-only tool. The description adds minimal behavioral context beyond this, mentioning 'access control' which hints at security implications but doesn't elaborate on permissions needed, rate limits, or specific destructive consequences of actions like 'delete'. No contradiction with annotations exists.

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

Conciseness4/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. It avoids redundancy and wastes no words, though it could be slightly more structured by explicitly listing the action types or providing brief examples.

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?

Given the tool's complexity (6 parameters, destructive annotations, no output schema), the description is minimally adequate. It covers the high-level purpose but lacks details on error handling, response formats, or operational constraints, leaving gaps that could hinder an agent's ability to use it effectively without trial and error.

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 schema fully documents all 6 parameters, including the 'action' enum with 6 values. The description adds no parameter-specific semantics beyond implying the tool handles 'group creation, membership, and security settings', which loosely maps to some action values but doesn't clarify parameter interactions or usage details.

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 Azure AD security groups for access control, specifying three key operations: creation, membership management, and security settings. It uses specific verbs and identifies the resource, but doesn't explicitly differentiate from sibling tools like 'manage_m365_groups' or 'manage_distribution_lists' which might handle similar group types.

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 exclusions, nor does it reference sibling tools that might handle related functionality like 'manage_m365_groups' for different group types or 'manage_azure_ad_roles' for role-based access control.

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