Skip to content

Conversation

@MischaPanch
Copy link
Contributor

Using a dedicated tool _update_tool_list which is added to the server at the very end. Unfortunately, there seems to be no better way to do that, as the session object is not exposed in the mcp sdk in other places than the tool's context

Doesn't work in Claude Code or Claude Desktop

Anthropic's products don't follow Anthropic's own specifications...
anthropics/claude-code#4118

We probably shouldn't merge until Anthropic resolves it

@MischaPanch MischaPanch requested a review from opcode81 October 31, 2025 20:07
@MischaPanch MischaPanch force-pushed the feature/dynamic_tool_management branch from 241e89f to 9583e87 Compare October 31, 2025 20:11
@opcode81
Copy link
Contributor

opcode81 commented Nov 1, 2025

We probably shouldn't merge until Anthropic resolves it

Was this successfully tested with any client? Because if it can be shown that the implementation works correctly, we could merge it but disable it in the frontend, so it cannot actually be used. (Otherwise, we might get too many conflicts, especially if we refactor the Dashboard.)

@MischaPanch MischaPanch force-pushed the feature/dynamic_tool_management branch from 9583e87 to fb7a0ab Compare November 1, 2025 21:51
@MischaPanch
Copy link
Contributor Author

MischaPanch commented Nov 1, 2025

Now tested with VSCode.

Limitations: currently only works in stdio mode (see below). They can be overcome, but that requires even more hackery, so let's do that later

My previous approach (an _update_tool_list tool which would be called by SerenaAgent) didn't work because you just can't call tools that use context from outside the mcp server. The context is extracted dynamically on each call from the client. The context contains the Session object which one can use to send the update tool list notification. This Session object is also created dynamically and never persisted. So we can't call the tool, and we also can't access the session....

So after a lot of crying and deliberation about life choices, I now have solved it by extending FastMCP in the following way:

  1. We override run_stdio_async which persists the read and write stream (meaning the current solution will only work for stdio servers). This is because the Session instance is created much deeper in the code and it would be harder to hook into that part.
  2. Copied the necessary methods from Session to send notifications

Since fastmcp is async first, we can't call these methods from outside (not thread safe) without the following trickery:

  1. Override the main entrypoint run to also set up a sync-async communication queue and trigger the processing of it in parallel to the normal server startup. Luckily, python async annoyed enough people for the janus project to exist, which serves for exactly that purpose.
  2. Finally add a sync method update_tool_list which places the notification call into the queue

As part of this PR, I also added an mcp configuration that uses serena on serena in VSCode

Btw, serena is on the VSC marketplace:
https://github.com/mcp/oraios/serena

Not sure what exactly the install button there will do...

@MischaPanch MischaPanch force-pushed the feature/dynamic_tool_management branch from fb7a0ab to dd78df3 Compare November 1, 2025 22:46
@openhands-ai
Copy link

openhands-ai bot commented Nov 1, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Tests on CI

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #719 at branch `feature/dynamic_tool_management`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants