chore(mcp.server): remove irregular environment patch
refactor(mcp.server): prevent browser-use from affecting mcp stdio communication
This commit is contained in:
parent
d4358ef537
commit
08a20f6880
0
app/__main__.py
Normal file
0
app/__main__.py
Normal file
@ -1,30 +1,19 @@
|
|||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler(sys.stderr)])
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import atexit
|
import atexit
|
||||||
import json
|
import json
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from inspect import Parameter, Signature
|
from inspect import Parameter, Signature
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
|
|
||||||
|
from app.logger import logger
|
||||||
# Add directories to Python path (needed for proper importing)
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
parent_dir = os.path.dirname(current_dir)
|
|
||||||
root_dir = os.path.dirname(parent_dir)
|
|
||||||
sys.path.insert(0, parent_dir)
|
|
||||||
sys.path.insert(0, current_dir)
|
|
||||||
sys.path.insert(0, root_dir)
|
|
||||||
|
|
||||||
# Configure logging (using the same format as original)
|
|
||||||
logging.basicConfig(
|
|
||||||
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
||||||
)
|
|
||||||
logger = logging.getLogger("mcp-server")
|
|
||||||
|
|
||||||
from app.tool.base import BaseTool
|
from app.tool.base import BaseTool
|
||||||
from app.tool.bash import Bash
|
from app.tool.bash import Bash
|
||||||
from app.tool.browser_use_tool import BrowserUseTool
|
from app.tool.browser_use_tool import BrowserUseTool
|
||||||
@ -45,11 +34,6 @@ class MCPServer:
|
|||||||
self.tools["editor"] = StrReplaceEditor()
|
self.tools["editor"] = StrReplaceEditor()
|
||||||
self.tools["terminate"] = Terminate()
|
self.tools["terminate"] = Terminate()
|
||||||
|
|
||||||
from app.logger import logger as app_logger
|
|
||||||
|
|
||||||
global logger
|
|
||||||
logger = app_logger
|
|
||||||
|
|
||||||
def register_tool(self, tool: BaseTool, method_name: Optional[str] = None) -> None:
|
def register_tool(self, tool: BaseTool, method_name: Optional[str] = None) -> None:
|
||||||
"""Register a tool with parameter validation and documentation."""
|
"""Register a tool with parameter validation and documentation."""
|
||||||
tool_name = method_name or tool.name
|
tool_name = method_name or tool.name
|
||||||
|
10
run_mcp.py
10
run_mcp.py
@ -13,10 +13,14 @@ class MCPRunner:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.root_path = config.root_path
|
self.root_path = config.root_path
|
||||||
self.server_script = self.root_path / "app" / "mcp" / "server.py"
|
self.server_reference = "app.mcp.server"
|
||||||
self.agent = MCPAgent()
|
self.agent = MCPAgent()
|
||||||
|
|
||||||
async def initialize(self, connection_type: str, server_url: str = None) -> None:
|
async def initialize(
|
||||||
|
self,
|
||||||
|
connection_type: str,
|
||||||
|
server_url: str | None = None,
|
||||||
|
) -> None:
|
||||||
"""Initialize the MCP agent with the appropriate connection."""
|
"""Initialize the MCP agent with the appropriate connection."""
|
||||||
logger.info(f"Initializing MCPAgent with {connection_type} connection...")
|
logger.info(f"Initializing MCPAgent with {connection_type} connection...")
|
||||||
|
|
||||||
@ -24,7 +28,7 @@ class MCPRunner:
|
|||||||
await self.agent.initialize(
|
await self.agent.initialize(
|
||||||
connection_type="stdio",
|
connection_type="stdio",
|
||||||
command=sys.executable,
|
command=sys.executable,
|
||||||
args=[str(self.server_script)],
|
args=["-m", self.server_reference],
|
||||||
)
|
)
|
||||||
else: # sse
|
else: # sse
|
||||||
await self.agent.initialize(connection_type="sse", server_url=server_url)
|
await self.agent.initialize(connection_type="sse", server_url=server_url)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user