Skip to content

Add in-memory transport #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 5, 2024
Merged

Add in-memory transport #25

merged 12 commits into from
Nov 5, 2024

Conversation

nick-merrill
Copy link
Contributor

@nick-merrill nick-merrill commented Nov 4, 2024

Goal

Support running an MCP server in the same process as the client, while preserving MCP abstractions.

Details

  1. (core change) Adds a new memory transport module that enables in-process client-server communication.
    This includes:

    • create_client_server_memory_streams() to create bidirectional memory streams
    • create_connected_server_and_client_session() to establish an in-process client-server connection
  2. (minor) Enhances error handling and timeout support:

    • Adds configurable read timeouts to sessions via read_timeout_seconds parameter
    • Improves exception handling in the server with a new raise_exceptions flag to control whether errors are returned to clients or raised directly
    • Ensures proper cleanup of request context tokens in error cases
  3. (minor) Makes server improvements:

    • Adds built-in ping handler support

@nick-merrill nick-merrill marked this pull request as ready for review November 5, 2024 15:17
Copy link
Member

@jspahrsummers jspahrsummers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

successkid

@@ -36,8 +36,15 @@ def __init__(
self,
read_stream: MemoryObjectReceiveStream[JSONRPCMessage | Exception],
write_stream: MemoryObjectSendStream[JSONRPCMessage],
read_timeout_seconds: int | float | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIOLI: Should this be a timedelta to avoid unit errors entirely?

@k6l3
Copy link
Contributor

k6l3 commented Nov 5, 2024

sweeeet

@nick-merrill nick-merrill force-pushed the merrill/mcp-memory-transport branch from 3849a4d to 5dd79b2 Compare November 5, 2024 19:59
@nick-merrill nick-merrill merged commit 60e9c7a into main Nov 5, 2024
5 checks passed
@nick-merrill nick-merrill deleted the merrill/mcp-memory-transport branch November 5, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants