Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/late/mcp/middleware/missing_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

_INSUFFICIENT_PERMISSIONS = "insufficient_permissions"

# The plugin's public page. ChatGPT documents no link that opens its Reconnect.
_PLUGIN_URL = (
"https://chatgpt.com/plugins/plugin_asdk_app_6aad5ef1fadc81919260bddebb06a407"
)

_SCOPE_PURPOSE = {
"messaging:read": "read your inbox, comments and messages",
"ads:read": "read your ad accounts, campaigns and results",
Expand All @@ -41,10 +46,9 @@ def relink_instructions(needed: str) -> str:
purpose = _SCOPE_PURPOSE.get(needed, f"use this ({needed})")
return (
f"Zernio needs one more permission to {purpose} ('{needed}'); this ChatGPT "
"connection was set up before Zernio asked for it. Nothing was sent or changed. "
"Tell the user, in these steps: open ChatGPT Settings > Plugins (Apps in some "
"versions) > Zernio, click ... next to the connected Zernio account, choose "
"Reconnect, approve the new permission, then ask again."
"connection was set up before Zernio asked for it. Do not retry. Nothing "
f"changed. Tell the user: open {_PLUGIN_URL}, Settings, ... by your account, "
"Reconnect, approve, ask again."
)


Expand Down
13 changes: 10 additions & 3 deletions tests/test_chatgpt_generated_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ async def _list_conversations(response: httpx.Response):
)


RELINK_STEPS = (
"Do not retry. Nothing changed. Tell the user: open "
"https://chatgpt.com/plugins/plugin_asdk_app_6aad5ef1fadc81919260bddebb06a407, "
"Settings, ... by your account, Reconnect, approve, ask again."
)


async def test_a_link_without_the_tools_scope_is_asked_to_relink(monkeypatch):
monkeypatch.setattr(
"late.mcp.middleware.missing_scope._granted_scopes", lambda: LINK_SCOPES
Expand All @@ -259,7 +266,7 @@ async def test_a_link_without_the_tools_scope_is_asked_to_relink(monkeypatch):
assert result.is_error
text = result.content[0].text
assert "read your inbox" in text and "'messaging:read'" in text
assert "Settings > Plugins" in text and "Reconnect" in text
assert RELINK_STEPS in text


async def test_the_relink_steps_carry_no_auth_challenge_chatgpt_would_hide_them_behind(
Expand Down Expand Up @@ -340,7 +347,7 @@ async def test_a_link_that_only_reads_accounts_is_asked_to_relink_before_a_write
assert result.is_error
text = result.content[0].text
assert "'accounts:write'" in text
assert "Settings > Plugins" in text and "Reconnect" in text
assert RELINK_STEPS in text


@pytest.mark.parametrize(
Expand All @@ -362,7 +369,7 @@ async def test_a_write_refused_despite_its_scope_keeps_the_apis_own_error(
result = await _create_profile(httpx.Response(403, json=ACCOUNTS_READ_ONLY))

assert result.is_error
assert "Settings > Plugins" not in result.content[0].text
assert "Do not retry" not in result.content[0].text
assert "can only read the 'accounts' resource group" in result.content[0].text


Expand Down
Loading