wcgw 5.0.1__py3-none-any.whl → 5.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of wcgw might be problematic. Click here for more details.

Files changed (39) hide show
  1. wcgw/client/bash_state/bash_state.py +2 -2
  2. wcgw/client/diff-instructions.txt +2 -2
  3. wcgw/client/file_ops/diff_edit.py +14 -2
  4. wcgw/client/file_ops/extensions.py +137 -0
  5. wcgw/client/file_ops/search_replace.py +1 -2
  6. wcgw/client/mcp_server/server.py +10 -18
  7. wcgw/client/memory.py +4 -1
  8. wcgw/client/tool_prompts.py +16 -15
  9. wcgw/client/tools.py +99 -39
  10. {wcgw-5.0.1.dist-info → wcgw-5.1.0.dist-info}/METADATA +2 -1
  11. wcgw-5.1.0.dist-info/RECORD +37 -0
  12. wcgw_cli/anthropic_client.py +8 -4
  13. wcgw_cli/openai_client.py +7 -3
  14. mcp_wcgw/__init__.py +0 -114
  15. mcp_wcgw/client/__init__.py +0 -0
  16. mcp_wcgw/client/__main__.py +0 -79
  17. mcp_wcgw/client/session.py +0 -234
  18. mcp_wcgw/client/sse.py +0 -142
  19. mcp_wcgw/client/stdio.py +0 -128
  20. mcp_wcgw/py.typed +0 -0
  21. mcp_wcgw/server/__init__.py +0 -514
  22. mcp_wcgw/server/__main__.py +0 -50
  23. mcp_wcgw/server/models.py +0 -16
  24. mcp_wcgw/server/session.py +0 -288
  25. mcp_wcgw/server/sse.py +0 -178
  26. mcp_wcgw/server/stdio.py +0 -83
  27. mcp_wcgw/server/websocket.py +0 -61
  28. mcp_wcgw/shared/__init__.py +0 -0
  29. mcp_wcgw/shared/context.py +0 -14
  30. mcp_wcgw/shared/exceptions.py +0 -9
  31. mcp_wcgw/shared/memory.py +0 -87
  32. mcp_wcgw/shared/progress.py +0 -40
  33. mcp_wcgw/shared/session.py +0 -288
  34. mcp_wcgw/shared/version.py +0 -3
  35. mcp_wcgw/types.py +0 -1060
  36. wcgw-5.0.1.dist-info/RECORD +0 -58
  37. {wcgw-5.0.1.dist-info → wcgw-5.1.0.dist-info}/WHEEL +0 -0
  38. {wcgw-5.0.1.dist-info → wcgw-5.1.0.dist-info}/entry_points.txt +0 -0
  39. {wcgw-5.0.1.dist-info → wcgw-5.1.0.dist-info}/licenses/LICENSE +0 -0
