Skip to content

Commit be0ff27

Browse files
authored
Merge pull request #236 from damassi/pass-session-id
feat: Pass `remote-mcp` mcp-session-id header along to GraphQL request
2 parents cda8765 + b6db171 commit be0ff27

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### feat: Pass `remote-mcp` mcp-session-id header along to GraphQL request - @damassi PR #236
2+
3+
This adds support for passing the `mcp-session-id` header through from `remote-mcp` via the MCP client config. This header [originates from the underlying `@modelcontextprotocol/sdk` library](https://github.com/modelcontextprotocol/typescript-sdk/blob/a1608a6513d18eb965266286904760f830de96fe/src/client/streamableHttp.ts#L182), invoked from `remote-mcp`.
4+
5+
With this change it is possible to correlate requests from MCP clients through to the final GraphQL server destination.

crates/apollo-mcp-server/src/server/states/running.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,21 @@ impl ServerHandler for Running {
208208
.await
209209
}
210210
EXECUTE_TOOL_NAME => {
211+
let mut headers = self.headers.clone();
212+
if let Some(axum_parts) = context.extensions.get::<axum::http::request::Parts>() {
213+
// Forward the mcp-session-id header if present
214+
if let Some(session_id) = axum_parts.headers.get("mcp-session-id") {
215+
headers.insert("mcp-session-id", session_id.clone());
216+
}
217+
}
218+
211219
self.execute_tool
212220
.as_ref()
213221
.ok_or(tool_not_found(&request.name))?
214222
.execute(graphql::Request {
215223
input: Value::from(request.arguments.clone()),
216224
endpoint: &self.endpoint,
217-
headers: self.headers.clone(),
225+
headers,
218226
})
219227
.await
220228
}
@@ -226,13 +234,17 @@ impl ServerHandler for Running {
226234
.await
227235
}
228236
_ => {
229-
// Optionally extract the validated token and propagate it to upstream servers
230-
// if found
231237
let mut headers = self.headers.clone();
232-
if let Some(axum_parts) = context.extensions.get::<axum::http::request::Parts>()
233-
&& let Some(token) = axum_parts.extensions.get::<ValidToken>()
234-
{
235-
headers.typed_insert(token.deref().clone());
238+
if let Some(axum_parts) = context.extensions.get::<axum::http::request::Parts>() {
239+
// Optionally extract the validated token and propagate it to upstream servers if present
240+
if let Some(token) = axum_parts.extensions.get::<ValidToken>() {
241+
headers.typed_insert(token.deref().clone());
242+
}
243+
244+
// Also forward the mcp-session-id header if present
245+
if let Some(session_id) = axum_parts.headers.get("mcp-session-id") {
246+
headers.insert("mcp-session-id", session_id.clone());
247+
}
236248
}
237249

238250
let graphql_request = graphql::Request {

0 commit comments

Comments
 (0)