Issues and solutions for connecting stdio client to the example server #6
Description
I ran into a couple of issues with connecting a client to the example server.
I was able to make the following changes to enable the client to connect to the server. The changes can be see in the repo https://github.com/jtorreggiani/test-python-mcp-server/blob/main/src/test_server/server.py. Note: I am running the code on a MacBook.
- Adding shebang to the top of the file
#!/usr/bin/env python3
- Adding a conditional runner to the end of the script.
if __name__ == "__main__":
asyncio.run(main())
- Update the permissions on the file
chmod a+x src/test_server/server.py
I wrote a test https://github.com/jtorreggiani/test-python-mcp-server/blob/main/src/test_server/test_client.py to exercise all the server methods. I ran into an issue with the following line where the tests would hang on this line.
# Notify clients that resources have changed
await server.request_context.session.send_resource_list_changed()
I observed the same issue running the code in a simple chatbot outside of the test environment. It is unclear if there is something the client should be doing to unblock this request or if this doesn't need an await.
I tried to creating a separate executable in a couple of ways that would be passed to StdioServerParameters, but only could get the client to connect if I updated the main server.py
file.
server_params = StdioServerParameters(
command=f"{test_dir}/server.py",
args=[],
env=None
)