55
66import anyio
77import pytest
8+ from mcp .shared .message import SessionMessage
89from mcp .types import (
910 JSONRPCError ,
1011 JSONRPCMessage ,
@@ -56,8 +57,8 @@ async def test_lambda_function_client_success(mock_client_creator, mock_session)
5657 )
5758
5859 # Create a test message
59- test_message = JSONRPCMessage (
60- root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" )
60+ test_message = SessionMessage (
61+ JSONRPCMessage ( root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" ) )
6162 )
6263
6364 async with lambda_function_client (lambda_parameters ) as (read_stream , write_stream ):
@@ -70,10 +71,11 @@ async def test_lambda_function_client_success(mock_client_creator, mock_session)
7071 response = await read_stream .receive ()
7172
7273 # Verify the response
73- assert isinstance (response , JSONRPCMessage )
74- assert isinstance (response .root , JSONRPCResponse )
75- assert response .root .id == "response-id"
76- assert response .root .result == {"message" : "success" }
74+ assert isinstance (response , SessionMessage )
75+ assert isinstance (response .message , JSONRPCMessage )
76+ assert isinstance (response .message .root , JSONRPCResponse )
77+ assert response .message .root .id == "response-id"
78+ assert response .message .root .result == {"message" : "success" }
7779
7880 # Verify Lambda was invoked with correct parameters
7981 mock_client .invoke .assert_called_once ()
@@ -100,8 +102,10 @@ async def test_lambda_function_notification_success(mock_client_creator, mock_se
100102 )
101103
102104 # Create a test message
103- test_message = JSONRPCMessage (
104- root = JSONRPCNotification (jsonrpc = "2.0" , method = "notifications/initialized" )
105+ test_message = SessionMessage (
106+ JSONRPCMessage (
107+ root = JSONRPCNotification (jsonrpc = "2.0" , method = "notifications/initialized" )
108+ )
105109 )
106110
107111 async with lambda_function_client (lambda_parameters ) as (read_stream , write_stream ):
@@ -146,9 +150,11 @@ async def test_lambda_function_client_function_error(mock_client_creator, mock_s
146150 )
147151
148152 # Create a test message
149- test_message = JSONRPCMessage (
150- root = JSONRPCRequest (
151- jsonrpc = "2.0" , id = 1 , method = "call/tool" , params = {"hello" : "world" }
153+ test_message = SessionMessage (
154+ JSONRPCMessage (
155+ root = JSONRPCRequest (
156+ jsonrpc = "2.0" , id = 1 , method = "call/tool" , params = {"hello" : "world" }
157+ )
152158 )
153159 )
154160
@@ -162,13 +168,15 @@ async def test_lambda_function_client_function_error(mock_client_creator, mock_s
162168 response = await read_stream .receive ()
163169
164170 # Verify the response is an error message
165- assert isinstance (response , JSONRPCMessage )
166- assert isinstance (response .root , JSONRPCError )
167- assert response .root .id == 1
168- assert response .root .error is not None
169- assert response .root .error .code == 500
171+ assert isinstance (response , SessionMessage )
172+ assert isinstance (response .message , JSONRPCMessage )
173+ assert isinstance (response .message .root , JSONRPCError )
174+ assert response .message .root .id == 1
175+ assert response .message .root .error is not None
176+ assert response .message .root .error .code == 500
170177 assert (
171- "Function invoke returned a function error" in response .root .error .message
178+ "Function invoke returned a function error"
179+ in response .message .root .error .message
172180 )
173181
174182 # Verify Lambda was invoked with correct parameters
@@ -198,8 +206,8 @@ async def test_lambda_function_client_invoke_exception(
198206 mock_client .invoke .side_effect = Exception ("Connection error" )
199207
200208 # Create a test message
201- test_message = JSONRPCMessage (
202- root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" )
209+ test_message = SessionMessage (
210+ JSONRPCMessage ( root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" ) )
203211 )
204212
205213 async with lambda_function_client (lambda_parameters ) as (read_stream , write_stream ):
@@ -212,12 +220,13 @@ async def test_lambda_function_client_invoke_exception(
212220 response = await read_stream .receive ()
213221
214222 # Verify the response is an error message
215- assert isinstance (response , JSONRPCMessage )
216- assert isinstance (response .root , JSONRPCError )
217- assert response .root .id == 1
218- assert response .root .error is not None
219- assert response .root .error .code == 500
220- assert "Connection error" in response .root .error .message
223+ assert isinstance (response , SessionMessage )
224+ assert isinstance (response .message , JSONRPCMessage )
225+ assert isinstance (response .message .root , JSONRPCError )
226+ assert response .message .root .id == 1
227+ assert response .message .root .error is not None
228+ assert response .message .root .error .code == 500
229+ assert "Connection error" in response .message .root .error .message
221230
222231 # Verify Lambda was invoked with correct parameters
223232 mock_client .invoke .assert_called_once ()
@@ -246,8 +255,8 @@ async def test_lambda_function_client_invalid_response(
246255 )
247256
248257 # Create a test message
249- test_message = JSONRPCMessage (
250- root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" )
258+ test_message = SessionMessage (
259+ JSONRPCMessage ( root = JSONRPCRequest (jsonrpc = "2.0" , id = 1 , method = "ping" ) )
251260 )
252261
253262 async with lambda_function_client (lambda_parameters ) as (read_stream , write_stream ):
@@ -260,12 +269,16 @@ async def test_lambda_function_client_invalid_response(
260269 response = await read_stream .receive ()
261270
262271 # Verify the response is an error message
263- assert isinstance (response , JSONRPCMessage )
264- assert isinstance (response .root , JSONRPCError )
265- assert response .root .id == 1
266- assert response .root .error is not None
267- assert response .root .error .code == 500
268- assert "4 validation errors for JSONRPCMessage" in response .root .error .message
272+ assert isinstance (response , SessionMessage )
273+ assert isinstance (response .message , JSONRPCMessage )
274+ assert isinstance (response .message .root , JSONRPCError )
275+ assert response .message .root .id == 1
276+ assert response .message .root .error is not None
277+ assert response .message .root .error .code == 500
278+ assert (
279+ "4 validation errors for JSONRPCMessage"
280+ in response .message .root .error .message
281+ )
269282
270283 # Verify Lambda was invoked with correct parameters
271284 mock_client .invoke .assert_called_once ()
0 commit comments