Skip to content

feat(js/plugins/mcp): Refactor to a client manager structure, with dynamic tool calling. #2884

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 57 commits into from
May 30, 2025

Conversation

ssbushi
Copy link
Contributor

@ssbushi ssbushi commented May 7, 2025

  • Modified the current McpClient class to a Client manager class
  • GenkitMcpClient is now a dedicated single client-server connection.
  • Tools are now fetched dynamically to support adding/removing/disabling clients in the manager.

Copy link

google-cla bot commented May 7, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ssbushi ssbushi changed the base branch from mcp-redux to main May 7, 2025 19:59
@ssbushi ssbushi requested review from mbleigh and pavelgj May 8, 2025 16:41
@ssbushi ssbushi marked this pull request as ready for review May 8, 2025 16:41
@mbleigh mbleigh changed the base branch from main to launch/mcp-redux May 10, 2025 15:26
Copy link
Collaborator

@mbleigh mbleigh left a comment

Choose a reason for hiding this comment

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

One more high-level piece of food for thought: in the client manager context, I think we probably want to be very robust to misconfiguration errors. It's possible people will use this for dynamic, user-configured tools and when that happens we should recover gracefully as best we can.

So maybe in the client manager there should be an {error?: {message, status, details}} and if there's an error trying to connect to the server it is put in a disabled state, an error-level log is emitted, and the error is also saved with the server.

@mbleigh
Copy link
Collaborator

mbleigh commented May 10, 2025

Oh also I think we should put this work into a launch branch - I created launch/mcp-redux and made #2896 to squash my own work and create a chain of commits. Can you rebase onto the launch/mcp-redux as your merge target?

pavelgj added 17 commits May 23, 2025 17:11
This commit improves the MCP client and manager's connection handling by:

- Renaming `initializeConnection` to `_initializeConnection` and making it private.
- Adding try/catch blocks to `_initializeConnection` and `_connect` to handle connection errors more gracefully.
- Changing log level from info to debug for connection messages.
- Adding checks to ensure clients exist before disabling or enabling them.
- Removing unused client property from McpTransportServerConfig.
- Removing outdated tests and adding new test files.
The `setup` method on the `GenkitMcpServer` is now explicitly called and awaited before starting the server. This ensures that any asynchronous setup tasks are completed before the server begins processing requests.

This change also updates the README and tests to reflect the new explicit setup call.
This commit moves the fetching of dynamic resource tools from the individual MCP client to the MCP manager. This allows the manager to aggregate resource tools from all active clients, providing a unified view of available resources.

The `fetchDynamicResourceTools` function is now called within the `getActiveTools` method of the `GenkitMcpManager`, and the `resourceTools` option is added to control whether resource tools are included.

Additionally, this commit includes minor refactoring and test updates to accommodate the change.
@pavelgj pavelgj requested a review from mbleigh May 25, 2025 21:43
pavelgj and others added 5 commits May 25, 2025 21:05
Updates the Model Context Protocol SDK dependency to version 1.12.0 in the MCP plugin's package.json and pnpm-lock.yaml. This ensures the plugin is using the latest version of the SDK.
Adds a GenkitError to `fromMcpPart` to handle cases where an unsupported part type is encountered, providing a clear message about the unimplemented type.
@pavelgj pavelgj merged commit b7f4e22 into launch/mcp-redux May 30, 2025
5 checks passed
@pavelgj pavelgj deleted the sb/mcp-redux branch May 30, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config docs Improvements or additions to documentation go js python Python root sample tooling
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants