diff --git a/openmanus_server/README.md b/openmanus_server/README.md index faf0459..d3a0cc0 100644 --- a/openmanus_server/README.md +++ b/openmanus_server/README.md @@ -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 + + + + ## 📖 Usage -### Starting the MCP Server +### Testing your server with Claude for Desktop -The server supports two communication modes: stdio and HTTP. + +Claude for Desktop is not yet available on Linux. Linux users can build an MCP client that connects to the server we just built. + -#### 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 ![hammer icon](./assets/claude-desktop-mcp-hammer-icon.svg) ## 💻 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 diff --git a/openmanus_server/assets/.DS_Store b/openmanus_server/assets/.DS_Store new file mode 100644 index 0000000..8ceabb1 Binary files /dev/null and b/openmanus_server/assets/.DS_Store differ diff --git a/openmanus_server/assets/claude-desktop-mcp-hammer-icon.svg b/openmanus_server/assets/claude-desktop-mcp-hammer-icon.svg new file mode 100644 index 0000000..d8e4f80 --- /dev/null +++ b/openmanus_server/assets/claude-desktop-mcp-hammer-icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/openmanus_server/assets/demo.mp4 b/openmanus_server/assets/demo.mp4 new file mode 100644 index 0000000..a1c9a89 Binary files /dev/null and b/openmanus_server/assets/demo.mp4 differ diff --git a/openmanus_server/openmanus_server.py b/openmanus_server/openmanus_server.py index 023d53d..d25f9a6 100644 --- a/openmanus_server/openmanus_server.py +++ b/openmanus_server/openmanus_server.py @@ -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(