feat: P0 LLM-readiness — Chrome aislado (9333), tab_select determinista, page_get_text, page_perceive

This commit is contained in:
agent
2026-06-06 11:15:12 +02:00
parent 6ecaf9a969
commit 9af2e75246
7 changed files with 272 additions and 36 deletions
+16 -7
View File
@@ -3,6 +3,8 @@ package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
@@ -30,19 +32,26 @@ type launchArgs struct {
func launchTool() mcp.Tool {
return mcp.NewTool("browser_launch",
mcp.WithDescription("Launch a Chrome/Chromium instance with CDP remote debugging enabled. Returns the launched PID. Waits up to 15s for the CDP port to be ready."),
mcp.WithNumber("port", mcp.Description("CDP remote debugging port. Default 9222.")),
mcp.WithDescription("Launch a Chrome/Chromium instance with CDP remote debugging enabled. By default launches a Chrome ISOLATED from the user's daily browser: port 9333 (default) and a dedicated user_data_dir under the temp dir. This keeps the agent off the daily chromium on 9222 (banking, email). Returns the launched PID. Waits up to 15s for the CDP port to be ready."),
mcp.WithNumber("port", mcp.Description("CDP remote debugging port. Default 9333 (the MCP's isolated Chrome). Pass 9222 only to attach to the daily browser.")),
mcp.WithBoolean("headless", mcp.Description("Run headless (--headless=new). Default false.")),
mcp.WithString("user_data_dir", mcp.Description("Chrome profile directory. Empty = /tmp/chrome-cdp-profile.")),
mcp.WithString("user_data_dir", mcp.Description("Chrome profile directory. Empty = a dedicated isolated dir (<tmp>/browser_mcp_userdata), kept separate from the daily browser profile.")),
mcp.WithString("url", mcp.Description("Optional initial URL to open on launch.")),
)
}
func (d *deps) handleLaunch(_ context.Context, _ mcp.CallToolRequest, a launchArgs) (*mcp.CallToolResult, error) {
// SECURITY (P0.3): default to an isolated user-data-dir so the MCP never
// reuses the user's daily browser profile. Created on demand.
userDataDir := a.UserDataDir
if userDataDir == "" {
userDataDir = filepath.Join(os.TempDir(), "browser_mcp_userdata")
_ = os.MkdirAll(userDataDir, 0o755)
}
opts := browser.ChromeLaunchOpts{
Port: portOr(a.Port),
Headless: a.Headless,
UserDataDir: a.UserDataDir,
UserDataDir: userDataDir,
}
if a.URL != "" {
opts.ExtraArgs = append(opts.ExtraArgs, a.URL)
@@ -51,7 +60,7 @@ func (d *deps) handleLaunch(_ context.Context, _ mcp.CallToolRequest, a launchAr
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
return mcp.NewToolResultText(fmt.Sprintf("launched pid=%d port=%d", pid, opts.Port)), nil
return mcp.NewToolResultText(fmt.Sprintf("launched pid=%d port=%d user_data_dir=%s", pid, opts.Port, userDataDir)), nil
}
// ---- browser_connect ----
@@ -63,7 +72,7 @@ type connectArgs struct {
func connectTool() mcp.Tool {
return mcp.NewTool("browser_connect",
mcp.WithDescription("Open (and pool) a CDP WebSocket connection to a running Chrome's first 'page' tab on the given port. Subsequent tools reuse this live session."),
mcp.WithNumber("port", mcp.Description("CDP port. Default 9222.")),
mcp.WithNumber("port", mcp.Description("CDP port. Default 9333 (Chrome isolated del MCP); usa 9222 explícito solo para adjuntarte al navegador diario.")),
)
}
@@ -84,7 +93,7 @@ type disconnectArgs struct {
func disconnectTool() mcp.Tool {
return mcp.NewTool("browser_disconnect",
mcp.WithDescription("Close and drop the pooled CDP connection for the given port (cancels any armed dialog handler). Does NOT kill Chrome."),
mcp.WithNumber("port", mcp.Description("CDP port. Default 9222.")),
mcp.WithNumber("port", mcp.Description("CDP port. Default 9333 (Chrome isolated del MCP); usa 9222 explícito solo para adjuntarte al navegador diario.")),
)
}