Validate tool edits before touching the connection; scope kept MCP connections

- Editing a connection-backed tool validates the config before writing
  new credentials, so a rejected edit no longer rotates the connection's
  key and resumes its sources.
- An MCP edit keeps its previous connection only when the caller owns it
  and it signs in the way the tool now does.
This commit is contained in:
arc53-machine committed 2026-09-28 19:31:02 +01:00
1 parent 4d533d24d6
commit 473e8ec15c
4 files changed
+41 -20

No files matched your search

+7 -3
View File
@@ -326,7 +326,11 @@ class TestMcpServerMismatch:
cid = _connection(pg_conn, provider="custom_mcp", server_url="https://old.example.com")
existing = {"connection_id": cid}
same = {"server_url": "https://old.example.com/mcp", "auth_type": "bearer"}
with patch("docsgpt.api.user.tools.mcp.db_readonly", _yield):
assert _previous_connection(existing, {"server_url": "https://old.example.com/mcp"}) == cid
assert _previous_connection(existing, {"server_url": "https://new.example.com/mcp"}) is None
assert _previous_connection(None, {"server_url": "https://old.example.com/mcp"}) is None
assert _previous_connection(existing, same, "alice") == cid
assert _previous_connection(existing, {**same, "server_url": "https://new.example.com/mcp"}, "alice") is None
assert _previous_connection(None, same, "alice") is None
# Someone else's connection, or one that signs in another way, is not kept.
assert _previous_connection(existing, same, "bob") is None
assert _previous_connection(existing, {**same, "auth_type": "oauth"}, "alice") is None