Commit c8f02a9
fix: tolerate duplicate initialize requests on the same session
go-sdk v1.7.0-pre.1 (bumped in #2787) started rejecting a second
"initialize" call on an already-initialized session with `duplicate
"initialize" received`, fixing modelcontextprotocol/go-sdk#961 (a
duplicate initialize with changed params could silently overwrite the
session's stored InitializeParams). go-sdk v1.6.1 and earlier
(github-mcp-server v1.5.0) accepted repeat calls and returned the same
result every time.
Some MCP clients resend "initialize" on the same transport/session
when a handshake is retried (e.g. a slow first response triggers a
client-side retry without tearing down the connection), which relied
on that old idempotent behavior and now hard-fails on v1.6.0+.
Add a receiving middleware that caches the first successful
InitializeResult and replays it for later "initialize" calls on the
same server, instead of forwarding to the SDK and hitting its error.
The response is otherwise constant for the process's lifetime, so a
single cached result (not a per-session cache) is enough and avoids
any per-session memory growth.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent eb088df commit c8f02a9
1 file changed
Lines changed: 56 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
190 | 191 | | |
191 | 192 | | |
192 | 193 | | |
| 194 | + | |
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
197 | 253 | | |
198 | 254 | | |
199 | 255 | | |
| |||
0 commit comments