Skip to content

Commit 3679445

Browse files
committed
Document when a caller-supplied request id can be minted again
The `request_id` key of `CallOptions` said only that a supplied id must not collide with an in-flight one. Spell out the rest of the contract: integer ids and numeric strings share the dispatcher's own counter, the dispatcher skips an id that is still in flight but may mint the same value again once that request has finished, and an id that must stay unique for the whole session should be a string that doesn't parse as an integer. No behaviour change. Fixes #3126
1 parent 449070c commit 3679445

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎src/mcp/shared/dispatcher.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ class CallOptions(TypedDict, total=False):
8686
with one of the sender's own in-flight request ids raises `ValueError`.
8787
Callers that need to know a request's id before its result arrives (a
8888
`subscriptions/listen` stream is demultiplexed by it) mint their own ids
89-
here; string ids that don't parse as integers can never collide with the
90-
dispatcher's minted sequence. Per the class contract, dispatchers that
91-
predate this key ignore it and mint as usual.
89+
here.
90+
91+
Integer ids, and strings that parse as integers, share the dispatcher's own
92+
counter. The dispatcher skips an id that is still in flight, but may mint
93+
the same value again once that request has finished. When an id must stay
94+
unique for the whole session, use a string that doesn't parse as an
95+
integer, as the `subscriptions/listen` driver does (`listen-1`,
96+
`listen-2`, ...). Per the class contract, dispatchers that predate this key
97+
ignore it and mint as usual.
9298
"""
9399

94100
timeout: float

0 commit comments

Comments
 (0)