mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-19 06:30:54 +08:00
Merge pull request #331 from Coff0xc/fix/browser-mcp-npx
fix(mcp): launch the browser MCP from playwright-mcp, not npx
This commit is contained in:
@@ -54,6 +54,7 @@ All notable changes to this project are documented in this file. The format is b
|
||||
- **Chat session directories**: `ChatAgent.Chat` accepts only `[A-Za-z0-9_-]` session ids (at most 64 bytes) before joining them under `<workDir>/sessions`, so `..` and path separators cannot escape that directory.
|
||||
- **Change-password rate limit**: `POST /api/auth/change-password` uses the same limiter as login, keyed by client IP and by the session token, so a stolen session cannot guess the current password without backoff.
|
||||
- **Ingested traffic headers**: `RecordExternal` rejects a method that is not an HTTP token and header names or values that contain CR, LF, or NUL, matching Replay, so ingested exchanges cannot inject extra header lines into stored evidence.
|
||||
- **Browser MCP starts offline** (#329): the seeded `browser` MCP ran `npx @playwright/mcp`, which contacts the npm registry on every start even with the package installed globally, and Playwright MCP defaulted to a Chrome channel the image does not ship. It now runs the image's `playwright-mcp` binary with `--headless --browser chromium`. Existing databases that still have a stock `npx @playwright/mcp` row (including the common `-y` form) or a `playwright-mcp` row with no `--browser` are rewritten once; any other command or package is left alone. The image also installs the Chromium build `@playwright/mcp` and `@playwright/cli` expect, which is not the same build `playwright install` puts in the cache.
|
||||
- **ask_operator image_path**: the screenshot path must resolve inside the task working directory (`<data>/tasks/<id>`). Absolute paths, `..` segments, and symlinks that leave that directory are refused, so the tool cannot copy an arbitrary server image into the operator transcript.
|
||||
- **insert_assets fail-closed**: when intercept or task allow/block rules cannot be loaded, `insert_assets` refuses the whole call instead of evaluating an empty rule set (which allowed every asset). The tool result does not include the underlying database error.
|
||||
- **BlobRange length no longer wraps int64**: `offset+length > size` overflowed when length was near MaxInt64, so the cap was skipped and `make([]byte, length)` could exhaust memory. The bound is now `length > size-offset`.
|
||||
|
||||
+13
-4
@@ -167,18 +167,27 @@ RUN set -eux; \
|
||||
! grep -qE "Installing|ERRR|CRITICAL" /tmp/bbot-dry.log || { cat /tmp/bbot-dry.log; exit 1; }
|
||||
|
||||
|
||||
# Preinstall Playwright MCP and CLI (globally) so no npx network download is needed at runtime.
|
||||
# @playwright/mcp: browser MCP runs directly via `npx @playwright/mcp` (installed globally, no -y/@latest needed).
|
||||
# Preinstall Playwright MCP and CLI (globally) so no network download is needed at runtime.
|
||||
# @playwright/mcp: the seeded browser MCP runs the playwright-mcp binary directly.
|
||||
# `npx @playwright/mcp` is not used: it queries the npm registry on every start even
|
||||
# with the package installed globally.
|
||||
# @playwright/cli: provides playwright-cli, verified with --help right after install.
|
||||
# Then install playwright (browser management) and preinstall chromium plus its system
|
||||
# dependencies via --with-deps, so MCP/CLI work on first start inside the container
|
||||
# without downloading browsers over the network. All three are pinned; upgrade deliberately.
|
||||
# dependencies via --with-deps. @playwright/mcp and @playwright/cli bundle their own
|
||||
# playwright-core, which expects a different Chromium build than
|
||||
# playwright@PLAYWRIGHT_VERSION installs, so that build is installed as well (second
|
||||
# install line); without it neither can launch a browser. All three packages are
|
||||
# pinned; upgrade deliberately.
|
||||
ARG PLAYWRIGHT_MCP_VERSION=0.0.83
|
||||
ARG PLAYWRIGHT_CLI_VERSION=0.1.22
|
||||
ARG PLAYWRIGHT_VERSION=1.64.1
|
||||
# playwright-core's exports map hides cli.js from require.resolve, so run the
|
||||
# binary npm links for @playwright/mcp instead: it is the copy MCP actually
|
||||
# loads, and it installs the Chromium revision that copy expects.
|
||||
RUN npm install -g "@playwright/mcp@${PLAYWRIGHT_MCP_VERSION}" "@playwright/cli@${PLAYWRIGHT_CLI_VERSION}" "playwright@${PLAYWRIGHT_VERSION}" \
|
||||
&& playwright-cli --help \
|
||||
&& playwright install --with-deps chromium \
|
||||
&& "$(npm root -g)/@playwright/mcp/node_modules/.bin/playwright-core" install chromium \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /app
|
||||
# Binary compiled from source in the build stage above.
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
browserMCPName = "browser"
|
||||
browserMCPCommand = "playwright-mcp"
|
||||
browserMCPDirectBinSetting = "browser_mcp_direct_bin_v1"
|
||||
)
|
||||
|
||||
// browserMCPSeedArgs is the JSON args array for a fresh browser MCP row.
|
||||
// --headless: the image has no display.
|
||||
// --browser chromium: Playwright MCP defaults to the "chrome" channel at
|
||||
// /opt/google/chrome, which the image does not ship.
|
||||
const browserMCPSeedArgs = `["--headless","--browser","chromium"]`
|
||||
|
||||
// npxMetaFlags are npx switches that do not take a value and that still leave
|
||||
// the following argument as the package spec. `-y` is the form the UI mock
|
||||
// used; `--` is a common separator. Flags that take a value (`-p`, `--package`)
|
||||
// are treated as a custom invocation and left alone.
|
||||
var npxMetaFlags = map[string]bool{
|
||||
"-y": true,
|
||||
"--yes": true,
|
||||
"--": true,
|
||||
"-q": true,
|
||||
"--quiet": true,
|
||||
}
|
||||
|
||||
func playwrightMCPPackageIndex(args []string) (int, bool) {
|
||||
for i := 0; i < len(args); i++ {
|
||||
a := args[i]
|
||||
if npxMetaFlags[a] {
|
||||
continue
|
||||
}
|
||||
if a == "@playwright/mcp" || strings.HasPrefix(a, "@playwright/mcp@") {
|
||||
return i, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// rewriteStockNpxBrowserMCP converts `npx [@meta...] @playwright/mcp [...]` to
|
||||
// the image's global playwright-mcp binary. ok is false when the row is not
|
||||
// that invocation (the operator changed the command or the package).
|
||||
func rewriteStockNpxBrowserMCP(command string, args []string) (string, []string, bool) {
|
||||
if command != "npx" {
|
||||
return command, args, false
|
||||
}
|
||||
idx, ok := playwrightMCPPackageIndex(args)
|
||||
if !ok {
|
||||
return command, args, false
|
||||
}
|
||||
rest := append([]string{}, args[idx+1:]...)
|
||||
if !hasCLIFlag(rest, "--headless") {
|
||||
rest = append(rest, "--headless")
|
||||
}
|
||||
if !hasCLIFlag(rest, "--browser") {
|
||||
rest = append(rest, "--browser", "chromium")
|
||||
}
|
||||
return browserMCPCommand, rest, true
|
||||
}
|
||||
|
||||
// rewriteBrowserMCPRow is the one-time row rewrite: stock npx @playwright/mcp
|
||||
// becomes playwright-mcp, and a playwright-mcp row that still has no --browser
|
||||
// (the MCP defaults to a Chrome channel the image does not ship) gets
|
||||
// --browser chromium. Any other command or package is left alone.
|
||||
func rewriteBrowserMCPRow(command string, args []string) (string, []string, bool) {
|
||||
cmd, out, ok := rewriteStockNpxBrowserMCP(command, args)
|
||||
if !ok {
|
||||
cmd, out = command, append([]string{}, args...)
|
||||
}
|
||||
if cmd == browserMCPCommand && !hasCLIFlag(out, "--browser") {
|
||||
out = append(out, "--browser", "chromium")
|
||||
ok = true
|
||||
}
|
||||
return cmd, out, ok
|
||||
}
|
||||
|
||||
func hasCLIFlag(args []string, flag string) bool {
|
||||
eq := flag + "="
|
||||
for _, a := range args {
|
||||
if a == flag || strings.HasPrefix(a, eq) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// migrateStockBrowserMCP rewrites a leftover stock `npx @playwright/mcp` browser
|
||||
// MCP row once, and adds `--browser chromium` to a playwright-mcp row that
|
||||
// still has none. Gated by a settings flag so an operator who later puts npx
|
||||
// back is not rewritten on the next start. Any other command or package is
|
||||
// left as-is.
|
||||
func (d *DB) migrateStockBrowserMCP() error {
|
||||
if v, _, _ := d.GetSetting(browserMCPDirectBinSetting); v == "done" {
|
||||
return nil
|
||||
}
|
||||
var command string
|
||||
var argsRaw []byte
|
||||
err := d.QueryRow(`SELECT COALESCE(command,''), args FROM mcp_servers WHERE name=$1`, browserMCPName).Scan(&command, &argsRaw)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return d.SetSetting(browserMCPDirectBinSetting, "done")
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("read browser mcp: %w", err)
|
||||
}
|
||||
var args []string
|
||||
if len(argsRaw) > 0 {
|
||||
if err := json.Unmarshal(argsRaw, &args); err != nil {
|
||||
return d.SetSetting(browserMCPDirectBinSetting, "done")
|
||||
}
|
||||
}
|
||||
newCommand, newArgs, ok := rewriteBrowserMCPRow(command, args)
|
||||
if ok {
|
||||
raw, err := json.Marshal(newArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("encode browser mcp args: %w", err)
|
||||
}
|
||||
if _, err := d.Exec(`UPDATE mcp_servers SET command=$1, args=$2 WHERE name=$3`, newCommand, string(raw), browserMCPName); err != nil {
|
||||
return fmt.Errorf("update browser mcp: %w", err)
|
||||
}
|
||||
}
|
||||
return d.SetSetting(browserMCPDirectBinSetting, "done")
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRewriteStockNpxBrowserMCP(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
command string
|
||||
args []string
|
||||
wantOK bool
|
||||
wantCommand string
|
||||
wantArgs []string
|
||||
}{
|
||||
{
|
||||
name: "stock seed",
|
||||
command: "npx",
|
||||
args: []string{"@playwright/mcp", "--headless"},
|
||||
wantOK: true,
|
||||
wantCommand: "playwright-mcp",
|
||||
wantArgs: []string{"--headless", "--browser", "chromium"},
|
||||
},
|
||||
{
|
||||
name: "package only",
|
||||
command: "npx",
|
||||
args: []string{"@playwright/mcp"},
|
||||
wantOK: true,
|
||||
wantCommand: "playwright-mcp",
|
||||
wantArgs: []string{"--headless", "--browser", "chromium"},
|
||||
},
|
||||
{
|
||||
name: "pinned package version",
|
||||
command: "npx",
|
||||
args: []string{"@playwright/mcp@0.0.83", "--headless"},
|
||||
wantOK: true,
|
||||
wantCommand: "playwright-mcp",
|
||||
wantArgs: []string{"--headless", "--browser", "chromium"},
|
||||
},
|
||||
{
|
||||
name: "capture proxy args kept",
|
||||
command: "npx",
|
||||
args: []string{"@playwright/mcp", "--headless", "--proxy-server", "http://127.0.0.1:8788"},
|
||||
wantOK: true,
|
||||
wantCommand: "playwright-mcp",
|
||||
wantArgs: []string{"--headless", "--proxy-server", "http://127.0.0.1:8788", "--browser", "chromium"},
|
||||
},
|
||||
{
|
||||
name: "existing --browser kept",
|
||||
command: "npx",
|
||||
args: []string{"@playwright/mcp", "--headless", "--browser", "firefox"},
|
||||
wantOK: true,
|
||||
wantCommand: "playwright-mcp",
|
||||
wantArgs: []string{"--headless", "--browser", "firefox"},
|
||||
},
|
||||
{
|
||||
name: "equals-form --browser kept",
|
||||
command: "npx",
|
||||
args: []string{"@playwright/mcp", "--browser=chrome"},
|
||||
wantOK: true,
|
||||
wantCommand: "playwright-mcp",
|
||||
wantArgs: []string{"--browser=chrome", "--headless"},
|
||||
},
|
||||
{
|
||||
name: "npx -y",
|
||||
command: "npx",
|
||||
args: []string{"-y", "@playwright/mcp", "--headless"},
|
||||
wantOK: true,
|
||||
wantCommand: "playwright-mcp",
|
||||
wantArgs: []string{"--headless", "--browser", "chromium"},
|
||||
},
|
||||
{
|
||||
name: "npx --yes -- separator",
|
||||
command: "npx",
|
||||
args: []string{"--yes", "--", "@playwright/mcp"},
|
||||
wantOK: true,
|
||||
wantCommand: "playwright-mcp",
|
||||
wantArgs: []string{"--headless", "--browser", "chromium"},
|
||||
},
|
||||
{
|
||||
name: "already playwright-mcp",
|
||||
command: "playwright-mcp",
|
||||
args: []string{"--headless"},
|
||||
},
|
||||
{
|
||||
name: "npx -p is a custom invocation",
|
||||
command: "npx",
|
||||
args: []string{"-p", "@playwright/mcp", "playwright-mcp", "--headless"},
|
||||
},
|
||||
{
|
||||
name: "different package",
|
||||
command: "npx",
|
||||
args: []string{"@modelcontextprotocol/server-github"},
|
||||
},
|
||||
{
|
||||
name: "empty args",
|
||||
command: "npx",
|
||||
},
|
||||
{
|
||||
name: "empty command",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
gotCommand, gotArgs, ok := rewriteStockNpxBrowserMCP(tc.command, tc.args)
|
||||
if ok != tc.wantOK {
|
||||
t.Fatalf("ok=%v, want %v", ok, tc.wantOK)
|
||||
}
|
||||
if !tc.wantOK {
|
||||
if gotCommand != tc.command || !slices.Equal(gotArgs, tc.args) {
|
||||
t.Fatalf("unchanged: got %q %q", gotCommand, gotArgs)
|
||||
}
|
||||
return
|
||||
}
|
||||
if gotCommand != tc.wantCommand {
|
||||
t.Fatalf("command=%q, want %q", gotCommand, tc.wantCommand)
|
||||
}
|
||||
if !slices.Equal(gotArgs, tc.wantArgs) {
|
||||
t.Fatalf("args=%q, want %q", gotArgs, tc.wantArgs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteBrowserMCPRow(t *testing.T) {
|
||||
cmd, args, ok := rewriteBrowserMCPRow("playwright-mcp", []string{"--headless"})
|
||||
if !ok || cmd != browserMCPCommand || !slices.Equal(args, []string{"--headless", "--browser", "chromium"}) {
|
||||
t.Fatalf("missing --browser: ok=%v %q %q", ok, cmd, args)
|
||||
}
|
||||
|
||||
cmd, args, ok = rewriteBrowserMCPRow("playwright-mcp", []string{"--headless", "--browser", "firefox"})
|
||||
if ok {
|
||||
t.Fatalf("existing --browser rewritten: %q %q", cmd, args)
|
||||
}
|
||||
|
||||
cmd, args, ok = rewriteBrowserMCPRow("npx", []string{"-y", "@playwright/mcp", "--headless"})
|
||||
if !ok || cmd != browserMCPCommand || !slices.Equal(args, []string{"--headless", "--browser", "chromium"}) {
|
||||
t.Fatalf("npx -y: ok=%v %q %q", ok, cmd, args)
|
||||
}
|
||||
|
||||
in := []string{"--headless"}
|
||||
orig := slices.Clone(in)
|
||||
_, out, ok := rewriteBrowserMCPRow("playwright-mcp", in)
|
||||
if !ok {
|
||||
t.Fatal("expected rewrite")
|
||||
}
|
||||
out[0] = "mutated"
|
||||
if !slices.Equal(in, orig) {
|
||||
t.Fatalf("input mutated: %q", in)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteStockNpxBrowserMCPDoesNotAliasInput(t *testing.T) {
|
||||
in := []string{"@playwright/mcp", "--headless"}
|
||||
orig := slices.Clone(in)
|
||||
_, out, ok := rewriteStockNpxBrowserMCP("npx", in)
|
||||
if !ok {
|
||||
t.Fatal("expected rewrite")
|
||||
}
|
||||
out[0] = "mutated"
|
||||
if !slices.Equal(in, orig) {
|
||||
t.Fatalf("input mutated: %q", in)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeedAndMigrateBrowserMCP(t *testing.T) {
|
||||
d, err := Open(testDSN(t))
|
||||
if err != nil {
|
||||
t.Skipf("postgres unavailable (%v) — skipping", err)
|
||||
}
|
||||
|
||||
origCmd, _, origRaw := readBrowserMCP(t, d)
|
||||
origSetting, origHad, err := d.GetSetting(browserMCPDirectBinSetting)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_, err := d.Exec(`UPDATE mcp_servers SET command=$1, args=$2 WHERE name=$3`, origCmd, origRaw, browserMCPName)
|
||||
cleanupErr(t, "restore browser mcp", err)
|
||||
if origHad {
|
||||
cleanupErr(t, "restore setting", d.SetSetting(browserMCPDirectBinSetting, origSetting))
|
||||
} else {
|
||||
cleanupExec(t, d, `DELETE FROM settings WHERE key=$1`, browserMCPDirectBinSetting)
|
||||
}
|
||||
d.Close()
|
||||
})
|
||||
|
||||
t.Run("stock npx rewritten once", func(t *testing.T) {
|
||||
putBrowserMCP(t, d, "npx", []string{"@playwright/mcp", "--headless"})
|
||||
cleanupExec(t, d, `DELETE FROM settings WHERE key=$1`, browserMCPDirectBinSetting)
|
||||
if err := d.seedBuiltins(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd, args, _ := readBrowserMCP(t, d)
|
||||
if cmd != browserMCPCommand || !slices.Equal(args, []string{"--headless", "--browser", "chromium"}) {
|
||||
t.Fatalf("got %q %q", cmd, args)
|
||||
}
|
||||
putBrowserMCP(t, d, "npx", []string{"@playwright/mcp", "--headless"})
|
||||
if err := d.seedBuiltins(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd, args, _ = readBrowserMCP(t, d)
|
||||
if cmd != "npx" || !slices.Equal(args, []string{"@playwright/mcp", "--headless"}) {
|
||||
t.Fatalf("second pass clobbered: %q %q", cmd, args)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("npx -y rewritten", func(t *testing.T) {
|
||||
putBrowserMCP(t, d, "npx", []string{"-y", "@playwright/mcp", "--headless"})
|
||||
cleanupExec(t, d, `DELETE FROM settings WHERE key=$1`, browserMCPDirectBinSetting)
|
||||
if err := d.seedBuiltins(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd, args, _ := readBrowserMCP(t, d)
|
||||
if cmd != browserMCPCommand || !slices.Equal(args, []string{"--headless", "--browser", "chromium"}) {
|
||||
t.Fatalf("got %q %q", cmd, args)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("playwright-mcp missing --browser", func(t *testing.T) {
|
||||
putBrowserMCP(t, d, "playwright-mcp", []string{"--headless"})
|
||||
cleanupExec(t, d, `DELETE FROM settings WHERE key=$1`, browserMCPDirectBinSetting)
|
||||
if err := d.seedBuiltins(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd, args, _ := readBrowserMCP(t, d)
|
||||
if cmd != browserMCPCommand || !slices.Equal(args, []string{"--headless", "--browser", "chromium"}) {
|
||||
t.Fatalf("got %q %q", cmd, args)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("custom package left alone", func(t *testing.T) {
|
||||
custom := []string{"@modelcontextprotocol/server-github"}
|
||||
putBrowserMCP(t, d, "npx", custom)
|
||||
cleanupExec(t, d, `DELETE FROM settings WHERE key=$1`, browserMCPDirectBinSetting)
|
||||
if err := d.seedBuiltins(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd, args, _ := readBrowserMCP(t, d)
|
||||
if cmd != "npx" || !slices.Equal(args, custom) {
|
||||
t.Fatalf("custom row rewritten: %q %q", cmd, args)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("proxy args preserved", func(t *testing.T) {
|
||||
putBrowserMCP(t, d, "npx", []string{"@playwright/mcp", "--headless", "--proxy-server", "http://127.0.0.1:8788"})
|
||||
cleanupExec(t, d, `DELETE FROM settings WHERE key=$1`, browserMCPDirectBinSetting)
|
||||
if err := d.seedBuiltins(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd, args, _ := readBrowserMCP(t, d)
|
||||
want := []string{"--headless", "--proxy-server", "http://127.0.0.1:8788", "--browser", "chromium"}
|
||||
if cmd != browserMCPCommand || !slices.Equal(args, want) {
|
||||
t.Fatalf("got %q %q", cmd, args)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func putBrowserMCP(t *testing.T, d *DB, command string, args []string) {
|
||||
t.Helper()
|
||||
raw, err := json.Marshal(args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, err := d.Exec(`UPDATE mcp_servers SET command=$1, args=$2 WHERE name=$3`, command, string(raw), browserMCPName)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
n, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 1 {
|
||||
t.Fatalf("update browser mcp: %d rows", n)
|
||||
}
|
||||
}
|
||||
|
||||
func readBrowserMCP(t *testing.T, d *DB) (command string, args []string, raw []byte) {
|
||||
t.Helper()
|
||||
err := d.QueryRow(`SELECT COALESCE(command,''), args FROM mcp_servers WHERE name=$1`, browserMCPName).Scan(&command, &raw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(raw) > 0 {
|
||||
if err := json.Unmarshal(raw, &args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -317,13 +317,21 @@ ON CONFLICT (agent_id, var_name) DO UPDATE
|
||||
// the recording proxy + CA at runtime (server.Manager.syncBrowserMCPProxy).
|
||||
// Insert only if absent so we never clobber user edits (args/env/enabled/
|
||||
// visibility) on restart.
|
||||
// Launched through the installed playwright-mcp binary, not `npx
|
||||
// @playwright/mcp`: npx asks the npm registry on every start, even with the
|
||||
// package installed globally, so the version that runs is the registry's.
|
||||
// --browser chromium: the default is the "chrome" channel (Google Chrome),
|
||||
// which the image does not have; it ships Playwright's Chromium.
|
||||
if _, err := d.Exec(`
|
||||
INSERT INTO mcp_servers(name, transport, command, args, env, enabled)
|
||||
VALUES ('browser', 'stdio', 'npx', $1, '{}', false)
|
||||
VALUES ('browser', 'stdio', $1, $2, '{}', false)
|
||||
ON CONFLICT (name) DO NOTHING`,
|
||||
`["@playwright/mcp","--headless"]`); err != nil {
|
||||
browserMCPCommand, browserMCPSeedArgs); err != nil {
|
||||
return fmt.Errorf("seed browser mcp: %w", err)
|
||||
}
|
||||
if err := d.migrateStockBrowserMCP(); err != nil {
|
||||
return fmt.Errorf("migrate browser mcp: %w", err)
|
||||
}
|
||||
// NOTE: the placeholder ScopeSentry data-source MCP (empty URL + empty X-API-Key,
|
||||
// disabled) is seeded directly in schema.sql §F so a raw `psql < schema.sql` init
|
||||
// also gets it. schema.sql is Exec'd on every startup, so it stays idempotent.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStripProxyArgsLeavesBrowserMCPFlags(t *testing.T) {
|
||||
in := []string{"--headless", "--browser", "chromium", "--proxy-server", "http://127.0.0.1:8788"}
|
||||
got := stripProxyArgs(in)
|
||||
want := []string{"--headless", "--browser", "chromium"}
|
||||
if !slices.Equal(got, want) {
|
||||
t.Fatalf("got %q, want %q", got, want)
|
||||
}
|
||||
if in[3] != "--proxy-server" {
|
||||
t.Fatal("input mutated")
|
||||
}
|
||||
|
||||
equals := []string{"--headless", "--proxy-server=http://127.0.0.1:8788", "--browser", "chromium"}
|
||||
got = stripProxyArgs(equals)
|
||||
if !slices.Equal(got, want) {
|
||||
t.Fatalf("equals form: got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func (s *Server) discoverAndCacheMCP(ctx context.Context, m *db.MCPServer) error
|
||||
|
||||
// discoverEmptyMCPsOnStartup fills the tool cache for any enabled MCP that has none
|
||||
// yet (notably the seeded browser MCP on first run). Runs sequentially in one
|
||||
// goroutine so we never spawn many stdio servers (npx) at once, and never blocks
|
||||
// goroutine so we never spawn many stdio servers at once, and never blocks
|
||||
// startup. Best-effort: a failure leaves the cache empty to retry next start.
|
||||
func (s *Server) discoverEmptyMCPsOnStartup() {
|
||||
servers, err := s.m.pg.ListMCP()
|
||||
|
||||
Reference in New Issue
Block a user