Skip to content

Conversation

@jba
Copy link
Contributor

@jba jba commented Jun 28, 2025

Support retrieving the session ID from client and server sessions.

For #65.

@jba jba requested a review from findleyr June 28, 2025 00:33
@jba
Copy link
Contributor Author

jba commented Jun 28, 2025

@findleyr Please take a careful look. I'm not familiar with the machinery underlying sessions, and there may be a much simpler way. I'm also not sure if I've gotten all the locking right.

Copy link
Contributor

@rwjblue-glean rwjblue-glean left a comment

Choose a reason for hiding this comment

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

Thank you!!

Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

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

Why don't we just set the session ID when creating each session? Then no locking is required. What am I missing?

@samthanawalla
Copy link
Contributor

Why don't we just set the session ID when creating each session? Then no locking is required. What am I missing?

IIUC, the session ID is not known when the session is created but only when a successful POST happens.

I think we could change the sessionID to an atomic.Value to avoid locking.

Support retrieving the session ID from client and server sessions.

For modelcontextprotocol#65.
@jba
Copy link
Contributor Author

jba commented Jul 1, 2025

Why don't we just set the session ID when creating each session? Then no locking is required. What am I missing?

The ID comes from the server, so clients can't create it.

streamableClientConn locks because you already had locking around its sessionID. I frankly didn't look deeply into why.

There is no other locking in this PR.

@samthanawalla We're not concerned with locking overhead here, because it's dwarfed by the cost of the networking.

@findleyr I was more concerned with the twists and turns I needed to surface these IDs, but as I look over the diffs, there's really not much code.

So I'm satisfied with this PR if you are.

findleyr
findleyr previously approved these changes Jul 1, 2025
Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

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

LGTM, with a couple actionable comments.

mcp/transport.go Outdated
},
})
assert(preempter.conn != nil, "unbound preempter")
h.setSessionIDFunc(conn.sessionID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is an internal detail, I think we could just set the store the Connection on the session, rather than indirecting through this func value. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did what I think you said. PTAL.

Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM.

@jba jba merged commit 9b6327b into modelcontextprotocol:main Jul 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants