forked from modelcontextprotocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_types.py
More file actions
32 lines (27 loc) · 932 Bytes
/
test_types.py
File metadata and controls
32 lines (27 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pytest
from mcp.types import (
LATEST_PROTOCOL_VERSION,
ClientRequest,
JSONRPCMessage,
JSONRPCRequest,
)
@pytest.mark.anyio
async def test_jsonrpc_request():
json_data = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": LATEST_PROTOCOL_VERSION,
"capabilities": {"batch": None, "sampling": None},
"clientInfo": {"name": "mcp", "version": "0.1.0"},
},
}
request = JSONRPCMessage.model_validate(json_data)
assert isinstance(request.root, JSONRPCRequest)
ClientRequest.model_validate(request.model_dump(by_alias=True, exclude_none=True))
assert request.root.jsonrpc == "2.0"
assert request.root.id == 1
assert request.root.method == "initialize"
assert request.root.params is not None
assert request.root.params["protocolVersion"] == LATEST_PROTOCOL_VERSION