Skip to content

Commit 949f981

Browse files
committed
feat!: Use new MCP SessionMessage for Lambda client transport
1 parent 14afb34 commit 949f981

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/python/src/mcp_lambda/client/lambda_client.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import anyio
55
import anyio.lowlevel
66
import mcp.types as types
7+
from mcp.shared.message import SessionMessage
78
from aiobotocore.session import get_session
89
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
910
from pydantic import BaseModel
@@ -23,11 +24,11 @@ async def lambda_function_client(lambda_function: LambdaFunctionParameters):
2324
Client transport for Lambda functions: this will invoke a Lambda function
2425
when requests are sent to the client.
2526
"""
26-
read_stream: MemoryObjectReceiveStream[types.JSONRPCMessage | Exception]
27-
read_stream_writer: MemoryObjectSendStream[types.JSONRPCMessage | Exception]
27+
read_stream: MemoryObjectReceiveStream[SessionMessage | Exception]
28+
read_stream_writer: MemoryObjectSendStream[SessionMessage | Exception]
2829

29-
write_stream: MemoryObjectSendStream[types.JSONRPCMessage]
30-
write_stream_reader: MemoryObjectReceiveStream[types.JSONRPCMessage]
30+
write_stream: MemoryObjectSendStream[SessionMessage]
31+
write_stream_reader: MemoryObjectReceiveStream[SessionMessage]
3132

3233
read_stream_writer, read_stream = anyio.create_memory_object_stream(0)
3334
write_stream, write_stream_reader = anyio.create_memory_object_stream(0)
@@ -44,7 +45,8 @@ async def invoke_function():
4445
"lambda", region_name=lambda_function.region_name
4546
) as lambda_client:
4647
async with write_stream_reader:
47-
async for message in write_stream_reader:
48+
async for session_message in write_stream_reader:
49+
message = session_message.message
4850
logging.debug(
4951
f"MCP JSON RPC message raw: {message.__class__.__name__} {message}"
5052
)
@@ -113,12 +115,15 @@ async def invoke_function():
113115
),
114116
)
115117
)
116-
await read_stream_writer.send(error_message)
118+
await read_stream_writer.send(
119+
SessionMessage(error_message)
120+
)
117121
else:
118122
await read_stream_writer.send(exc)
119123
continue
120124

121-
await read_stream_writer.send(response_message)
125+
session_message = SessionMessage(response_message)
126+
await read_stream_writer.send(session_message)
122127
except anyio.ClosedResourceError:
123128
await anyio.lowlevel.checkpoint()
124129
except Exception as exc:

0 commit comments

Comments
 (0)