Stop a removed MCP connection from saving its server as a custom tool

After removing a Linear connection, connecting again could skip signing in
and save Linear as an unconnected custom tool: a client cached before the
removal still held the old tokens, and a late token write re-created a
connection for them. A token write for a named connection no longer creates
one, removing or disconnecting a connection drops its cached clients, and a
sign-in server is never saved without its connection.
This commit is contained in:
arc53-machine committed 2026-09-29 13:13:27 +01:00
1 parent 159ac03904
commit 56ababae71
5 files changed
+124 -6

No files matched your search

+11
View File
@@ -399,6 +399,17 @@ class MCPServerSave(Resource):
connection_id = _mcp_connection(
user, storage_config, auth_type, auth_credentials, display_name,
) or _previous_connection(existing_doc, storage_config, user)
if auth_type == "oauth" and not connection_id:
# A sign-in server's tokens live on its connection. Without one
# (it was removed, and a client cached before that answered the
# discovery) the tool would be saved unconnected.
return make_response(
jsonify({
"success": False,
"error": "Not signed in to this server. Sign in again to connect it.",
}),
400,
)
if connection_id and auth_type != "oauth":
# The secret lives on the connection only.
storage_config.pop("encrypted_credentials", None)