You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: adk/README.md
+65-14Lines changed: 65 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,36 @@ The JSON configuration for `AGENT_TOOLS` should follow this structure:
72
72
{
73
73
"tool_name": {
74
74
"url":"https://mcp-tool-endpoint:8000/mcp",
75
-
"timeout":30// Optional: connect timeout in seconds
75
+
"timeout":30, // Optional: connect timeout in seconds (default: 30)
76
+
"propagate_headers": ["X-API-Key", "Authorization"] // Optional: list of headers to propagate (default: [])
77
+
}
78
+
}
79
+
```
80
+
81
+
### Header Propagation
82
+
83
+
You can configure which HTTP headers are passed from the incoming A2A request to each MCP server using the `propagate_headers` field. This provides fine-grained control over which headers each MCP server receives.
84
+
85
+
**Key features:**
86
+
-**Per-server configuration**: Each MCP server can receive different headers
87
+
-**Security**: Headers are only sent to servers explicitly configured to receive them
88
+
-**Case-insensitive matching**: Header names are matched case-insensitively
89
+
-**Default behavior**: When `propagate_headers` is not specified or is empty, no headers are passed
// No propagate_headers - no headers will be passed
76
105
}
77
106
}
78
107
```
@@ -102,46 +131,68 @@ Body logging behavior:
102
131
**Note**: Starlette body logging is more limited than HTTPX because it must avoid consuming request/response streams.
103
132
Bodies are only captured when already buffered in the ASGI scope.
104
133
105
-
## External API Token Passing
134
+
## HTTP Header Propagation to MCP Tools
106
135
107
-
The SDK supports passing external API tokens from A2A requests to MCP tools. This enables MCP servers to authenticate with external APIs on behalf of users.
136
+
The SDK supports passing HTTP headers from A2A requests to MCP tools. This enables MCP servers to authenticate with external APIs on behalf of users, and provides flexible header-based configuration.
108
137
109
138
### How It Works
110
139
111
-
1.**Token Capture**: When an A2A request includes the `X-External-Token` header, the SDK automatically captures and stores it in the ADK session state
112
-
2.**Secure Storage**: The token is stored in ADK's session state (not in memory state accessible to the LLM), ensuring the agent cannot directly access or leak it
113
-
3.**Automatic Injection**: When MCP tools are invoked, the SDK uses ADK's `header_provider` hook to retrieve the token from the session and inject it as the `X-External-Token` header in tool requests
140
+
1.**Header Capture**: When an A2A request is received, all HTTP headers are captured and stored in the ADK session state
141
+
2.**Secure Storage**: Headers are stored in ADK's session state (not in memory state accessible to the LLM), ensuring the agent cannot directly access or leak sensitive information
142
+
3.**Per-Server Filtering**: Each MCP server receives only the headers configured in its `propagate_headers` list
143
+
4.**Automatic Injection**: When MCP tools are invoked, the SDK uses ADK's `header_provider` hook to retrieve the configured headers from the session and inject them into tool requests
114
144
115
-
**Current Limitations**: The token is only passed to MCP servers. Propagation to sub-agents is not currently supported due to ADK limitations in passing custom HTTP headers in A2A requests.
145
+
### Configuration
146
+
147
+
Configure which headers to propagate using the `propagate_headers` field in your MCP tool configuration:
"parts": [{"kind": "text", "text": "What is the weather?"}],
133
180
"messageId": "msg-123",
134
181
"contextId": "ctx-123"
135
182
}
136
183
}
137
184
}'
138
185
```
139
186
140
-
The SDK will automatically pass `your-api-token-here` to all MCP tool calls and sub-agent requests made during that session.
187
+
Based on the configuration above:
188
+
-`weather_api` MCP server will receive `X-API-Key` and `X-User-Location` headers
189
+
-`database_tool` MCP server will receive only the `Authorization` header
190
+
191
+
**Limitations**: Header propagation is only supported for MCP servers. Propagation to sub-agents is not currently supported due to ADK limitations in passing custom HTTP headers in A2A requests.
141
192
142
193
### Security Considerations
143
194
144
-
-Tokens are stored in ADK session state (separate from memory state that the LLM can access)
145
-
-Tokens are not directly accessible to agent code through normal session state queries
146
-
-Tokens persist for the session duration and are managed by ADK's session lifecycle
195
+
-Headers are stored in ADK session state (separate from memory state that the LLM can access)
196
+
-Headers are not directly accessible to agent code through normal session state queries
197
+
-Headers persist for the session duration and are managed by ADK's session lifecycle
147
198
- This is a simple authentication mechanism; for production use, consider implementing more sophisticated authentication and authorization schemes
0 commit comments