Skip to content

Commit 08a20f6

Browse files
committed
chore(mcp.server): remove irregular environment patch
refactor(mcp.server): prevent browser-use from affecting mcp stdio communication
1 parent d4358ef commit 08a20f6

3 files changed

Lines changed: 14 additions & 26 deletions

File tree

app/__main__.py

Whitespace-only changes.

app/mcp/server.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
1+
import logging
2+
import sys
3+
4+
5+
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler(sys.stderr)])
6+
17
import argparse
28
import asyncio
39
import atexit
410
import json
5-
import logging
6-
import os
7-
import sys
811
from inspect import Parameter, Signature
912
from typing import Any, Dict, Optional
1013

1114
from mcp.server.fastmcp import FastMCP
1215

13-
14-
# Add directories to Python path (needed for proper importing)
15-
current_dir = os.path.dirname(os.path.abspath(__file__))
16-
parent_dir = os.path.dirname(current_dir)
17-
root_dir = os.path.dirname(parent_dir)
18-
sys.path.insert(0, parent_dir)
19-
sys.path.insert(0, current_dir)
20-
sys.path.insert(0, root_dir)
21-
22-
# Configure logging (using the same format as original)
23-
logging.basicConfig(
24-
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
25-
)
26-
logger = logging.getLogger("mcp-server")
27-
16+
from app.logger import logger
2817
from app.tool.base import BaseTool
2918
from app.tool.bash import Bash
3019
from app.tool.browser_use_tool import BrowserUseTool
@@ -45,11 +34,6 @@ def __init__(self, name: str = "openmanus"):
4534
self.tools["editor"] = StrReplaceEditor()
4635
self.tools["terminate"] = Terminate()
4736

48-
from app.logger import logger as app_logger
49-
50-
global logger
51-
logger = app_logger
52-
5337
def register_tool(self, tool: BaseTool, method_name: Optional[str] = None) -> None:
5438
"""Register a tool with parameter validation and documentation."""
5539
tool_name = method_name or tool.name

run_mcp.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ class MCPRunner:
1313

1414
def __init__(self):
1515
self.root_path = config.root_path
16-
self.server_script = self.root_path / "app" / "mcp" / "server.py"
16+
self.server_reference = "app.mcp.server"
1717
self.agent = MCPAgent()
1818

19-
async def initialize(self, connection_type: str, server_url: str = None) -> None:
19+
async def initialize(
20+
self,
21+
connection_type: str,
22+
server_url: str | None = None,
23+
) -> None:
2024
"""Initialize the MCP agent with the appropriate connection."""
2125
logger.info(f"Initializing MCPAgent with {connection_type} connection...")
2226

2327
if connection_type == "stdio":
2428
await self.agent.initialize(
2529
connection_type="stdio",
2630
command=sys.executable,
27-
args=[str(self.server_script)],
31+
args=["-m", self.server_reference],
2832
)
2933
else: # sse
3034
await self.agent.initialize(connection_type="sse", server_url=server_url)

0 commit comments

Comments
 (0)