langchain - ✅(Solved) Fix MCP Header Forwarding Failure (Discovery Phase) [1 pull requests, 9 comments, 5 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
langchain-ai/langchain#35574Fetched 2026-04-08 00:25:28
View on GitHub
Comments
9
Participants
5
Timeline
23
Reactions
0
Author
Timeline (top)
commented ×9mentioned ×4subscribed ×4labeled ×3

The LangSmith Agent Builder backend proxy does not forward custom static headers (specifically Authorization and Accept) during the initial discovery request to remote MCP servers using the HTTP Streamable transport. This causes servers with strict authentication requirements (like Directus 11.14+) to return a 403 Forbidden, preventing tool discovery. Internal Workaround Status: The only current workaround is injecting headers at the target server's Nginx/load-balancer layer for the LangSmith egress IP, which is identified as a security risk and fragile.

Error Message

Error Message and Stack Trace (if applicable)

Root Cause

1. User adds a remote MCP server in the Agent Builder UI.
2. User provides correct Authorization: Bearer <token> and Accept: application/json headers (tried via raw string and Workspace Secrets).
3. The Agent Builder attempts to discover tools but fails because the outgoing probe request lacks the required headers.
4. Discovery fails to populate the toolbox, despite the server being accessible via curl and other MCP clients.

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

The LangSmith Agent Builder backend proxy does not forward custom static headers (specifically Authorization and Accept) during the initial discovery request to remote MCP servers using the HTTP Streamable transport. This causes servers with strict authentication requirements (like Directus 11.14+) to return a 403 Forbidden, preventing tool discovery. Internal Workaround Status: The only current workaround is injecting headers at the target server's Nginx/load-balancer layer for the LangSmith egress IP, which is identified as a security risk and fragile.

PR fix notes

PR #36193: fix(anthropic): redact mcp_servers authorization_token from invocation params

Description (problem / solution / changelog)

Summary

Closes #35574

When mcp_servers entries containing an authorization_token are passed via kwargs at invoke/bind time (rather than as a model attribute), the token was forwarded verbatim into LangSmith tracing through _get_invocation_params. This leaks credentials into traces.

  • Override _get_invocation_params in ChatAnthropic to replace authorization_token with "**REDACTED**" in tracing params
  • Mirrors the analogous redaction already in ChatOpenAI for MCP tool headers
  • The actual API payload built by _get_request_payload is not affected — credentials continue to be forwarded correctly to the Anthropic API
  • Creates a shallow copy of each server dict so the original list is never mutated

Test plan

  • Existing test_mcp_tracing extended with assertions that authorization_token is redacted in invocation_params and that the original list is not mutated
cd libs/partners/anthropic
pip install -e .
pytest tests/unit_tests/test_chat_models.py::test_mcp_tracing -v

🤖 Generated with Claude Code

Changed files

  • libs/partners/anthropic/langchain_anthropic/chat_models.py (modified, +27/-0)
  • libs/partners/anthropic/tests/unit_tests/test_chat_models.py (modified, +21/-2)

Code Example

1. User adds a remote MCP server in the Agent Builder UI.
2. User provides correct Authorization: Bearer <token> and Accept: application/json headers (tried via raw string and Workspace Secrets).
3. The Agent Builder attempts to discover tools but fails because the outgoing probe request lacks the required headers.
4. Discovery fails to populate the toolbox, despite the server being accessible via curl and other MCP clients.

---

Nginx log:
34.59.65.97 - - [05/Mar/2026:07:44:21 +0000] "GET /mcp HTTP/1.1" 403 102 "-" "python-httpx/0.28.1"                              
34.59.65.97 - - [05/Mar/2026:07:44:22 +0000] "POST /mcp HTTP/1.1" 403 102 "-" "python-httpx/0.28.1"

Response from the MCP server:
{"detail":"Could not fetch tools from MCP server"}
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

1. User adds a remote MCP server in the Agent Builder UI.
2. User provides correct Authorization: Bearer <token> and Accept: application/json headers (tried via raw string and Workspace Secrets).
3. The Agent Builder attempts to discover tools but fails because the outgoing probe request lacks the required headers.
4. Discovery fails to populate the toolbox, despite the server being accessible via curl and other MCP clients.

Error Message and Stack Trace (if applicable)

Nginx log:
34.59.65.97 - - [05/Mar/2026:07:44:21 +0000] "GET /mcp HTTP/1.1" 403 102 "-" "python-httpx/0.28.1"                              
34.59.65.97 - - [05/Mar/2026:07:44:22 +0000] "POST /mcp HTTP/1.1" 403 102 "-" "python-httpx/0.28.1"

Response from the MCP server:
{"detail":"Could not fetch tools from MCP server"}

Description

The LangSmith Agent Builder backend proxy does not forward custom static headers (specifically Authorization and Accept) during the initial discovery request to remote MCP servers using the HTTP Streamable transport. This causes servers with strict authentication requirements (like Directus 11.14+) to return a 403 Forbidden, preventing tool discovery. Internal Workaround Status: The only current workaround is injecting headers at the target server's Nginx/load-balancer layer for the LangSmith egress IP, which is identified as a security risk and fragile.

System Info

Egress IP: 34.59.65.97 Observed User-Agent: python-httpx/0.28.1 Endpoint: GET /mcp or POST /mcp (Discovery Phase) Symptom: Nginx logs on the target server confirm that requests from the LangSmith proxy arrive with zero of the custom headers configured in the UI. Environment: Hosted LangSmith (smith.langchain.com)

extent analysis

Fix Plan

1. Update the HTTP Streamable transport to forward custom headers

  • Step 1: Update the http_streamable transport in langchain

Before

transport = http_streamable.HTTPStreamableTransport( url="https://example.com/mcp", headers={"Accept": "application/json"} )

After

transport = http_streamable.HTTPStreamableTransport( url="https://example.com/mcp", headers={ "Authorization": "Bearer <token>", "Accept": "application/json" } )


*   **Step 2: Update the `AgentBuilder` to use the updated transport**
    ```python
# Before
transport = http_streamable.HTTPStreamableTransport(
    url="https://example.com/mcp",
    headers={"Accept": "application/json"}
)

# After
transport = http_streamable.HTTPStreamableTransport(
    url="https://example.com/mcp",
    headers={
        "Authorization": "Bearer <token>",
        "Accept": "application/json"
    }
)

2. Verify the fix

  • Run the AgentBuilder with the updated transport and verify that the custom headers are forwarded correctly.
  • Check the Nginx logs on the target server to confirm that the requests from the LangSmith proxy arrive with the custom headers.

Extra Tips

  • Make sure to update the http_streamable transport in all relevant places in the codebase.
  • Consider adding a test case to verify that the custom headers are forwarded correctly.
  • If you're using a CI/CD pipeline, make sure to update the pipeline to use the updated transport.

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

langchain - ✅(Solved) Fix MCP Header Forwarding Failure (Discovery Phase) [1 pull requests, 9 comments, 5 participants]