mcp-types 0.0.1__tar.gz

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.
@@ -0,0 +1,61 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "**"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+
15
+ outputs:
16
+ package-version: ${{ steps.inspect_package.outputs.version }}
17
+
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: astral-sh/setup-uv@v6
21
+ with:
22
+ python-version: '3.12'
23
+
24
+ - run: uv build
25
+ - run: ls -lh dist/
26
+
27
+ - name: Inspect package version
28
+ id: inspect_package
29
+ run: |
30
+ uv tool install --with uv-dynamic-versioning hatchling
31
+ version=$(uvx hatchling version)
32
+ echo "version=$version" >> "$GITHUB_OUTPUT"
33
+ - name: Upload to GitHub
34
+ uses: actions/upload-artifact@v4
35
+ with:
36
+ name: dist
37
+ path: dist
38
+
39
+ release:
40
+ if: success() && startsWith(github.ref, 'refs/tags/')
41
+ needs: [build]
42
+ runs-on: ubuntu-latest
43
+
44
+ environment:
45
+ name: pypi
46
+ url: https://pypi.org/project/mcp-types/${{ needs.build.outputs.package-version }}
47
+
48
+ permissions:
49
+ id-token: write
50
+
51
+ steps:
52
+ - name: Download dist
53
+ uses: actions/download-artifact@v4
54
+ with:
55
+ name: dist
56
+ path: dist
57
+
58
+ - name: Publish to PyPI
59
+ uses: pypa/gh-action-pypi-publish@release/v1
60
+ with:
61
+ skip-existing: true
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-types
3
+ Version: 0.0.1
4
+ Summary: Add your description here
5
+ Requires-Python: >=3.13
6
+ Requires-Dist: pydantic>=2.11.3
7
+ Requires-Dist: typing-extensions>=4.13.2
File without changes
File without changes
@@ -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]
@@ -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]
File without changes
@@ -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