feat: browser_mcp — servidor MCP de control de navegador CDP (33 tools + pool de conexiones)

This commit is contained in:
agent
2026-06-06 10:57:13 +02:00
commit 6ecaf9a969
15 changed files with 1668 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
package main
import (
"context"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"fn-registry/functions/browser"
)
// registerStorageTools wires storage_save (read) + storage_load (MUTA).
func registerStorageTools(s *server.MCPServer, d *deps) {
s.AddTool(storageSaveTool(), mcp.NewTypedToolHandler(d.handleStorageSave))
if !d.readOnly {
s.AddTool(storageLoadTool(), mcp.NewTypedToolHandler(d.handleStorageLoad))
}
}
// ---- storage_save ----
type storageSaveArgs struct {
Port int `json:"port"`
Path string `json:"path"`
}
func storageSaveTool() mcp.Tool {
return mcp.NewTool("storage_save",
mcp.WithDescription("Save the current session storage state (cookies + localStorage) to a JSON file for later reuse."),
mcp.WithNumber("port", mcp.Description("CDP port. Default 9222.")),
mcp.WithString("path", mcp.Required(), mcp.Description("Output JSON file path.")),
)
}
func (d *deps) handleStorageSave(_ context.Context, _ mcp.CallToolRequest, a storageSaveArgs) (*mcp.CallToolResult, error) {
if a.Path == "" {
return mcp.NewToolResultError("path is required"), nil
}
err := d.withConn(portOr(a.Port), func(c *browser.CDPConn) error {
return browser.CdpSaveStorageState(c, a.Path)
})
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
return mcp.NewToolResultText("storage state saved to " + a.Path), nil
}
// ---- storage_load (MUTA) ----
type storageLoadArgs struct {
Port int `json:"port"`
Path string `json:"path"`
}
func storageLoadTool() mcp.Tool {
return mcp.NewTool("storage_load",
mcp.WithDescription("Load a previously saved session storage state (cookies + localStorage) from a JSON file into the live browser."),
mcp.WithNumber("port", mcp.Description("CDP port. Default 9222.")),
mcp.WithString("path", mcp.Required(), mcp.Description("Input JSON file path.")),
)
}
func (d *deps) handleStorageLoad(_ context.Context, _ mcp.CallToolRequest, a storageLoadArgs) (*mcp.CallToolResult, error) {
if a.Path == "" {
return mcp.NewToolResultError("path is required"), nil
}
err := d.withConn(portOr(a.Port), func(c *browser.CDPConn) error {
return browser.CdpLoadStorageState(c, a.Path)
})
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
return mcp.NewToolResultText("storage state loaded from " + a.Path), nil
}