forked from modelcontextprotocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_requirements.py
More file actions
2822 lines (2791 loc) · 143 KB
/
Copy path_requirements.py
File metadata and controls
2822 lines (2791 loc) · 143 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
from dataclasses import dataclass
from typing import Literal, TypeVar
import pytest
SPEC_REVISION = "2025-11-25"
SPEC_BASE_URL = f"https://modelcontextprotocol.io/specification/{SPEC_REVISION}"
Transport = Literal["in-memory", "stdio", "streamable-http", "sse"]
_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 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
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}")
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."
),
),
"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.",
),
"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.",
),
"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."
),
),
"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.",
),
"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.",
),
"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)."
),
),
"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."
),
),
"lifecycle:ping": Requirement(
source=f"{SPEC_BASE_URL}/basic/utilities/ping#behavior-requirements",
behavior="ping in either direction returns an empty result.",
),
"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.",
),
"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.",
),
"lifecycle:requests-before-initialized": Requirement(
source="sdk",
behavior=(
"A request other than ping sent before the initialization handshake completes is rejected with an error."
),
),
"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."
),
),
"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."
),
),
"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."
),
),
"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."
),
),
# ═══════════════════════════════════════════════════════════════════════════
# 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: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=(
"Cancelling an in-flight request through the client API sends notifications/cancelled with "
"the request id and fails the local call."
),
deferred=(
"Not implemented in the SDK: there is no public client-side API to cancel an in-flight "
"request; cancellation requires hand-constructing the notification (which is how "
"protocol:cancel:in-flight exercises the receiving side)."
),
),
"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.",
),
"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; the server sends an error response (code 0, 'Request cancelled'), which is what "
"unblocks the SDK client's pending call."
),
),
),
"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.",
deferred=(
"Not implemented in the SDK: the client has no public cancellation API at all, so no pathway "
"exists that could cancel initialize; there is no distinct behaviour to pin beyond that absence."
),
),
"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."
),
divergence=Divergence(
note=(
"A response whose id matches no in-flight request is delivered to the message handler "
"as a RuntimeError rather than being silently ignored. The post-cancellation case is the "
"same code path; tested in its unknown-id form because that is deterministic without the "
"client-side cancellation API the SDK does not yet provide."
),
),
),
"protocol:cancel:server-survives": Requirement(
source="sdk",
behavior="The session continues to serve new requests after an earlier request was cancelled.",
),
"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."
),
divergence=Divergence(
note=(
"Abandoning a server-side send_request emits no cancellation notification, and the client "
"could not act on one anyway: client callbacks run inline in the receive loop, so a "
"cancellation is not even read until the callback has finished."
),
),
deferred=(
"Not implemented in the SDK: abandoning a server-side send_request emits no cancellation "
"notification (the same sender-side gap recorded on protocol:timeout:sends-cancellation), and "
"the client could not act on one anyway because client callbacks run inline in the receive "
"loop, so a cancellation would not even be read until the callback had already finished."
),
),
"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."
),
),
),
"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: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,
),
"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.",
),
"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."
),
),
"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."),
),
"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."
),
),
),
"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."
),
),
"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.",
),
"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."
),
divergence=Divergence(
note=(
"The client only raises locally and sends nothing on timeout, so the server keeps running the handler."
),
),
),
"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."
),
),
"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."
),
),
"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.",
),
"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."
),
),
"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:cache-hints": Requirement(
source="issue:#2802",
behavior="tools/list responses include SEP-2549 cache hints on the wire.",
transports=("in-memory",),
),
"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."
),
),
),
"mcpserver:tool:extra": Requirement(
source="sdk",
behavior=(
"Tool functions can access request metadata (request id, client params, session) through the "
"Context parameter."
),
),
"mcpserver:tool:handler-throws": Requirement(
source="sdk",
behavior=(
"An exception raised by a tool function (ToolError or otherwise) is caught and returned as a "
"tool result with isError true and the failure text in content; it does not become a JSON-RPC error."
),
),
"mcpserver:tool:input-validation": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#error-handling",
behavior=(
"Arguments that fail the tool's input validation produce a tool execution error (isError true "
"with the validation failure described in content) without invoking the function."
),
),
"mcpserver:tool:naming-validation": Requirement(
source="sdk",
behavior=(
"Registering a tool whose name violates the spec's tool-naming conventions emits a warning; "
"registration still succeeds."
),
),
"mcpserver:tool:output-schema:model": Requirement(
source="sdk",
behavior=(
"A tool returning a typed model advertises a matching generated outputSchema and returns the "
"model's fields as structuredContent alongside a serialised text block."
),
),
"mcpserver:tool:output-schema:wrapped": Requirement(
source="sdk",
behavior=(
"A tool returning a non-object type (primitive or list) wraps the value as {'result': ...} in "
"structuredContent, with a matching generated outputSchema."
),
),
"mcpserver:tool:schema-variants": Requirement(
source="sdk",
behavior=(
"Tool input schemas generated from complex parameter types (unions, nested models, "
"constrained types) validate and coerce arguments before the function runs."
),
),
"mcpserver:tool:unknown-name": Requirement(
source=f"{SPEC_BASE_URL}/server/tools#error-handling",
behavior="tools/call for a name that was never registered returns a JSON-RPC error.",
divergence=Divergence(
note=(
"The spec classifies unknown tools as a protocol error (its example uses -32602 Invalid "
"params); MCPServer reports a tool execution error (isError true) instead. The low-level "
"path follows the spec example (see tools:call:unknown-name)."
),
),
),
"mcpserver:tool:url-elicitation-error": Requirement(
source="sdk",
behavior=(
"A tool function that raises the URL-elicitation-required error surfaces to the caller as "
"error -32042 with the elicitation parameters intact."
),
),
# ═══════════════════════════════════════════════════════════════════════════
# MCPServer: Context helpers (SDK)
# ═══════════════════════════════════════════════════════════════════════════
"mcpserver:context:logging": Requirement(
source="sdk",
behavior=(
"The Context logging helpers (debug/info/warning/error) send log message notifications at the "
"corresponding severity."
),
),
"mcpserver:context:progress": Requirement(
source="sdk",
behavior=(
"Context.report_progress sends a progress notification against the requesting client's progress token."
),
),
"mcpserver:context:elicit": Requirement(
source="sdk",
behavior=(
"Context.elicit sends a form elicitation built from a typed schema and returns a typed "
"accepted/declined/cancelled result."
),
),
"mcpserver:context:read-resource": Requirement(
source="sdk",
behavior="Context.read_resource reads a resource registered on the same server from inside a tool.",
),
# ═══════════════════════════════════════════════════════════════════════════
# Resources
# ═══════════════════════════════════════════════════════════════════════════
"resources:annotations": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#annotations",
behavior="Resource annotations supplied by the server round-trip to the client in the list result.",
divergence=Divergence(
note=(
"The SDK Annotations model is missing the schema's lastModified field; MCPModel uses the "
"pydantic default extra='ignore', so the value is silently dropped on parse."
),
),
),
"resources:capability:declared": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#capabilities",
behavior=(
"A server with resource handlers advertises the resources capability, including the subscribe "
"sub-flag when a subscribe handler is registered."
),
),
"resources:list-changed": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#list-changed-notification",
behavior=(
"When the resource set changes, the server sends notifications/resources/list_changed and it "
"reaches the client's handler."
),
),
"resources:list:basic": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#listing-resources",
behavior=(
"resources/list returns the registered resources with uri, name, and the optional descriptive "
"fields supplied by the server."
),
),
"resources:list:pagination": Requirement(
source=f"{SPEC_BASE_URL}/server/utilities/pagination#operations-supporting-pagination",
behavior="resources/list supports cursor pagination.",
),
"resources:read:blob": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#reading-resources",
behavior="resources/read returns binary contents base64-encoded in blob.",
),
"resources:read:template-vars": Requirement(
source="sdk",
behavior="Variables extracted from a templated resource URI reach the resource function as typed arguments.",
),
"resources:read:text": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#reading-resources",
behavior="resources/read returns text contents carrying uri, mimeType, and the text.",
),
"resources:read:unknown-uri": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#error-handling",
behavior="resources/read for an unknown URI returns JSON-RPC error -32002 (resource not found).",
),
"resources:subscribe": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#subscriptions",
behavior="resources/subscribe delivers the URI to the server's subscribe handler and returns an empty result.",
),
"resources:subscribe:capability-required": Requirement(
source="sdk",
behavior=(
"resources/subscribe to a server that did not advertise the subscribe capability is rejected with an error."
),
),
"resources:subscribe:updated": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#subscriptions",
behavior="After resources/subscribe, changes to that resource send notifications/resources/updated.",
deferred=(
"Not implemented in the SDK: the server keeps no subscription state linking subscribe to "
"updated notifications; emitting updates is entirely handler code. The two halves are pinned "
"separately by resources:subscribe and resources:updated-notification."
),
),
"resources:templates:list": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#resource-templates",
behavior=(
"resources/templates/list returns the registered templates with their uriTemplate and descriptive fields."
),
),
"resources:templates:pagination": Requirement(
source=f"{SPEC_BASE_URL}/server/utilities/pagination#operations-supporting-pagination",
behavior="resources/templates/list supports cursor pagination.",
),
"resources:unsubscribe": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#subscriptions",
behavior=(
"resources/unsubscribe delivers the URI to the server's unsubscribe handler and returns an empty result."
),
),
"resources:unsubscribe:stops-updates": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#subscriptions",
behavior="After resources/unsubscribe the server stops sending updated notifications for that URI.",
deferred=(
"Not implemented in the SDK: the server keeps no subscription state, so whether updated "
"notifications stop after unsubscribe is entirely handler code; there is no SDK behaviour to "
"pin beyond the unsubscribe request reaching the handler (covered by resources:unsubscribe)."
),
),
"resources:updated-notification": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#subscriptions",
behavior=(
"A resources/updated notification sent by the server reaches the client carrying the URI of "
"the changed resource."
),
),
# ═══════════════════════════════════════════════════════════════════════════
# Resources: SDK guarantees
# ═══════════════════════════════════════════════════════════════════════════
"mcpserver:resource:duplicate-name": Requirement(
source="sdk",
behavior="Registering a resource or template with a duplicate identifier is rejected at registration time.",
divergence=Divergence(
note=(
"MCPServer logs a warning and keeps the first registration instead of rejecting; same "
"warn-and-ignore behaviour as duplicate tool names (mcpserver:tool:duplicate-name). "
"Templates differ: a duplicate uri_template silently replaces the first with no warning."
),
),
),
"mcpserver:resource:read-throws-surfaced": Requirement(
source="sdk",
behavior="A resource function that raises is surfaced to the caller as a JSON-RPC error response.",
),
"mcpserver:resource:static": Requirement(
source="sdk",
behavior=(
"A function registered with @mcp.resource() for a fixed URI is listed by resources/list and "
"served by resources/read at that URI."
),
),
"mcpserver:resource:template": Requirement(
source="sdk",
behavior=(
"A function registered with a URI template is listed by resources/templates/list and matched "
"by resources/read, receiving the parameters extracted from the requested URI."
),
),
"mcpserver:resource:unknown-uri": Requirement(
source=f"{SPEC_BASE_URL}/server/resources#error-handling",
behavior="resources/read for a URI matching no registered resource returns JSON-RPC error -32002.",
divergence=Divergence(
note=(
"The spec reserves -32002 for resource-not-found; MCPServer raises ResourceError, which "
"the low-level server converts to error code 0."
),
),
),
# ═══════════════════════════════════════════════════════════════════════════
# Prompts
# ═══════════════════════════════════════════════════════════════════════════
"prompts:capability:declared": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#capabilities",
behavior="A server with a list_prompts handler advertises the prompts capability in its initialize result.",
),
"prompts:get:content:audio": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#audio-content",
behavior="Prompt messages may contain audio content with base64 data and a mimeType.",
),
"prompts:get:content:embedded-resource": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#embedded-resources",
behavior="Prompt messages may contain embedded resource content.",
),
"prompts:get:content:image": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#image-content",
behavior="Prompt messages may contain image content.",
),
"prompts:get:missing-required-args": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#error-handling",
behavior="prompts/get omitting a required argument returns JSON-RPC error -32602 (Invalid params).",
divergence=Divergence(
note=(
"MCPServer's prompt renderer raises a plain ValueError before the prompt function runs, "
"which the low-level server converts to error code 0 with the exception text as the message."
),
),
),
"prompts:get:multi-message": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#getting-a-prompt",
behavior="A prompt can return multiple messages mixing user and assistant roles; order is preserved.",
),
"prompts:get:no-args": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#getting-a-prompt",
behavior="prompts/get with no arguments returns the prompt's messages.",
),
"prompts:get:unknown-name": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#error-handling",
behavior="prompts/get for an unknown prompt name returns JSON-RPC error -32602 (Invalid params).",
),
"prompts:get:with-args": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#getting-a-prompt",
behavior="prompts/get delivers the supplied arguments to the prompt handler and returns its messages.",
),
"prompts:list-changed": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#list-changed-notification",
behavior=(
"When the prompt set changes, the server sends notifications/prompts/list_changed and it "
"reaches the client's handler."
),
),
"prompts:list:basic": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#listing-prompts",
behavior="prompts/list returns the registered prompts with name, description, and argument declarations.",
),
"prompts:list:pagination": Requirement(
source=f"{SPEC_BASE_URL}/server/utilities/pagination#operations-supporting-pagination",
behavior="prompts/list supports cursor pagination.",
),
# ═══════════════════════════════════════════════════════════════════════════
# Prompts: SDK guarantees
# ═══════════════════════════════════════════════════════════════════════════
"mcpserver:prompt:args-validation": Requirement(
source=f"{SPEC_BASE_URL}/server/prompts#implementation-considerations",
behavior="prompts/get arguments that fail the prompt's argument schema are rejected before the function runs.",
),
"mcpserver:prompt:decorated": Requirement(
source="sdk",
behavior=(
"A function registered with @mcp.prompt() is listed with arguments derived from its signature "
"and rendered into prompt messages by prompts/get."
),
),
"mcpserver:prompt:duplicate-name": Requirement(
source="sdk",
behavior="Registering a duplicate prompt name is rejected at registration time.",
divergence=Divergence(
note=(
"MCPServer logs a warning and keeps the first registration instead of rejecting; same "
"warn-and-ignore behaviour as duplicate tool names (mcpserver:tool:duplicate-name)."
),
),
),
"mcpserver:prompt:optional-args": Requirement(