Don't re-export types
We will be a bit more low level and expect callees to import mcp.types instead of relying in re-exported types. This makes usage more explicit and avoids potential collisions in mcp.server.
This commit is contained in:
parent
f5d82bd229
commit
b9b44e6dad
1 changed files with 231 additions and 413 deletions
|
|
@ -5,7 +5,7 @@ import anyio
|
|||
import anyio.lowlevel
|
||||
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
|
||||
|
||||
from mcp.types import JSONRPCMessage
|
||||
import mcp.types as types
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
|
|
@ -24,11 +24,11 @@ async def stdio_server(
|
|||
if not stdout:
|
||||
stdout = anyio.wrap_file(sys.stdout)
|
||||
|
||||
read_stream: MemoryObjectReceiveStream[JSONRPCMessage | Exception]
|
||||
read_stream_writer: MemoryObjectSendStream[JSONRPCMessage | Exception]
|
||||
read_stream: MemoryObjectReceiveStream[types.JSONRPCMessage | Exception]
|
||||
read_stream_writer: MemoryObjectSendStream[types.JSONRPCMessage | Exception]
|
||||
|
||||
write_stream: MemoryObjectSendStream[JSONRPCMessage]
|
||||
write_stream_reader: MemoryObjectReceiveStream[JSONRPCMessage]
|
||||
write_stream: MemoryObjectSendStream[types.JSONRPCMessage]
|
||||
write_stream_reader: MemoryObjectReceiveStream[types.JSONRPCMessage]
|
||||
|
||||
read_stream_writer, read_stream = anyio.create_memory_object_stream(0)
|
||||
write_stream, write_stream_reader = anyio.create_memory_object_stream(0)
|
||||
|
|
@ -38,7 +38,7 @@ async def stdio_server(
|
|||
async with read_stream_writer:
|
||||
async for line in stdin:
|
||||
try:
|
||||
message = JSONRPCMessage.model_validate_json(line)
|
||||
message = types.JSONRPCMessage.model_validate_json(line)
|
||||
except Exception as exc:
|
||||
await read_stream_writer.send(exc)
|
||||
continue
|
||||
|
|
|
|||
Loading…
Reference in a new issue