mcp-types 0.0.1__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.
- mcp_types/__init__.py +0 -0
- mcp_types/errors.py +10 -0
- mcp_types/jsonrpc.py +74 -0
- mcp_types/py.typed +0 -0
- mcp_types/requests.py +421 -0
- mcp_types/responses.py +373 -0
- mcp_types-0.0.1.dist-info/METADATA +7 -0
- mcp_types-0.0.1.dist-info/RECORD +9 -0
- mcp_types-0.0.1.dist-info/WHEEL +4 -0
mcp_types/__init__.py
ADDED
|
File without changes
|
mcp_types/errors.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from __future__ import annotations as _annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
from mcp_types.jsonrpc import JSONRPCError
|
|
5
|
+
|
|
6
|
+
MethodNotFoundCode = Literal[-32601]
|
|
7
|
+
InternalErrorCode = Literal[-32603]
|
|
8
|
+
|
|
9
|
+
ListRootNotFound = JSONRPCError[MethodNotFoundCode]
|
|
10
|
+
ListRootInternalError = JSONRPCError[InternalErrorCode]
|
mcp_types/jsonrpc.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""This module contains the JSON RPC types for the MCP.
|
|
2
|
+
|
|
3
|
+
The request types are `TypedDict`s, while the response types are `BaseModel`s.
|
|
4
|
+
|
|
5
|
+
This not only provides the best developer experience, but also conceptually, there's no
|
|
6
|
+
need to validate the request types using a type checker. On the other hand, you need to
|
|
7
|
+
make sure the data that you receive in the response is valid.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations as _annotations
|
|
11
|
+
|
|
12
|
+
from typing import Annotated, Any, Generic, Literal, TypeVar
|
|
13
|
+
from pydantic import BaseModel, Field
|
|
14
|
+
from typing_extensions import TypedDict, NotRequired
|
|
15
|
+
|
|
16
|
+
RequestId = Annotated[int | str, Field(union_mode="left_to_right")]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
MethodT = TypeVar("MethodT", bound=str)
|
|
20
|
+
ParamsT = TypeVar("ParamsT", default=None)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class JSONRPCRequest(TypedDict, Generic[MethodT, ParamsT]):
|
|
24
|
+
"""A JSON RPC request."""
|
|
25
|
+
|
|
26
|
+
jsonrpc: Literal["2.0"]
|
|
27
|
+
"""The JSON RPC version."""
|
|
28
|
+
|
|
29
|
+
id: RequestId
|
|
30
|
+
|
|
31
|
+
method: MethodT
|
|
32
|
+
"""The method to call."""
|
|
33
|
+
|
|
34
|
+
params: NotRequired[ParamsT]
|
|
35
|
+
"""The parameters to pass to the method."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
CodeT = TypeVar("CodeT", bound=int)
|
|
39
|
+
MessageT = TypeVar("MessageT", bound=str, default=str)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ErrorData(BaseModel, Generic[CodeT, MessageT]):
|
|
43
|
+
"""A JSON RPC error."""
|
|
44
|
+
|
|
45
|
+
code: CodeT
|
|
46
|
+
message: MessageT
|
|
47
|
+
data: Any = None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
ResultT = TypeVar("ResultT", bound=BaseModel)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class _BaseJSONRPCResponse(BaseModel):
|
|
54
|
+
"""A base class for JSON RPC responses."""
|
|
55
|
+
|
|
56
|
+
jsonrpc: Literal["2.0"]
|
|
57
|
+
"""The JSON RPC version."""
|
|
58
|
+
|
|
59
|
+
id: RequestId
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class JSONRPCResponse(_BaseJSONRPCResponse, Generic[ResultT]):
|
|
63
|
+
"""A JSON RPC response."""
|
|
64
|
+
|
|
65
|
+
result: ResultT
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
ErrorT = TypeVar("ErrorT")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class JSONRPCError(_BaseJSONRPCResponse, Generic[CodeT, MessageT]):
|
|
72
|
+
"""A JSON RPC response that indicates an error occurred."""
|
|
73
|
+
|
|
74
|
+
error: ErrorData[CodeT, MessageT]
|
mcp_types/py.typed
ADDED
|
File without changes
|
mcp_types/requests.py
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
from __future__ import annotations as _annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Literal, NotRequired
|
|
4
|
+
from pydantic import BaseModel, Discriminator, Field
|
|
5
|
+
from typing_extensions import Annotated, TypedDict
|
|
6
|
+
from mcp_types.jsonrpc import JSONRPCRequest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RootsCapability(TypedDict, total=False):
|
|
10
|
+
"""Ability to provide filesystem roots.
|
|
11
|
+
|
|
12
|
+
See more on <https://modelcontextprotocol.io/specification/2025-06-18/client/roots>.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
list_changed: bool
|
|
16
|
+
"""indicates whether the client will emit notifications when the list of roots changes."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SamplingCapability(TypedDict):
|
|
20
|
+
"""Support for LLM sampling requests.
|
|
21
|
+
|
|
22
|
+
See more on <https://modelcontextprotocol.io/specification/2025-06-18/client/sampling>.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ElicitationCapability(BaseModel):
|
|
27
|
+
"""Capability for elicitation operations.
|
|
28
|
+
|
|
29
|
+
See more on <https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation>.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ClientCapabilities(TypedDict):
|
|
34
|
+
"""Capabilities a client may support.
|
|
35
|
+
|
|
36
|
+
Known capabilities are defined here, in this schema, but this is not a closed set:
|
|
37
|
+
any client can define its own, additional capabilities.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
roots: NotRequired[RootsCapability]
|
|
41
|
+
"""Ability to provide filesystem roots.
|
|
42
|
+
|
|
43
|
+
See more on <https://modelcontextprotocol.io/specification/2025-06-18/client/roots>.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
sampling: NotRequired[SamplingCapability]
|
|
47
|
+
"""Support for LLM sampling requests.
|
|
48
|
+
|
|
49
|
+
See more on <https://modelcontextprotocol.io/specification/2025-06-18/client/sampling>.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
elicitation: NotRequired[ElicitationCapability]
|
|
53
|
+
"""Support for elicitation requests.
|
|
54
|
+
|
|
55
|
+
See more on <https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation>.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
experimental: NotRequired[dict[str, dict[str, Any]]]
|
|
59
|
+
"""Experimental, non-standard capabilities that the client supports."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Implementation(BaseModel):
|
|
63
|
+
name: str
|
|
64
|
+
title: str | None = None
|
|
65
|
+
version: str
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class InitializeRequestParams(TypedDict):
|
|
69
|
+
"""Parameters for the initialize request."""
|
|
70
|
+
|
|
71
|
+
protocol_version: Annotated[Literal["2025-06-18"], Field(alias="protocolVersion")]
|
|
72
|
+
"""The latest version of the Model Context Protocol that the client supports."""
|
|
73
|
+
|
|
74
|
+
capabilities: ClientCapabilities
|
|
75
|
+
|
|
76
|
+
client_info: Annotated[Implementation, Field(alias="clientInfo")]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class TextContent(TypedDict):
|
|
80
|
+
"""A text content."""
|
|
81
|
+
|
|
82
|
+
type: Literal["text"]
|
|
83
|
+
"""The type of content."""
|
|
84
|
+
|
|
85
|
+
text: str
|
|
86
|
+
"""The text content."""
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ImageContent(TypedDict):
|
|
90
|
+
"""An image content."""
|
|
91
|
+
|
|
92
|
+
type: Literal["image"]
|
|
93
|
+
"""The type of content."""
|
|
94
|
+
|
|
95
|
+
data: str
|
|
96
|
+
"""Base64 encoded image data."""
|
|
97
|
+
|
|
98
|
+
mime_type: Annotated[str, Field(alias="mimeType")]
|
|
99
|
+
"""The MIME type of the image."""
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class AudioContent(TypedDict):
|
|
103
|
+
"""An audio content."""
|
|
104
|
+
|
|
105
|
+
type: Literal["audio"]
|
|
106
|
+
"""The type of content."""
|
|
107
|
+
|
|
108
|
+
data: str
|
|
109
|
+
"""Base64 encoded audio data."""
|
|
110
|
+
|
|
111
|
+
mime_type: Annotated[str, Field(alias="mimeType")]
|
|
112
|
+
"""The MIME type of the audio."""
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class TextResourceContents(TypedDict):
|
|
116
|
+
"""Text resource contents."""
|
|
117
|
+
|
|
118
|
+
uri: str
|
|
119
|
+
"""The URI of this resource."""
|
|
120
|
+
|
|
121
|
+
text: str
|
|
122
|
+
"""The text content of the resource."""
|
|
123
|
+
|
|
124
|
+
mime_type: Annotated[NotRequired[str], Field(alias="mimeType")]
|
|
125
|
+
"""The MIME type of this resource, if known."""
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class BlobResourceContents(TypedDict):
|
|
129
|
+
"""Binary resource contents."""
|
|
130
|
+
|
|
131
|
+
uri: str
|
|
132
|
+
"""The URI of this resource."""
|
|
133
|
+
|
|
134
|
+
blob: str
|
|
135
|
+
"""A base64-encoded string representing the binary data."""
|
|
136
|
+
|
|
137
|
+
mime_type: Annotated[NotRequired[str], Field(alias="mimeType")]
|
|
138
|
+
"""The MIME type of this resource, if known."""
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class EmbeddedResource(TypedDict):
|
|
142
|
+
"""An embedded resource."""
|
|
143
|
+
|
|
144
|
+
type: Literal["resource"]
|
|
145
|
+
"""The type of resource."""
|
|
146
|
+
|
|
147
|
+
resource: TextResourceContents | BlobResourceContents
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
Role = Literal["user", "assistant"]
|
|
151
|
+
Content = Annotated[TextContent | ImageContent | AudioContent | EmbeddedResource, Discriminator("type")]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class SamplingMessage(TypedDict):
|
|
155
|
+
role: Role
|
|
156
|
+
content: Content
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class ModelHint(TypedDict):
|
|
160
|
+
"""A hint for the model to use."""
|
|
161
|
+
|
|
162
|
+
name: str
|
|
163
|
+
"""The name of the model."""
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class ModelPreferences(TypedDict):
|
|
167
|
+
"""The server's preferences for which model to select."""
|
|
168
|
+
|
|
169
|
+
cost_priority: Annotated[NotRequired[float], Field(alias="costPriority")]
|
|
170
|
+
"""How important is minimizing costs? Higher values prefer cheaper models."""
|
|
171
|
+
|
|
172
|
+
speed_priority: Annotated[NotRequired[float], Field(alias="speedPriority")]
|
|
173
|
+
"""How important is low latency? Higher values prefer faster models."""
|
|
174
|
+
|
|
175
|
+
intelligence_priority: Annotated[NotRequired[float], Field(alias="intelligencePriority")]
|
|
176
|
+
"""How important are advanced capabilities? Higher values prefer more capable models."""
|
|
177
|
+
|
|
178
|
+
hints: NotRequired[list[ModelHint]]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class CreateMessageSamplingRequestParams(TypedDict):
|
|
182
|
+
"""Parameters for creating a message."""
|
|
183
|
+
|
|
184
|
+
messages: list[SamplingMessage]
|
|
185
|
+
|
|
186
|
+
model_preferences: Annotated[NotRequired[ModelPreferences], Field(alias="modelPreferences")]
|
|
187
|
+
"""The server's preferences for which model to select.
|
|
188
|
+
|
|
189
|
+
The client MAY ignore these preferences.
|
|
190
|
+
|
|
191
|
+
See more on <https://modelcontextprotocol.io/specification/2025-06-18/client/sampling#model-preferences>.
|
|
192
|
+
"""
|
|
193
|
+
system_prompt: Annotated[NotRequired[str], Field(alias="systemPrompt")]
|
|
194
|
+
"""An optional system prompt the server wants to use for sampling."""
|
|
195
|
+
|
|
196
|
+
temperature: NotRequired[float]
|
|
197
|
+
"""The temperature to use for sampling."""
|
|
198
|
+
|
|
199
|
+
max_tokens: Annotated[int, Field(alias="maxTokens")]
|
|
200
|
+
"""The maximum number of tokens to sample, as requested by the server."""
|
|
201
|
+
|
|
202
|
+
stop_sequences: Annotated[NotRequired[list[str]], Field(alias="stopSequences")]
|
|
203
|
+
"""Stop sequences for sampling."""
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class GetPromptRequestParams(TypedDict):
|
|
207
|
+
"""Parameters for getting a message."""
|
|
208
|
+
|
|
209
|
+
name: str
|
|
210
|
+
"""The name of the message to get."""
|
|
211
|
+
|
|
212
|
+
arguments: NotRequired[dict[str, str]]
|
|
213
|
+
"""Arguments to use for templating the message."""
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class ListResourcesRequestParams(TypedDict, total=False):
|
|
217
|
+
"""Parameters for listing resources."""
|
|
218
|
+
|
|
219
|
+
cursor: str
|
|
220
|
+
"""An opaque token representing the current pagination position."""
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class ReadResourceRequestParams(TypedDict):
|
|
224
|
+
"""Parameters for reading a resource."""
|
|
225
|
+
|
|
226
|
+
uri: str
|
|
227
|
+
"""The URI of the resource to read."""
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class ListResourceTemplatesRequestParams(TypedDict, total=False):
|
|
231
|
+
"""Parameters for listing resource templates."""
|
|
232
|
+
|
|
233
|
+
cursor: str
|
|
234
|
+
"""An opaque token representing the current pagination position."""
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class SubscribeRequestParams(TypedDict):
|
|
238
|
+
"""Parameters for subscribing to resource updates."""
|
|
239
|
+
|
|
240
|
+
uri: str
|
|
241
|
+
"""The URI of the resource to subscribe to."""
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class UnsubscribeRequestParams(TypedDict):
|
|
245
|
+
"""Parameters for unsubscribing from resource updates."""
|
|
246
|
+
|
|
247
|
+
uri: str
|
|
248
|
+
"""The URI of the resource to unsubscribe from."""
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class ListPromptsRequestParams(TypedDict, total=False):
|
|
252
|
+
"""Parameters for listing prompts."""
|
|
253
|
+
|
|
254
|
+
cursor: str
|
|
255
|
+
"""An opaque token representing the current pagination position."""
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class ListToolsRequestParams(TypedDict, total=False):
|
|
259
|
+
"""Parameters for listing tools."""
|
|
260
|
+
|
|
261
|
+
cursor: str
|
|
262
|
+
"""An opaque token representing the current pagination position."""
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
class CallToolRequestParams(TypedDict):
|
|
266
|
+
"""Parameters for calling a tool."""
|
|
267
|
+
|
|
268
|
+
name: str
|
|
269
|
+
"""The name of the tool to call."""
|
|
270
|
+
|
|
271
|
+
arguments: NotRequired[dict[str, Any]]
|
|
272
|
+
"""Arguments to pass to the tool."""
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class SetLevelRequestParams(TypedDict):
|
|
276
|
+
"""Parameters for setting logging level."""
|
|
277
|
+
|
|
278
|
+
level: str
|
|
279
|
+
"""The logging level to set."""
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class CompleteRequestParams(TypedDict):
|
|
283
|
+
"""Parameters for completion request."""
|
|
284
|
+
|
|
285
|
+
ref: dict[str, Any]
|
|
286
|
+
"""Reference to the resource being completed."""
|
|
287
|
+
|
|
288
|
+
argument: dict[str, str]
|
|
289
|
+
"""The argument information for completion."""
|
|
290
|
+
|
|
291
|
+
context: NotRequired[dict[str, Any]]
|
|
292
|
+
"""Additional context for completion."""
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
class PingRequestParams(TypedDict):
|
|
296
|
+
"""A ping, issued by either the server or the client, to check that the other party is still alive.
|
|
297
|
+
|
|
298
|
+
The receiver must promptly respond, or else may be disconnected.
|
|
299
|
+
"""
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
class CreateMessageRequestParams(TypedDict):
|
|
303
|
+
"""Parameters for creating a message."""
|
|
304
|
+
|
|
305
|
+
messages: list[SamplingMessage]
|
|
306
|
+
"""The messages to send to the LLM."""
|
|
307
|
+
|
|
308
|
+
max_tokens: Annotated[int, Field(alias="maxTokens")]
|
|
309
|
+
"""The maximum number of tokens to sample."""
|
|
310
|
+
|
|
311
|
+
model_preferences: Annotated[NotRequired[ModelPreferences], Field(alias="modelPreferences")]
|
|
312
|
+
"""The server's preferences for which model to select."""
|
|
313
|
+
|
|
314
|
+
system_prompt: Annotated[NotRequired[str], Field(alias="systemPrompt")]
|
|
315
|
+
"""An optional system prompt the server wants to use for sampling."""
|
|
316
|
+
|
|
317
|
+
temperature: NotRequired[float]
|
|
318
|
+
"""The temperature to use for sampling."""
|
|
319
|
+
|
|
320
|
+
stop_sequences: Annotated[NotRequired[list[str]], Field(alias="stopSequences")]
|
|
321
|
+
"""Stop sequences for sampling."""
|
|
322
|
+
|
|
323
|
+
include_context: Annotated[NotRequired[str], Field(alias="includeContext")]
|
|
324
|
+
"""A request to include context from MCP servers."""
|
|
325
|
+
|
|
326
|
+
metadata: NotRequired[dict[str, Any]]
|
|
327
|
+
"""Optional metadata to pass through to the LLM provider."""
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class ListRootsRequestParams(TypedDict, total=False):
|
|
331
|
+
"""Parameters for listing roots."""
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class ElicitRequestParams(TypedDict):
|
|
335
|
+
"""Parameters for elicitation requests."""
|
|
336
|
+
|
|
337
|
+
message: str
|
|
338
|
+
"""The message to present to the user."""
|
|
339
|
+
requested_schema: Annotated[dict[str, Any], Field(alias="requestedSchema")]
|
|
340
|
+
"""A restricted subset of JSON Schema."""
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
InitializeRequest = JSONRPCRequest[Literal["initialize"], InitializeRequestParams]
|
|
344
|
+
"""This request is sent from the client to the server when it first connects, asking it to begin initialization."""
|
|
345
|
+
|
|
346
|
+
PingRequest = JSONRPCRequest[Literal["ping"], PingRequestParams]
|
|
347
|
+
"""A ping, issued by either the server or the client, to check that the other party is still alive.
|
|
348
|
+
|
|
349
|
+
The receiver must promptly respond, or else may be disconnected.
|
|
350
|
+
"""
|
|
351
|
+
|
|
352
|
+
InitializedNotification = JSONRPCRequest[Literal["notifications/initialized"]]
|
|
353
|
+
"""his notification is sent from the client to the server after initialization has finished."""
|
|
354
|
+
|
|
355
|
+
ListRootsRequest = JSONRPCRequest[Literal["roots/list"]]
|
|
356
|
+
"""Retrieve the list of filesystem roots."""
|
|
357
|
+
|
|
358
|
+
ListChangedRootsNotification = JSONRPCRequest[Literal["notifications/roots/list_changed"]]
|
|
359
|
+
"""A notification that the list of filesystem roots has changed."""
|
|
360
|
+
|
|
361
|
+
CreateMessageSamplingRequest = JSONRPCRequest[Literal["sampling/createMessage"], CreateMessageSamplingRequestParams]
|
|
362
|
+
|
|
363
|
+
GetPromptRequest = JSONRPCRequest[Literal["prompts/get"], GetPromptRequestParams]
|
|
364
|
+
|
|
365
|
+
ListResourcesRequest = JSONRPCRequest[Literal["resources/list"], ListResourcesRequestParams]
|
|
366
|
+
"""Sent from the client to request a list of resources the server has."""
|
|
367
|
+
|
|
368
|
+
ReadResourceRequest = JSONRPCRequest[Literal["resources/read"], ReadResourceRequestParams]
|
|
369
|
+
"""Sent from the client to the server, to read a specific resource URI."""
|
|
370
|
+
|
|
371
|
+
ListResourceTemplatesRequest = JSONRPCRequest[Literal["resources/templates/list"], ListResourceTemplatesRequestParams]
|
|
372
|
+
"""Sent from the client to request a list of resource templates the server has."""
|
|
373
|
+
|
|
374
|
+
SubscribeRequest = JSONRPCRequest[Literal["resources/subscribe"], SubscribeRequestParams]
|
|
375
|
+
"""Sent from the client to request resources/updated notifications from the server."""
|
|
376
|
+
|
|
377
|
+
UnsubscribeRequest = JSONRPCRequest[Literal["resources/unsubscribe"], UnsubscribeRequestParams]
|
|
378
|
+
"""Sent from the client to request cancellation of resources/updated notifications."""
|
|
379
|
+
|
|
380
|
+
ListPromptsRequest = JSONRPCRequest[Literal["prompts/list"], ListPromptsRequestParams]
|
|
381
|
+
"""Sent from the client to request a list of prompts and prompt templates the server has."""
|
|
382
|
+
|
|
383
|
+
ListToolsRequest = JSONRPCRequest[Literal["tools/list"], ListToolsRequestParams]
|
|
384
|
+
"""Sent from the client to request a list of tools the server has."""
|
|
385
|
+
|
|
386
|
+
CallToolRequest = JSONRPCRequest[Literal["tools/call"], CallToolRequestParams]
|
|
387
|
+
"""Used by the client to invoke a tool provided by the server."""
|
|
388
|
+
|
|
389
|
+
SetLevelRequest = JSONRPCRequest[Literal["logging/setLevel"], SetLevelRequestParams]
|
|
390
|
+
"""A request from the client to the server, to enable or adjust logging."""
|
|
391
|
+
|
|
392
|
+
CompleteRequest = JSONRPCRequest[Literal["completion/complete"], CompleteRequestParams]
|
|
393
|
+
"""A request from the client to the server, to ask for completion options."""
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
CreateMessageRequest = JSONRPCRequest[Literal["sampling/createMessage"], CreateMessageRequestParams]
|
|
397
|
+
"""A request from the server to sample an LLM via the client."""
|
|
398
|
+
|
|
399
|
+
ListRootsRequest = JSONRPCRequest[Literal["roots/list"], ListRootsRequestParams]
|
|
400
|
+
"""Sent from the server to request a list of root URIs from the client."""
|
|
401
|
+
|
|
402
|
+
ElicitRequest = JSONRPCRequest[Literal["elicitation/create"], ElicitRequestParams]
|
|
403
|
+
"""A request from the server to elicit additional information from the user via the client."""
|
|
404
|
+
|
|
405
|
+
ClientNotification = InitializedNotification | ListChangedRootsNotification
|
|
406
|
+
ClientRequest = (
|
|
407
|
+
InitializeRequest
|
|
408
|
+
| PingRequest
|
|
409
|
+
| ListResourcesRequest
|
|
410
|
+
| ListResourceTemplatesRequest
|
|
411
|
+
| ReadResourceRequest
|
|
412
|
+
| SubscribeRequest
|
|
413
|
+
| UnsubscribeRequest
|
|
414
|
+
| ListPromptsRequest
|
|
415
|
+
| GetPromptRequest
|
|
416
|
+
| ListToolsRequest
|
|
417
|
+
| CallToolRequest
|
|
418
|
+
| SetLevelRequest
|
|
419
|
+
| CompleteRequest
|
|
420
|
+
)
|
|
421
|
+
ServerRequest = PingRequest | CreateMessageRequest | ListRootsRequest | ElicitRequest
|
mcp_types/responses.py
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
from __future__ import annotations as _annotations
|
|
2
|
+
from typing import Annotated, Any, Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
|
|
6
|
+
from mcp_types.jsonrpc import JSONRPCResponse
|
|
7
|
+
from mcp_types.requests import Role, TextResourceContents, BlobResourceContents
|
|
8
|
+
|
|
9
|
+
PROTOCOL_VERSION = "2025-06-18"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BaseResult(BaseModel):
|
|
13
|
+
"""Base result for all responses."""
|
|
14
|
+
|
|
15
|
+
_meta: dict[str, Any] | None = None
|
|
16
|
+
"""See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CompletionsCapability(BaseModel, extra="allow"): ...
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class LoggingCapability(BaseModel, extra="allow"): ...
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class PromptsCapability(BaseModel):
|
|
26
|
+
"""Present if the server offers any prompt templates."""
|
|
27
|
+
|
|
28
|
+
list_changed: Annotated[bool | None, Field(alias="listChanged")] = None
|
|
29
|
+
"""Whether this server supports notifications for changes to the prompt list."""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ResourcesCapability(BaseModel):
|
|
33
|
+
"""Present if the server offers any resources to read."""
|
|
34
|
+
|
|
35
|
+
list_changed: Annotated[bool | None, Field(alias="listChanged")] = None
|
|
36
|
+
"""Whether this server supports notifications for changes to the resource list."""
|
|
37
|
+
|
|
38
|
+
subscribe: bool | None = None
|
|
39
|
+
"""Whether this server supports subscribing to resource updates."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ToolsCapability(BaseModel):
|
|
43
|
+
"""Present if the server offers any tools to call."""
|
|
44
|
+
|
|
45
|
+
list_changed: Annotated[bool | None, Field(alias="listChanged")] = None
|
|
46
|
+
"""Whether this server supports notifications for changes to the tool list."""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ServerCapabilities(BaseModel):
|
|
50
|
+
"""Capabilities that a server may support.
|
|
51
|
+
|
|
52
|
+
Known capabilities are defined here, in this schema, but this is not a closed set:
|
|
53
|
+
any server can define its own, additional capabilities.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
completions: CompletionsCapability | None = None
|
|
57
|
+
"""Present if the server supports argument autocompletion suggestions."""
|
|
58
|
+
|
|
59
|
+
logging: LoggingCapability | None = None
|
|
60
|
+
"""Present if the server supports sending log messages to the client."""
|
|
61
|
+
|
|
62
|
+
prompts: PromptsCapability | None = None
|
|
63
|
+
"""Present if the server offers any prompt templates."""
|
|
64
|
+
|
|
65
|
+
resources: ResourcesCapability | None = None
|
|
66
|
+
"""Present if the server offers any resources to read."""
|
|
67
|
+
|
|
68
|
+
tools: ToolsCapability | None = None
|
|
69
|
+
"""Present if the server offers any tools to call."""
|
|
70
|
+
|
|
71
|
+
experimental: dict[str, dict[str, Any]] | None = None
|
|
72
|
+
"""Experimental, non-standard capabilities that the server supports."""
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class Implementation(BaseModel):
|
|
76
|
+
name: str
|
|
77
|
+
title: str | None = None
|
|
78
|
+
version: str
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class InitializeResult(BaseResult):
|
|
82
|
+
"""After receiving an initialize request from the client, the server sends this response."""
|
|
83
|
+
|
|
84
|
+
capabilities: ServerCapabilities
|
|
85
|
+
"""Capabilities that a server may support.
|
|
86
|
+
|
|
87
|
+
Known capabilities are defined here, in this schema, but this is not a closed set:
|
|
88
|
+
any server can define its own, additional capabilities.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
instructions: str | None = None
|
|
92
|
+
"""Instructions describing how to use the server and its features.
|
|
93
|
+
|
|
94
|
+
This can be used by clients to improve the LLM's understanding of available tools,
|
|
95
|
+
resources, etc. It can be thought of like a "hint" to the model. For example, this
|
|
96
|
+
information MAY be added to the system prompt.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
protocol_version: Annotated[str, Field(alias="protocolVersion")] = PROTOCOL_VERSION
|
|
100
|
+
"""The version of the Model Context Protocol that the server wants to use.
|
|
101
|
+
|
|
102
|
+
This may not match the version that the client requested. If the client cannot support
|
|
103
|
+
this version, it MUST disconnect.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
server_info: Annotated[Implementation, Field(alias="serverInfo")]
|
|
107
|
+
"""Describes the name and version of an MCP implementation, with an optional title for UI representation."""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class TextContent(BaseModel):
|
|
111
|
+
"""A text content."""
|
|
112
|
+
|
|
113
|
+
type: Literal["text"] = "text"
|
|
114
|
+
"""The type of content."""
|
|
115
|
+
text: str
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class ImageContent(BaseModel):
|
|
119
|
+
"""An image content."""
|
|
120
|
+
|
|
121
|
+
type: Literal["image"] = "image"
|
|
122
|
+
"""The type of content."""
|
|
123
|
+
data: str
|
|
124
|
+
"""Base64 encoded image data."""
|
|
125
|
+
mime_type: Annotated[str, Field(alias="mimeType")]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class AudioContent(BaseModel):
|
|
129
|
+
"""An audio content."""
|
|
130
|
+
|
|
131
|
+
type: Literal["audio"] = "audio"
|
|
132
|
+
"""The type of content."""
|
|
133
|
+
data: str
|
|
134
|
+
"""Base64 encoded audio data."""
|
|
135
|
+
mime_type: Annotated[str, Field(alias="mimeType")]
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
ContentBlock = TextContent | ImageContent | AudioContent
|
|
139
|
+
StopReason = Literal["endTurn", "stopSequence", "maxTokens"]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class Resource(BaseModel):
|
|
143
|
+
"""A known resource that the server is capable of reading."""
|
|
144
|
+
|
|
145
|
+
uri: str
|
|
146
|
+
"""The URI of this resource."""
|
|
147
|
+
name: str
|
|
148
|
+
"""The name of the resource."""
|
|
149
|
+
title: str | None = None
|
|
150
|
+
"""The title of the resource."""
|
|
151
|
+
description: str | None = None
|
|
152
|
+
"""A description of what this resource represents."""
|
|
153
|
+
mime_type: Annotated[str | None, Field(alias="mimeType")] = None
|
|
154
|
+
"""The MIME type of this resource, if known."""
|
|
155
|
+
size: int | None = None
|
|
156
|
+
"""The size of the resource in bytes."""
|
|
157
|
+
_meta: dict[str, Any] | None = None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class ResourceTemplate(BaseModel):
|
|
161
|
+
"""A template description for resources available on the server."""
|
|
162
|
+
|
|
163
|
+
uri_template: Annotated[str, Field(alias="uriTemplate")]
|
|
164
|
+
"""A URI template that can be used to construct resource URIs."""
|
|
165
|
+
name: str
|
|
166
|
+
"""The name of the template."""
|
|
167
|
+
title: str | None = None
|
|
168
|
+
"""The title of the template."""
|
|
169
|
+
description: str | None = None
|
|
170
|
+
"""A description of what this template is for."""
|
|
171
|
+
mime_type: Annotated[str | None, Field(alias="mimeType")] = None
|
|
172
|
+
"""The MIME type for all resources that match this template."""
|
|
173
|
+
_meta: dict[str, Any] | None = None
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class ListResourcesResult(BaseResult):
|
|
177
|
+
"""The server's response to a resources/list request from the client."""
|
|
178
|
+
|
|
179
|
+
resources: list[Resource]
|
|
180
|
+
"""List of resources available."""
|
|
181
|
+
next_cursor: Annotated[str | None, Field(alias="nextCursor")] = None
|
|
182
|
+
"""An opaque token for pagination."""
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class ListResourceTemplatesResult(BaseResult):
|
|
186
|
+
"""The server's response to a resources/templates/list request from the client."""
|
|
187
|
+
|
|
188
|
+
resource_templates: Annotated[list[ResourceTemplate], Field(alias="resourceTemplates")]
|
|
189
|
+
"""List of resource templates available."""
|
|
190
|
+
next_cursor: Annotated[str | None, Field(alias="nextCursor")] = None
|
|
191
|
+
"""An opaque token for pagination."""
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class ReadResourceResult(BaseResult):
|
|
195
|
+
"""The server's response to a resources/read request from the client."""
|
|
196
|
+
|
|
197
|
+
contents: list[TextResourceContents | BlobResourceContents]
|
|
198
|
+
"""The contents of the resource."""
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
class CreateMessageSamplingResult(BaseModel):
|
|
202
|
+
"""The client's response to a sampling/create_message request from the server."""
|
|
203
|
+
|
|
204
|
+
role: Role
|
|
205
|
+
content: TextContent | ImageContent | AudioContent
|
|
206
|
+
model: str
|
|
207
|
+
"""The name of the model that generated the message."""
|
|
208
|
+
stop_reason: Annotated[StopReason | None, Field(alias="stopReason")] = None
|
|
209
|
+
"""The reason why sampling stopped, if known."""
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class Tool(BaseModel):
|
|
213
|
+
"""Definition for a tool the client can call."""
|
|
214
|
+
|
|
215
|
+
name: str
|
|
216
|
+
"""The name of the tool."""
|
|
217
|
+
title: str | None = None
|
|
218
|
+
"""The title of the tool."""
|
|
219
|
+
description: str | None = None
|
|
220
|
+
"""A description of the tool."""
|
|
221
|
+
input_schema: Annotated[dict[str, Any], Field(alias="inputSchema")]
|
|
222
|
+
"""A JSON Schema object defining the expected parameters for the tool."""
|
|
223
|
+
output_schema: Annotated[dict[str, Any] | None, Field(alias="outputSchema")] = None
|
|
224
|
+
"""An optional JSON Schema object defining the structure of the tool's output."""
|
|
225
|
+
_meta: dict[str, Any] | None = None
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class ListToolsResult(BaseResult):
|
|
229
|
+
"""The server's response to a tools/list request from the client."""
|
|
230
|
+
|
|
231
|
+
tools: list[Tool]
|
|
232
|
+
"""List of tools available."""
|
|
233
|
+
next_cursor: Annotated[str | None, Field(alias="nextCursor")] = None
|
|
234
|
+
"""An opaque token for pagination."""
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class CallToolResult(BaseResult):
|
|
238
|
+
"""The server's response to a tool call."""
|
|
239
|
+
|
|
240
|
+
content: list[ContentBlock]
|
|
241
|
+
"""A list of content objects that represent the unstructured result of the tool call."""
|
|
242
|
+
is_error: Annotated[bool | None, Field(alias="isError")] = None
|
|
243
|
+
"""Whether the tool call ended in an error."""
|
|
244
|
+
structured_content: Annotated[dict[str, Any] | None, Field(alias="structuredContent")] = None
|
|
245
|
+
"""An optional JSON object that represents the structured result of the tool call."""
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class PromptArgument(BaseModel):
|
|
249
|
+
"""Describes an argument that a prompt can accept."""
|
|
250
|
+
|
|
251
|
+
name: str
|
|
252
|
+
"""The name of the argument."""
|
|
253
|
+
title: str | None = None
|
|
254
|
+
"""The title of the argument."""
|
|
255
|
+
description: str | None = None
|
|
256
|
+
"""A description of the argument."""
|
|
257
|
+
required: bool | None = None
|
|
258
|
+
"""Whether this argument must be provided."""
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
class Prompt(BaseModel):
|
|
262
|
+
"""A prompt or prompt template that the server offers."""
|
|
263
|
+
|
|
264
|
+
name: str
|
|
265
|
+
"""The name of the prompt."""
|
|
266
|
+
title: str | None = None
|
|
267
|
+
"""The title of the prompt."""
|
|
268
|
+
description: str | None = None
|
|
269
|
+
"""An optional description of what this prompt provides."""
|
|
270
|
+
arguments: list[PromptArgument] | None = None
|
|
271
|
+
"""A list of arguments to use for templating the prompt."""
|
|
272
|
+
_meta: dict[str, Any] | None = None
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class PromptMessage(BaseModel):
|
|
276
|
+
"""Describes a message returned as part of a prompt."""
|
|
277
|
+
|
|
278
|
+
role: Role
|
|
279
|
+
"""The role of the message sender."""
|
|
280
|
+
content: ContentBlock
|
|
281
|
+
"""The content of the message."""
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
class ListPromptsResult(BaseResult):
|
|
285
|
+
"""The server's response to a prompts/list request from the client."""
|
|
286
|
+
|
|
287
|
+
prompts: list[Prompt]
|
|
288
|
+
"""List of prompts available."""
|
|
289
|
+
next_cursor: Annotated[str | None, Field(alias="nextCursor")] = None
|
|
290
|
+
"""An opaque token for pagination."""
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class GetPromptResult(BaseResult):
|
|
294
|
+
"""The server's response to a prompts/get request from the client."""
|
|
295
|
+
|
|
296
|
+
description: str | None = None
|
|
297
|
+
"""An optional description for the prompt."""
|
|
298
|
+
messages: list[PromptMessage]
|
|
299
|
+
"""The messages that make up the prompt."""
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
class CompleteResult(BaseResult):
|
|
303
|
+
"""The server's response to a completion/complete request."""
|
|
304
|
+
|
|
305
|
+
completion: dict[str, Any]
|
|
306
|
+
"""The completion information."""
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
class Root(BaseModel):
|
|
310
|
+
"""Represents a root directory or file that the server can operate on."""
|
|
311
|
+
|
|
312
|
+
uri: str
|
|
313
|
+
"""The URI identifying the root."""
|
|
314
|
+
name: str | None = None
|
|
315
|
+
"""An optional name for the root."""
|
|
316
|
+
_meta: dict[str, Any] | None = None
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
class ListRootsResult(BaseResult):
|
|
320
|
+
"""The client's response to a roots/list request from the server."""
|
|
321
|
+
|
|
322
|
+
roots: list[Root]
|
|
323
|
+
"""List of root directories or files."""
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
class ElicitResult(BaseResult):
|
|
327
|
+
"""The client's response to an elicitation request."""
|
|
328
|
+
|
|
329
|
+
action: Literal["accept", "decline", "cancel"]
|
|
330
|
+
"""The user action in response to the elicitation."""
|
|
331
|
+
content: dict[str, str | int | bool] | None = None
|
|
332
|
+
"""The submitted form data, only present when action is 'accept'."""
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
class CreateMessageResult(BaseResult):
|
|
336
|
+
"""The client's response to a sampling/createMessage request from the server."""
|
|
337
|
+
|
|
338
|
+
role: Role
|
|
339
|
+
"""The role of the message."""
|
|
340
|
+
content: ContentBlock
|
|
341
|
+
"""The content of the message."""
|
|
342
|
+
model: str
|
|
343
|
+
"""The name of the model that generated the message."""
|
|
344
|
+
stop_reason: Annotated[str | None, Field(alias="stopReason")] = None
|
|
345
|
+
"""The reason why sampling stopped, if known."""
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
InitializeResponse = JSONRPCResponse[InitializeResult]
|
|
349
|
+
ListResourcesResponse = JSONRPCResponse[ListResourcesResult]
|
|
350
|
+
ListResourceTemplatesResponse = JSONRPCResponse[ListResourceTemplatesResult]
|
|
351
|
+
ReadResourceResponse = JSONRPCResponse[ReadResourceResult]
|
|
352
|
+
ListPromptsResponse = JSONRPCResponse[ListPromptsResult]
|
|
353
|
+
GetPromptResponse = JSONRPCResponse[GetPromptResult]
|
|
354
|
+
ListToolsResponse = JSONRPCResponse[ListToolsResult]
|
|
355
|
+
CallToolResponse = JSONRPCResponse[CallToolResult]
|
|
356
|
+
CompleteResponse = JSONRPCResponse[CompleteResult]
|
|
357
|
+
ListRootsResponse = JSONRPCResponse[ListRootsResult]
|
|
358
|
+
ElicitResponse = JSONRPCResponse[ElicitResult]
|
|
359
|
+
CreateMessageResponse = JSONRPCResponse[CreateMessageResult]
|
|
360
|
+
|
|
361
|
+
ClientResponse = CreateMessageResponse | ListRootsResponse | ElicitResponse
|
|
362
|
+
|
|
363
|
+
ServerResponse = (
|
|
364
|
+
InitializeResponse
|
|
365
|
+
| ListResourcesResponse
|
|
366
|
+
| ListResourceTemplatesResponse
|
|
367
|
+
| ReadResourceResponse
|
|
368
|
+
| ListPromptsResponse
|
|
369
|
+
| GetPromptResponse
|
|
370
|
+
| ListToolsResponse
|
|
371
|
+
| CallToolResponse
|
|
372
|
+
| CompleteResponse
|
|
373
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
mcp_types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
mcp_types/errors.py,sha256=Ru9YF_VODCKUNHzyGO5FyRw8OHIdN_xRzCYGmnaE_AM,305
|
|
3
|
+
mcp_types/jsonrpc.py,sha256=HiSM-itij9kXGIRrJESfUzS5LzEpEnfe2fX3dlk8vGk,1815
|
|
4
|
+
mcp_types/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
mcp_types/requests.py,sha256=uhGwlnsXf06n_D51om2rMhTNWrxilX6wS0kwGPOcONw,13418
|
|
6
|
+
mcp_types/responses.py,sha256=5FgspuQajfAfSFdN2EBA8vC_ivNTWWMwpZDANvlI2Ak,12469
|
|
7
|
+
mcp_types-0.0.1.dist-info/METADATA,sha256=_TGx7Z9sTPv6iWNkMzVeId713zU3OT58PTxqnpFphTo,185
|
|
8
|
+
mcp_types-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
mcp_types-0.0.1.dist-info/RECORD,,
|