From db29a6b7fabb2783be1dd18d3068fcb0724c0ada Mon Sep 17 00:00:00 2001 From: Audel Rouhi Date: Thu, 12 Nov 2026 13:49:04 -0600 Subject: [PATCH 1/2] feat(microsoft): use the SDK's one destructive declaration and guard Destructive Microsoft operations had their own gate: a MICROSOFT_ALLOW_DESTRUCTIVE setting checked by the tool policy and the Windows companion tool, and a destructive_action_acknowledged field in the Intune confirmation evidence. That gate is removed. Eleven Graph client methods the SDK would not classify (application passwords, service principals, role assignments, conditional access, organization and admin SharePoint updates, risky-user dismissal, device wipe and retire) carry the SDK declaration, and the hand-written destructive tools (Intune reboot and shutdown, desktop-flow cancellation, PowerPoint slide deletion, Windows companion actions) run the SDK guard. Each served tool has the MCP destructive hint and the standard confirm argument; a call without a live confirmation makes no request. MICROSOFT_ALLOW_WRITES stays as deployment access scope. The single operator setting for unattended use is SCION_ALLOW_DESTRUCTIVE. Requires scion-sdk 0.10.2. Impact: MICROSOFT_ALLOW_DESTRUCTIVE is no longer read; callers pass confirm (or are confirmed by the gateway); Intune evidence no longer carries an acknowledgement field. Verification: 52 targeted tests pass, including a served check of the hint and confirm argument on every destructive tool and a refusal check that sends no request. Spec: CONN-MICROSOFT-AGENT-CONNECTOR-CONTENT-R002 (destructive operations use the SDK declaration and guard) Co-Authored-By: Claude Sonnet 5.5 --- .env.example | 1 - AGENTS.md | 6 +- README.md | 12 +-- docs/authentication.md | 6 +- docs/integrations.md | 3 +- docs/office-addin.md | 4 +- docs/usage.md | 4 +- mcp_config.json | 1 - microsoft_agent/api/api_client_admin.py | 6 ++ microsoft_agent/api/api_client_directory.py | 2 + microsoft_agent/api/api_client_drive.py | 3 + microsoft_agent/api/api_client_other.py | 7 ++ microsoft_agent/config_cli.py | 1 - microsoft_agent/connector_contracts.py | 46 +++++----- microsoft_agent/integration_tools.py | 66 ++++++++++++--- microsoft_agent/intune_service.py | 6 -- microsoft_agent/mcp_config.json | 1 - microsoft_agent/office_bridge.py | 13 ++- microsoft_agent/settings.py | 4 - .../microsoft-calendar-scheduling/SKILL.md | 2 +- .../skills/microsoft-contacts/SKILL.md | 2 +- .../microsoft-document-authoring/SKILL.md | 2 +- .../microsoft-education-booking/SKILL.md | 2 +- .../microsoft-endpoint-management/SKILL.md | 2 +- .../microsoft-files-sharepoint/SKILL.md | 2 +- .../microsoft-graph-integration/SKILL.md | 2 +- .../microsoft-identity-directory/SKILL.md | 2 +- .../skills/microsoft-mail-operations/SKILL.md | 2 +- .../skills/microsoft-office-apps/SKILL.md | 2 +- .../skills/microsoft-power-platform/SKILL.md | 2 +- .../microsoft-security-operations/SKILL.md | 2 +- .../skills/microsoft-service-reports/SKILL.md | 2 +- .../microsoft-session-management/SKILL.md | 2 +- .../skills/microsoft-teams-messaging/SKILL.md | 2 +- .../skills/microsoft-universal-print/SKILL.md | 2 +- microsoft_agent/tool_policy.py | 11 +-- pyproject.toml | 4 +- specs/connector-content/requirements.md | 1 + specs/connector-content/tasks.md | 1 + specs/connector-content/test-spec.md | 1 + tests/test_destructive_declaration.py | 83 +++++++++++++++++++ tests/test_intune_service.py | 21 +---- tests/test_settings_and_policy.py | 15 ++-- uv.lock | 10 +-- 44 files changed, 242 insertions(+), 129 deletions(-) create mode 100644 tests/test_destructive_declaration.py diff --git a/.env.example b/.env.example index cda2602..abb0e33 100644 --- a/.env.example +++ b/.env.example @@ -21,7 +21,6 @@ MICROSOFT_GRAPH_SCOPES= # Tools are registered, but side effects remain disabled until explicitly enabled. MICROSOFT_ENABLED_TOOL_GROUPS=misc,auth,meta,mail,files,calendar,notes,tasks,contacts,user,chat,teams,sites,search,groups,communications,documents,power_platform,windows,intune MICROSOFT_ALLOW_WRITES=false -MICROSOFT_ALLOW_DESTRUCTIVE=false # Required only for graph projection/ingestion. Resolve from AgentConfig or a # secret store; use at least 32 bytes and never reuse an identity credential. diff --git a/AGENTS.md b/AGENTS.md index aae72d3..95d158b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -68,8 +68,10 @@ asynchronous tool execution. Core libraries: `scion-sdk`, `fastmcp`, tokens in memory and must not enable plaintext persistence. - Each tool is authorized by its own name; unknown verbs are treated as writes and fail closed. No tool routes an `action` argument. -- Writes require `MICROSOFT_ALLOW_WRITES`; destructive actions also require - `MICROSOFT_ALLOW_DESTRUCTIVE`. +- Writes require `MICROSOFT_ALLOW_WRITES`; destructive actions also need a live + confirmation (the gateway's approval or the `confirm` argument); there is no + connector destructive setting (the operator's one setting is + `SCION_ALLOW_DESTRUCTIVE`). - Connector materialization remains quarantined until tenant, ACL, provenance, schema, and privacy policy are checked. - Tests must mock all provider and network interactions. diff --git a/README.md b/README.md index 19f17c8..38ffbd5 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,6 @@ tokens remain in memory and are not written to plaintext files. | `MICROSOFT_GRAPH_SCOPES` | — | | | `MICROSOFT_ENABLED_TOOL_GROUPS` | `misc,auth,meta,mail,files,calendar,notes,tasks,contacts,user,chat,teams,sites,search,groups,communications,documents,power_platform,windows,intune` | Tools are registered, but side effects remain disabled until explicitly enabled. | | `MICROSOFT_ALLOW_WRITES` | `false` | | -| `MICROSOFT_ALLOW_DESTRUCTIVE` | `false` | | | `MICROSOFT_INGESTION_PSEUDONYMIZATION_KEY_REF` | — | Required only for graph projection/ingestion. Resolve from AgentConfig or a secret store; use at least 32 bytes and never reuse an identity credential. | | `MICROSOFT_INTEGRATIONS_CONFIG_PATH` | — | Complex Power Platform, Intune, and Windows companion allowlists. | | `MICROSOFT_DOCUMENT_ARTIFACT_ROOT` | — | | @@ -264,13 +263,13 @@ and MCP caller identity are separate boundaries and both must be configured. | `microsoft_tasks` | `TASKSTOOL` | Manage microsoft tasks operations. | | `microsoft_teams` | `TEAMSTOOL` | Manage microsoft teams operations. | | `microsoft_user` | `USERTOOL` | Manage microsoft user operations. | -| `reboot_intune_device` | `INTUNETOOL` | Immediately reboot an allowlisted Intune device after destructive action acknowledgement and time-bound confirmation. | +| `reboot_intune_device` | `INTUNETOOL` | Immediately reboot an allowlisted Intune device after time-bound confirmation. | | `remote_lock_intune_device` | `INTUNETOOL` | Remotely lock an allowlisted Intune device after time-bound confirmation bound to that device and action. | | `replace_word_placeholders_in_office` | `DOCUMENTSTOOL` | Replace a literal placeholder throughout a paired, open Word document. | | `run_power_automate_desktop_flow` | `POWER_PLATFORMTOOL` | Run one allowlisted Power Automate desktop flow using its fixed Dataverse connection or connection reference. | | `run_power_automate_flow` | `POWER_PLATFORMTOOL` | Invoke one named, allowlisted, OAuth-protected Power Automate HTTP trigger. The caller cannot supply a trigger URL. | | `scan_intune_device_with_defender` | `INTUNETOOL` | Request a quick or full Microsoft Defender scan on an allowlisted Intune device with time-bound confirmation. | -| `shut_down_intune_device` | `INTUNETOOL` | Immediately shut down an allowlisted Intune device after destructive action acknowledgement and time-bound confirmation. | +| `shut_down_intune_device` | `INTUNETOOL` | Immediately shut down an allowlisted Intune device after time-bound confirmation. | | `submit_windows_action` | `WINDOWS_COMPANIONTOOL` | Submit one typed allowlisted laptop action through the authenticated outbound relay. Arbitrary shell, process, and URL execution are absent. | | `sync_intune_device` | `INTUNETOOL` | Request an Intune sync for an allowlisted device. Time-bound confirmation evidence bound to the action and device is required. | | `write_word_selection_in_office` | `DOCUMENTSTOOL` | Write bounded text at the selection in a paired, open Word task pane. | @@ -558,8 +557,8 @@ _79 action-routed tool(s) · 268 verbose 1:1 tool(s). Each is enabled unless its Every routed action passes the fail-closed tool policy. Reads are permitted by default; unknown actions are treated as writes. Writes require -`MICROSOFT_ALLOW_WRITES=true`, and destructive actions also require -`MICROSOFT_ALLOW_DESTRUCTIVE=true`. +`MICROSOFT_ALLOW_WRITES=true`, and destructive actions also need a live +confirmation (the gateway's approval or the `confirm` argument). ## MCP client configuration @@ -607,7 +606,6 @@ default; unknown actions are treated as writes. Writes require "KGTOOL": "true", "MAILTOOL": "true", "METATOOL": "true", - "MICROSOFT_ALLOW_DESTRUCTIVE": "false", "MICROSOFT_ALLOW_DEVICE_CODE": "false", "MICROSOFT_ALLOW_WRITES": "false", "MICROSOFT_AUTHORITY_HOST": "https://login.microsoftonline.com", @@ -692,7 +690,6 @@ own runtime secret boundary. "KGTOOL": "true", "MAILTOOL": "true", "METATOOL": "true", - "MICROSOFT_ALLOW_DESTRUCTIVE": "false", "MICROSOFT_ALLOW_DEVICE_CODE": "false", "MICROSOFT_ALLOW_WRITES": "false", "MICROSOFT_AUTHORITY_HOST": "https://login.microsoftonline.com", @@ -776,7 +773,6 @@ docker run -i --rm \ -e KGTOOL=true \ -e MAILTOOL=true \ -e METATOOL=true \ - -e MICROSOFT_ALLOW_DESTRUCTIVE=false \ -e MICROSOFT_ALLOW_DEVICE_CODE=false \ -e MICROSOFT_ALLOW_WRITES=false \ -e MICROSOFT_AUTHORITY_HOST=https://login.microsoftonline.com \ diff --git a/docs/authentication.md b/docs/authentication.md index 6356140..8e19900 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -103,12 +103,12 @@ server is currently allowed to invoke: ```text MICROSOFT_ALLOW_WRITES=false -MICROSOFT_ALLOW_DESTRUCTIVE=false ``` -Reads work with both flags disabled. Sends, creates, edits, uploads, flow runs, +Reads work with writes disabled. Sends, creates, edits, uploads, flow runs, and remote actions require writes. Deletes, wipes, retirements, immediate -reboots, shutdowns, and other destructive tools require both flags. Intune and +reboots, shutdowns, and other destructive tools require writes and also a live +confirmation (the gateway's approval or the `confirm` argument). Intune and Windows companion actions also enforce per-device/action allowlists and time-bound confirmation evidence inside their service layer. diff --git a/docs/integrations.md b/docs/integrations.md index a28c8fa..5a5f9ac 100644 --- a/docs/integrations.md +++ b/docs/integrations.md @@ -77,7 +77,8 @@ protected. Intune configuration requires at least one managed-device UUID and an explicit action allowlist. Every mutation requires evidence bound to the device, action, correlation ID, idempotency key, approver, reason, and a short expiration. Reboot -and shutdown also require destructive acknowledgement. +and shutdown also need a live confirmation (the gateway's approval or the +`confirm` argument). The service uses only Microsoft Graph v1.0. `rotateBitLockerKeys` is visible in the capability report as unsupported because Microsoft currently documents it diff --git a/docs/office-addin.md b/docs/office-addin.md index 4c6b084..d5e94ba 100644 --- a/docs/office-addin.md +++ b/docs/office-addin.md @@ -27,8 +27,8 @@ URLs, or an open-ended action name. 1. Start the MCP server over HTTPS and set `MICROSOFT_OFFICE_ADDIN_ORIGINS` to the task pane's exact HTTPS origin. -2. Enable `documents` and `MICROSOFT_ALLOW_WRITES`. Enable - `MICROSOFT_ALLOW_DESTRUCTIVE` only if the agent may delete slides. +2. Enable `documents` and `MICROSOFT_ALLOW_WRITES`. Deleting a slide also needs + a live confirmation (the gateway's approval or the `confirm` argument). 3. Ask the agent to call `create_office_pairing` with `Word` or `PowerPoint` and a recognizable window label. 4. Paste the returned one-time secret into **Agent pairing** in that intended diff --git a/docs/usage.md b/docs/usage.md index c81b0d9..b990a9f 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -23,8 +23,8 @@ The installed provider families cover: Every routed action crosses the fail-closed Microsoft tool policy. Read actions are available by default. Unknown actions are classified as writes. Non-destructive -writes require `MICROSOFT_ALLOW_WRITES=true`; destructive actions also -require `MICROSOFT_ALLOW_DESTRUCTIVE=true`. +writes require `MICROSOFT_ALLOW_WRITES=true`; destructive actions also need a live +confirmation (the gateway's approval or the `confirm` argument). `list_microsoft_ingestion_projection` returns only keyed opaque node identifiers, types, and relationships. Arbora validates the signed source manifest and diff --git a/mcp_config.json b/mcp_config.json index 7c33ff8..bc6790f 100644 --- a/mcp_config.json +++ b/mcp_config.json @@ -31,7 +31,6 @@ "KGTOOL": "true", "MAILTOOL": "true", "METATOOL": "true", - "MICROSOFT_ALLOW_DESTRUCTIVE": "false", "MICROSOFT_ALLOW_DEVICE_CODE": "false", "MICROSOFT_ALLOW_WRITES": "false", "MICROSOFT_AUTHORITY_HOST": "https://login.microsoftonline.com", diff --git a/microsoft_agent/api/api_client_admin.py b/microsoft_agent/api/api_client_admin.py index abc28cf..ff67a1a 100644 --- a/microsoft_agent/api/api_client_admin.py +++ b/microsoft_agent/api/api_client_admin.py @@ -1,5 +1,7 @@ from typing import Any +from scion_sdk.mcp.destructive import destructive_operation + from microsoft_agent.api._graph_models import ( graph_model_from_dict, ) @@ -137,6 +139,7 @@ async def get_organization( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def update_organization( self, org_id: str, data: dict[str, Any], params: dict | None = None ) -> dict[str, Any]: @@ -555,6 +558,7 @@ async def get_conditional_access_policy( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def create_conditional_access_policy( self, data: dict[str, Any], params: dict | None = None ) -> dict[str, Any]: @@ -582,6 +586,7 @@ async def create_conditional_access_policy( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def update_conditional_access_policy( self, policy_id: str, data: dict[str, Any], params: dict | None = None ) -> dict[str, Any]: @@ -919,6 +924,7 @@ async def get_role_assignment( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def create_role_assignment( self, data: dict[str, Any], params: dict | None = None ) -> dict[str, Any]: diff --git a/microsoft_agent/api/api_client_directory.py b/microsoft_agent/api/api_client_directory.py index 4ae74a3..4bc1919 100644 --- a/microsoft_agent/api/api_client_directory.py +++ b/microsoft_agent/api/api_client_directory.py @@ -1,6 +1,7 @@ from typing import Any from msgraph.generated.users.users_request_builder import UsersRequestBuilder +from scion_sdk.mcp.destructive import destructive_operation from microsoft_agent.api._graph_models import ( graph_model_from_dict, @@ -639,6 +640,7 @@ async def get_risky_user( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def dismiss_risky_user( self, user_id: str, params: dict | None = None ) -> dict[str, Any]: diff --git a/microsoft_agent/api/api_client_drive.py b/microsoft_agent/api/api_client_drive.py index b14e770..209940d 100644 --- a/microsoft_agent/api/api_client_drive.py +++ b/microsoft_agent/api/api_client_drive.py @@ -1,5 +1,7 @@ from typing import Any +from scion_sdk.mcp.destructive import destructive_operation + from microsoft_agent.api._graph_models import ( comma_separated_values, graph_model_from_dict, @@ -581,6 +583,7 @@ async def get_admin_sharepoint(self, params: dict | None = None) -> dict[str, An print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def update_admin_sharepoint( self, data: dict[str, Any], params: dict | None = None ) -> dict[str, Any]: diff --git a/microsoft_agent/api/api_client_other.py b/microsoft_agent/api/api_client_other.py index 8dc7627..5b36d47 100644 --- a/microsoft_agent/api/api_client_other.py +++ b/microsoft_agent/api/api_client_other.py @@ -5,6 +5,8 @@ if TYPE_CHECKING: from microsoft_agent.power_platform import AsyncHttpTransport +from scion_sdk.mcp.destructive import destructive_operation + from microsoft_agent.api._graph_models import ( decode_graph_base64, graph_model_from_dict, @@ -482,6 +484,7 @@ async def get_application( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def create_application( self, data: dict[str, Any], params: dict | None = None ) -> dict[str, Any]: @@ -553,6 +556,7 @@ async def delete_application( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def add_application_password( self, app_id: str, data: dict[str, Any], params: dict | None = None ) -> dict[str, Any]: @@ -657,6 +661,7 @@ async def get_service_principal( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def create_service_principal( self, data: dict[str, Any], params: dict | None = None ) -> dict[str, Any]: @@ -1069,6 +1074,7 @@ async def list_device_configurations( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def wipe_managed_device( self, device_id: str, params: dict | None = None ) -> dict[str, Any]: @@ -1094,6 +1100,7 @@ async def wipe_managed_device( print(f"Operation failed: {type(e).__name__}") return {"error": "Operation failed"} + @destructive_operation async def retire_managed_device( self, device_id: str, params: dict | None = None ) -> dict[str, Any]: diff --git a/microsoft_agent/config_cli.py b/microsoft_agent/config_cli.py index 28548d5..c93c0ef 100644 --- a/microsoft_agent/config_cli.py +++ b/microsoft_agent/config_cli.py @@ -39,7 +39,6 @@ def configuration_report() -> dict[str, Any]: }, "policy": { "writes_enabled": settings.allow_write_tools, - "destructive_enabled": settings.allow_destructive_tools, "enabled_tool_groups": list(settings.enabled_tool_groups), }, "documents": get_document_capabilities().model_dump(mode="json"), diff --git a/microsoft_agent/connector_contracts.py b/microsoft_agent/connector_contracts.py index d154cb0..cb0d769 100644 --- a/microsoft_agent/connector_contracts.py +++ b/microsoft_agent/connector_contracts.py @@ -70,7 +70,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -133,7 +133,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -226,7 +226,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -289,7 +289,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -330,7 +330,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -542,7 +542,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -753,7 +753,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -994,7 +994,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1057,7 +1057,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1087,7 +1087,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1150,7 +1150,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1247,7 +1247,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1377,7 +1377,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1440,7 +1440,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1481,7 +1481,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1680,7 +1680,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1731,7 +1731,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1794,7 +1794,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1846,7 +1846,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -1938,7 +1938,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -2294,7 +2294,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -2431,7 +2431,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), @@ -3543,7 +3543,7 @@ refusals=( Refusal( code="FORBIDDEN", - when="destructive calls are disabled (MICROSOFT_ALLOW_DESTRUCTIVE is off) or approval is missing", + when="the destructive call is not confirmed (no gateway approval and no confirm argument)", ), Refusal(code="NOT_FOUND", when="the target record does not exist"), ), diff --git a/microsoft_agent/integration_tools.py b/microsoft_agent/integration_tools.py index 62e3425..b47fc1f 100644 --- a/microsoft_agent/integration_tools.py +++ b/microsoft_agent/integration_tools.py @@ -7,9 +7,10 @@ from urllib.parse import urlparse from uuid import UUID -from fastmcp import FastMCP +from fastmcp import Context, FastMCP from pydantic import Field from scion_sdk.http.retry import RetryPolicy +from scion_sdk.mcp.destructive import guard_destructive from microsoft_agent.document_service import ( ArtifactDelivery, @@ -630,9 +631,19 @@ async def get_power_automate_desktop_flow_outputs( ) async def cancel_power_automate_desktop_flow_run( flow_session_id: UUID, + confirm: bool = False, + ctx: Context | None = None, ) -> dict[str, Any]: """Cancel a desktop-flow session under both global and integration policy.""" + refused = await guard_destructive( + ctx, + "cancel_power_automate_desktop_flow_run", + {"flow_session_id": str(flow_session_id)}, + confirm=confirm is True, + ) + if refused is not None: + return refused result = await _power_platform_client().cancel_desktop_flow_run(flow_session_id) return result.model_dump(mode="json") @@ -705,13 +716,15 @@ async def get_windows_device_health(device_alias: str) -> dict[str, Any]: "outbound relay. Arbitrary shell, process, and URL execution are absent." ), tags={"windows", "devices"}, - annotations={"readOnlyHint": False, "destructiveHint": False}, + annotations={"readOnlyHint": False, "destructiveHint": True}, ) async def submit_windows_action( device_alias: str, companion_action: CompanionAction, confirmation: ConfirmationEvidence | None = None, idempotency_key: str | None = None, + confirm: bool = False, + ctx: Context | None = None, ) -> dict[str, Any]: """Validate device/action policy and enqueue an expiring action request.""" @@ -722,10 +735,15 @@ async def submit_windows_action( action_policy = integration_settings.action_policies.get(kind) if action_policy is None: raise ValueError("Windows action has no configured policy.") - if action_policy.destructive and not get_settings().allow_destructive_tools: - raise ValueError( - "This Windows action requires MICROSOFT_ALLOW_DESTRUCTIVE=true." + if action_policy.destructive: + refused = await guard_destructive( + ctx, + f"windows action {kind.value}", + {"device_alias": device_alias, "action": kind.value}, + confirm=confirm is True, ) + if refused is not None: + return refused values: dict[str, Any] = { "action": companion_action, "confirmation": confirmation, @@ -849,17 +867,28 @@ async def sync_intune_device( @mcp.tool( name="reboot_intune_device", description=( - "Immediately reboot an allowlisted Intune device after destructive " - "action acknowledgement and time-bound confirmation." + "Immediately reboot an allowlisted Intune device after " + "time-bound confirmation." ), tags={"intune", "devices"}, annotations={"readOnlyHint": False, "destructiveHint": True}, ) async def reboot_intune_device( - device_id: UUID, confirmation: IntuneConfirmationEvidence + device_id: UUID, + confirmation: IntuneConfirmationEvidence, + confirm: bool = False, + ctx: Context | None = None, ) -> dict[str, Any]: - """Submit a confirmed and explicitly acknowledged rebootNow action.""" + """Submit a confirmed rebootNow action.""" + refused = await guard_destructive( + ctx, + "reboot_intune_device", + {"device_id": str(device_id)}, + confirm=confirm is True, + ) + if refused is not None: + return refused result = await _intune_service().reboot_now( device_id, confirmation=confirmation ) @@ -887,17 +916,28 @@ async def remote_lock_intune_device( @mcp.tool( name="shut_down_intune_device", description=( - "Immediately shut down an allowlisted Intune device after destructive " - "action acknowledgement and time-bound confirmation." + "Immediately shut down an allowlisted Intune device after " + "time-bound confirmation." ), tags={"intune", "devices"}, annotations={"readOnlyHint": False, "destructiveHint": True}, ) async def shut_down_intune_device( - device_id: UUID, confirmation: IntuneConfirmationEvidence + device_id: UUID, + confirmation: IntuneConfirmationEvidence, + confirm: bool = False, + ctx: Context | None = None, ) -> dict[str, Any]: - """Submit a confirmed and explicitly acknowledged shutDown action.""" + """Submit a confirmed shutDown action.""" + refused = await guard_destructive( + ctx, + "shut_down_intune_device", + {"device_id": str(device_id)}, + confirm=confirm is True, + ) + if refused is not None: + return refused result = await _intune_service().shut_down(device_id, confirmation=confirmation) return result.model_dump(mode="json") diff --git a/microsoft_agent/intune_service.py b/microsoft_agent/intune_service.py index 9a8d934..e8be421 100644 --- a/microsoft_agent/intune_service.py +++ b/microsoft_agent/intune_service.py @@ -153,7 +153,6 @@ class ConfirmationEvidence(BaseModel): expires_at: AwareDatetime idempotency_key: UUID correlation_id: UUID - destructive_action_acknowledged: bool = False @model_validator(mode="after") def validate_time_order(self) -> ConfirmationEvidence: @@ -678,11 +677,6 @@ def _validate_confirmation( seconds=self.settings.max_confirmation_lifetime_seconds ): message = "Confirmation evidence lifetime exceeds policy" - elif ( - capability.destructive - and not confirmation.destructive_action_acknowledged - ): - message = "The destructive action was not explicitly acknowledged" if message: raise ConfirmationError( IntuneError( diff --git a/microsoft_agent/mcp_config.json b/microsoft_agent/mcp_config.json index 7c33ff8..bc6790f 100644 --- a/microsoft_agent/mcp_config.json +++ b/microsoft_agent/mcp_config.json @@ -31,7 +31,6 @@ "KGTOOL": "true", "MAILTOOL": "true", "METATOOL": "true", - "MICROSOFT_ALLOW_DESTRUCTIVE": "false", "MICROSOFT_ALLOW_DEVICE_CODE": "false", "MICROSOFT_ALLOW_WRITES": "false", "MICROSOFT_AUTHORITY_HOST": "https://login.microsoftonline.com", diff --git a/microsoft_agent/office_bridge.py b/microsoft_agent/office_bridge.py index 6b7cfed..a190327 100644 --- a/microsoft_agent/office_bridge.py +++ b/microsoft_agent/office_bridge.py @@ -26,7 +26,7 @@ from typing import Annotated, Any, Literal from uuid import UUID, uuid4 -from fastmcp import FastMCP +from fastmcp import Context, FastMCP from pydantic import ( BaseModel, ConfigDict, @@ -37,6 +37,7 @@ field_validator, model_validator, ) +from scion_sdk.mcp.destructive import guard_destructive from starlette.requests import Request from starlette.responses import JSONResponse, Response @@ -1095,9 +1096,19 @@ async def delete_powerpoint_slide( session_id: UUID, slide_number: int = Field(ge=1, le=10_000), wait_timeout_seconds: float = Field(default=20, ge=0, le=55), + confirm: bool = False, + ctx: Context | None = None, ) -> dict[str, Any]: """Enqueue a policy-classified destructive PowerPoint slide deletion.""" + refused = await guard_destructive( + ctx, + "delete_powerpoint_slide_in_office", + {"session_id": str(session_id), "slide_number": slide_number}, + confirm=confirm is True, + ) + if refused is not None: + return refused return await _dispatch_and_wait( bridge, session_id, diff --git a/microsoft_agent/settings.py b/microsoft_agent/settings.py index 7ca92b2..f5abbb5 100644 --- a/microsoft_agent/settings.py +++ b/microsoft_agent/settings.py @@ -209,7 +209,6 @@ class MicrosoftSettings(BaseModel): require_secure_cache: bool = True enabled_tool_groups: tuple[str, ...] = DEFAULT_TOOL_GROUPS allow_write_tools: bool = False - allow_destructive_tools: bool = False graph_base_url: str = "https://graph.microsoft.com/v1.0" graph_tls_profile: str | None = None graph_tls_profile_ref: str | None = None @@ -464,9 +463,6 @@ def from_env(cls, env: Mapping[str, str] | None = None) -> MicrosoftSettings: ), enabled_tool_groups=groups or DEFAULT_TOOL_GROUPS, allow_write_tools=_configured_bool(env, "MICROSOFT_ALLOW_WRITES", False), - allow_destructive_tools=_configured_bool( - env, "MICROSOFT_ALLOW_DESTRUCTIVE", False - ), graph_base_url=_configured_value( env, "MICROSOFT_GRAPH_BASE_URL", "https://graph.microsoft.com/v1.0" ), diff --git a/microsoft_agent/skills/microsoft-calendar-scheduling/SKILL.md b/microsoft_agent/skills/microsoft-calendar-scheduling/SKILL.md index e6923c5..f22416a 100644 --- a/microsoft_agent/skills/microsoft-calendar-scheduling/SKILL.md +++ b/microsoft_agent/skills/microsoft-calendar-scheduling/SKILL.md @@ -28,7 +28,7 @@ Typed calendar operations including the calendar view, specific-calendar events, - Contacts: use microsoft-contacts. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (23) diff --git a/microsoft_agent/skills/microsoft-contacts/SKILL.md b/microsoft_agent/skills/microsoft-contacts/SKILL.md index 03a07be..a2904e5 100644 --- a/microsoft_agent/skills/microsoft-contacts/SKILL.md +++ b/microsoft_agent/skills/microsoft-contacts/SKILL.md @@ -23,7 +23,7 @@ Personal contacts only; tenant users live in the directory. - Tenant users and groups: use microsoft-identity-directory. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (5) diff --git a/microsoft_agent/skills/microsoft-document-authoring/SKILL.md b/microsoft_agent/skills/microsoft-document-authoring/SKILL.md index 562c786..c120c27 100644 --- a/microsoft_agent/skills/microsoft-document-authoring/SKILL.md +++ b/microsoft_agent/skills/microsoft-document-authoring/SKILL.md @@ -25,7 +25,7 @@ Document generation and Office add-in bridge operations. - Excel: use microsoft-office-apps. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (15) diff --git a/microsoft_agent/skills/microsoft-education-booking/SKILL.md b/microsoft_agent/skills/microsoft-education-booking/SKILL.md index af515c2..b094076 100644 --- a/microsoft_agent/skills/microsoft-education-booking/SKILL.md +++ b/microsoft_agent/skills/microsoft-education-booking/SKILL.md @@ -24,7 +24,7 @@ Specialist workloads of Microsoft Graph. - Tenant users and groups: use microsoft-identity-directory. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (13) diff --git a/microsoft_agent/skills/microsoft-endpoint-management/SKILL.md b/microsoft_agent/skills/microsoft-endpoint-management/SKILL.md index 8dae45c..58a798b 100644 --- a/microsoft_agent/skills/microsoft-endpoint-management/SKILL.md +++ b/microsoft_agent/skills/microsoft-endpoint-management/SKILL.md @@ -26,7 +26,7 @@ Remote actions affect real devices and are destructive-tier: they need allowlist - Directory device objects: use microsoft-identity-directory. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (19) diff --git a/microsoft_agent/skills/microsoft-files-sharepoint/SKILL.md b/microsoft_agent/skills/microsoft-files-sharepoint/SKILL.md index 73ad086..9e771d5 100644 --- a/microsoft_agent/skills/microsoft-files-sharepoint/SKILL.md +++ b/microsoft_agent/skills/microsoft-files-sharepoint/SKILL.md @@ -27,7 +27,7 @@ Typed drive and site operations. Download returns file content; upload writes it - Spreadsheet or notebook content: use microsoft-office-apps. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (26) diff --git a/microsoft_agent/skills/microsoft-graph-integration/SKILL.md b/microsoft_agent/skills/microsoft-graph-integration/SKILL.md index e6b1c94..2a4b639 100644 --- a/microsoft_agent/skills/microsoft-graph-integration/SKILL.md +++ b/microsoft_agent/skills/microsoft-graph-integration/SKILL.md @@ -27,7 +27,7 @@ Integration operations. The ingestion projection returns keyed opaque nodes only - Reading item content: use the domain skills. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (11) diff --git a/microsoft_agent/skills/microsoft-identity-directory/SKILL.md b/microsoft_agent/skills/microsoft-identity-directory/SKILL.md index 2df29a2..41fcab7 100644 --- a/microsoft_agent/skills/microsoft-identity-directory/SKILL.md +++ b/microsoft_agent/skills/microsoft-identity-directory/SKILL.md @@ -30,7 +30,7 @@ Typed directory operations. Role assignments, conditional access and application - Managed devices: use microsoft-endpoint-management. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (73) diff --git a/microsoft_agent/skills/microsoft-mail-operations/SKILL.md b/microsoft_agent/skills/microsoft-mail-operations/SKILL.md index ec5a23c..989b03e 100644 --- a/microsoft_agent/skills/microsoft-mail-operations/SKILL.md +++ b/microsoft_agent/skills/microsoft-mail-operations/SKILL.md @@ -29,7 +29,7 @@ Typed mail operations over `/me/messages`, `/me/mailFolders` and shared mailboxe - Teams chat and channel posts: use microsoft-teams-messaging. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (19) diff --git a/microsoft_agent/skills/microsoft-office-apps/SKILL.md b/microsoft_agent/skills/microsoft-office-apps/SKILL.md index 5109700..6dfdb1f 100644 --- a/microsoft_agent/skills/microsoft-office-apps/SKILL.md +++ b/microsoft_agent/skills/microsoft-office-apps/SKILL.md @@ -26,7 +26,7 @@ Typed operations over workbook ranges and tables, notebook pages, plan tasks and - Word and PowerPoint documents: use microsoft-document-authoring. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (26) diff --git a/microsoft_agent/skills/microsoft-power-platform/SKILL.md b/microsoft_agent/skills/microsoft-power-platform/SKILL.md index 4d6742c..9f46989 100644 --- a/microsoft_agent/skills/microsoft-power-platform/SKILL.md +++ b/microsoft_agent/skills/microsoft-power-platform/SKILL.md @@ -25,7 +25,7 @@ Running a flow executes real automation: confirm inputs and approval first. - Device actions: use microsoft-endpoint-management. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (12) diff --git a/microsoft_agent/skills/microsoft-security-operations/SKILL.md b/microsoft_agent/skills/microsoft-security-operations/SKILL.md index 7fac03c..9bd620f 100644 --- a/microsoft_agent/skills/microsoft-security-operations/SKILL.md +++ b/microsoft_agent/skills/microsoft-security-operations/SKILL.md @@ -27,7 +27,7 @@ Typed security operations. Updating an alert or incident changes its state: reco - Changing roles or policies: use microsoft-identity-directory. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (24) diff --git a/microsoft_agent/skills/microsoft-service-reports/SKILL.md b/microsoft_agent/skills/microsoft-service-reports/SKILL.md index 1dd483e..98df05b 100644 --- a/microsoft_agent/skills/microsoft-service-reports/SKILL.md +++ b/microsoft_agent/skills/microsoft-service-reports/SKILL.md @@ -25,7 +25,7 @@ Read-only reporting operations. - Security events: use microsoft-security-operations. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (7) diff --git a/microsoft_agent/skills/microsoft-session-management/SKILL.md b/microsoft_agent/skills/microsoft-session-management/SKILL.md index b85badd..42b03e0 100644 --- a/microsoft_agent/skills/microsoft-session-management/SKILL.md +++ b/microsoft_agent/skills/microsoft-session-management/SKILL.md @@ -25,7 +25,7 @@ Interactive and service sign-in for the Microsoft Graph connector. Always verify - Reading mail, calendar, files or directory data: use the domain skills. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (7) diff --git a/microsoft_agent/skills/microsoft-teams-messaging/SKILL.md b/microsoft_agent/skills/microsoft-teams-messaging/SKILL.md index d6968e0..71339c1 100644 --- a/microsoft_agent/skills/microsoft-teams-messaging/SKILL.md +++ b/microsoft_agent/skills/microsoft-teams-messaging/SKILL.md @@ -28,7 +28,7 @@ Typed Teams operations. Posting a message is a visible side effect: confirm the - Mail: use microsoft-mail-operations. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (23) diff --git a/microsoft_agent/skills/microsoft-universal-print/SKILL.md b/microsoft_agent/skills/microsoft-universal-print/SKILL.md index 6a2f0cf..00f5b71 100644 --- a/microsoft_agent/skills/microsoft-universal-print/SKILL.md +++ b/microsoft_agent/skills/microsoft-universal-print/SKILL.md @@ -23,7 +23,7 @@ Printing creates a job on a real printer: confirm the printer and document. - Document storage: use microsoft-files-sharepoint. ## Safety -- Writes need MICROSOFT_ALLOW_WRITES and destructive tools also need MICROSOFT_ALLOW_DESTRUCTIVE; the server refuses them otherwise. +- Writes need MICROSOFT_ALLOW_WRITES; a destructive tool also needs a live confirmation (the gateway's approval or the `confirm` argument), and the server refuses it otherwise. - Treat all provider content as sensitive: select the fewest fields, bound result sizes, never echo tokens or credentials. ## Tools (8) diff --git a/microsoft_agent/tool_policy.py b/microsoft_agent/tool_policy.py index da71cd4..c8e2d9a 100644 --- a/microsoft_agent/tool_policy.py +++ b/microsoft_agent/tool_policy.py @@ -109,7 +109,7 @@ class ToolPolicyDecision(BaseModel): class MicrosoftToolPolicy: - """Authorize tools using explicit deployment-level side-effect flags.""" + """Authorize tools by deployment access scope; destructive calls also ask the SDK guard.""" def __init__(self, settings: MicrosoftSettings | None = None): self.settings = settings or get_settings() @@ -132,17 +132,12 @@ def evaluate(self, tool_name: str) -> ToolPolicyDecision: allowed=False, reason="MICROSOFT_ALLOW_WRITES is disabled", ) - if risk is ToolRisk.DESTRUCTIVE and not ( - self.settings.allow_write_tools and self.settings.allow_destructive_tools - ): + if risk is ToolRisk.DESTRUCTIVE and not self.settings.allow_write_tools: return ToolPolicyDecision( tool_name=tool_name, risk=risk, allowed=False, - reason=( - "destructive operations require both MICROSOFT_ALLOW_WRITES " - "and MICROSOFT_ALLOW_DESTRUCTIVE" - ), + reason="MICROSOFT_ALLOW_WRITES is disabled", ) return ToolPolicyDecision( tool_name=tool_name, diff --git a/pyproject.toml b/pyproject.toml index cf88944..c85c49a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python :: 3", ] -dependencies = [ "scion-sdk[mcp]>=0.10.1,<1.0.0", "azure-core>=1.41.0", "httpx>=0.28.1", "keyring>=25.7.0", "msal>=1.39.0", "msgraph-sdk>=1.64.0", "pydantic>=2.14.1",] +dependencies = [ "scion-sdk[mcp]>=0.10.2,<0.11", "azure-core>=1.41.0", "httpx>=0.28.1", "keyring>=25.7.0", "msal>=1.39.0", "msgraph-sdk>=1.64.0", "pydantic>=2.14.1",] license = "MIT" [[project.authors]] @@ -22,7 +22,7 @@ name = "Repository Maintainers" email = "maintainers@knuckles.team" [project.optional-dependencies] -mcp = [ "scion-sdk[mcp]>=0.10.1,<1.0.0",] +mcp = [ "scion-sdk[mcp]>=0.10.2,<0.11",] documents = ["python-docx>=1.2.0", "python-pptx>=1.0.2"] cloud = ["azure-identity>=1.26.0", "httpx>=0.28.1"] windows = [ diff --git a/specs/connector-content/requirements.md b/specs/connector-content/requirements.md index 91922e2..98e2759 100644 --- a/specs/connector-content/requirements.md +++ b/specs/connector-content/requirements.md @@ -7,3 +7,4 @@ Each row is one requirement. A row names the file it touches and the test that p | ID | Requirement | Acceptance | |---|---|---| | `CONN-MICROSOFT-AGENT-CONNECTOR-CONTENT-R001` | **Default content.** `pyproject.toml` declares `microsoft-mcp` as the single `scion_sdk.connector` entry point. The server lists the packaged `skill://` and `ontology://` resources and the packaged prompts with no `content=` argument. Caller chain: `microsoft-mcp` in `pyproject.toml` runs `microsoft_agent.mcp_server:mcp_server`, which builds the server from the `scion_sdk.connector` entry point `microsoft_agent:connector` (`microsoft_agent/__init__.py:19`); the SDK `Connector` then lists the packaged skills, ontology and prompts. Shape: `pyproject.toml` entry point `microsoft-mcp` plus the `connector = Connector(.)` object in `microsoft_agent/__init__.py`; the packaged `skills/`, `ontology/` and `prompts/` directories of `microsoft_agent` are reused as is, with no connector-local registration code. Proving test: `tests/test_default_content_surfaces.py::test_default_content_surfaces`. | `resources/list` includes `skill://` and `ontology://`; `prompts/list` includes each packaged prompt. | +| `CONN-MICROSOFT-AGENT-CONNECTOR-CONTENT-R002` | **Destructive operations use the SDK's one declaration and guard.** Every destructive operation (deletes, removals, wipes, retirements, application passwords, service principals, role assignments, conditional access, organization and admin SharePoint updates, risky-user dismissal, immediate Intune reboot and shutdown, desktop-flow cancellation, PowerPoint slide deletion, and destructive Windows companion actions) is declared with the SDK (`destructive_operation` on the Graph client methods, `guard_destructive` in the hand-written tools; `SCION-CONNECTOR-CONTROL-R930`, provider). Each served tool carries the MCP `destructiveHint` and the standard `confirm` argument, and a call without a live confirmation, `confirm`, or the operator setting `SCION_ALLOW_DESTRUCTIVE` makes no request. The connector defines no `MICROSOFT_ALLOW_DESTRUCTIVE` setting and no acknowledgement field in the Intune confirmation evidence; the gateway decides approval (`ARBORA-FLEET-R015.6`, consumer). `MICROSOFT_ALLOW_WRITES` stays as deployment access scope. Caller chain: `microsoft-mcp` runs `scion_sdk.cli:serve` to `microsoft_agent/mcp_server.py`, which serves the Graph client methods through `register_tool_surface` and the hand-written tools of `integration_tools.py` and `office_bridge.py`. Shape: `@destructive_operation` on eleven methods in `microsoft_agent/api/`; `guard_destructive` in five hand-written tools; `tool_policy.py` keeps only the access-scope tier. Proving test: `tests/test_destructive_declaration.py::test_destructive_tools_are_declared_and_take_confirm`. | diff --git a/specs/connector-content/tasks.md b/specs/connector-content/tasks.md index db69207..4ba69bd 100644 --- a/specs/connector-content/tasks.md +++ b/specs/connector-content/tasks.md @@ -5,3 +5,4 @@ Governing spec: [spec.md](spec.md). Design: [plan.md](plan.md). Rows: [requireme Each task line reads `- [ ] T001 [P] [US1] -R012.4 description`. Tasks run producer first; a checked task has landed. - [x] T001 [US1] CONN-MICROSOFT-AGENT-CONNECTOR-CONTENT-R001 Default content. +- [ ] T002 [US1] CONN-MICROSOFT-AGENT-CONNECTOR-CONTENT-R002 Destructive operations use the SDK's one declaration and guard diff --git a/specs/connector-content/test-spec.md b/specs/connector-content/test-spec.md index 4ad88b0..25a637a 100644 --- a/specs/connector-content/test-spec.md +++ b/specs/connector-content/test-spec.md @@ -5,6 +5,7 @@ Governing spec: [spec.md](spec.md). | Test ID | Requirement | Proving test | Expected observation | |---|---|---|---| | T-001 | `CONN-MICROSOFT-AGENT-CONNECTOR-CONTENT-R001` | `tests/test_default_content_surfaces.py::test_default_content_surfaces` | `resources/list` includes `skill://` and `ontology://`; `prompts/list` includes each packaged prompt. | +| T-002 | `CONN-MICROSOFT-AGENT-CONNECTOR-CONTENT-R002` | `tests/test_destructive_declaration.py::test_destructive_tools_are_declared_and_take_confirm` | Each destructive tool is served with `destructiveHint` true and a `confirm` argument, none has an allow argument, and a hand-written destructive tool refuses without confirmation and sends no request. | ## Negative and boundary cases diff --git a/tests/test_destructive_declaration.py b/tests/test_destructive_declaration.py new file mode 100644 index 0000000..eb762a5 --- /dev/null +++ b/tests/test_destructive_declaration.py @@ -0,0 +1,83 @@ +"""Destructive operations are declared with the SDK and ask before they run.""" + +from __future__ import annotations + +import pytest + +from microsoft_agent.mcp_server import get_mcp_instance +from microsoft_agent.tool_policy import ToolRisk, classify_tool_risk + +DECLARED_GRAPH = ( + "add_application_password create_application create_conditional_access_policy " + "create_role_assignment create_service_principal dismiss_risky_user " + "retire_managed_device update_admin_sharepoint update_conditional_access_policy " + "update_organization wipe_managed_device" +).split() +HAND_WRITTEN = ( + "delete_powerpoint_slide_in_office", + "cancel_power_automate_desktop_flow_run", + "reboot_intune_device", + "shut_down_intune_device", + "submit_windows_action", +) + + +async def _tools(monkeypatch): + monkeypatch.setenv("MICROSOFT_ALLOW_WRITES", "true") + monkeypatch.setattr("sys.argv", ["microsoft-mcp"]) + server = [x for x in get_mcp_instance() if hasattr(x, "list_tools")][0] + return server, {tool.name: tool for tool in await server.list_tools()} + + +@pytest.mark.asyncio +async def test_destructive_tools_are_declared_and_take_confirm(monkeypatch): + _, tools = await _tools(monkeypatch) + names = [f"microsoft_{name}" for name in DECLARED_GRAPH] + [ + name + for name in tools + if classify_tool_risk(name) is ToolRisk.DESTRUCTIVE + and name.removeprefix("microsoft_").split("_", 1)[0] + in {"delete", "remove", "wipe", "retire", "cancel"} + ] + names += [name for name in HAND_WRITTEN if name in tools] + assert names + for name in names: + assert name in tools, name + properties = tools[name].parameters["properties"] + assert tools[name].annotations.destructive_hint is True, name + assert "confirm" in properties, name + assert not [key for key in properties if key.startswith("allow_")], name + + +def test_connector_defines_no_destructive_setting(): + from microsoft_agent.settings import MicrosoftSettings + + assert not hasattr(MicrosoftSettings(), "allow_destructive_tools") + assert "destructive_action_acknowledged" not in _evidence_fields() + + +def _evidence_fields(): + from microsoft_agent.intune_service import ConfirmationEvidence + + return ConfirmationEvidence.model_fields + + +@pytest.mark.asyncio +async def test_hand_written_tool_refuses_without_confirmation(monkeypatch): + server, tools = await _tools(monkeypatch) + called = [] + + async def refuse(ctx, operation, arguments=None, *, confirm=False): + called.append((operation, confirm)) + return {"cancelled": True, "operation": operation} + + monkeypatch.setattr("microsoft_agent.office_bridge.guard_destructive", refuse) + tool = await server.get_tool("delete_powerpoint_slide_in_office") + result = await tool.fn( + session_id="00000000-0000-4000-8000-000000000000", slide_number=1 + ) + assert result == { + "cancelled": True, + "operation": "delete_powerpoint_slide_in_office", + } + assert called == [("delete_powerpoint_slide_in_office", False)] diff --git a/tests/test_intune_service.py b/tests/test_intune_service.py index 5d9b89b..af49067 100644 --- a/tests/test_intune_service.py +++ b/tests/test_intune_service.py @@ -96,7 +96,6 @@ def confirmation( correlation_id: UUID = UUID("55555555-5555-4555-8555-555555555555"), confirmed_at: datetime = NOW - timedelta(minutes=1), expires_at: datetime = NOW + timedelta(minutes=4), - destructive_acknowledged: bool = False, ) -> ConfirmationEvidence: return ConfirmationEvidence( confirmation_id=UUID("66666666-6666-4666-8666-666666666666"), @@ -109,7 +108,6 @@ def confirmation( expires_at=expires_at, idempotency_key=idempotency_key, correlation_id=correlation_id, - destructive_action_acknowledged=destructive_acknowledged, ) @@ -268,7 +266,7 @@ async def test_documented_actions_use_fixed_paths_and_audit_headers( ) -> None: http = FakeHttpClient(FakeResponse(204, headers={"request-id": "graph-id"})) client = service(http) - evidence = confirmation(action, destructive_acknowledged=destructive) + evidence = confirmation(action) method = getattr(client, method_name) if action == DeviceAction.WINDOWS_DEFENDER_SCAN: @@ -332,18 +330,6 @@ async def test_actions_require_allowlists_and_bound_fresh_confirmation() -> None assert denied_http.calls == [] -@pytest.mark.asyncio -async def test_destructive_actions_require_separate_acknowledgement() -> None: - client = service(FakeHttpClient()) - - with pytest.raises(ConfirmationError) as exc_info: - await client.reboot_now( - DEVICE_ID, confirmation=confirmation(DeviceAction.REBOOT_NOW) - ) - - assert "not explicitly acknowledged" in exc_info.value.error.message - - @pytest.mark.asyncio async def test_idempotency_replays_same_action_and_rejects_key_reuse() -> None: http = FakeHttpClient(FakeResponse(204)) @@ -378,10 +364,7 @@ async def test_rotate_bitlocker_keys_is_stably_unsupported_and_never_calls_beta( with pytest.raises(UnsupportedCapabilityError) as exc_info: await client.rotate_bitlocker_keys( DEVICE_ID, - confirmation=confirmation( - DeviceAction.ROTATE_BITLOCKER_KEYS, - destructive_acknowledged=True, - ), + confirmation=confirmation(DeviceAction.ROTATE_BITLOCKER_KEYS), ) assert exc_info.value.error.code == IntuneErrorCode.CAPABILITY_UNSUPPORTED diff --git a/tests/test_settings_and_policy.py b/tests/test_settings_and_policy.py index d1b2f47..b062d00 100644 --- a/tests/test_settings_and_policy.py +++ b/tests/test_settings_and_policy.py @@ -191,16 +191,11 @@ def test_policy_separates_writes_and_destructive_actions(): write_settings = MicrosoftSettings(allow_write_tools=True) write_policy = MicrosoftToolPolicy(write_settings) assert write_policy.require("send_mail").allowed is True - with pytest.raises(ToolError, match="MICROSOFT_ALLOW_DESTRUCTIVE"): - write_policy.require("delete_mail_message") - - destructive_policy = MicrosoftToolPolicy( - MicrosoftSettings( - allow_write_tools=True, - allow_destructive_tools=True, - ) - ) - assert destructive_policy.require("delete_mail_message").allowed is True + assert write_policy.require("delete_mail_message").allowed is True + read_only = MicrosoftToolPolicy(MicrosoftSettings()) + with pytest.raises(ToolError, match="MICROSOFT_ALLOW_WRITES"): + read_only.require("delete_mail_message") + assert not hasattr(MicrosoftSettings(), "allow_destructive_tools") def test_served_tool_prefix_does_not_hide_a_read_verb(): diff --git a/uv.lock b/uv.lock index fb2d2e7..b84c2a1 100644 --- a/uv.lock +++ b/uv.lock @@ -1915,8 +1915,8 @@ requires-dist = [ { name = "pywin32", marker = "sys_platform == 'win32' and extra == 'all'", specifier = ">=312" }, { name = "pywin32", marker = "sys_platform == 'win32' and extra == 'windows'", specifier = ">=312" }, { name = "pyyaml", marker = "extra == 'test'", specifier = ">=6.0.3" }, - { name = "scion-sdk", extras = ["mcp"], specifier = ">=0.10.1,<1.0.0" }, - { name = "scion-sdk", extras = ["mcp"], marker = "extra == 'mcp'", specifier = ">=0.10.1,<1.0.0" }, + { name = "scion-sdk", extras = ["mcp"], specifier = ">=0.10.2,<0.11" }, + { name = "scion-sdk", extras = ["mcp"], marker = "extra == 'mcp'", specifier = ">=0.10.2,<0.11" }, { name = "uvicorn", marker = "extra == 'all'", specifier = ">=0.54.0" }, { name = "uvicorn", marker = "extra == 'control-plane'", specifier = ">=0.54.0" }, { name = "win10toast", marker = "sys_platform == 'win32' and extra == 'all'", specifier = ">=0.9" }, @@ -3425,7 +3425,7 @@ wheels = [ [[package]] name = "scion-sdk" -version = "0.10.1" +version = "0.10.2" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "anyio" }, @@ -3438,9 +3438,9 @@ dependencies = [ { name = "pydantic" }, { name = "pyyaml" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/a4/af/d9eb8f54d69fceb786519fe97f0e86465d7b06023a928dfe9f24976b2907/scion_sdk-0.10.1.tar.gz", hash = "sha256:72e51d440fd55e660ce537df436dde140724b79f96efef488d3df444471e0e1f", size = 1258898, upload-time = "2026-11-08T00:13:11.273Z" } +sdist = { url = "https://files.pythonhosted.org/packages/6f/a5/049d408593ba40ce2a7074ddd4a8e5bb2972656fa1501710ddeffca3ecec/scion_sdk-0.10.2.tar.gz", hash = "sha256:424a8dc0bb5f0a749bbb34113db9688a83b466e350e0869b3725020842f2420a", size = 1264088, upload-time = "2026-11-12T18:47:04.271Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/88/66/b46a5b67e4df01701a8e37940a593ffdca61c240ac6c10c45d39c2b3e65b/scion_sdk-0.10.1-py3-none-any.whl", hash = "sha256:8887292948874cdc634aeb58b421ef6a5eee1a0a62c5a3c716dba89f2d1b0120", size = 1219348, upload-time = "2026-11-08T00:13:08.397Z" }, + { url = "https://files.pythonhosted.org/packages/78/5b/9f74bd390a9dca2cb3720687ed15adecc498adb79cb802384d037fd5f431/scion_sdk-0.10.2-py3-none-any.whl", hash = "sha256:c6a4bb77ca348e08ab642a1ef66fd5134292feb0ae0c4a58a97c97bf3d412a7b", size = 1221399, upload-time = "2026-11-12T18:47:00.635Z" }, ] [package.optional-dependencies] From bec0128bfd86152a79facffaffbf33b78b154de1 Mon Sep 17 00:00:00 2001 From: Audel Rouhi Date: Thu, 12 Nov 2026 13:58:37 -0600 Subject: [PATCH 2/2] fix(ontology): roll the Microsoft classes up to core classes Message and Event now extend core DomainEntity and File extends core Artifact so the connector-surface ontology check passes. Spec: none (class roll-up to the core ontology; no new requirement) Co-Authored-By: Claude Sonnet 5.5 --- microsoft_agent/ontology/microsoft.ttl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/microsoft_agent/ontology/microsoft.ttl b/microsoft_agent/ontology/microsoft.ttl index 48ff193..6700397 100644 --- a/microsoft_agent/ontology/microsoft.ttl +++ b/microsoft_agent/ontology/microsoft.ttl @@ -1,4 +1,5 @@ @prefix : . +@prefix core: . @prefix owl: . @prefix rdfs: . @@ -6,13 +7,16 @@ # identifiers. Provider identifiers, names, addresses, content, filenames, URLs, # timestamps, and attachment bytes are not properties in this ontology. -:Message a owl:Class . +:Message a owl:Class ; + rdfs:subClassOf core:DomainEntity . -:Event a owl:Class . +:Event a owl:Class ; + rdfs:subClassOf core:DomainEntity . -:File a owl:Class . +:File a owl:Class ; + rdfs:subClassOf core:Artifact . :sentBy a owl:ObjectProperty ;