-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Long-running MCP servers , MCP server logging #167
Conversation
…exit. Also add logging so messages go to file instead of screen.
Wow Tom, this is really nice thank you! One thing that comes to mind: Since you already implemented a simple tool, would you like to put some more effort and add some unit tests using your tool? There are a few examples in the tests folder that should help. This way we can expand the MCP features more easily in the future. |
Good morning Yiorgis, Upon further testing with multiple concurrent servers it seems that this solution is not quite right, so please don't merge it. When there are multiple servers, the teardown step does not execute cleanly, because the task-groups I will continue to examine the situation and work towards multiple long-running servers. I will also look at the unit tests. Thanks again for this nice tool. |
Hey Tom! |
Ok. I will mark it as a draft and we can use this thread to discuss the issues around running multiple subprocesses. Question: One of the things that has been difficult for me in debugging this is observing error log messages since they go to the terminal and textual.app (?) frameworks seems to absorb stderr. Is there an easy way to direct logging and error output to a file? I used typescript, but I"m wondering if you know a better way. Thanks. |
Reopen and mark as draft. |
Thanks for re-opening!
And then
This is the textual console, with disabled basically all events. Here, you will see all your You then run
See here for proper docs and additional things you can do to debug. |
A few things:
CleanupThe teardown_mcp_servers method works and has been tested in a set-up with two concurrent MCP servers (a database and the simple example). It seems fragile however. I think the cleanest way to run servers might be something like the following one day.
ProblemThe following structure was problematic.
Instead of creating a list of callables each of which is bound to a different tool and its callable, all of the callables referenced the same values of "client" and "tool". It is as if set_mcp_server.client and set_mcp_server.tool were instance variables and all of the callables referenced them. As such, they all got the last value of client and tool in the iteration. This seems like a Python bug. |
Thanks for the help in understanding how to view logging with Textual. Was a huge help. |
Remove the stderr/errlog override. Forgot to take this out. |
Hey Tom! |
Hi Yiorgis - |
Hey Tom! |
Hi Yirogis - Thanks for all your good work on this tool. |
Thanks Tom, from the little that I've seen, you have done an excellent work! Will ping you when I get to it and you can review. |
Hey Tom, I am very sorry for being so late, life changes are overwhelming atm :)
|
Hi Yiorgis - are you able to tell if the servers start? Do they respond if you do not include my changes? |
Merged as #174 |
This PR is a suggestion for how to make MCP servers long running. There may be a cleaner way to do it and you may want to rewrite this.
(But first of all - oterm mcp is great work and I'm using it with llama3.2 :-)
Also, to see what was going on I needed to add debugging logs to MCP and that is described in this PR there: modelcontextprotocol/python-sdk#191
Problem: each call to list-tools or call/tool restarts the python script. With Claude Desktop, servers are long-running and calls to tools are messages sent to that server. My modification keeps the session running and does not restart it if there is already one running. But to do that, an explicit teardown needed to be added.
To Test:
include the "simple_tool" attached and ask ollama:
"Please call the simple tool with 100 and 200."
"Now call it with 250 and 350"
The per-server log is named "mcp-server-Tom5Server.log" and its contents are the following. Note that the server is called once and the tool is invoked twice.
The source for the MCP server is this