feat: 4 tools nuevas + browser_list enriquecido
Tools nuevas (wrappers finos sobre funciones del registry functions/browser): - page_collect_console -> cdp_collect_console (console + exceptions + log, snapshot) - page_pdf -> cdp_print_pdf (Page.printToPDF a archivo) - dom_select_option -> cdp_select_option (<select> por value/texto + input/change) - dom_set_files -> cdp_set_file_input (subir archivos a <input type=file>) browser_list ahora enriquece cada master con CDP con pages (nº de page targets), active_title y active_url via GET /json (best-effort: si el puerto no responde los campos quedan a cero y el listado de procesos no falla). Total tools: 46 -> 50. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+40
-2
@@ -16,6 +16,8 @@ import (
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
|
||||
"fn-registry/functions/browser"
|
||||
)
|
||||
|
||||
// registerLifecycleTools wires the per-profile Chromium lifecycle tools:
|
||||
@@ -55,7 +57,10 @@ type chromiumMaster struct {
|
||||
UserDataDir string `json:"user_data_dir"` // value of --user-data-dir
|
||||
CDPPort string `json:"cdp_port"` // value of --remote-debugging-port ("" if none)
|
||||
HasCDP bool `json:"has_cdp"`
|
||||
Headless bool `json:"headless"` // true if launched with --headless / --headless=new / --headless=old
|
||||
Headless bool `json:"headless"` // true if launched with --headless / --headless=new / --headless=old
|
||||
Pages int `json:"pages"` // count of "page" targets (best-effort via GET /json; 0 if no CDP or unreachable)
|
||||
ActiveTitle string `json:"active_title,omitempty"` // title of the first "page" target
|
||||
ActiveURL string `json:"active_url,omitempty"` // URL of the first "page" target
|
||||
}
|
||||
|
||||
// parseCmdline turns the raw bytes of /proc/<pid>/cmdline into argv.
|
||||
@@ -271,7 +276,7 @@ type browserListArgs struct{}
|
||||
|
||||
func browserListTool() mcp.Tool {
|
||||
return mcp.NewTool("browser_list",
|
||||
mcp.WithDescription("List the running Chromium MASTER processes (one per user-data-dir master, NOT zygote/gpu/renderer children). For each: pid, profile (--profile-directory value), user_data_dir, cdp_port (--remote-debugging-port value, empty if none), has_cdp, headless (true if launched with --headless). Returns a JSON array. Read-only."),
|
||||
mcp.WithDescription("List the running Chromium MASTER processes (one per user-data-dir master, NOT zygote/gpu/renderer children). For each: pid, profile (--profile-directory value), user_data_dir, cdp_port (--remote-debugging-port value, empty if none), has_cdp, headless (true if launched with --headless), pages (count of open page targets via GET /json, best-effort), active_title/active_url (first open page). Returns a JSON array. Read-only."),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -283,10 +288,43 @@ func (d *deps) handleBrowserList(_ context.Context, _ mcp.CallToolRequest, _ bro
|
||||
if masters == nil {
|
||||
masters = []chromiumMaster{}
|
||||
}
|
||||
// Enriquecer cada master con CDP con su nº de páginas y la primera página
|
||||
// (título/URL) consultando GET /json. Best-effort: si el puerto no responde,
|
||||
// se dejan los campos a cero — el listado de procesos nunca falla por esto.
|
||||
for i := range masters {
|
||||
enrichMasterTabs(&masters[i])
|
||||
}
|
||||
b, _ := json.MarshalIndent(masters, "", " ")
|
||||
return mcp.NewToolResultText(string(b)), nil
|
||||
}
|
||||
|
||||
// enrichMasterTabs rellena Pages/ActiveTitle/ActiveURL de un master consultando
|
||||
// sus targets CDP por HTTP. No devuelve error: cualquier fallo (sin CDP, puerto
|
||||
// caído, timeout) deja los campos en su cero y el master se reporta igual.
|
||||
func enrichMasterTabs(m *chromiumMaster) {
|
||||
if m.CDPPort == "" {
|
||||
return
|
||||
}
|
||||
port, err := strconv.Atoi(m.CDPPort)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tabs, err := browser.CdpListTabs("localhost", port)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, t := range tabs {
|
||||
if t.Type != "page" {
|
||||
continue
|
||||
}
|
||||
m.Pages++
|
||||
if m.ActiveURL == "" {
|
||||
m.ActiveTitle = t.Title
|
||||
m.ActiveURL = t.URL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- browser_launch_profile (MUTA) ----
|
||||
|
||||
type launchProfileArgs struct {
|
||||
|
||||
Reference in New Issue
Block a user