5
5
6
6
import anyio
7
7
import pytest
8
+ from mcp .shared .message import SessionMessage
8
9
from mcp .types import (
9
10
JSONRPCError ,
10
11
JSONRPCMessage ,
@@ -56,8 +57,8 @@ async def test_lambda_function_client_success(mock_client_creator, mock_session)
56
57
)
57
58
58
59
# 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" ) )
61
62
)
62
63
63
64
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)
70
71
response = await read_stream .receive ()
71
72
72
73
# 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" }
77
79
78
80
# Verify Lambda was invoked with correct parameters
79
81
mock_client .invoke .assert_called_once ()
@@ -100,8 +102,10 @@ async def test_lambda_function_notification_success(mock_client_creator, mock_se
100
102
)
101
103
102
104
# 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
+ )
105
109
)
106
110
107
111
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
146
150
)
147
151
148
152
# 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
+ )
152
158
)
153
159
)
154
160
@@ -162,13 +168,15 @@ async def test_lambda_function_client_function_error(mock_client_creator, mock_s
162
168
response = await read_stream .receive ()
163
169
164
170
# 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
170
177
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
172
180
)
173
181
174
182
# Verify Lambda was invoked with correct parameters
@@ -198,8 +206,8 @@ async def test_lambda_function_client_invoke_exception(
198
206
mock_client .invoke .side_effect = Exception ("Connection error" )
199
207
200
208
# 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" ) )
203
211
)
204
212
205
213
async with lambda_function_client (lambda_parameters ) as (read_stream , write_stream ):
@@ -212,12 +220,13 @@ async def test_lambda_function_client_invoke_exception(
212
220
response = await read_stream .receive ()
213
221
214
222
# 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
221
230
222
231
# Verify Lambda was invoked with correct parameters
223
232
mock_client .invoke .assert_called_once ()
@@ -246,8 +255,8 @@ async def test_lambda_function_client_invalid_response(
246
255
)
247
256
248
257
# 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" ) )
251
260
)
252
261
253
262
async with lambda_function_client (lambda_parameters ) as (read_stream , write_stream ):
@@ -260,12 +269,16 @@ async def test_lambda_function_client_invalid_response(
260
269
response = await read_stream .receive ()
261
270
262
271
# 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
+ )
269
282
270
283
# Verify Lambda was invoked with correct parameters
271
284
mock_client .invoke .assert_called_once ()
0 commit comments