Repository navigation
Pyjo.MCP.Client: the transport stdio, of a server in a child process - #55
Merged
Merged
Conversation
A client with a command runs its server with Pyjo.IOLoop.ChildProcess at its first request, and sends the messages to its standard input and reads them from its standard output, one on each line, with Pyjo.IOLoop.Messages. The methods are those of Streamable HTTP: a response goes to its request by its id, a message of a subscription to the function of listen by its subscriptionId, and another notification is the event notification. The standard error of the server is the event stderr, or the standard error of the process. A server that exits fails the requests in progress, and the next request runs it again. close, close_p and a with block end it as the specification asks: the end of its standard input, then SIGTERM and SIGKILL after shutdown_timeout. A promise of a method is cancellable with Pyjo.Promise.cancel: the transport stdio sends notifications/cancelled, and Streamable HTTP closes the connection. examples/mcp_cli.py takes a command with -c as well as a URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Tests
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pyjo.MCP.Clientgets the transport stdio: a client with acommandruns its server in a child process and talks to it over its standard input and output. The methods are the same as over Streamable HTTP.Closes #53
The transport stdio
Pyjo.IOLoop.ChildProcessruns the server at the first request.Pyjo.IOLoop.Messagesframes one message on each line. The client writes the requests that it built, with its ownids, so it does not use the client ofPyjo.JSON.RPC.id. A message of a subscription goes to the function oflistenby itssubscriptionId. Any other notification, such as progress or a log message, is the eventnotification.input_requiredresults.stderr, or the standard error of the process when nothing subscribes to the event.close(),close_p(),withandasync with. They close the standard input, waitshutdown_timeout(5 s), sendSIGTERM, and sendSIGKILLafter another timeout. A client of HTTP closes its user agent, unless the user agent was given to it._pwork.Cancellation
_pcan be cancelled withPyjo.Promise.cancel, which also happens when a coroutine that awaits it is cancelled. Over stdio it sendsnotifications/cancelledand drops a response that comes later. Over HTTP it closes the connection, withstart_pofPyjo.UserAgent.listenover stdio sendsnotifications/cancelledwhen its function returnsFalse.thendoes not cancel the promise it follows.Other changes
examples/mcp_cli.pytakes-c/--command(orMCP_COMMAND) as well as a URL.AGENTS.md.Validation
t/MCP_Client.pyrunsexamples/calculator.pyand the tutorial servers (progress.py,confirm.py,notes.py) over stdio. It covers:_p, and requests at the same timelistenclosed by its functionstderr,cwdandenvSIGTERM) and one that ignoresSIGTERMtoo (SIGKILL)async witht/docs/MCP_Client.py,t/docs/guides_tutorial.pyandt/examples/mcp_cli.pycover the new docstrings, the tutorial snippet and--command.python -m Pyjo.Prove -l -r tpasses all 21 files withPYTHONDEVMODE=1and thePYTHONWARNINGSof CI, with noResourceWarning.t/sdkpasses too.sphinx-build -W --keep-goingbuilds andtrunk checkis clean.🤖 Generated with Claude Code