Skip to content

Commit a8d0517

Browse files
authored
add info about run time headers (#219)
1 parent 210be04 commit a8d0517

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,39 @@ agent = create_react_agent("openai:gpt-4.1", tools)
200200
math_response = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"})
201201
```
202202
203+
## Passing runtime headers
204+
205+
When connecting to MCP servers, you can include custom headers (e.g., for authentication or tracing) using the `headers` field in the connection configuration. This is supported for the following transports:
206+
207+
* `sse`
208+
* `streamable_http`
209+
210+
### Example: passing headers with `MultiServerMCPClient`
211+
212+
```python
213+
from langchain_mcp_adapters.client import MultiServerMCPClient
214+
from langgraph.prebuilt import create_react_agent
215+
216+
client = MultiServerMCPClient(
217+
{
218+
"weather": {
219+
"transport": "streamable_http",
220+
"url": "http://localhost:8000/mcp",
221+
"headers": {
222+
"Authorization": "Bearer YOUR_TOKEN",
223+
"X-Custom-Header": "custom-value"
224+
},
225+
}
226+
}
227+
)
228+
tools = await client.get_tools()
229+
agent = create_react_agent("openai:gpt-4.1", tools)
230+
response = await agent.ainvoke({"messages": "what is the weather in nyc?"})
231+
```
232+
233+
> Only `sse` and `streamable_http` transports support runtime headers. These headers are passed with every HTTP request to the MCP server.
234+
235+
203236
## Using with LangGraph StateGraph
204237
205238
```python

0 commit comments

Comments
 (0)