mcp_wcgw/types.py DELETED
@@ -1,1060 +0,0 @@
1
- from typing import Any, Generic, Literal, Optional, TypeVar
2
-
3
- from pydantic import BaseModel, ConfigDict, FileUrl, RootModel
4
- from pydantic.networks import AnyUrl
5
-
6
- """
7
- Model Context Protocol bindings for Python
8
-
9
- These bindings were generated from https://github.com/modelcontextprotocol/specification,
10
- using Claude, with a prompt something like the following:
11
-
12
- Generate idiomatic Python bindings for this schema for MCP, or the "Model Context
13
- Protocol." The schema is defined in TypeScript, but there's also a JSON Schema version
14
- for reference.
15
-
16
- * For the bindings, let's use Pydantic V2 models.
17
- * Each model should allow extra fields everywhere, by specifying `model_config =
18
- ConfigDict(extra='allow')`. Do this in every case, instead of a custom base class.
19
- * Union types should be represented with a Pydantic `RootModel`.
20
- * Define additional model classes instead of using dictionaries. Do this even if they're
21
- not separate types in the schema.
22
- """
23
-
24
- LATEST_PROTOCOL_VERSION = "2024-11-05"
25
-
26
- ProgressToken = str | int
27
- Cursor = str
28
-
29
-
30
- class RequestParams(BaseModel):
31
- class Meta(BaseModel):
32
- progressToken: ProgressToken | None = None
33
- """
34
- If specified, the caller is requesting out-of-band progress notifications for
35
- this request (as represented by notifications/progress). The value of this
36
- parameter is an opaque token that will be attached to any subsequent
37
- notifications. The receiver is not obligated to provide these notifications.
38
- """
39
-
40
- model_config = ConfigDict(extra="allow")
41
-
42
- _meta: Meta | None = None
43
-
44
-
45
- class NotificationParams(BaseModel):
46
- class Meta(BaseModel):
47
- model_config = ConfigDict(extra="allow")
48
-
49
- _meta: Meta | None = None
50
- """
51
- This parameter name is reserved by MCP to allow clients and servers to attach
52
- additional metadata to their notifications.
53
- """
54
-
55
-
56
- RequestParamsT = TypeVar("RequestParamsT", bound=RequestParams)
57
- NotificationParamsT = TypeVar("NotificationParamsT", bound=NotificationParams)
58
- MethodT = TypeVar("MethodT", bound=str)
59
-
60
-
61
- class Request(BaseModel, Generic[RequestParamsT, MethodT]):
62
- """Base class for JSON-RPC requests."""
63
-
64
- method: MethodT
65
- params: RequestParamsT
66
- model_config = ConfigDict(extra="allow")
67
-
68
-
69
- class PaginatedRequest(Request[RequestParamsT, MethodT]):
70
- cursor: Cursor | None = None
71
- """
72
- An opaque token representing the current pagination position.
73
- If provided, the server should return results starting after this cursor.
74
- """
75
-
76
-
77
- class Notification(BaseModel, Generic[NotificationParamsT, MethodT]):
78
- """Base class for JSON-RPC notifications."""
79
-
80
- method: MethodT
81
- model_config = ConfigDict(extra="allow")
82
-
83
-
84
- class Result(BaseModel):
85
- """Base class for JSON-RPC results."""
86
-
87
- model_config = ConfigDict(extra="allow")
88
-
89
- _meta: dict[str, Any] | None = None
90
- """
91
- This result property is reserved by the protocol to allow clients and servers to
92
- attach additional metadata to their responses.
93
- """
94
-
95
-
96
- class PaginatedResult(Result):
97
- nextCursor: Cursor | None = None
98
- """
99
- An opaque token representing the pagination position after the last returned result.
100
- If present, there may be more results available.
101
- """
102
-
103
-
104
- RequestId = str | int
105
-
106
-
107
- class JSONRPCRequest(Request):
108
- """A request that expects a response."""
109
-
110
- jsonrpc: Literal["2.0"]
111
- id: RequestId
112
- params: dict[str, Any] | None = None
113
-
114
-
115
- class JSONRPCNotification(Notification):
116
- """A notification which does not expect a response."""
117
-
118
- jsonrpc: Literal["2.0"]
119
- params: dict[str, Any] | None = None
120
-
121
-
122
- class JSONRPCResponse(BaseModel):
123
- """A successful (non-error) response to a request."""
124
-
125
- jsonrpc: Literal["2.0"]
126
- id: RequestId
127
- result: dict[str, Any]
128
- model_config = ConfigDict(extra="allow")
129
-
130
-
131
- # Standard JSON-RPC error codes
132
- PARSE_ERROR = -32700
133
- INVALID_REQUEST = -32600
134
- METHOD_NOT_FOUND = -32601
135
- INVALID_PARAMS = -32602
136
- INTERNAL_ERROR = -32603
137
-
138
-
139
- class ErrorData(BaseModel):
140
- """Error information for JSON-RPC error responses."""
141
-
142
- code: int
143
- """The error type that occurred."""
144
-
145
- message: str
146
- """
147
- A short description of the error. The message SHOULD be limited to a concise single
148
- sentence.
149
- """
150
-
151
- data: Any | None = None
152
- """
153
- Additional information about the error. The value of this member is defined by the
154
- sender (e.g. detailed error information, nested errors etc.).
155
- """
156
-
157
- model_config = ConfigDict(extra="allow")
158
-
159
-
160
- class JSONRPCError(BaseModel):
161
- """A response to a request that indicates an error occurred."""
162
-
163
- jsonrpc: Literal["2.0"]
164
- id: str | int
165
- error: ErrorData
166
- model_config = ConfigDict(extra="allow")
167
-
168
-
169
- class JSONRPCMessage(
170
- RootModel[JSONRPCRequest | JSONRPCNotification | JSONRPCResponse | JSONRPCError]
171
- ):
172
- pass
173
-
174
-
175
- class EmptyResult(Result):
176
- """A response that indicates success but carries no data."""
177
-
178
-
179
- class Implementation(BaseModel):
180
- """Describes the name and version of an MCP implementation."""
181
-
182
- name: str
183
- version: str
184
- model_config = ConfigDict(extra="allow")
185
-
186
-
187
- class RootsCapability(BaseModel):
188
- """Capability for root operations."""
189
-
190
- listChanged: bool | None = None
191
- """Whether the client supports notifications for changes to the roots list."""
192
- model_config = ConfigDict(extra="allow")
193
-
194
-
195
- class SamplingCapability(BaseModel):
196
- """Capability for logging operations."""
197
-
198
- model_config = ConfigDict(extra="allow")
199
-
200
-
201
- class ClientCapabilities(BaseModel):
202
- """Capabilities a client may support."""
203
-
204
- experimental: dict[str, dict[str, Any]] | None = None
205
- """Experimental, non-standard capabilities that the client supports."""
206
- sampling: SamplingCapability | None = None
207
- """Present if the client supports sampling from an LLM."""
208
- roots: RootsCapability | None = None
209
- """Present if the client supports listing roots."""
210
- model_config = ConfigDict(extra="allow")
211
-
212
-
213
- class PromptsCapability(BaseModel):
214
- """Capability for prompts operations."""
215
-
216
- listChanged: bool | None = None
217
- """Whether this server supports notifications for changes to the prompt list."""
218
- model_config = ConfigDict(extra="allow")
219
-
220
-
221
- class ResourcesCapability(BaseModel):
222
- """Capability for resources operations."""
223
-
224
- subscribe: bool | None = None
225
- """Whether this server supports subscribing to resource updates."""
226
- listChanged: bool | None = None
227
- """Whether this server supports notifications for changes to the resource list."""
228
- model_config = ConfigDict(extra="allow")
229
-
230
-
231
- class ToolsCapability(BaseModel):
232
- """Capability for tools operations."""
233
-
234
- listChanged: bool | None = None
235
- """Whether this server supports notifications for changes to the tool list."""
236
- model_config = ConfigDict(extra="allow")
237
-
238
-
239
- class LoggingCapability(BaseModel):
240
- """Capability for logging operations."""
241
-
242
- model_config = ConfigDict(extra="allow")
243
-
244
-
245
- class ServerCapabilities(BaseModel):
246
- """Capabilities that a server may support."""
247
-
248
- experimental: dict[str, dict[str, Any]] | None = None
249
- """Experimental, non-standard capabilities that the server supports."""
250
- logging: LoggingCapability | None = None
251
- """Present if the server supports sending log messages to the client."""
252
- prompts: PromptsCapability | None = None
253
- """Present if the server offers any prompt templates."""
254
- resources: ResourcesCapability | None = None
255
- """Present if the server offers any resources to read."""
256
- tools: ToolsCapability | None = None
257
- """Present if the server offers any tools to call."""
258
- model_config = ConfigDict(extra="allow")
259
-
260
-
261
- class InitializeRequestParams(RequestParams):
262
- """Parameters for the initialize request."""
263
-
264
- protocolVersion: str | int
265
- """The latest version of the Model Context Protocol that the client supports."""
266
- capabilities: ClientCapabilities
267
- clientInfo: Implementation
268
- model_config = ConfigDict(extra="allow")
269
-
270
-
271
- class InitializeRequest(Request):
272
- """
273
- This request is sent from the client to the server when it first connects, asking it
274
- to begin initialization.
275
- """
276
-
277
- method: Literal["initialize"]
278
- params: InitializeRequestParams
279
-
280
-
281
- class InitializeResult(Result):
282
- """After receiving an initialize request from the client, the server sends this."""
283
-
284
- protocolVersion: str | int
285
- """The version of the Model Context Protocol that the server wants to use."""
286
- capabilities: ServerCapabilities
287
- serverInfo: Implementation
288
-
289
-
290
- class InitializedNotification(Notification):
291
- """
292
- This notification is sent from the client to the server after initialization has
293
- finished.
294
- """
295
-
296
- method: Literal["notifications/initialized"]
297
- params: NotificationParams | None = None
298
-
299
-
300
- class PingRequest(Request):
301
- """
302
- A ping, issued by either the server or the client, to check that the other party is
303
- still alive.
304
- """
305
-
306
- method: Literal["ping"]
307
- params: RequestParams | None = None
308
-
309
-
310
- class ProgressNotificationParams(NotificationParams):
311
- """Parameters for progress notifications."""
312
-
313
- progressToken: ProgressToken
314
- """
315
- The progress token which was given in the initial request, used to associate this
316
- notification with the request that is proceeding.
317
- """
318
- progress: float
319
- """
320
- The progress thus far. This should increase every time progress is made, even if the
321
- total is unknown.
322
- """
323
- total: float | None = None
324
- """Total number of items to process (or total progress required), if known."""
325
- model_config = ConfigDict(extra="allow")
326
-
327
-
328
- class CancelledParams(BaseModel):
329
- requestId: Optional[int] = None
330
- reason: Optional[str] = ""
331
-
332
-
333
- class CancellationNotification(Notification):
334
- """
335
- An out-of-band notification used to inform the receiver of a progress update for a
336
- long-running request.
337
- """
338
-
339
- method: Literal["notifications/cancelled"]
340
- params: CancelledParams
341
-
342
-
343
- class ProgressNotification(Notification):
344
- """
345
- An out-of-band notification used to inform the receiver of a progress update for a
346
- long-running request.
347
- """
348
-
349
- method: Literal["notifications/progress"]
350
- params: ProgressNotificationParams
351
-
352
-
353
- class ListResourcesRequest(PaginatedRequest):
354
- """Sent from the client to request a list of resources the server has."""
355
-
356
- method: Literal["resources/list"]
357
- params: RequestParams | None = None
358
-
359
-
360
- class Resource(BaseModel):
361
- """A known resource that the server is capable of reading."""
362
-
363
- uri: AnyUrl
364
- """The URI of this resource."""
365
- name: str
366
- """A human-readable name for this resource."""
367
- description: str | None = None
368
- """A description of what this resource represents."""
369
- mimeType: str | None = None
370
- """The MIME type of this resource, if known."""
371
- model_config = ConfigDict(extra="allow")
372
-
373
-
374
- class ResourceTemplate(BaseModel):
375
- """A template description for resources available on the server."""
376
-
377
- uriTemplate: str
378
- """
379
- A URI template (according to RFC 6570) that can be used to construct resource
380
- URIs.
381
- """
382
- name: str
383
- """A human-readable name for the type of resource this template refers to."""
384
- description: str | None = None
385
- """A human-readable description of what this template is for."""
386
- mimeType: str | None = None
387
- """
388
- The MIME type for all resources that match this template. This should only be
389
- included if all resources matching this template have the same type.
390
- """
391
- model_config = ConfigDict(extra="allow")
392
-
393
-
394
- class ListResourcesResult(PaginatedResult):
395
- """The server's response to a resources/list request from the client."""
396
-
397
- resources: list[Resource]
398
-
399
-
400
- class ListResourceTemplatesRequest(PaginatedRequest):
401
- """Sent from the client to request a list of resource templates the server has."""
402
-
403
- method: Literal["resources/templates/list"]
404
- params: RequestParams | None = None
405
-
406
-
407
- class ListResourceTemplatesResult(PaginatedResult):
408
- """The server's response to a resources/templates/list request from the client."""
409
-
410
- resourceTemplates: list[ResourceTemplate]
411
-
412
-
413
- class ReadResourceRequestParams(RequestParams):
414
- """Parameters for reading a resource."""
415
-
416
- uri: AnyUrl
417
- """
418
- The URI of the resource to read. The URI can use any protocol; it is up to the
419
- server how to interpret it.
420
- """
421
- model_config = ConfigDict(extra="allow")
422
-
423
-
424
- class ReadResourceRequest(Request):
425
- """Sent from the client to the server, to read a specific resource URI."""
426
-
427
- method: Literal["resources/read"]
428
- params: ReadResourceRequestParams
429
-
430
-
431
- class ResourceContents(BaseModel):
432
- """The contents of a specific resource or sub-resource."""
433
-
434
- uri: AnyUrl
435
- """The URI of this resource."""
436
- mimeType: str | None = None
437
- """The MIME type of this resource, if known."""
438
- model_config = ConfigDict(extra="allow")
439
-
440
-
441
- class TextResourceContents(ResourceContents):
442
- """Text contents of a resource."""
443
-
444
- text: str
445
- """
446
- The text of the item. This must only be set if the item can actually be represented
447
- as text (not binary data).
448
- """
449
-
450
-
451
- class BlobResourceContents(ResourceContents):
452
- """Binary contents of a resource."""
453
-
454
- blob: str
455
- """A base64-encoded string representing the binary data of the item."""
456
-
457
-
458
- class ReadResourceResult(Result):
459
- """The server's response to a resources/read request from the client."""
460
-
461
- contents: list[TextResourceContents | BlobResourceContents]
462
-
463
-
464
- class ResourceListChangedNotification(Notification):
465
- """
466
- An optional notification from the server to the client, informing it that the list
467
- of resources it can read from has changed.
468
- """
469
-
470
- method: Literal["notifications/resources/list_changed"]
471
- params: NotificationParams | None = None
472
-
473
-
474
- class SubscribeRequestParams(RequestParams):
475
- """Parameters for subscribing to a resource."""
476
-
477
- uri: AnyUrl
478
- """
479
- The URI of the resource to subscribe to. The URI can use any protocol; it is up to
480
- the server how to interpret it.
481
- """
482
- model_config = ConfigDict(extra="allow")
483
-
484
-
485
- class SubscribeRequest(Request):
486
- """
487
- Sent from the client to request resources/updated notifications from the server
488
- whenever a particular resource changes.
489
- """
490
-
491
- method: Literal["resources/subscribe"]
492
- params: SubscribeRequestParams
493
-
494
-
495
- class UnsubscribeRequestParams(RequestParams):
496
- """Parameters for unsubscribing from a resource."""
497
-
498
- uri: AnyUrl
499
- """The URI of the resource to unsubscribe from."""
500
- model_config = ConfigDict(extra="allow")
501
-
502
-
503
- class UnsubscribeRequest(Request):
504
- """
505
- Sent from the client to request cancellation of resources/updated notifications from
506
- the server.
507
- """
508
-
509
- method: Literal["resources/unsubscribe"]
510
- params: UnsubscribeRequestParams
511
-
512
-
513
- class ResourceUpdatedNotificationParams(NotificationParams):
514
- """Parameters for resource update notifications."""
515
-
516
- uri: AnyUrl
517
- """
518
- The URI of the resource that has been updated. This might be a sub-resource of the
519
- one that the client actually subscribed to.
520
- """
521
- model_config = ConfigDict(extra="allow")
522
-
523
-
524
- class ResourceUpdatedNotification(Notification):
525
- """
526
- A notification from the server to the client, informing it that a resource has
527
- changed and may need to be read again.
528
- """
529
-
530
- method: Literal["notifications/resources/updated"]
531
- params: ResourceUpdatedNotificationParams
532
-
533
-
534
- class ListPromptsRequest(PaginatedRequest):
535
- """Sent from the client to request a list of prompts and prompt templates."""
536
-
537
- method: Literal["prompts/list"]
538
- params: RequestParams | None = None
539
-
540
-
541
- class PromptArgument(BaseModel):
542
- """An argument for a prompt template."""
543
-
544
- name: str
545
- """The name of the argument."""
546
- description: str | None = None
547
- """A human-readable description of the argument."""
548
- required: bool | None = None
549
- """Whether this argument must be provided."""
550
- model_config = ConfigDict(extra="allow")
551
-
552
-
553
- class Prompt(BaseModel):
554
- """A prompt or prompt template that the server offers."""
555
-
556
- name: str
557
- """The name of the prompt or prompt template."""
558
- description: str | None = None
559
- """An optional description of what this prompt provides."""
560
- arguments: list[PromptArgument] | None = None
561
- """A list of arguments to use for templating the prompt."""
562
- model_config = ConfigDict(extra="allow")
563
-
564
-
565
- class ListPromptsResult(PaginatedResult):
566
- """The server's response to a prompts/list request from the client."""
567
-
568
- prompts: list[Prompt]
569
-
570
-
571
- class GetPromptRequestParams(RequestParams):
572
- """Parameters for getting a prompt."""
573
-
574
- name: str
575
- """The name of the prompt or prompt template."""
576
- arguments: dict[str, str] | None = None
577
- """Arguments to use for templating the prompt."""
578
- model_config = ConfigDict(extra="allow")
579
-
580
-
581
- class GetPromptRequest(Request):
582
- """Used by the client to get a prompt provided by the server."""
583
-
584
- method: Literal["prompts/get"]
585
- params: GetPromptRequestParams
586
-
587
-
588
- class TextContent(BaseModel):
589
- """Text content for a message."""
590
-
591
- type: Literal["text"]
592
- text: str
593
- """The text content of the message."""
594
- model_config = ConfigDict(extra="allow")
595
-
596
-
597
- class ImageContent(BaseModel):
598
- """Image content for a message."""
599
-
600
- type: Literal["image"]
601
- data: str
602
- """The base64-encoded image data."""
603
- mimeType: str
604
- """
605
- The MIME type of the image. Different providers may support different
606
- image types.
607
- """
608
- model_config = ConfigDict(extra="allow")
609
-
610
-
611
- Role = Literal["user", "assistant"]
612
-
613
-
614
- class SamplingMessage(BaseModel):
615
- """Describes a message issued to or received from an LLM API."""
616
-
617
- role: Role
618
- content: TextContent | ImageContent
619
- model_config = ConfigDict(extra="allow")
620
-
621
-
622
- class EmbeddedResource(BaseModel):
623
- """
624
- The contents of a resource, embedded into a prompt or tool call result.
625
-
626
- It is up to the client how best to render embedded resources for the benefit
627
- of the LLM and/or the user.
628
- """
629
-
630
- type: Literal["resource"]
631
- resource: TextResourceContents | BlobResourceContents
632
- model_config = ConfigDict(extra="allow")
633
-
634
-
635
- class PromptMessage(BaseModel):
636
- """Describes a message returned as part of a prompt."""
637
-
638
- role: Role
639
- content: TextContent | ImageContent | EmbeddedResource
640
- model_config = ConfigDict(extra="allow")
641
-
642
-
643
- class GetPromptResult(Result):
644
- """The server's response to a prompts/get request from the client."""
645
-
646
- description: str | None = None
647
- """An optional description for the prompt."""
648
- messages: list[PromptMessage]
649
-
650
-
651
- class PromptListChangedNotification(Notification):
652
- """
653
- An optional notification from the server to the client, informing it that the list
654
- of prompts it offers has changed.
655
- """
656
-
657
- method: Literal["notifications/prompts/list_changed"]
658
- params: NotificationParams | None = None
659
-
660
-
661
- class ListToolsRequest(PaginatedRequest):
662
- """Sent from the client to request a list of tools the server has."""
663
-
664
- method: Literal["tools/list"]
665
- params: RequestParams | None = None
666
-
667
-
668
- class Tool(BaseModel):
669
- """Definition for a tool the client can call."""
670
-
671
- name: str
672
- """The name of the tool."""
673
- description: str | None = None
674
- """A human-readable description of the tool."""
675
- inputSchema: dict[str, Any]
676
- """A JSON Schema object defining the expected parameters for the tool."""
677
- model_config = ConfigDict(extra="allow")
678
-
679
-
680
- class ListToolsResult(PaginatedResult):
681
- """The server's response to a tools/list request from the client."""
682
-
683
- tools: list[Tool]
684
-
685
-
686
- class CallToolRequestParams(RequestParams):
687
- """Parameters for calling a tool."""
688
-
689
- name: str
690
- arguments: dict[str, Any] | None = None
691
- model_config = ConfigDict(extra="allow")
692
-
693
-
694
- class CallToolRequest(Request):
695
- """Used by the client to invoke a tool provided by the server."""
696
-
697
- method: Literal["tools/call"]
698
- params: CallToolRequestParams
699
-
700
-
701
- class CallToolResult(Result):
702
- """The server's response to a tool call."""
703
-
704
- content: list[TextContent | ImageContent | EmbeddedResource]
705
- isError: bool = False
706
-
707
-
708
- class ToolListChangedNotification(Notification):
709
- """
710
- An optional notification from the server to the client, informing it that the list
711
- of tools it offers has changed.
712
- """
713
-
714
- method: Literal["notifications/tools/list_changed"]
715
- params: NotificationParams | None = None
716
-
717
-
718
- LoggingLevel = Literal[
719
- "debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"
720
- ]
721
-
722
-
723
- class SetLevelRequestParams(RequestParams):
724
- """Parameters for setting the logging level."""
725
-
726
- level: LoggingLevel
727
- """The level of logging that the client wants to receive from the server."""
728
- model_config = ConfigDict(extra="allow")
729
-
730
-
731
- class SetLevelRequest(Request):
732
- """A request from the client to the server, to enable or adjust logging."""
733
-
734
- method: Literal["logging/setLevel"]
735
- params: SetLevelRequestParams
736
-
737
-
738
- class LoggingMessageNotificationParams(NotificationParams):
739
- """Parameters for logging message notifications."""
740
-
741
- level: LoggingLevel
742
- """The severity of this log message."""
743
- logger: str | None = None
744
- """An optional name of the logger issuing this message."""
745
- data: Any
746
- """
747
- The data to be logged, such as a string message or an object. Any JSON serializable
748
- type is allowed here.
749
- """
750
- model_config = ConfigDict(extra="allow")
751
-
752
-
753
- class LoggingMessageNotification(Notification):
754
- """Notification of a log message passed from server to client."""
755
-
756
- method: Literal["notifications/message"]
757
- params: LoggingMessageNotificationParams
758
-
759
-
760
- IncludeContext = Literal["none", "thisServer", "allServers"]
761
-
762
-
763
- class ModelHint(BaseModel):
764
- """Hints to use for model selection."""
765
-
766
- name: str | None = None
767
- """A hint for a model name."""
768
-
769
- model_config = ConfigDict(extra="allow")
770
-
771
-
772
- class ModelPreferences(BaseModel):
773
- """
774
- The server's preferences for model selection, requested of the client during
775
- sampling.
776
-
777
- Because LLMs can vary along multiple dimensions, choosing the "best" model is
778
- rarely straightforward. Different models excel in different areas—some are
779
- faster but less capable, others are more capable but more expensive, and so
780
- on. This interface allows servers to express their priorities across multiple
781
- dimensions to help clients make an appropriate selection for their use case.
782
-
783
- These preferences are always advisory. The client MAY ignore them. It is also
784
- up to the client to decide how to interpret these preferences and how to
785
- balance them against other considerations.
786
- """
787
-
788
- hints: list[ModelHint] | None = None
789
- """
790
- Optional hints to use for model selection.
791
-
792
- If multiple hints are specified, the client MUST evaluate them in order
793
- (such that the first match is taken).
794
-
795
- The client SHOULD prioritize these hints over the numeric priorities, but
796
- MAY still use the priorities to select from ambiguous matches.
797
- """
798
-
799
- costPriority: float | None = None
800
- """
801
- How much to prioritize cost when selecting a model. A value of 0 means cost
802
- is not important, while a value of 1 means cost is the most important
803
- factor.
804
- """
805
-
806
- speedPriority: float | None = None
807
- """
808
- How much to prioritize sampling speed (latency) when selecting a model. A
809
- value of 0 means speed is not important, while a value of 1 means speed is
810
- the most important factor.
811
- """
812
-
813
- intelligencePriority: float | None = None
814
- """
815
- How much to prioritize intelligence and capabilities when selecting a
816
- model. A value of 0 means intelligence is not important, while a value of 1
817
- means intelligence is the most important factor.
818
- """
819
-
820
- model_config = ConfigDict(extra="allow")
821
-
822
-
823
- class CreateMessageRequestParams(RequestParams):
824
- """Parameters for creating a message."""
825
-
826
- messages: list[SamplingMessage]
827
- modelPreferences: ModelPreferences | None = None
828
- """
829
- The server's preferences for which model to select. The client MAY ignore
830
- these preferences.
831
- """
832
- systemPrompt: str | None = None
833
- """An optional system prompt the server wants to use for sampling."""
834
- includeContext: IncludeContext | None = None
835
- """
836
- A request to include context from one or more MCP servers (including the caller), to
837
- be attached to the prompt.
838
- """
839
- temperature: float | None = None
840
- maxTokens: int
841
- """The maximum number of tokens to sample, as requested by the server."""
842
- stopSequences: list[str] | None = None
843
- metadata: dict[str, Any] | None = None
844
- """Optional metadata to pass through to the LLM provider."""
845
- model_config = ConfigDict(extra="allow")
846
-
847
-
848
- class CreateMessageRequest(Request):
849
- """A request from the server to sample an LLM via the client."""
850
-
851
- method: Literal["sampling/createMessage"]
852
- params: CreateMessageRequestParams
853
-
854
-
855
- StopReason = Literal["endTurn", "stopSequence", "maxTokens"] | str
856
-
857
-
858
- class CreateMessageResult(Result):
859
- """The client's response to a sampling/create_message request from the server."""
860
-
861
- role: Role
862
- content: TextContent | ImageContent
863
- model: str
864
- """The name of the model that generated the message."""
865
- stopReason: StopReason | None = None
866
- """The reason why sampling stopped, if known."""
867
-
868
-
869
- class ResourceReference(BaseModel):
870
- """A reference to a resource or resource template definition."""
871
-
872
- type: Literal["ref/resource"]
873
- uri: str
874
- """The URI or URI template of the resource."""
875
- model_config = ConfigDict(extra="allow")
876
-
877
-
878
- class PromptReference(BaseModel):
879
- """Identifies a prompt."""
880
-
881
- type: Literal["ref/prompt"]
882
- name: str
883
- """The name of the prompt or prompt template"""
884
- model_config = ConfigDict(extra="allow")
885
-
886
-
887
- class CompletionArgument(BaseModel):
888
- """The argument's information for completion requests."""
889
-
890
- name: str
891
- """The name of the argument"""
892
- value: str
893
- """The value of the argument to use for completion matching."""
894
- model_config = ConfigDict(extra="allow")
895
-
896
-
897
- class CompleteRequestParams(RequestParams):
898
- """Parameters for completion requests."""
899
-
900
- ref: ResourceReference | PromptReference
901
- argument: CompletionArgument
902
- model_config = ConfigDict(extra="allow")
903
-
904
-
905
- class CompleteRequest(Request):
906
- """A request from the client to the server, to ask for completion options."""
907
-
908
- method: Literal["completion/complete"]
909
- params: CompleteRequestParams
910
-
911
-
912
- class Completion(BaseModel):
913
- """Completion information."""
914
-
915
- values: list[str]
916
- """An array of completion values. Must not exceed 100 items."""
917
- total: int | None = None
918
- """
919
- The total number of completion options available. This can exceed the number of
920
- values actually sent in the response.
921
- """
922
- hasMore: bool | None = None
923
- """
924
- Indicates whether there are additional completion options beyond those provided in
925
- the current response, even if the exact total is unknown.
926
- """
927
- model_config = ConfigDict(extra="allow")
928
-
929
-
930
- class CompleteResult(Result):
931
- """The server's response to a completion/complete request"""
932
-
933
- completion: Completion
934
-
935
-
936
- class ListRootsRequest(Request):
937
- """
938
- Sent from the server to request a list of root URIs from the client. Roots allow
939
- servers to ask for specific directories or files to operate on. A common example
940
- for roots is providing a set of repositories or directories a server should operate
941
- on.
942
-
943
- This request is typically used when the server needs to understand the file system
944
- structure or access specific locations that the client has permission to read from.
945
- """
946
-
947
- method: Literal["roots/list"]
948
- params: RequestParams | None = None
949
-
950
-
951
- class Root(BaseModel):
952
- """Represents a root directory or file that the server can operate on."""
953
-
954
- uri: FileUrl
955
- """
956
- The URI identifying the root. This *must* start with file:// for now.
957
- This restriction may be relaxed in future versions of the protocol to allow
958
- other URI schemes.
959
- """
960
- name: str | None = None
961
- """
962
- An optional name for the root. This can be used to provide a human-readable
963
- identifier for the root, which may be useful for display purposes or for
964
- referencing the root in other parts of the application.
965
- """
966
- model_config = ConfigDict(extra="allow")
967
-
968
-
969
- class ListRootsResult(Result):
970
- """
971
- The client's response to a roots/list request from the server.
972
- This result contains an array of Root objects, each representing a root directory
973
- or file that the server can operate on.
974
- """
975
-
976
- roots: list[Root]
977
-
978
-
979
- class RootsListChangedNotification(Notification):
980
- """
981
- A notification from the client to the server, informing it that the list of
982
- roots has changed.
983
-
984
- This notification should be sent whenever the client adds, removes, or
985
- modifies any root. The server should then request an updated list of roots
986
- using the ListRootsRequest.
987
- """
988
-
989
- method: Literal["notifications/roots/list_changed"]
990
- params: NotificationParams | None = None
991
-
992
-
993
- class ClientRequest(
994
- RootModel[
995
- PingRequest
996
- | InitializeRequest
997
- | CompleteRequest
998
- | SetLevelRequest
999
- | GetPromptRequest
1000
- | ListPromptsRequest
1001
- | ListResourcesRequest
1002
- | ListResourceTemplatesRequest
1003
- | ReadResourceRequest
1004
- | SubscribeRequest
1005
- | UnsubscribeRequest
1006
- | CallToolRequest
1007
- | ListToolsRequest
1008
- ]
1009
- ):
1010
- pass
1011
-
1012
-
1013
- class ClientNotification(
1014
- RootModel[
1015
- ProgressNotification
1016
- | InitializedNotification
1017
- | RootsListChangedNotification
1018
- | CancellationNotification
1019
- ]
1020
- ):
1021
- pass
1022
-
1023
-
1024
- class ClientResult(RootModel[EmptyResult | CreateMessageResult | ListRootsResult]):
1025
- pass
1026
-
1027
-
1028
- class ServerRequest(RootModel[PingRequest | CreateMessageRequest | ListRootsRequest]):
1029
- pass
1030
-
1031
-
1032
- class ServerNotification(
1033
- RootModel[
1034
- ProgressNotification
1035
- | LoggingMessageNotification
1036
- | ResourceUpdatedNotification
1037
- | ResourceListChangedNotification
1038
- | ToolListChangedNotification
1039
- | PromptListChangedNotification
1040
- | CancellationNotification
1041
- ]
1042
- ):
1043
- pass
1044
-
1045
-
1046
- class ServerResult(
1047
- RootModel[
1048
- EmptyResult
1049
- | InitializeResult
1050
- | CompleteResult
1051
- | GetPromptResult
1052
- | ListPromptsResult
1053
- | ListResourcesResult
1054
- | ListResourceTemplatesResult
1055
- | ReadResourceResult
1056
- | CallToolResult
1057
- | ListToolsResult
1058
- ]
1059
- ):
1060
- pass