[mcp] implement openmanus server based on MCP
This commit is contained in:
parent
099074eec1
commit
463bc0fe75
@ -36,38 +36,64 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
uv venv
|
||||
source .venv/bin/activate # Unix/macOS
|
||||
# or .venv\Scripts\activate # Windows
|
||||
uv sync
|
||||
uv pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Install MCP dependencies:
|
||||
|
||||
```bash
|
||||
pip install mcp-python
|
||||
uv pip install -r openmanus_server/mcp_requirements.txt
|
||||
```
|
||||
|
||||
## Demo display
|
||||
<video src="./assets/demo.mp4" data-canonical-src="./assets/demo.mp4" controls="controls" muted="muted" class="d-block rounded-bottom-2 border-top width-fit" style="max-height:640px; min-height: 200px"></video>
|
||||
|
||||
|
||||
|
||||
## 📖 Usage
|
||||
|
||||
### Starting the MCP Server
|
||||
### Testing your server with Claude for Desktop
|
||||
|
||||
The server supports two communication modes: stdio and HTTP.
|
||||
<Note>
|
||||
Claude for Desktop is not yet available on Linux. Linux users can build an MCP client that connects to the server we just built.
|
||||
</Note>
|
||||
|
||||
#### stdio mode (default)
|
||||
First, make sure you have Claude for Desktop installed. [You can install the latest version
|
||||
here.](https://claude.ai/download) If you already have Claude for Desktop, **make sure it's updated to the latest version.**
|
||||
|
||||
We'll need to configure Claude for Desktop for this server you want to use. To do this, open your Claude for Desktop App configuration at `~/Library/Application Support/Claude/claude_desktop_config.json` in a text editor. Make sure to create the file if it doesn't exist.
|
||||
|
||||
```bash
|
||||
python mcp_server.py
|
||||
```
|
||||
|
||||
#### HTTP mode
|
||||
|
||||
```bash
|
||||
python mcp_server.py --transport http --host 127.0.0.1 --port 8000
|
||||
vim ~/Library/Application\ Support/Claude/claude_desktop_config.json
|
||||
```
|
||||
You'll then add your servers in the mcpServers key. The MCP UI elements will only show up in Claude for Desktop if at least one server is properly configured.
|
||||
|
||||
### Command Line Arguments
|
||||
In this case, we'll add our single Openmanus server like so:
|
||||
```
|
||||
{
|
||||
"mcpServers": {
|
||||
"openmanus": {
|
||||
"command": "/ABSOLUTE/PATH/TO/PARENT/FOLDER/uv",
|
||||
"args": [
|
||||
"--directory",
|
||||
"/ABSOLUTE/PATH/TO/OpenManus/openmanus_server",
|
||||
"run",
|
||||
"openmanus_server.py"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
* ! You may need to put the full path to the uv executable in the command field. You can get this by running ```which uv``` on MacOS/Linux or ```where uv``` on Windows.
|
||||
|
||||
- `--transport`: Communication method, choose "stdio" or "http" (default: stdio)
|
||||
- `--host`: HTTP server host address (default: 127.0.0.1)
|
||||
- `--port`: HTTP server port (default: 8000)
|
||||
This tells Claude for Desktop:
|
||||
|
||||
1. There's an MCP server named "openmanus"
|
||||
2. To launch it by running uv --directory /ABSOLUTE/PATH/TO/OpenManus/openmanus_server run openmanus_server.py
|
||||
|
||||
Save the file, and restart Claude for Desktop.
|
||||
|
||||
Let's make sure Claude for Desktop is picking up the six tools we've exposed in our `openmanus` server. You can do this by looking for the hammer icon 
|
||||
|
||||
## 💻 Client Example
|
||||
|
||||
@ -75,71 +101,7 @@ Check out `mcp_client_example.py` to learn how to connect to the server and call
|
||||
|
||||
### Running the Client Example
|
||||
|
||||
1. First, start the server in HTTP mode:
|
||||
|
||||
```bash
|
||||
python mcp_server.py --transport http
|
||||
```
|
||||
|
||||
2. In another terminal, run the client example:
|
||||
|
||||
```bash
|
||||
python mcp_client_example.py
|
||||
```
|
||||
|
||||
## 🤖 LLM Integration
|
||||
|
||||
The MCP server can be integrated with LLMs that support tool calling, such as Claude 3 Opus/Sonnet/Haiku.
|
||||
|
||||
### Example with Claude
|
||||
|
||||
```python
|
||||
import anthropic
|
||||
from mcp.client import MCPClient
|
||||
|
||||
# Initialize Claude client
|
||||
client = anthropic.Anthropic(api_key="your_api_key")
|
||||
|
||||
# Connect to MCP server
|
||||
mcp_client = await MCPClient.create_http("http://localhost:8000")
|
||||
|
||||
# Get tool definitions
|
||||
tools = await mcp_client.list_tools()
|
||||
tool_definitions = [tool.to_dict() for tool in tools]
|
||||
|
||||
# Create Claude message
|
||||
message = client.messages.create(
|
||||
model="claude-3-opus-20240229",
|
||||
max_tokens=1000,
|
||||
temperature=0,
|
||||
system="You are a helpful assistant that can use tools to help users.",
|
||||
messages=[{"role": "user", "content": "Search for Model Context Protocol and summarize the top 3 results"}],
|
||||
tools=tool_definitions
|
||||
)
|
||||
|
||||
# Handle tool calls
|
||||
for tool_call in message.content:
|
||||
if hasattr(tool_call, "tool_use"):
|
||||
tool_name = tool_call.tool_use.name
|
||||
tool_params = tool_call.tool_use.input
|
||||
|
||||
# Call MCP tool
|
||||
result = await mcp_client.invoke_tool(tool_name, tool_params)
|
||||
|
||||
# Send results back to Claude
|
||||
message = client.messages.create(
|
||||
model="claude-3-opus-20240229",
|
||||
max_tokens=1000,
|
||||
temperature=0,
|
||||
system="You are a helpful assistant that can use tools to help users.",
|
||||
messages=[
|
||||
{"role": "user", "content": "Search for Model Context Protocol and summarize the top 3 results"},
|
||||
{"role": "assistant", "content": [tool_call]},
|
||||
{"role": "user", "content": [{"type": "tool_result", "tool_use_id": tool_call.tool_use.id, "content": result}]}
|
||||
],
|
||||
tools=tool_definitions
|
||||
)
|
||||
```
|
||||
|
||||
## 🔒 Security Considerations
|
||||
|
||||
|
BIN
openmanus_server/assets/.DS_Store
vendored
Normal file
BIN
openmanus_server/assets/.DS_Store
vendored
Normal file
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M31.4175 14L22.985 5.51002C20.7329 3.26243 17.6811 2.00012 14.4993 2.00012C11.3176 2.00012 8.26581 3.26243 6.01372 5.51002L6.00247 5.52127L4.28122 7.30002C4.10292 7.49163 4.00685 7.74552 4.01364 8.00717C4.02043 8.26883 4.12954 8.51739 4.31754 8.6995C4.50554 8.88161 4.75745 8.98276 5.01919 8.98122C5.28092 8.97968 5.53163 8.87558 5.71747 8.69127L7.43372 6.91877C8.12421 6.22842 8.91217 5.64303 9.77247 5.18127L15.585 11L3.58497 23C3.39921 23.1857 3.25185 23.4062 3.15131 23.6489C3.05077 23.8916 2.99902 24.1517 2.99902 24.4144C2.99902 24.6771 3.05077 24.9372 3.15131 25.1799C3.25185 25.4225 3.39921 25.643 3.58497 25.8288L6.17122 28.415C6.35694 28.6008 6.57744 28.7481 6.82012 28.8487C7.06281 28.9492 7.32291 29.001 7.5856 29.001C7.84828 29.001 8.10839 28.9492 8.35107 28.8487C8.59375 28.7481 8.81425 28.6008 8.99997 28.415L21 16.415L22.7925 18.2075L25 20.4125C25.1857 20.5983 25.4062 20.7456 25.6489 20.8462C25.8916 20.9467 26.1517 20.9985 26.4143 20.9985C26.677 20.9985 26.9371 20.9467 27.1798 20.8462C27.4225 20.7456 27.643 20.5983 27.8287 20.4125L31.415 16.8263C31.7897 16.4516 32.0005 15.9436 32.0009 15.4137C32.0014 14.8838 31.7915 14.3753 31.4175 14ZM7.58497 27L4.99997 24.4138L13.5 15.9138L16.085 18.5L7.58497 27ZM20.2925 14.29L17.5 17.0838L14.9137 14.5L17.7075 11.7063C17.8004 11.6134 17.8742 11.5031 17.9245 11.3817C17.9749 11.2603 18.0008 11.1302 18.0008 10.9988C18.0008 10.8673 17.9749 10.7372 17.9245 10.6158C17.8742 10.4944 17.8004 10.3841 17.7075 10.2913L11.79 4.37502C13.4996 3.89351 15.3067 3.87606 17.0253 4.32445C18.744 4.77284 20.3122 5.67089 21.5687 6.92627L27.0962 12.49L23.5 16.0825L21.7075 14.29C21.6146 14.197 21.5043 14.1233 21.3829 14.073C21.2615 14.0226 21.1314 13.9967 21 13.9967C20.8686 13.9967 20.7384 14.0226 20.617 14.073C20.4956 14.1233 20.3853 14.197 20.2925 14.29ZM26.4175 18.9975L24.9175 17.4975L28.5 13.9063L30 15.4063L26.4175 18.9975Z" fill="#343330"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.0 KiB |
BIN
openmanus_server/assets/demo.mp4
Normal file
BIN
openmanus_server/assets/demo.mp4
Normal file
Binary file not shown.
@ -4,6 +4,14 @@ import json
|
||||
import argparse
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Add current directory to Python path
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
sys.path.insert(0, parent_dir)
|
||||
sys.path.insert(0, current_dir)
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
|
Loading…
x
Reference in New Issue
Block a user