Skip to main content
Glama
DynamicEndpoints

Microsoft 365 Core MCP Server

manage_service_principals

Destructive

Manage application service principals to control permissions, credentials, and enterprise applications in Microsoft 365 environments.

Instructions

Manage service principals for application access including permissions, credentials, and enterprise applications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesService principal management action
spIdNoObject ID of the Service Principal
ownerIdNoObject ID of the user to add/remove as owner
filterNoOData filter string

Implementation Reference

  • The core handler function implementing the manage_service_principals tool logic. Handles actions like listing service principals (GET /servicePrincipals), getting specific SP, adding/removing owners via Graph API.
    export async function handleServicePrincipals(
      graphClient: Client,
      args: AzureAdSpArgs
    ): Promise<{ content: { type: string; text: string }[] }> {
      let apiPath = '';
      let result: any;
    
      switch (args.action) {
        case 'list_sps':
          apiPath = '/servicePrincipals';
          if (args.filter) {
            apiPath += `?$filter=${encodeURIComponent(args.filter)}`;
          }
          result = await graphClient.api(apiPath).get();
          break;
    
        case 'get_sp':
          if (!args.spId) {
            throw new McpError(ErrorCode.InvalidParams, 'spId is required for get_sp');
          }
          apiPath = `/servicePrincipals/${args.spId}`;
          result = await graphClient.api(apiPath).get();
          break;
    
        case 'add_owner':
          if (!args.spId || !args.ownerId) {
            throw new McpError(ErrorCode.InvalidParams, 'spId and ownerId are required for add_owner');
          }
          // Requires Application.ReadWrite.All or Directory.ReadWrite.All
          apiPath = `/servicePrincipals/${args.spId}/owners/$ref`;
          const ownerPayload = {
            '@odata.id': `https://graph.microsoft.com/v1.0/users/${args.ownerId}`
          };
          await graphClient.api(apiPath).post(ownerPayload);
          result = { message: 'Owner added successfully to Service Principal' };
          break;
    
        case 'remove_owner':
          if (!args.spId || !args.ownerId) {
            throw new McpError(ErrorCode.InvalidParams, 'spId and ownerId are required for remove_owner');
          }
          // Requires Application.ReadWrite.All or Directory.ReadWrite.All
          // Similar to app owners, requires the directoryObject ID of the owner relationship
          apiPath = `/servicePrincipals/${args.spId}/owners/${args.ownerId}/$ref`;
          await graphClient.api(apiPath).delete();
          result = { message: 'Owner removed successfully from Service Principal' };
          break;
    
        default:
          throw new McpError(ErrorCode.InvalidParams, `Invalid action: ${args.action}`);
      }
    
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
  • src/server.ts:587-607 (registration)
    Registers the 'manage_service_principals' tool with the MCP server, associating it with the handleServicePrincipals handler, input schema (azureAdSpSchema), and metadata annotations.
    this.server.tool(
      "manage_service_principals",
      "Manage service principals for application access including permissions, credentials, and enterprise applications.",
      azureAdSpSchema.shape,
      {"readOnlyHint":false,"destructiveHint":true,"idempotentHint":false},
      wrapToolHandler(async (args: AzureAdSpArgs) => {
        // Validate credentials only when tool is executed (lazy loading)
        this.validateCredentials();
        try {
          return await handleServicePrincipals(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'}`
          );
        }
      })
    );
  • Zod schema defining the input parameters and validation for the manage_service_principals tool (azureAdSpSchema), used in tool registration.
    export const azureAdSpSchema = z.object({
      action: z.enum(['list_sps', 'get_sp', 'add_owner', 'remove_owner']).describe('Service principal management action'),
      spId: z.string().optional().describe('Object ID of the Service Principal'),
      ownerId: z.string().optional().describe('Object ID of the user to add/remove as owner'),
      filter: z.string().optional().describe('OData filter string'),
    });
  • Tool metadata providing description, title, and MCP annotations (readOnlyHint, destructiveHint, etc.) for 'manage_service_principals'.
    manage_service_principals: {
      description: "Manage service principals for application access including permissions, credentials, and enterprise applications.",
      title: "Service Principal Manager",
      annotations: { title: "Service Principal 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 indicate destructiveHint=true, readOnlyHint=false, and idempotentHint=false, which already inform the agent about mutation, non-idempotency, and potential data loss. The description adds minimal behavioral context by mentioning 'permissions, credentials, and enterprise applications,' but doesn't elaborate on side effects, authentication needs, or rate limits. 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 without unnecessary elaboration. It avoids redundancy and wastes no words, though it could be slightly more structured by breaking down the 'including' list for clarity.

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 (4 parameters, destructive operations, no output schema) and rich annotations, the description is adequate but incomplete. It covers the what but lacks details on behavioral nuances, error handling, or output expectations. With annotations handling safety, it meets minimum viability but leaves gaps for effective agent use.

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?

Schema description coverage is 100%, with clear descriptions for all parameters, including an enum for 'action' that lists specific operations. The description doesn't add any parameter-specific details beyond what the schema provides, such as explaining the 'filter' format or 'spId' sourcing. With high schema coverage, the baseline of 3 is appropriate.

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's purpose: managing service principals for application access, with specific mention of permissions, credentials, and enterprise applications. It uses a specific verb ('manage') and resource ('service principals'), distinguishing it from sibling tools like manage_azure_ad_apps or manage_security_groups. However, it doesn't explicitly differentiate from all siblings, keeping it at a 4 rather than a 5.

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, context for choosing specific actions, or comparisons to sibling tools like manage_azure_ad_apps. Without any usage context, the agent must infer based on the name and parameters alone.

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