dify - 💡(How to fix) Fix reset-encrypt-key-pair leaves stale MCP tool data and breaks tool-providers API [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langgenius/dify#35396Fetched 2026-04-20 12:16:13
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
1
Timeline (top)
labeled ×2commented ×1

Root Cause

  • reset-encrypt-key-pair should leave the system in a recoverable state for the Tool page.
  • /console/api/workspaces/current/tool-providers should not return 400 just because one stored MCP provider contains ciphertext encrypted with the old tenant key.
  • After key rotation, invalidated MCP/tool credentials should either be cleaned up automatically or shown in a reconnect/re-enter state so users can recover from the UI.

Fix Action

Fix / Workaround

  • After the key reset, old tenant-encrypted MCP data remains in the database.
  • In my case, deleting the rows in tool_mcp_providers immediately made the Tool page load again. This looks like a workaround, not a real fix.
  • From reading the current code path, the MCP list response is still decrypting server_url during list rendering even when the request is using the list-view include_sensitive=false path.
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.13.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Connect an MCP server in Dify. For instance: https://demo-day.mcp.cloudflare.com/sse
<img width="2410" height="568" alt="Image" src="https://github.com/user-attachments/assets/e3afc3fa-35c7-42c1-90f2-eb4de85a6350" />
  1. Run flask reset-encrypt-key-pair in dify-api terminal.
  2. Delete the tenant private key cache in Redis, this mocks key expiration.
<img width="1932" height="998" alt="Image" src="https://github.com/user-attachments/assets/cfd37bfb-6109-43ec-81c3-2a3419b3f937" />
  1. Visit the Tool page in the UI, which requests /console/api/workspaces/current/tool-providers.
<img width="2398" height="1126" alt="Image" src="https://github.com/user-attachments/assets/3560aa67-f731-45cd-a29b-4ab45dd9701c" />

No stack trace was shown, only 400 http request log. <img width="2394" height="746" alt="Image" src="https://github.com/user-attachments/assets/6839fc13-90b3-48eb-983e-0993e95aa034" />

Additional context:

  • After the key reset, old tenant-encrypted MCP data remains in the database.
  • In my case, deleting the rows in tool_mcp_providers immediately made the Tool page load again. This looks like a workaround, not a real fix.
  • From reading the current code path, the MCP list response is still decrypting server_url during list rendering even when the request is using the list-view include_sensitive=false path.

✔️ Expected Behavior

  • reset-encrypt-key-pair should leave the system in a recoverable state for the Tool page.
  • /console/api/workspaces/current/tool-providers should not return 400 just because one stored MCP provider contains ciphertext encrypted with the old tenant key.
  • After key rotation, invalidated MCP/tool credentials should either be cleaned up automatically or shown in a reconnect/re-enter state so users can recover from the UI.

❌ Actual Behavior

  • /console/api/workspaces/current/tool-providers returns 400.
  • The Tool page becomes empty / unusable, so I cannot re-enter credentials from the UI.
  • The immediate trigger appears to be stale encrypted MCP provider data left behind after reset-encrypt-key-pair.

Suggested fix direction:

  • Expand reset-encrypt-key-pair so it also clears or invalidates tenant-encrypted tool data that cannot survive key rotation, instead of only resetting legacy model-provider data.
  • Make MCP list serialization defensive so broken encrypted rows do not fail the entire /tool-providers response.

extent analysis

TL;DR

The issue can be fixed by modifying the reset-encrypt-key-pair command to clear or invalidate tenant-encrypted tool data that cannot survive key rotation.

Guidance

  • Review the current implementation of reset-encrypt-key-pair and identify the necessary changes to clear or invalidate tenant-encrypted tool data.
  • Consider adding a defensive mechanism to the MCP list serialization to handle broken encrypted rows without failing the entire response.
  • Investigate the possibility of automatically cleaning up invalidated MCP/tool credentials or displaying them in a reconnect/re-enter state after key rotation.
  • Verify that the proposed fix does not introduce any security vulnerabilities or data loss.

Example

No code snippet is provided as the issue does not contain sufficient information about the implementation details.

Notes

The proposed fix direction suggests modifying the reset-encrypt-key-pair command, but the exact implementation details are not provided. Additionally, the issue highlights the need for a defensive mechanism in the MCP list serialization, but the specifics of this implementation are not clear.

Recommendation

Apply a workaround by manually deleting the rows in tool_mcp_providers as a temporary solution, and then work on implementing the suggested fix direction to modify the reset-encrypt-key-pair command and add a defensive mechanism to the MCP list serialization. This is because the workaround provides an immediate solution, but the suggested fix direction addresses the root cause of the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

dify - 💡(How to fix) Fix reset-encrypt-key-pair leaves stale MCP tool data and breaks tool-providers API [1 comments, 2 participants]