mirror of
https://github.com/mcp-use/mcp-use.git
synced 2026-09-14 18:06:01 +08:00
8348c59a53
* docs: reorganize navigation and clean up content - Remove 'Misc' group with misplaced blog posts - Remove 'Libraries' redirect group from Home nav - Simplify 'Dev Tools' group (flatten Inspector, CLI, Tunneling) - Remove individual changelog versions from Python nav (keep summary) - Remove changelog from TypeScript 'Get Started' group - Remove tunneling duplicate from Python Development group - Rewrite mcp101 as clean MCP concepts page (was pitch deck) - Delete typescript/blog posts (not technical docs) - Add redirects for deleted blog post URLs * docs: fix content accuracy and remove sloppy language - Fix broken python/server/mcp-apps link in home page - Remove informal pitch-speak from python/server/index.mdx - Fix grammar error in typescript/server/index.mdx - Update typescript/client/logging.mdx: remove fake 'coming soon' API code - Fix non-existent model name gpt-5.1 in typescript quickstart - Fix mcp_use naming in development contributing guide * docs: fix incorrect TypeScript server API calls in inspector docs - Replace server.addTool() with server.tool() (correct mcp-use API) - Add missing zod import to debugging-chatgpt-apps example * docs: fix fake model names (gpt-5.1 → gpt-4o) in agent docs * docs: update model names, fix APIs, and add agent visibility hints - Replace all deprecated model names with latest: gpt-4.1, gpt-4.1-mini, claude-sonnet-4-6, claude-opus-4-7, gemini-2.5-flash across all docs - Fix TypeScript server.tool() API in installation.mdx (old positional string form) - Fix TypeScript agent.run() in quickstart.mdx (deprecated string form → object) - Remove broken manufact.com/docs/llms.txt hidden hints from 5 pages - Add <Visibility for="agents"> block to mcp101.mdx with install commands, key classes, and API signatures for agent-oriented navigation - Add LangChain provider install note to Python quickstart (mcp-use agent requires a separate langchain-* provider package) - Update model name cards in Python llm-integration.mdx * docs: clean up remaining stale model names and improve accuracy - Update supported model lists in Python and TypeScript llm-integration pages - Fix cost optimization table to use current model IDs - Update TypeScript agent overview supported providers list * docs: add LangChain provider install to TypeScript quickstart agent section The MCPAgent requires a separate @langchain/* provider package; this was not mentioned before the code example that imports from @langchain/openai. * docs: update to latest flagship model IDs (May 2026) - OpenAI: gpt-4.1 → gpt-5.5, gpt-4.1-mini → gpt-5.5-mini - Google: gemini-2.5-flash → gemini-3.1-flash, gemini-2.5-pro → gemini-3.1-pro - Groq: llama-3.1-* → llama-4-scout-17b-16e-instruct - Anthropic (claude-opus-4-7, claude-sonnet-4-6) already current, no change * docs: replace all em dashes with hyphens * docs: restore llms.txt hints using Visibility component * docs: simplify TypeScript logging page to unsupported notice only * docs: rewrite mcp101 to explain MCP protocol with mcp-use examples and doc links * docs: remove goal.md * docs: revert nav changes, keep only Misc group removal and blog redirects * docs: reorder mcp101 to Server/App -> Client/Inspector -> Agent, restore title * docs: add code examples for Resources and Prompts in mcp101 * docs: remove em dashes from mcp101 * docs: add MCPClient code examples to mcp101 * docs: add React client example to mcp101 * docs: add agent code examples to mcp101 * docs: expand MCP Apps section in mcp101 with example and links * docs: restore Contacts, Socials, and Founders sections to mcp101 * docs: add context-setting intro paragraph to mcp101 for new readers * docs: add MCP stores section to mcp101 intro with Claude, ChatGPT, Cursor * docs: fix Claude store link * docs: fix ChatGPT store link * docs: fix Cursor store link * docs: replace store Cards with linked image grid * docs: add captions to store images * docs: add Notifications to client primitives table in mcp101 * docs: add lead-in paragraph before resource cards at bottom of mcp101 * docs: move resource cards to end of page after Contacts/Socials/Founders * docs: demote Contacts/Socials/Founders to bold text to remove from TOC * docs: move Contacts/Socials/Founders to very end of mcp101 * docs: add Resources and Contacts section headers, link official MCP docs * chore(docs): update site metadata, footer links, and rename mcp_use to mcp-use * update docs metadata + images * docs: enhance MCP section by highlighting the reach of MCP stores with 1 billion weekly active users * api ref
278 lines
8.2 KiB
Plaintext
278 lines
8.2 KiB
Plaintext
---
|
||
title: 'Server Manager'
|
||
description: 'Intelligent management of multiple MCP servers and dynamic tool discovery'
|
||
icon: 'server-cog'
|
||
---
|
||
|
||
# Server Manager: Dynamic Multi-Server Intelligence
|
||
|
||
The Server Manager is the brain behind intelligent MCP server orchestration. It transforms your agent from a static tool user into a dynamic, adaptive assistant that can discover, connect to, and intelligently utilize tools from multiple MCP servers on-demand.
|
||
|
||
## What Makes It Special
|
||
|
||
Instead of overwhelming your agent with hundreds of tools from all servers at once, the Server Manager:
|
||
|
||
- **Dynamically loads tools** only when needed, with full schemas
|
||
- **Intelligently discovers** the right server for each task
|
||
- **Automatically updates** available tools as connections change
|
||
- **Provides semantic search** across all server tools
|
||
- **Manages connection lifecycle** efficiently
|
||
|
||
## Architecture Overview
|
||
|
||
```mermaid
|
||
graph TB
|
||
Agent[MCPAgent] --> SM[ServerManager]
|
||
SM --> S1[Web Server]
|
||
SM --> S2[File Server]
|
||
SM --> S3[Database Server]
|
||
|
||
SM --> Tools[Dynamic Tools]
|
||
```
|
||
|
||
## Dynamic Tool Loading Process
|
||
|
||
```mermaid
|
||
sequenceDiagram
|
||
Agent->>ServerManager: Connect to server
|
||
ServerManager->>Server: Get tools
|
||
Server->>ServerManager: Return tools
|
||
ServerManager->>Agent: Tools now available
|
||
Agent->>Server: Use tools directly
|
||
```
|
||
|
||
## Getting Started
|
||
|
||
Enable the Server Manager in your agent:
|
||
|
||
<CodeGroup>
|
||
```python Python
|
||
from mcp_use import MCPClient, MCPAgent
|
||
from langchain_openai import ChatOpenAI
|
||
|
||
# Create client with multiple servers
|
||
client = MCPClient.from_dict({
|
||
"mcpServers": {
|
||
"playwright": {
|
||
"command": "npx",
|
||
"args": ["@playwright/mcp@latest"]
|
||
},
|
||
"filesystem": {
|
||
"command": "uvx",
|
||
"args": ["mcp-server-filesystem", "/tmp"]
|
||
}
|
||
}
|
||
})
|
||
|
||
# Enable Server Manager
|
||
agent = MCPAgent(
|
||
llm=ChatOpenAI(model="gpt-4"),
|
||
client=client,
|
||
use_server_manager=True # This is the magic switch!
|
||
)
|
||
```
|
||
</CodeGroup>
|
||
|
||
|
||
## Tool Discovery Flow
|
||
|
||
|
||
|
||
|
||
## Management Tools Deep Dive
|
||
|
||
### Core Server Management
|
||
|
||
| Tool | Purpose | Example |
|
||
|------|---------|---------|
|
||
| `list_mcp_servers` | Discovery of available servers and their tools | "What servers do I have access to?" |
|
||
| `connect_to_mcp_server` | Activate a server and load its tools | "Connect to the filesystem server" |
|
||
| `get_active_mcp_server` | Check current connection status | "Which server am I currently using?" |
|
||
| `disconnect_from_mcp_server` | Deactivate server and remove its tools | "Disconnect from current server" |
|
||
| `search_mcp_tools` | Semantic search across all server tools | "Find tools for image processing" |
|
||
|
||
### Smart Tool Search Example
|
||
|
||
<CodeGroup>
|
||
```python Python
|
||
# Agent automatically discovers and uses the right tools
|
||
result = await agent.run("""
|
||
I need to:
|
||
1. Find tools for web scraping
|
||
2. Connect to the right server
|
||
3. Scrape data from https://example.com
|
||
4. Save it to a file
|
||
|
||
Start by searching for relevant tools.
|
||
""")
|
||
```
|
||
</CodeGroup>
|
||
|
||
**Agent Process:**
|
||
```mermaid
|
||
graph LR
|
||
Search[Search Tools] --> Connect[Connect Server]
|
||
Connect --> Use[Use Tools]
|
||
```
|
||
|
||
## Real-World Use Cases
|
||
|
||
### 1. Multi-Server Data Pipeline
|
||
|
||
<CodeGroup>
|
||
```python Python
|
||
result = await agent.run("""
|
||
Create a data pipeline that:
|
||
1. Scrapes product data from an e-commerce site
|
||
2. Processes and cleans the data
|
||
3. Saves it to a CSV file
|
||
4. Loads it into a SQLite database
|
||
|
||
Figure out which servers and tools you need.
|
||
""")
|
||
```
|
||
</CodeGroup>
|
||
|
||
**Server Flow:**
|
||
```
|
||
playwright → filesystem → database
|
||
↓ ↓ ↓
|
||
scraping → save CSV → load data
|
||
```
|
||
|
||
### 2. Content Creation Workflow
|
||
|
||
<CodeGroup>
|
||
```python Python
|
||
result = await agent.run("""
|
||
I want to:
|
||
1. Search for trending topics online
|
||
2. Generate an image based on the topic
|
||
3. Write a blog post about it
|
||
4. Save everything to files
|
||
|
||
What tools do I need for this?
|
||
""")
|
||
```
|
||
</CodeGroup>
|
||
|
||
## Performance Benefits
|
||
|
||
The Server Manager provides focused tool access:
|
||
|
||
- **Without Server Manager**: All 100+ tools from all servers loaded at once, overwhelming the model
|
||
- **With Server Manager**: Only 5-15 relevant tools from the active server, providing clear focus
|
||
|
||
## Core Features
|
||
|
||
The Server Manager provides these powerful capabilities:
|
||
|
||
- **Dynamic Tool Addition**: Server tools automatically added with full schemas
|
||
- **Real-time Updates**: Tool list updates immediately when connecting/disconnecting
|
||
- **Clean Architecture**: Direct tool access with proper schemas
|
||
- **Model Understanding**: Tools come with native schemas and validation
|
||
- **Smart Logging**: Detailed insights into tool changes and server status
|
||
|
||
## Complete Example
|
||
|
||
<CodeGroup>
|
||
```python Python
|
||
import asyncio
|
||
from mcp_use import MCPClient, MCPAgent
|
||
from langchain_openai import ChatOpenAI
|
||
|
||
async def demo_server_manager():
|
||
# Multi-server configuration
|
||
client = MCPClient.from_dict({
|
||
"mcpServers": {
|
||
"web": {"command": "npx", "args": ["@playwright/mcp@latest"]},
|
||
"files": {"command": "uvx", "args": ["mcp-server-filesystem", "/tmp"]},
|
||
"database": {"command": "uvx", "args": ["mcp-server-sqlite"]}
|
||
}
|
||
})
|
||
|
||
# Agent with Server Manager
|
||
agent = MCPAgent(
|
||
llm=ChatOpenAI(model="gpt-4"),
|
||
client=client,
|
||
use_server_manager=True,
|
||
verbose=True # See the magic happen!
|
||
)
|
||
|
||
# Complex multi-server task
|
||
result = await agent.run("""
|
||
I need to build a complete data collection system:
|
||
|
||
1. First, show me what servers and tools are available
|
||
2. Scrape product information from https://example-store.com
|
||
3. Clean and structure the data
|
||
4. Save it as both JSON and CSV files
|
||
5. Load the data into a SQLite database
|
||
6. Generate a summary report
|
||
|
||
Guide me through each step and show me how you discover and use the right tools.
|
||
""")
|
||
|
||
print("Task completed!")
|
||
print(result)
|
||
|
||
await agent.close()
|
||
|
||
if __name__ == "__main__":
|
||
asyncio.run(demo_server_manager())
|
||
```
|
||
</CodeGroup>
|
||
|
||
The Server Manager transforms your MCP agent from a static tool user into an intelligent, adaptive assistant that can dynamically discover and utilize the perfect tools for any task!
|
||
|
||
|
||
|
||
## Bring Your Own Server Manager
|
||
|
||
For ultimate control, you can create your own server manager. By implementing the `BaseServerManager` abstract class, you can define custom logic for tool discovery, dynamic tool creation, or integration with other systems. The server manager's primary role is to provide tools **to the agent**. These can be management tools for connecting to external MCP servers, or, as shown below, custom tools that operate entirely within the agent's environment without needing an external server.
|
||
|
||
Here’s a minimal example of a custom server manager that provides a single, hard-coded tool directly to the agent.
|
||
|
||
```python
|
||
import asyncio
|
||
from mcp_use.agents import MCPAgent
|
||
from mcp_use.managers.base import BaseServerManager
|
||
from langchain_core.tools import BaseTool
|
||
from langchain_openai import ChatOpenAI
|
||
from pydantic import BaseModel
|
||
|
||
# 1. Define a custom tool
|
||
class HelloWorldTool(BaseTool):
|
||
"""A simple tool that returns a greeting."""
|
||
name: str = "hello_world"
|
||
description: str = "Returns 'Hello, World!'"
|
||
args_schema: type[BaseModel] | None = None
|
||
def _run(self) -> str: return "Hello, World!"
|
||
async def _arun(self) -> str: return "Hello, World!"
|
||
|
||
# 2. Implement the BaseServerManager interface
|
||
class SimpleServerManager(BaseServerManager):
|
||
"""A minimal server manager with one tool."""
|
||
def __init__(self):
|
||
self._tools = [HelloWorldTool()]
|
||
async def initialize(self) -> None: pass
|
||
@property
|
||
def tools(self) -> list[BaseTool]: return self._tools
|
||
def has_tool_changes(self, current_tool_names: set[str]) -> bool:
|
||
return {tool.name for tool in self.tools} != current_tool_names
|
||
|
||
# 3. Pass your custom manager to the agent
|
||
async def useCustomManager():
|
||
agent = MCPAgent(
|
||
llm=ChatOpenAI(model="gpt-5.5"),
|
||
use_server_manager=True,
|
||
server_manager=SimpleServerManager(),
|
||
)
|
||
# The agent now has access to your custom tool
|
||
result = await agent.run("Use the hello_world tool")
|
||
print(result) #> "Hello, World!"
|
||
await agent.close()
|
||
|
||
asyncio.run(useCustomManager())
|
||
```
|