From 87a527a5ff03d7a140f15f73fc52363bb27b1860 Mon Sep 17 00:00:00 2001 From: Oscar Perez Date: Thu, 26 Nov 2026 18:53:03 +0100 Subject: [PATCH 1/2] feat(mcp): advertise the six area read scopes commerce:read, calendar:read, files:read, campaigns:read, money:read and automations:read, appended after messaging:read to match libs/oauth/scopes.ts in Schedule-Posts-API (#10954), each with a relink purpose. Co-Authored-By: Claude Opus 5.5 --- src/late/mcp/constants.py | 6 ++++++ src/late/mcp/middleware/missing_scope.py | 6 ++++++ tests/test_mcp_protected_resource_metadata.py | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/late/mcp/constants.py b/src/late/mcp/constants.py index 9acfa33dc..ef1112ff2 100644 --- a/src/late/mcp/constants.py +++ b/src/late/mcp/constants.py @@ -82,6 +82,12 @@ "ads:read", "contacts:read", "messaging:read", + "commerce:read", + "calendar:read", + "files:read", + "campaigns:read", + "money:read", + "automations:read", ] # Documentation diff --git a/src/late/mcp/middleware/missing_scope.py b/src/late/mcp/middleware/missing_scope.py index 75f114c30..51004a6db 100644 --- a/src/late/mcp/middleware/missing_scope.py +++ b/src/late/mcp/middleware/missing_scope.py @@ -39,6 +39,12 @@ "messaging:write": "send messages, replies and broadcasts for you", "ads:write": "create ads and pause or resume campaigns, which spends your ad budget", "accounts:write": "create, change or remove your profiles and connected accounts", + "commerce:read": "read your shop's orders, products and promotions", + "calendar:read": "read your calendar events and availability", + "files:read": "list and download your Drive and OneDrive files", + "campaigns:read": "read your creator campaigns, creators and payouts", + "money:read": "read your balance, ledger and transfers", + "automations:read": "read your contacts and webhooks", } diff --git a/tests/test_mcp_protected_resource_metadata.py b/tests/test_mcp_protected_resource_metadata.py index 4d4895cfa..8b7b3935c 100644 --- a/tests/test_mcp_protected_resource_metadata.py +++ b/tests/test_mcp_protected_resource_metadata.py @@ -6,6 +6,7 @@ from late.mcp.auth import build_auth_provider from late.mcp.constants import OAUTH_AUTHORIZATION_SERVER +from late.mcp.middleware.missing_scope import relink_instructions def _metadata(scopes: list[str] | None = None) -> dict: @@ -45,6 +46,26 @@ def test_metadata_advertises_the_google_and_microsoft_and_commerce_scopes() -> N assert {"calendar:write", "files:write", "commerce:write"} <= set(_metadata()["scopes_supported"]) +AREA_READ_SCOPES = [ + "commerce:read", + "calendar:read", + "files:read", + "campaigns:read", + "money:read", + "automations:read", +] + + +def test_metadata_advertises_the_area_read_scopes_at_the_end() -> None: + # Appended after messaging:read to match libs/oauth/scopes.ts in Schedule-Posts-API (#10954). + assert _metadata()["scopes_supported"][-6:] == AREA_READ_SCOPES + + +def test_every_area_read_scope_has_a_relink_purpose() -> None: + for scope in AREA_READ_SCOPES: + assert f"use this ({scope})" not in relink_instructions(scope) + + def test_metadata_scopes_match_the_live_authorization_server() -> None: supported = httpx.get( f"{OAUTH_AUTHORIZATION_SERVER}/.well-known/oauth-authorization-server", From 9d04bab91195a0f7fcb10797ae7d1e81c2744995 Mon Sep 17 00:00:00 2001 From: Oscar Perez Date: Thu, 26 Nov 2026 18:56:09 +0100 Subject: [PATCH 2/2] fix(mcp): relink purposes for the area write scopes; changelog entry A token narrowed to an area's :read that calls a write tool is refused on the tool's first declared scope, the :write, which had no purpose. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + src/late/mcp/middleware/missing_scope.py | 6 ++++++ tests/test_mcp_protected_resource_metadata.py | 6 ++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5a9e80f..93feb027f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **`pip install zernio-sdk` without extras could not import the models.** `EmailStr` fields need `email-validator`, which only arrived through FastMCP. The SDK now depends on `pydantic[email]`. ### Added +- **The hosted MCP server advertises a read scope for every area: `commerce:read`, `calendar:read`, `files:read`, `campaigns:read`, `money:read` and `automations:read`.** They are appended after `messaging:read`, in the order the Zernio authorization server lists them, so a client can ask for read-only access to a shop, calendar, Drive, creator campaigns, balance or contacts and webhooks. A ChatGPT link narrowed to one of them that calls a write tool now gets re-link steps naming what the write does. - **`idempotency_key` on every MCP tool whose API operation accepts `Idempotency-Key` (84 tools, including `posts_create_post`).** The generator used to drop all optional headers, so an agent whose chat stopped or timed out mid-create had no safe way to retry: retrying could create a second post, message, transfer or campaign. The tool now takes the key and sends it as the header; a retry with the same key within 24 hours returns the original result, or 409 while it is still processing. It stays optional (required only where the spec requires it, as on the tracking-site and tracking-link tools), and no key is invented when the caller passes none, because a key turns off the API's content duplicate check. The four ad-create tools that derive a key from their arguments use the caller's key when given and keep the derived one otherwise. Other optional headers (`x-request-id`, `If-Match`, connect tokens) stay hidden. - **`transport=` on `Late` / `Zernio`.** Pass an `httpx.BaseTransport` to reuse connections and TLS sessions across requests and clients. The caller owns it; the client never closes it. Without it nothing changes: a new connection per request. - **Tool call telemetry on the hosted MCP server.** One JSON log line per tool call (tool, latency, outcome, hashed caller), and with `SENTRY_DSN` one Sentry transaction per tool call. `/health` reports the deployed commit. diff --git a/src/late/mcp/middleware/missing_scope.py b/src/late/mcp/middleware/missing_scope.py index 51004a6db..54c8c75b8 100644 --- a/src/late/mcp/middleware/missing_scope.py +++ b/src/late/mcp/middleware/missing_scope.py @@ -45,6 +45,12 @@ "campaigns:read": "read your creator campaigns, creators and payouts", "money:read": "read your balance, ledger and transfers", "automations:read": "read your contacts and webhooks", + "commerce:write": "fulfil orders, handle returns and refunds, and manage your shop's catalog and promotions", + "calendar:write": "create, edit and RSVP to events on your calendars", + "files:write": "upload and share files in your Drive and OneDrive", + "campaigns:write": "create and run creator campaigns, invite creators and record payouts", + "money:write": "add funds to your balance and transfer money to creators and other payees", + "automations:write": "create, edit and delete contacts and leads, and manage SMS opt-outs and webhooks", } diff --git a/tests/test_mcp_protected_resource_metadata.py b/tests/test_mcp_protected_resource_metadata.py index 8b7b3935c..a594431c4 100644 --- a/tests/test_mcp_protected_resource_metadata.py +++ b/tests/test_mcp_protected_resource_metadata.py @@ -61,8 +61,10 @@ def test_metadata_advertises_the_area_read_scopes_at_the_end() -> None: assert _metadata()["scopes_supported"][-6:] == AREA_READ_SCOPES -def test_every_area_read_scope_has_a_relink_purpose() -> None: - for scope in AREA_READ_SCOPES: +def test_every_area_scope_has_a_relink_purpose() -> None: + # A token narrowed to an area's :read reaches its write tools, whose first declared scope is the :write. + area_write_scopes = [scope.replace(":read", ":write") for scope in AREA_READ_SCOPES] + for scope in AREA_READ_SCOPES + area_write_scopes: assert f"use this ({scope})" not in relink_instructions(scope)