4
4
import pytest
5
5
6
6
from mcp .server .stdio import stdio_server
7
+ from mcp .shared .session import ParsedMessage
7
8
from mcp .types import JSONRPCMessage , JSONRPCRequest , JSONRPCResponse
8
9
9
10
@@ -13,8 +14,12 @@ async def test_stdio_server():
13
14
stdout = io .StringIO ()
14
15
15
16
messages = [
16
- JSONRPCMessage (root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" )),
17
- JSONRPCMessage (root = JSONRPCResponse (jsonrpc = "2.0" , id = 2 , result = {})),
17
+ ParsedMessage (
18
+ root = JSONRPCMessage (root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" ))
19
+ ),
20
+ ParsedMessage (
21
+ root = JSONRPCMessage (root = JSONRPCResponse (jsonrpc = "2.0" , id = 2 , result = {}))
22
+ ),
18
23
]
19
24
20
25
for message in messages :
@@ -35,17 +40,25 @@ async def test_stdio_server():
35
40
36
41
# Verify received messages
37
42
assert len (received_messages ) == 2
38
- assert received_messages [0 ] == JSONRPCMessage (
39
- root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" )
43
+ assert received_messages [0 ] == ParsedMessage (
44
+ root = JSONRPCMessage ( root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" ) )
40
45
)
41
- assert received_messages [1 ] == JSONRPCMessage (
42
- root = JSONRPCResponse (jsonrpc = "2.0" , id = 2 , result = {})
46
+ assert received_messages [1 ] == ParsedMessage (
47
+ root = JSONRPCMessage ( root = JSONRPCResponse (jsonrpc = "2.0" , id = 2 , result = {}) )
43
48
)
44
49
45
50
# Test sending responses from the server
46
51
responses = [
47
- JSONRPCMessage (root = JSONRPCRequest (jsonrpc = "2.0" , id = 3 , method = "ping" )),
48
- JSONRPCMessage (root = JSONRPCResponse (jsonrpc = "2.0" , id = 4 , result = {})),
52
+ ParsedMessage (
53
+ root = JSONRPCMessage (
54
+ root = JSONRPCRequest (jsonrpc = "2.0" , id = 3 , method = "ping" )
55
+ )
56
+ ),
57
+ ParsedMessage (
58
+ root = JSONRPCMessage (
59
+ root = JSONRPCResponse (jsonrpc = "2.0" , id = 4 , result = {})
60
+ )
61
+ ),
49
62
]
50
63
51
64
async with write_stream :
@@ -57,12 +70,12 @@ async def test_stdio_server():
57
70
assert len (output_lines ) == 2
58
71
59
72
received_responses = [
60
- JSONRPCMessage .model_validate_json (line .strip ()) for line in output_lines
73
+ ParsedMessage .model_validate_json (line .strip ()) for line in output_lines
61
74
]
62
75
assert len (received_responses ) == 2
63
- assert received_responses [0 ] == JSONRPCMessage (
64
- root = JSONRPCRequest (jsonrpc = "2.0" , id = 3 , method = "ping" )
76
+ assert received_responses [0 ] == ParsedMessage (
77
+ root = JSONRPCMessage ( root = JSONRPCRequest (jsonrpc = "2.0" , id = 3 , method = "ping" ) )
65
78
)
66
- assert received_responses [1 ] == JSONRPCMessage (
67
- root = JSONRPCResponse (jsonrpc = "2.0" , id = 4 , result = {})
79
+ assert received_responses [1 ] == ParsedMessage (
80
+ root = JSONRPCMessage ( root = JSONRPCResponse (jsonrpc = "2.0" , id = 4 , result = {}) )
68
81
)
0 commit comments