bug(api): MCP tool invoke drops OAuth Authorization when any custom header is set

オープン 初心者向け
#42,326 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

api/core/tools/mcp_tool/tool.py の MCPTool.invoke_remote_mcp_tool から始め、ヘッダー処理を api/services/tools/mcp_tools_manage_service.py の _prepare_auth_headers と比較します。カスタム X-Tenant ヘッダーと保存済みの OAuth トークンを使ってユニットケースを再現し、呼び出しによってカスタムヘッダーが保持され、Authorization が含まれ、一覧表示が退行しないことを確認します。

索引モデルが issue の本文から書いたものです。

説明

Self Checks
  • I have read the Contributing Guide and Language Policy.
  • I have searched for existing issues and pull requests, including closed ones.
  • I confirm that I am using English to submit this report.
Dify version

main (current)

Cloud or Self Hosted

Both

Problem

MCP tool listing and MCP tool invoke prepare Authorization differently.

  • MCPToolManageService.list_provider_tools uses _prepare_auth_headers(), which always merges OAuth tokens into the request headers (custom headers + OAuth coexist).
  • MCPTool.invoke_remote_mcp_tool gated token injection behind if not headers:. Any non-empty custom header map (for example X-Tenant: abc) skipped retrieve_tokens() entirely.

Falsifiable consequence:

  1. Configure an MCP provider with at least one custom header and complete OAuth (tokens stored).
  2. Refresh / list tools → succeeds (Authorization present via _prepare_auth_headers).
  3. Invoke the same tool from Agent / Workflow → request goes out without Authorization, typically 401 from the MCP server, while listing still works.

This is an auth/header state asymmetry between list and invoke, not a UI issue.

Relevant code (before fix):

  • api/services/tools/mcp_tools_manage_service.py_prepare_auth_headers
  • api/core/tools/mcp_tool/tool.pyinvoke_remote_mcp_tool (if not headers: gate)
Steps to reproduce

Minimal unit repro (fails on main):

# decrypt_headers returns {"X-Tenant": "abc"}
# retrieve_tokens returns OAuthTokens(access_token="oauth-access-token", token_type="bearer", ...)
# invoke_remote_mcp_tool(...)
# MCPClientWithAuthRetry receives headers WITHOUT Authorization

Or manually:

  1. Add MCP server with custom header X-Tenant=abc and OAuth credentials.
  2. Click to fetch tools (list succeeds).
  3. Call the tool from a workflow/agent → auth failure / 401.
Expected Behavior

Invoke must apply the same header merge as listing: custom headers kept, OAuth Authorization still attached when tokens exist.

Actual Behavior

Invoke drops OAuth whenever any custom header is present.

I am preparing a focused fix with regression tests and will open a PR linking this issue.

主要言語
TypeScript
スター
157k
フォーク
24.7k
平均マージ
22時間 32分
マージ済み PR(30日)
611

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

langgenius/dify のほかの issue

langgenius/dify の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。