-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy path_requirements.py
More file actions
4175 lines (4122 loc) · 215 KB
/
Copy path_requirements.py
File metadata and controls
4175 lines (4122 loc) · 215 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Requirements manifest for the interaction-model test suite.
Every user-facing behaviour the SDK must satisfy, keyed by a stable `<area>:<feature>[:<variant>]`
ID. Each entry owns the tests that exercise it: tests declare `@requirement("<id>")` (a test that
proves several behaviours stacks several decorators) and `test_coverage.py` enforces the contract
in both directions: every non-deferred requirement has at least one test, and every test carries
at least one requirement.
Sources:
spec URL -- externally mandated by the MCP specification (deep link to the section)
`sdk` -- a behavioural guarantee the SDK chose; not spec-mandated
`issue:#n` -- regression lock-in for a previously fixed bug
The `behavior` sentence describes the REQUIRED behaviour -- what the specification (or the SDK's
own contract) says should happen. Tests always pin the SDK's current behaviour. Where current
behaviour falls short of `behavior`, the gap is recorded as data: `divergence` on entries whose
tests pin the divergent behaviour, or `deferred` on entries that are tracked but not yet covered
by a test in this suite. An entry may carry both: `divergence` records the spec-compliance gap
(issue-able) and `deferred` records why no test exists; `divergence` alone implies a test pins
the divergent behaviour. `issue` carries the tracking link for a recorded gap once one is filed.
`deferred` reasons take one of three shapes: where the behaviour is exercised elsewhere in this
repo the reason names the covering test path; where the SDK does not implement the behaviour at
all the reason starts with "Not implemented in the SDK"; and where an interaction-level test is
planned but not yet written the reason starts with "Not yet covered here".
`transports` records which transports a behaviour applies to (or is observable on); None means
the behaviour is transport-independent.
The ID vocabulary and entry granularity are aligned with the TypeScript SDK's end-to-end
requirements suite, so coverage and recorded divergences can be compared across the two SDKs
entry by entry; IDs that exist in only one SDK reflect genuinely different API surface.
"""
import re
from collections.abc import Callable, Sequence
from dataclasses import dataclass
from typing import Any, Literal, TypeVar
import pytest
from mcp_types.version import KNOWN_PROTOCOL_VERSIONS
SpecVersion = Literal["2025-11-25", "2026-07-28"]
"""A protocol version the suite parametrizes over. Both values are typed even though only one is
on the active axis (SPEC_VERSIONS) until the 2026-07-28 implementation lands."""
SPEC_VERSIONS: tuple[SpecVersion, ...] = ("2025-11-25", "2026-07-28")
"""The active spec-version matrix axis, ordered oldest to newest. Every entry must be in KNOWN_PROTOCOL_VERSIONS."""
SPEC_BASE_URL = "https://modelcontextprotocol.io/specification/2025-11-25"
"""Deep-link base for entries citing the 2025-11-25 revision (the bulk of the manifest). Pinned --
not derived from SPEC_VERSIONS -- so adding a newer revision to the active axis does not silently
repoint existing source URLs."""
SPEC_2026_BASE_URL = "https://modelcontextprotocol.io/specification/2026-07-28"
"""Deep-link base for entries citing the 2026-07-28 revision."""
Transport = Literal["in-memory", "stdio", "streamable-http", "streamable-http-stateless", "sse"]
CONNECTABLE_TRANSPORTS: tuple[Transport, ...] = ("in-memory", "sse", "streamable-http", "streamable-http-stateless")
"""Transports the connect fixture fans out over (the subset with a factory in conftest._FACTORIES)."""
TRANSPORT_SPEC_VERSIONS: dict[Transport, tuple[SpecVersion, ...]] = {
"sse": ("2025-11-25",),
"in-memory": ("2025-11-25", "2026-07-28"),
# At the newer revision the protocol-version header check runs before the stateless branch is
# taken, so a stateless connection at that revision behaves identically to the stateful one.
# Locked to avoid a redundant matrix column; revisit if the header/stateless ordering changes.
"streamable-http-stateless": ("2025-11-25",),
}
"""Transports that only serve a subset of SPEC_VERSIONS. Absent => serves all. Consulted by compute_cells()."""
ArmExclusionReason = Literal[
"asserts-legacy-handshake",
"method-not-in-modern-registry",
"legacy-only-vocabulary",
"modern-error-surface",
"requires-session",
"drives-transport-directly",
"server-initiated-request",
]
"""Machine-readable reasons a requirement is excluded from a (transport, spec_version) matrix cell.
The set doubles as a re-admission checklist: when a feature lands, grep for its reason to find the
cells to re-admit. Values are kept byte-identical to the typescript-sdk's EntryExclusionReason."""
_TestFn = TypeVar("_TestFn", bound=Callable[..., object])
_SOURCE_PATTERN = re.compile(r"https://modelcontextprotocol\.io/specification/.+|sdk|issue:#\d+")
_TASKS_DEFERRAL = (
"Tasks have been removed from the draft spec and from this SDK; they are expected to return "
"as a separate MCP extension. These 2025-11-25 requirements are tracked but intentionally "
"unimplemented."
)
@dataclass(frozen=True, kw_only=True)
class Divergence:
"""A documented gap between the SDK behaviour this suite pins and what `source` mandates."""
note: str
issue: str | None = None
@dataclass(frozen=True, kw_only=True)
class ArmExclusion:
"""Excludes a requirement from a (transport, spec_version) matrix cell, with a typed reason."""
reason: ArmExclusionReason
transport: Transport | None = None
spec_version: SpecVersion | None = None
note: str | None = None
def __post_init__(self) -> None:
if self.spec_version is not None and self.spec_version not in KNOWN_PROTOCOL_VERSIONS:
raise ValueError(f"spec_version {self.spec_version!r} is not in KNOWN_PROTOCOL_VERSIONS")
@dataclass(frozen=True, kw_only=True)
class KnownFailure:
"""A (transport, spec_version) cell where the requirement's test is expected to fail (strict xfail)."""
note: str
transport: Transport | None = None
spec_version: SpecVersion | None = None
issue: str | None = None
def __post_init__(self) -> None:
if not self.note.strip():
raise ValueError("note must be non-empty")
if self.spec_version is not None and self.spec_version not in KNOWN_PROTOCOL_VERSIONS:
raise ValueError(f"spec_version {self.spec_version!r} is not in KNOWN_PROTOCOL_VERSIONS")
if self.issue is not None and not re.fullmatch(r"#\d+|https://github\.com/\S+", self.issue):
raise ValueError(f"issue must be '#<n>' or a GitHub URL, got {self.issue!r}")
@dataclass(frozen=True, kw_only=True)
class Requirement:
"""A single testable behaviour and the provenance of why it must hold."""
source: str
behavior: str
transports: tuple[Transport, ...] | None = None
divergence: Divergence | None = None
deferred: str | None = None
issue: str | None = None
note: str | None = None
added_in: SpecVersion | None = None
removed_in: SpecVersion | None = None
supersedes: tuple[str, ...] = ()
superseded_by: str | None = None
arm_exclusions: tuple[ArmExclusion, ...] = ()
known_failures: tuple[KnownFailure, ...] = ()
def __post_init__(self) -> None:
if not _SOURCE_PATTERN.fullmatch(self.source):
raise ValueError(f"source must be a specification URL, 'sdk', or 'issue:#n', got {self.source!r}")
if self.added_in is not None and self.added_in not in KNOWN_PROTOCOL_VERSIONS:
raise ValueError(f"added_in {self.added_in!r} is not in KNOWN_PROTOCOL_VERSIONS")
if self.removed_in is not None and self.removed_in not in KNOWN_PROTOCOL_VERSIONS:
raise ValueError(f"removed_in {self.removed_in!r} is not in KNOWN_PROTOCOL_VERSIONS")
if (
self.added_in is not None
and self.removed_in is not None
and KNOWN_PROTOCOL_VERSIONS.index(self.added_in) >= KNOWN_PROTOCOL_VERSIONS.index(self.removed_in)
):
raise ValueError(f"added_in {self.added_in!r} must be earlier than removed_in {self.removed_in!r}")
REQUIREMENTS: dict[str, Requirement] = {
# ═══════════════════════════════════════════════════════════════════════════
# Lifecycle & version negotiation
# ═══════════════════════════════════════════════════════════════════════════
"lifecycle:capability:client-not-declared": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#operation",
behavior=(
"The client rejects sending notifications or registering handlers for capabilities it did not declare."
),
divergence=Divergence(
note=(
"The client does not check its own declared capabilities before sending notifications or "
"serving callbacks; nothing prevents a caller from violating the spec's MUST."
),
),
deferred=(
"Not implemented in the SDK: the client does not check its own declared capabilities before "
"sending notifications or serving callbacks."
),
),
"lifecycle:capability:server-not-advertised": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#operation",
behavior=(
"The client rejects calls to methods (e.g. resources/list) for capabilities the server did not advertise."
),
divergence=Divergence(
note=(
"The client sends any request regardless of the server's advertised capabilities and "
"surfaces whatever the server answers; the spec's MUST is not enforced."
),
),
deferred=(
"Not implemented in the SDK: the client sends any request regardless of the server's "
"advertised capabilities and surfaces whatever the server answers."
),
),
"lifecycle:initialize:basic": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#initialization",
behavior=(
"Connecting sends initialize with the protocol version, client capabilities, and client "
"info; the server responds with its own and the connection is established."
),
removed_in="2026-07-28",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
),
"lifecycle:initialize:server-info": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#initialization",
behavior="The initialize result identifies the server: name and version, plus title when declared.",
removed_in="2026-07-28",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
),
"lifecycle:initialize:instructions": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#initialization",
behavior="A server may include an instructions string in the initialize result; the client exposes it.",
removed_in="2026-07-28",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
),
"lifecycle:initialize:capabilities:from-handlers": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#capability-negotiation",
behavior=(
"The server advertises a capability for each feature area it has a registered handler for, "
"and omits the capability for areas it does not."
),
removed_in="2026-07-28",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
),
"lifecycle:initialize:capabilities:minimal": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#capability-negotiation",
behavior="A server with no feature handlers advertises no feature capabilities.",
removed_in="2026-07-28",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
),
"lifecycle:initialize:client-info": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#initialization",
behavior="The client's name, version, and title are visible to server handlers after initialization.",
removed_in="2026-07-28",
superseded_by="lifecycle:envelope:stamped-on-every-request",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
arm_exclusions=(ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),),
),
"lifecycle:initialize:client-capabilities": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#capability-negotiation",
behavior=(
"The client capabilities visible to the server reflect which client callbacks are configured "
"(sampling, elicitation, roots)."
),
removed_in="2026-07-28",
superseded_by="lifecycle:envelope:stamped-on-every-request",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
arm_exclusions=(ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),),
),
"lifecycle:initialized-notification": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#initialization",
behavior=(
"After successful initialization, the client sends exactly one initialized notification, "
"before any non-ping request."
),
removed_in="2026-07-28",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
),
"lifecycle:ping": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/ping#behavior-requirements",
behavior="ping in either direction returns an empty result.",
removed_in="2026-07-28",
note="removed in 2026-07-28 (SEP-2575); ping deleted from the schema, no replacement.",
),
"ping:client-to-server": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/ping#behavior-requirements",
behavior="A client-initiated ping receives an empty result from the server.",
removed_in="2026-07-28",
note="removed in 2026-07-28 (SEP-2575); ping deleted from the schema, no replacement.",
),
"ping:server-to-client": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/ping#behavior-requirements",
behavior="A server-initiated ping receives an empty result from the client.",
removed_in="2026-07-28",
note="removed in 2026-07-28 (SEP-2575); ping deleted from the schema, no replacement.",
arm_exclusions=(ArmExclusion(reason="server-initiated-request", transport="streamable-http-stateless"),),
),
"lifecycle:requests-before-initialized": Requirement(
source="sdk",
behavior=(
"A request other than ping sent before the initialization handshake completes is rejected with an error."
),
removed_in="2026-07-28",
note="initialize handshake removed at 2026-07-28; per-request _meta envelope replaces it.",
),
"lifecycle:pre-initialization-ordering": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#initialization",
behavior=(
"Before initialization completes, the client sends no requests other than pings, and the "
"server sends no requests other than pings and logging."
),
divergence=Divergence(
note=(
"The server's send methods (create_message / elicit_form / list_roots) do not check "
"initialization state before sending; on the client side, Client always completes the "
"handshake before any caller code runs."
),
),
deferred=(
"Not implemented in the SDK: neither side enforces sender-side restraint. The server's send "
"methods (create_message / elicit_form / list_roots) do not check initialization state before "
"sending, and there is no natural hook to issue a server-to-client request between the "
"initialize response and the initialized notification through the public API; on the client "
"side, Client always completes the handshake before any caller code runs."
),
),
"lifecycle:version:downgrade": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#version-negotiation",
behavior=(
"When the server returns an older supported protocol version, the client downgrades to it "
"and the connection succeeds at that version."
),
removed_in="2026-07-28",
note="initialize-time version negotiation removed at 2026-07-28; version carried per-request in _meta.",
),
"lifecycle:version:match": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#version-negotiation",
behavior=(
"When the server supports the requested protocol version it echoes that version in the "
"initialize result, and the connection proceeds at that version."
),
removed_in="2026-07-28",
note="initialize-time version negotiation removed at 2026-07-28; version carried per-request in _meta.",
),
"lifecycle:version:server-fallback-latest": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#version-negotiation",
behavior=(
"An initialize request carrying a protocol version the server does not support is answered "
"with another version the server supports — the latest one — rather than an error."
),
removed_in="2026-07-28",
note="initialize-time version negotiation removed at 2026-07-28; version carried per-request in _meta.",
),
"lifecycle:version:reject-unsupported": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#version-negotiation",
behavior=(
"A client that receives an initialize response carrying a protocol version it does not "
"support fails initialization with an error rather than proceeding with the session."
),
removed_in="2026-07-28",
note="initialize-time version negotiation removed at 2026-07-28; version carried per-request in _meta.",
),
"lifecycle:stateless:request-envelope": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/lifecycle#stateless-operation",
behavior=(
"At protocol_version 2026-07-28, every request carries io.modelcontextprotocol/protocolVersion "
"and /clientCapabilities in params._meta (/clientInfo is optional); no initialize handshake occurs."
),
added_in="2026-07-28",
),
"lifecycle:stateless:no-initialize": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/lifecycle#stateless-operation",
behavior=(
"A ClientSession pinned to 2026-07-28 is born initialized: initialize() is idempotent "
"and returns the synthesized result without any frame sent."
),
added_in="2026-07-28",
deferred="covered by a tests/client/ unit test; not observable as an interaction",
),
"lifecycle:stateless:caller-meta-preserved": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/lifecycle#stateless-operation",
behavior=(
"Caller-supplied _meta keys on a request survive the per-request envelope merge: the "
"three io.modelcontextprotocol/* envelope keys overwrite any caller-supplied values for "
"those keys; non-colliding caller keys are preserved."
),
added_in="2026-07-28",
),
"lifecycle:stateless:unpinned-legacy-wire": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/versioning",
behavior=(
"An unpinned session that negotiates an earlier protocol version emits no 2026-07-28 "
"vocabulary on any JSON-RPC frame in either direction."
),
deferred=(
"bare-ClientSession seam; the high-level Client + HTTP-seam scan in "
"hosting:http:legacy-no-modern-vocabulary covers the same vocabulary set"
),
),
"lifecycle:envelope:stamped-on-every-request": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic#_meta",
behavior=(
"Every client→server request on a modern-negotiated session carries "
"_meta.{protocolVersion,clientInfo,clientCapabilities}; notifications do not."
),
added_in="2026-07-28",
supersedes=("lifecycle:initialize:client-info", "lifecycle:initialize:client-capabilities"),
),
"lifecycle:envelope:header-matches-meta": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/transports/streamable-http#headers",
behavior="On HTTP, the MCP-Protocol-Version header on every POST matches _meta.protocolVersion in the body.",
transports=("streamable-http", "streamable-http-stateless"),
added_in="2026-07-28",
note="HTTP-only: the header is a streamable-http transport concern; stdio and in-memory carry no headers.",
),
"lifecycle:discover:basic": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/lifecycle#discover",
behavior=(
"Calling discover() sends server/discover with no params and returns a typed DiscoverResult "
"carrying supportedVersions, capabilities and the cache hint fields; the server's identity "
"travels as the io.modelcontextprotocol/serverInfo stamp in the result _meta."
),
added_in="2026-07-28",
),
"lifecycle:discover:retry-on-32022": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/lifecycle#version-errors",
behavior=(
"When server/discover returns -32022 UnsupportedProtocolVersion, the client retries once with "
"the intersection of error.data.supported and its own modern versions; an empty intersection raises."
),
added_in="2026-07-28",
),
"lifecycle:discover:fallback-method-not-found": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/transports/stdio#backward-compatibility",
behavior=(
"When server/discover returns any JSON-RPC error or a bare HTTP 4xx, an auto-negotiating "
"client falls back to the legacy initialize handshake and the connection succeeds at a "
"handshake-era version (legacy servers reject the probe with various codes)."
),
added_in="2026-07-28",
),
"lifecycle:discover:network-error-raises": Requirement(
source="sdk",
behavior=(
"A network/connection error during server/discover propagates to the caller without "
"falling back to initialize; any rpc-error or 4xx falls back (legacy servers reject the "
"probe with various codes). An outage is never an era verdict."
),
transports=("streamable-http", "streamable-http-stateless"),
added_in="2026-07-28",
note="HTTP-only: distinguishes transport-level failures from server-side rejection.",
),
"lifecycle:mode:legacy-never-probes": Requirement(
source="sdk",
behavior=(
"A Client constructed with mode='legacy' sends initialize as its first request "
"and never sends server/discover."
),
added_in="2026-07-28",
),
"lifecycle:mode:pin-never-handshakes": Requirement(
source="sdk",
behavior=(
"A Client constructed with mode='2026-07-28' sends no initialize and no server/discover; its "
"first wire request is the caller's first call, carrying the full _meta envelope."
),
added_in="2026-07-28",
),
"lifecycle:mode:prior-discover-zero-rtt": Requirement(
source="sdk",
behavior=(
"A Client constructed with prior_discover=<DiscoverResult> sends no negotiation traffic; "
"server_info and capabilities are populated from the prior result."
),
added_in="2026-07-28",
),
# ═══════════════════════════════════════════════════════════════════════════
# Protocol primitives: cancellation, timeout, progress, errors, _meta
# ═══════════════════════════════════════════════════════════════════════════
"protocol:request-id:unique": Requirement(
source=f"{SPEC_BASE_URL}/basic#requests",
behavior=(
"Every request sent on a session carries a unique, non-null string or integer id; ids are "
"never reused within the session."
),
),
"protocol:request-id:caller-supplied": Requirement(
source="sdk",
behavior=(
"A caller can supply the id of a request it sends, so the id is known before any response "
"arrives; subscriptions/listen streams are demultiplexed by exactly that id."
),
note=(
f"The demux-by-listen-request-id obligation is the spec's "
f"({SPEC_2026_BASE_URL}/basic/patterns/subscriptions#receiving-notifications); supplying the "
"id up front is the SDK surface that makes it satisfiable."
),
added_in="2026-07-28",
),
"protocol:notifications:no-response": Requirement(
source=f"{SPEC_BASE_URL}/basic#notifications",
behavior=(
"Notifications are never answered: every message the server delivers is either the response "
"to a request the client sent or a notification carrying no id."
),
),
"protocol:cancel:abort-signal": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#cancellation-flow",
behavior=(
"Abandoning an in-flight request client-side (cancelling the task awaiting it) cancels the "
"request itself: the server-side handler stops and the session serves later requests "
"normally."
),
note=(
"The per-transport wire spelling (frame vs response-stream close) is pinned separately by "
"protocol:cancel:stream-frame and the client-transport:http:cancel-* pair."
),
arm_exclusions=(
ArmExclusion(
reason="requires-session",
transport="streamable-http-stateless",
note=(
"The 2025-era cancel frame POSTs on a fresh per-request transport that shares no "
"in-flight state with the blocked request, so the handler is never interrupted."
),
),
),
),
"protocol:cancel:abort-scoped": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#behavior-requirements",
behavior=(
"Abandoning one in-flight request cancels only that request: a concurrent request on the "
"same connection keeps running and returns its result."
),
arm_exclusions=(ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),),
),
"protocol:cancel:handler-abort-propagates": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#behavior-requirements",
behavior="On the receiving side, a cancellation notification stops the running request handler.",
arm_exclusions=(
ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),
ArmExclusion(reason="requires-session", spec_version="2026-07-28"),
),
),
"protocol:cancel:in-flight": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#behavior-requirements",
behavior=(
"A cancellation notification for an in-flight request stops the server-side handler, and the "
"receiver does not send a response for the cancelled request."
),
divergence=Divergence(
note=(
"The spec says receivers of a cancellation SHOULD NOT send a response for the cancelled "
"request; both seats send an error response (code 0, 'Request cancelled') instead — the "
"server for cancelled client requests, and the client for cancelled server-initiated "
"requests — which is what unblocks the sender's pending call."
),
),
arm_exclusions=(
ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),
ArmExclusion(reason="requires-session", spec_version="2026-07-28"),
),
),
"protocol:cancel:initialize-not-cancellable": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#behavior-requirements",
behavior="The client never sends notifications/cancelled for the initialize request.",
),
"protocol:cancel:late-response-ignored": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#behavior-requirements",
behavior=(
"A response that arrives after the sender issued notifications/cancelled is ignored; the "
"request stays failed and no error is raised."
),
),
"protocol:cancel:server-survives": Requirement(
source="sdk",
behavior="The session continues to serve new requests after an earlier request was cancelled.",
arm_exclusions=(
ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),
ArmExclusion(reason="requires-session", spec_version="2026-07-28"),
),
),
"protocol:cancel:server-to-client": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#behavior-requirements",
behavior=(
"A server that abandons an in-flight server-initiated request (sampling, elicitation, roots) "
"cancels it, and the client stops processing the cancelled request."
),
arm_exclusions=(
ArmExclusion(reason="server-initiated-request", transport="streamable-http-stateless"),
ArmExclusion(reason="server-initiated-request", spec_version="2026-07-28"),
),
),
"protocol:cancel:stream-frame": Requirement(
source=f"{SPEC_2026_BASE_URL}/basic/patterns/cancellation#transport-specific-cancellation",
behavior=(
"On stream (stdio-shaped) wires at 2026-07-28, abandoning an in-flight request sends exactly "
"one notifications/cancelled naming its request id - streams keep the frame spelling of "
"cancellation that streamable HTTP dropped."
),
added_in="2026-07-28",
note="Exercised over the in-memory stream pair, the same dual-era wire stdio serves.",
),
"protocol:cancel:unknown-id-ignored": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#error-handling",
behavior=(
"The receiver silently ignores a cancellation notification referencing an unknown or "
"already-completed request id; no error response is sent and no exception is raised."
),
),
"protocol:cancel:sender-targeting": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/cancellation#behavior-requirements",
behavior=(
"Cancellation notifications reference only requests that were previously issued in the same "
"direction and are believed to still be in flight."
),
deferred=(
"Not implemented in the SDK: there is no public client-side cancel API to drive (see "
"protocol:cancel:abort-signal), so the sender-side targeting rule has nothing to pin."
),
),
"protocol:error:connection-closed": Requirement(
source="sdk",
behavior="Closing the transport fails all in-flight requests with a connection-closed error.",
),
"protocol:error:internal-error": Requirement(
source=f"{SPEC_BASE_URL}/basic#responses",
behavior=(
"An unhandled exception in a request handler is returned to the caller as JSON-RPC error "
"-32603 Internal error."
),
divergence=Divergence(
note=(
"The low-level Server returns code 0 (not a defined JSON-RPC code) instead of -32603 and "
"leaks str(exc) as the error message."
),
),
arm_exclusions=(
ArmExclusion(
reason="modern-error-surface",
spec_version="2026-07-28",
note=(
"The modern entry maps Exception->INTERNAL_ERROR (-32603) with an opaque message, so the "
"2026 arm SATISFIES this requirement; the test pins the legacy code-0 divergence and "
"needs an era-aware assertion before re-admission."
),
),
),
),
"protocol:error:invalid-params": Requirement(
source=f"{SPEC_BASE_URL}/basic#responses",
behavior="A request with malformed params is answered with JSON-RPC error -32602 Invalid params.",
),
"protocol:error:method-not-found": Requirement(
source=f"{SPEC_BASE_URL}/basic#responses",
behavior="A request whose method has no registered handler is answered with a METHOD_NOT_FOUND error.",
),
"protocol:error:null-id": Requirement(
source="sdk",
behavior=(
"An error response carrying a null id — the JSON-RPC shape for a peer reporting a failure it "
"could not attribute to a request, such as a parse error — is surfaced to the application "
"rather than silently discarded."
),
divergence=Divergence(
note=(
"The dispatcher drops null-id error responses with a debug log; in v1, JSONRPCError.id was "
"non-nullable, so a null-id error response failed transport validation and the resulting "
"ValidationError was surfaced to message_handler as an exception. A typed fault channel "
"restoring visibility is planned before v2 stable."
),
),
deferred=(
"Not yet covered here: the current drop is pinned at the dispatcher level by "
"tests/shared/test_jsonrpc_dispatcher.py; an interaction-level test waits on the planned "
"fault channel."
),
),
"protocol:meta:related-task": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/tasks#related-task-metadata",
behavior="Messages may carry related-task _meta associating them with a task.",
deferred=_TASKS_DEFERRAL,
removed_in="2026-07-28",
note=(
"removed in 2026-07-28 (SEP-2663); tasks moved out of core into the io.modelcontextprotocol/tasks "
"extension."
),
),
"meta:request-to-handler": Requirement(
source=f"{SPEC_BASE_URL}/basic#_meta",
behavior="The _meta object the client attaches to a request is visible to the server handler.",
arm_exclusions=(ArmExclusion(reason="asserts-legacy-handshake", spec_version="2026-07-28"),),
),
"meta:result-to-client": Requirement(
source=f"{SPEC_BASE_URL}/basic#_meta",
behavior="The _meta object a handler attaches to its result is delivered to the client.",
),
"protocol:progress:callback": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/progress#progress-flow",
behavior=(
"Progress notifications emitted by a handler during a request are delivered to the caller's "
"progress callback, in order, with their progress, total, and message."
),
),
"protocol:progress:token-injected": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/progress#progress-flow",
behavior=(
"Supplying a progress callback attaches a progress token to the outgoing request, which the "
"server-side handler can observe in its request metadata."
),
arm_exclusions=(ArmExclusion(reason="asserts-legacy-handshake", spec_version="2026-07-28"),),
),
"protocol:progress:token-unique": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/progress#progress-flow",
behavior=("Concurrent in-flight requests that each supply a progress callback carry distinct progress tokens."),
note=(
"Tested as the consequence: each callback receives only its own request's progress under "
"interleaved emission. Token distinctness is the JSON-RPC mechanism for that; the in-process "
"direct dispatcher carries the callback per-request without a wire-level token."
),
),
"protocol:progress:monotonic": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/progress#progress-flow",
behavior=(
"The progress value increases with each notification for a given token, even when the total is unknown."
),
divergence=Divergence(
note=(
"The spec MUST is not enforced: progress values are not validated on either side, so a "
"handler that emits non-increasing values has them forwarded to the callback unchanged."
),
),
),
"protocol:progress:stops-after-completion": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/progress#behavior-requirements",
behavior="Progress notifications for a token stop once the associated request completes.",
divergence=Divergence(
note=(
"send_progress_notification does not check whether the token's request has already "
"completed; the late notification is sent and reaches the client."
),
),
arm_exclusions=(
ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),
ArmExclusion(reason="requires-session", spec_version="2026-07-28"),
),
),
"protocol:progress:late-dropped-by-client": Requirement(
source="sdk",
behavior=(
"A progress notification that arrives after its request has completed is not delivered to the "
"original progress callback."
),
arm_exclusions=(
ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),
ArmExclusion(reason="requires-session", spec_version="2026-07-28"),
),
),
"protocol:progress:no-token": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/progress#progress-flow",
behavior="Without a progress callback the request carries no progress token.",
),
"protocol:progress:client-to-server": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/progress#progress-flow",
behavior="A progress notification sent by the client is delivered to the server's progress handler.",
arm_exclusions=(ArmExclusion(reason="requires-session", spec_version="2026-07-28"),),
),
"protocol:timeout:basic": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#timeouts",
behavior=(
"A request that exceeds its read timeout fails with a request-timeout error instead of "
"waiting forever for the response."
),
),
"protocol:timeout:max-total": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#timeouts",
behavior="A maximum total timeout is enforced even when progress notifications keep arriving.",
divergence=Divergence(
note=(
"There is no maximum-total-timeout option; only the per-request read timeout exists, so the "
"spec's SHOULD that an overall maximum is always enforced cannot be satisfied."
),
),
deferred=(
"Not implemented in the SDK: there is no maximum-total-timeout option; only the per-request "
"read timeout exists."
),
),
"protocol:timeout:reset-on-progress": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#timeouts",
behavior="When configured to do so, each progress notification resets the request's read timeout.",
deferred=(
"Not implemented in the SDK: progress notifications do not reset the request read timeout and "
"no option exists to enable that."
),
),
"protocol:timeout:sends-cancellation": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#timeouts",
behavior=(
"When a request times out, the sender issues notifications/cancelled for that request before "
"failing the local call."
),
),
"protocol:timeout:session-survives": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#timeouts",
behavior="The session continues to serve new requests after an earlier request timed out.",
),
"protocol:timeout:session-default": Requirement(
source=f"{SPEC_BASE_URL}/basic/lifecycle#timeouts",
behavior="A session-level read timeout applies to every request that does not override it.",
),
# ═══════════════════════════════════════════════════════════════════════════
# Tools
# ═══════════════════════════════════════════════════════════════════════════
"tools:call:content:audio": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#audio-content",
behavior="A tool result can carry audio content: base64 data with a mimeType.",
),
"tools:call:content:embedded-resource": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#embedded-resources",
behavior="A tool result can carry an embedded resource with full text or blob contents.",
),
"tools:call:content:image": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#image-content",
behavior="A tool result can carry image content: base64 data with a mimeType.",
),
"tools:call:content:mixed": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#tool-result",
behavior="A tool result can carry multiple content blocks of different types; order is preserved.",
),
"tools:call:content:resource-link": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#resource-links",
behavior="A tool result can carry a resource_link content block referencing a resource by URI.",
),
"tools:call:content:text": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#text-content",
behavior="tools/call delivers arguments to the tool handler and returns its text content to the caller.",
),
"tools:call:concurrent": Requirement(
source="sdk",
behavior=(
"Multiple tool calls in flight on one session are dispatched concurrently, and each caller "
"receives the response to its own request."
),
),
"tools:call:elicitation-roundtrip": Requirement(
source=f"{SPEC_BASE_URL}/client/elicitation#user-interaction-model",
behavior=(
"A tool handler that issues an elicitation receives the client's result and can embed it in "
"the tool call result."
),
arm_exclusions=(
ArmExclusion(reason="server-initiated-request", transport="streamable-http-stateless"),
ArmExclusion(reason="server-initiated-request", spec_version="2026-07-28"),
),
),
"tools:call:is-error": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#error-handling",
behavior=(
"A tool execution failure is returned as a result with isError true and the failure described "
"in content, not as a JSON-RPC error."
),
),
"tools:call:logging-mid-execution": Requirement(
source=f"{SPEC_BASE_URL}/server/utilities/logging#log-message-notifications",
behavior=(
"Log notifications emitted by a tool handler during execution reach the client's logging "
"callback before the tool result returns."
),
),
"tools:call:progress": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/progress#progress-flow",
behavior=(
"Progress notifications emitted by a tool handler reach the caller's progress callback before "
"the tool result returns."
),
),
"tools:call:sampling-roundtrip": Requirement(
source=f"{SPEC_BASE_URL}/client/sampling#creating-messages",
behavior=(
"A tool handler that issues a sampling request receives the client's completion and can embed "
"it in the tool call result."
),
arm_exclusions=(
ArmExclusion(reason="server-initiated-request", transport="streamable-http-stateless"),
ArmExclusion(reason="server-initiated-request", spec_version="2026-07-28"),
),
),
"tools:call:structured-content": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#structured-content",
behavior="A tool result can carry structuredContent alongside content; the client receives both.",
),
"tools:call:structured-content:text-mirror": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#structured-content",
behavior="A tool returning structured content also returns the serialized JSON as a text content block.",
),
"tools:call:unknown-name": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#error-handling",
behavior="tools/call for a name the server does not recognise returns a JSON-RPC error.",
),
"tools:capability:declared": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#capabilities",
behavior="A server with a list_tools handler advertises the tools capability in its initialize result.",
arm_exclusions=(ArmExclusion(reason="legacy-only-vocabulary", spec_version="2026-07-28"),),
),
"tools:input-schema:json-schema-2020-12": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#tool",
behavior=(
"A tool registered with a JSON Schema 2020-12 inputSchema (nested objects, $defs references) "
"is discoverable and callable."
),
),
"tools:input-schema:preserve-additional-properties": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#tool",
behavior="tools/list preserves inputSchema additionalProperties as registered.",
),
"tools:input-schema:preserve-defs": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#tool",
behavior="tools/list preserves inputSchema $defs as registered.",
),
"tools:input-schema:preserve-schema-dialect": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#tool",
behavior="tools/list preserves the inputSchema $schema dialect URI as registered.",
),
"tools:list-changed": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#list-changed-notification",
behavior=(
"When the tool set changes, the server sends notifications/tools/list_changed and it reaches "
"the client's handler."
),
arm_exclusions=(
ArmExclusion(reason="requires-session", transport="streamable-http-stateless"),
ArmExclusion(reason="requires-session", spec_version="2026-07-28"),
),
),
"tools:list:basic": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#listing-tools",
behavior="tools/list returns the registered tools with name, description, and inputSchema.",
),
"tools:list:metadata": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#tool",
behavior=(
"Optional Tool fields supplied by the server (title, annotations, outputSchema, icons, _meta) "
"are delivered to the client unchanged."
),
),
"tools:list:pagination": Requirement(
source=f"{SPEC_BASE_URL}/server/utilities/pagination#response-format",
behavior=(
"tools/list supports cursor pagination: the nextCursor returned by a list handler round-trips "
"back to the handler as an opaque cursor until the listing is exhausted."
),
),
# ═══════════════════════════════════════════════════════════════════════════
# Tools: SDK guarantees
# ═══════════════════════════════════════════════════════════════════════════
"client:output-schema:skip-on-error": Requirement(
source="sdk",
behavior="The client skips structured-content validation when the tool result has isError true.",
),
"client:output-schema:validate": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#output-schema",
behavior=(
"A tool result whose structuredContent does not conform to the tool's declared outputSchema "
"is rejected by the client: the call raises instead of returning the invalid result."
),
),
"client:output-schema:missing-structured": Requirement(
source="sdk",
behavior="A tool that declares an output schema but returns no structuredContent fails client-side validation.",
),
"client:output-schema:auto-list": Requirement(
source="sdk",
behavior=(
"Calling a tool whose output schema is not yet cached issues an implicit tools/list to "
"populate the cache; subsequent calls of the same tool do not."
),
divergence=Divergence(
note=(
"Design concern rather than spec violation: the implicit request is invisible to the "
"caller, and against a server that registers only on_call_tool a successful call surfaces "
"as METHOD_NOT_FOUND from a tools/list the caller never asked for."
),
),
),
"mcpserver:output-schema:missing-structured": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#output-schema",
behavior="A tool with an output schema whose function returns no structured content produces a server error.",
),
"mcpserver:output-schema:server-validate": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#output-schema",
behavior=(
"MCPServer validates structured content against the tool's output schema before returning; a "
"mismatch produces a server error."
),
),
"mcpserver:output-schema:skip-on-error": Requirement(
source="sdk",
behavior="Server-side output schema validation is skipped when the tool returns an isError result.",
),
"mcpserver:tool:duplicate-name": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#tool-names",
behavior="Registering a tool with a name already in use is rejected at registration time.",
divergence=Divergence(
note=(
"MCPServer logs a warning and keeps the first registration instead of rejecting; "
"warn_on_duplicate_tools defaults to True and warning is the only effect -- there is "
"no rejection mode."
),