Skip to content

Conversation

@pietrozullo
Copy link
Member

@pietrozullo pietrozullo commented Jun 28, 2025

Description

This pull request introduces a powerful new capability for the MCPAgent: dynamic server management. The agent can now be equipped with a tool that allows it to add and connect to new MCP servers at runtime, based on the user's prompt. This significantly enhances the agent's autonomy and flexibility, as it can now dynamically expand its own toolset as required by the task at hand.

The core of this change is the new AddMCPServerTool, which is now provided and managed by the ServerManager. When used, this tool:

  1. Adds a new server configuration to the MCPClient.
  2. Establishes a session with the new server.
  3. Discovers the tools provided by that server.
  4. Registers the new tools with the ServerManager and sets the new server as the active one.

The ServerManager has been enhanced to be aware of the "active" server, and it now dynamically includes the active server's tools in the list it provides to the agent. This ensures that once a server is added, the agent immediately has access to its capabilities for the next step.

Additionally, this PR includes several improvements:

  • Enhanced Observability: A logState method was added to the ServerManager which, when the log level is set to 'debug', prints a detailed table of all configured servers, their connection status, tool count, and active status. This provides excellent visibility into the manager's state at each step of an agent's run.
  • Bug Fixes: Corrected a typo from logger.warning to logger.warn and fixed an incorrect import path for zod.
  • Code Organization: The server management tools were consolidated into the src/managers/tools/ directory for better project structure.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • The title of my pull request follows the conventional commits standard
  • Changes have been documented in the README/documentation (if applicable)

@pietrozullo pietrozullo requested a review from Copilot June 28, 2025 17:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces dynamic server management by adding a new AddMCPServerTool to enable on‑the‑fly addition and connection of MCP servers, along with enhanced observability via a logState method in the ServerManager. Key changes include:

  • Implementation of AddMCPServerTool for dynamic server addition and tool discovery.
  • Enhancement of ServerManager with logState for detailed debugging and a corrected logger method.
  • Updates to project examples and package.json to support the new server tool.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/managers/tools/add_server.ts Adds the new tool to connect and add MCP servers dynamically.
src/managers/server_manager.ts Includes logState improvements and corrected logger method usage.
package.json Adds a new example command for the server tool.
examples/browser_use.ts Minor cleanup of extraneous empty line.
examples/add_sever_tool.ts Provides a usage example for dynamic server management.
.husky/pre-commit Updated pre-commit hook command to use npm run lint.
Comments suppressed due to low confidence (1)

examples/add_sever_tool.ts:1

  • The filename 'add_sever_tool.ts' appears to have a typographical error. Consider renaming it to 'add_server_tool.ts' for clarity.
/**

pietrozullo and others added 2 commits June 28, 2025 10:26
@pietrozullo pietrozullo merged commit 58e46aa into main Jun 28, 2025
1 check passed
@pietrozullo pietrozullo deleted the feat/add-server-tool branch June 28, 2025 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants