Skip to content

Commit b42d5cd

Browse files
committed
Extract protocol types into a standalone mcp-types package
Convert the repository into a uv workspace mirroring pydantic/httpx2. The root pyproject becomes a pure coordinator (package = false) and the two distributable packages live nested under src/<pkg>/<pkg>/ each with their own pyproject: - src/mcp/mcp/ -> mcp - src/mcp-types/mcp_types/ -> mcp-types (import mcp_types) The protocol types (_types.py, jsonrpc.py) move into mcp_types, which only depends on pydantic and typing-extensions. mcp depends on mcp-types via uv-dynamic-versioning, so installing mcp still pulls the types in. The mcp.types module path is removed; all imports now use mcp_types. The curated re-exports on the top-level mcp package are unchanged.
1 parent 616476f commit b42d5cd

279 files changed

Lines changed: 1033 additions & 870 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.v2.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ For full control over tool responses including the `_meta` field (for passing da
412412

413413
from typing import Annotated
414414

415+
from mcp_types import CallToolResult, TextContent
415416
from pydantic import BaseModel
416417

417418
from mcp.server.mcpserver import MCPServer
418-
from mcp.types import CallToolResult, TextContent
419419

420420
mcp = MCPServer("CallToolResult Example")
421421

@@ -732,9 +732,10 @@ uv run completion-client
732732
import asyncio
733733
import os
734734

735+
from mcp_types import PromptReference, ResourceTemplateReference
736+
735737
from mcp import ClientSession, StdioServerParameters
736738
from mcp.client.stdio import stdio_client
737-
from mcp.types import PromptReference, ResourceTemplateReference
738739

739740
# Create server parameters for stdio connection
740741
server_params = StdioServerParameters(
@@ -821,11 +822,11 @@ like OAuth flows, credential collection, or payment processing.
821822

822823
import uuid
823824

825+
from mcp_types import ElicitRequestURLParams
824826
from pydantic import BaseModel, Field
825827

826828
from mcp.server.mcpserver import Context, MCPServer
827829
from mcp.shared.exceptions import UrlElicitationRequiredError
828-
from mcp.types import ElicitRequestURLParams
829830

830831
mcp = MCPServer(name="Elicitation Example")
831832

@@ -929,8 +930,9 @@ Tools can interact with LLMs through sampling (generating text):
929930

930931
<!-- snippet-source examples/snippets/servers/sampling.py -->
931932
```python
933+
from mcp_types import SamplingMessage, TextContent
934+
932935
from mcp.server.mcpserver import Context, MCPServer
933-
from mcp.types import SamplingMessage, TextContent
934936

935937
mcp = MCPServer(name="Sampling Example")
936938

@@ -1639,8 +1641,9 @@ from collections.abc import AsyncIterator
16391641
from contextlib import asynccontextmanager
16401642
from typing import TypedDict
16411643

1644+
import mcp_types as types
1645+
16421646
import mcp.server.stdio
1643-
from mcp import types
16441647
from mcp.server import Server, ServerRequestContext
16451648

16461649

@@ -1751,8 +1754,9 @@ uv run examples/snippets/servers/lowlevel/basic.py
17511754

17521755
import asyncio
17531756

1757+
import mcp_types as types
1758+
17541759
import mcp.server.stdio
1755-
from mcp import types
17561760
from mcp.server import Server, ServerRequestContext
17571761

17581762

@@ -1828,8 +1832,9 @@ uv run examples/snippets/servers/lowlevel/structured_output.py
18281832
import asyncio
18291833
import json
18301834

1835+
import mcp_types as types
1836+
18311837
import mcp.server.stdio
1832-
from mcp import types
18331838
from mcp.server import Server, ServerRequestContext
18341839

18351840

@@ -1920,8 +1925,9 @@ uv run examples/snippets/servers/lowlevel/direct_call_tool_result.py
19201925

19211926
import asyncio
19221927

1928+
import mcp_types as types
1929+
19231930
import mcp.server.stdio
1924-
from mcp import types
19251931
from mcp.server import Server, ServerRequestContext
19261932

19271933

@@ -1991,7 +1997,8 @@ For servers that need to handle large datasets, the low-level server provides pa
19911997
```python
19921998
"""Example of implementing pagination with the low-level MCP server."""
19931999

1994-
from mcp import types
2000+
import mcp_types as types
2001+
19952002
from mcp.server import Server, ServerRequestContext
19962003

19972004
# Sample data to paginate
@@ -2037,9 +2044,10 @@ _Full example: [examples/snippets/servers/pagination_example.py](https://github.
20372044

20382045
import asyncio
20392046

2047+
from mcp_types import PaginatedRequestParams, Resource
2048+
20402049
from mcp.client.session import ClientSession
20412050
from mcp.client.stdio import StdioServerParameters, stdio_client
2042-
from mcp.types import PaginatedRequestParams, Resource
20432051

20442052

20452053
async def list_all_resources() -> None:
@@ -2099,7 +2107,9 @@ uv run client
20992107
import asyncio
21002108
import os
21012109

2102-
from mcp import ClientSession, StdioServerParameters, types
2110+
import mcp_types as types
2111+
2112+
from mcp import ClientSession, StdioServerParameters
21032113
from mcp.client.context import ClientRequestContext
21042114
from mcp.client.stdio import stdio_client
21052115

docs/experimental/tasks-client.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Call a tool as a task and poll for the result:
1212

1313
```python
1414
from mcp.client.session import ClientSession
15-
from mcp.types import CallToolResult
15+
from mcp_types import CallToolResult
1616

1717
async with ClientSession(read, write) as session:
1818
await session.initialize()
@@ -96,7 +96,7 @@ The elicitation callback (set during session creation) handles the actual user i
9696
To handle elicitation requests from the server, provide a callback when creating the session:
9797

9898
```python
99-
from mcp.types import ElicitRequestParams, ElicitResult
99+
from mcp_types import ElicitRequestParams, ElicitResult
100100

101101
async def handle_elicitation(context, params: ElicitRequestParams) -> ElicitResult:
102102
# Display the message to the user
@@ -125,7 +125,7 @@ async with ClientSession(
125125
Similarly, handle sampling requests with a callback:
126126

127127
```python
128-
from mcp.types import CreateMessageRequestParams, CreateMessageResult, TextContent
128+
from mcp_types import CreateMessageRequestParams, CreateMessageResult, TextContent
129129

130130
async def handle_sampling(context, params: CreateMessageRequestParams) -> CreateMessageResult:
131131
# In a real implementation, call your LLM here
@@ -207,7 +207,7 @@ Register task handlers to declare what task-augmented requests your client accep
207207

208208
```python
209209
from mcp.client.experimental.task_handlers import ExperimentalTaskHandlers
210-
from mcp.types import (
210+
from mcp_types import (
211211
CreateTaskResult, GetTaskResult, GetTaskPayloadResult,
212212
TaskMetadata, ElicitRequestParams,
213213
)
@@ -283,7 +283,7 @@ A client that handles all task scenarios:
283283
import anyio
284284
from mcp.client.session import ClientSession
285285
from mcp.client.stdio import stdio_client
286-
from mcp.types import CallToolResult, ElicitRequestParams, ElicitResult
286+
from mcp_types import CallToolResult, ElicitRequestParams, ElicitResult
287287

288288

289289
async def elicitation_callback(context, params: ElicitRequestParams) -> ElicitResult:

docs/experimental/tasks-server.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The simplest way to add task support:
1313
```python
1414
from mcp.server import Server
1515
from mcp.server.experimental.task_context import ServerTaskContext
16-
from mcp.types import CallToolResult, CreateTaskResult, TextContent, Tool, ToolExecution, TASK_REQUIRED
16+
from mcp_types import CallToolResult, CreateTaskResult, TextContent, Tool, ToolExecution, TASK_REQUIRED
1717

1818
server = Server("my-server")
1919
server.experimental.enable_tasks() # Registers all task handlers automatically
@@ -58,7 +58,7 @@ That's it. `enable_tasks()` automatically:
5858
Tools declare task support via the `execution.taskSupport` field:
5959

6060
```python
61-
from mcp.types import Tool, ToolExecution, TASK_REQUIRED, TASK_OPTIONAL, TASK_FORBIDDEN
61+
from mcp_types import Tool, ToolExecution, TASK_REQUIRED, TASK_OPTIONAL, TASK_FORBIDDEN
6262

6363
Tool(
6464
name="my_tool",
@@ -199,7 +199,7 @@ async def work(task: ServerTaskContext) -> CallToolResult:
199199
Tasks can request LLM completions from the client:
200200

201201
```python
202-
from mcp.types import SamplingMessage, TextContent
202+
from mcp_types import SamplingMessage, TextContent
203203

204204
async def work(task: ServerTaskContext) -> CallToolResult:
205205
await task.update_status("Generating response...")
@@ -256,7 +256,7 @@ For production, implement `TaskStore` with persistent storage:
256256

257257
```python
258258
from mcp.shared.experimental.tasks.store import TaskStore
259-
from mcp.types import Task, TaskMetadata, Result
259+
from mcp_types import Task, TaskMetadata, Result
260260

261261
class RedisTaskStore(TaskStore):
262262
def __init__(self, redis_client):
@@ -299,7 +299,7 @@ A server with multiple task-supporting tools:
299299
```python
300300
from mcp.server import Server
301301
from mcp.server.experimental.task_context import ServerTaskContext
302-
from mcp.types import (
302+
from mcp_types import (
303303
CallToolResult, CreateTaskResult, TextContent, Tool, ToolExecution,
304304
SamplingMessage, TASK_REQUIRED,
305305
)
@@ -412,7 +412,7 @@ import uvicorn
412412

413413
from mcp.server import Server
414414
from mcp.server.experimental.task_context import ServerTaskContext
415-
from mcp.types import (
415+
from mcp_types import (
416416
CallToolResult, CreateTaskResult, TextContent, Tool, ToolExecution, TASK_REQUIRED,
417417
)
418418

@@ -468,7 +468,7 @@ Test task functionality with the SDK's testing utilities:
468468
import pytest
469469
import anyio
470470
from mcp.client.session import ClientSession
471-
from mcp.types import CallToolResult
471+
from mcp_types import CallToolResult
472472

473473

474474
@pytest.mark.anyio

docs/experimental/tasks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Server Client
102102
When augmenting a request with task execution, include `TaskMetadata`:
103103

104104
```python
105-
from mcp.types import TaskMetadata
105+
from mcp_types import TaskMetadata
106106

107107
task = TaskMetadata(ttl=60000) # TTL in milliseconds
108108
```
@@ -143,7 +143,7 @@ The SDK manages these automatically when you enable task support.
143143
```python
144144
from mcp.server import Server
145145
from mcp.server.experimental.task_context import ServerTaskContext
146-
from mcp.types import CallToolResult, TextContent, TASK_REQUIRED
146+
from mcp_types import CallToolResult, TextContent, TASK_REQUIRED
147147

148148
server = Server("my-server")
149149
server.experimental.enable_tasks() # One-line setup
@@ -165,7 +165,7 @@ async def handle_tool(name: str, arguments: dict):
165165

166166
```python
167167
from mcp.client.session import ClientSession
168-
from mcp.types import CallToolResult
168+
from mcp_types import CallToolResult
169169

170170
async with ClientSession(read, write) as session:
171171
await session.initialize()

0 commit comments

Comments
 (0)