Skip to content

fix: unable to import mcp from local - #16590

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
Haruko386:major
Jul 3, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
Haruko386:major

Conversation

@Haruko386

Copy link
Copy Markdown
Member

Summary

As title

@Haruko386 Haruko386 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jul 3, 2026
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 3, 2026
@Haruko386
Haruko386 marked this pull request as draft July 3, 2026 04:25
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR simplifies comments in MCP handler and service files without altering logic, and adds authorization_token support to ImportServers so a config's root-level token is stored as a variable and injected as an Authorization bearer header when none exists.

Changes

MCP Handler and Service Updates

Layer / File(s) Summary
Comment simplification
internal/handler/mcp.go, internal/service/mcp.go
Verbose explanatory comments around ImportMCPServers, TestMCPServer, sentinel error declarations, ImportServers, TestServer, and toolsAsMap are shortened or removed; no logic changes.
authorization_token propagation
internal/service/mcp.go
ImportServers stores a config's root authorization_token into variables/stringVars and injects an Authorization bearer template into headers/headerVals when no Authorization header already exists.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: size:S

Suggested reviewers: yuzhichang

Poem

A rabbit hopped through lines of code,
Trimming comments to lighten the load,
Then found a token, plain to see,
Wrapped it in "Bearer" for security,
Hop, hop, hooray — the headers now know! 🐇🔑

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description only says 'As title' and omits the required summary and background context. Replace the placeholder with a brief Summary section describing the bug, the fix, and any relevant context.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main bug fix: importing MCP from local.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Haruko386
Haruko386 marked this pull request as ready for review July 3, 2026 04:25

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/service/mcp.go (1)

521-541: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Treat Authorization detection case-insensitively. headers and headerVals can diverge here when the input already has an authorization-cased header or a non-string value, so this block may inject a bearer header even though auth is already present and persist a different value than the one used for discovery. Use one strings.EqualFold check over the raw headers and apply the same result to both maps.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/service/mcp.go` around lines 521 - 541, The Authorization header
check in mcp.go is case-sensitive and can treat existing authorization headers
as missing when the input uses different casing or non-string values. Update the
header handling in the block that builds headers and headerVals to inspect the
raw headers with a single strings.EqualFold-based Authorization presence check,
then use that same result to decide whether to inject the Bearer
${authorization_token} value into both maps. Keep the behavior aligned between
headers and headerVals so discovery and persistence always match.
🧹 Nitpick comments (1)
internal/service/mcp.go (1)

532-533: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant assignment: authorization_token is already copied by the generic loop above.

The loop at lines 503-511 copies every config key except type, url, headers into variables/stringVars — authorization_token isn't excluded, so it's already present there. Line 532's variables["authorization_token"] = token just re-assigns the same value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/service/mcp.go` around lines 532 - 533, Remove the redundant
authorization_token re-assignment in the MCP config handling: the generic copy
loop already populates variables and stringVars for this key. In the code around
the token setup in the MCP service, keep the existing loop behavior and only
preserve the separate stringVars["authorization_token"] assignment if it is
still needed for string-specific handling; otherwise delete the duplicate
variables["authorization_token"] = token line.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/service/mcp.go`:
- Around line 521-541: The Authorization header check in mcp.go is
case-sensitive and can treat existing authorization headers as missing when the
input uses different casing or non-string values. Update the header handling in
the block that builds headers and headerVals to inspect the raw headers with a
single strings.EqualFold-based Authorization presence check, then use that same
result to decide whether to inject the Bearer ${authorization_token} value into
both maps. Keep the behavior aligned between headers and headerVals so discovery
and persistence always match.

---

Nitpick comments:
In `@internal/service/mcp.go`:
- Around line 532-533: Remove the redundant authorization_token re-assignment in
the MCP config handling: the generic copy loop already populates variables and
stringVars for this key. In the code around the token setup in the MCP service,
keep the existing loop behavior and only preserve the separate
stringVars["authorization_token"] assignment if it is still needed for
string-specific handling; otherwise delete the duplicate
variables["authorization_token"] = token line.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 02878278-77c5-49f1-9985-993da0845ecc

📥 Commits

Reviewing files that changed from the base of the PR and between 9182296 and a577843.

📒 Files selected for processing (2)
  • internal/handler/mcp.go
  • internal/service/mcp.go

@JinHai-CN
JinHai-CN merged commit b2e4740 into infiniflow:main Jul 3, 2026
6 of 12 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants