mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 22:10:34 +00:00
Add mcp/packages/browser-extension, a Manifest V3 extension that will wake a frozen Penpot tab when an MCP task needs it. It is written in TypeScript, bundled with esbuild and imports the protocol types from mcp-common. The package joins the mcp workspace, so the build, test and fmt scripts of mcp/ cover it; the server release build skips it. Its content script runs on design.penpot.app and on local development instances. It asks the page for its MCP session on load, again when the page says it is ready and when the page returns from the back/forward cache, and forwards each valid session announcement to the service worker. It accepts only messages the page posted on its own window from its own origin, and posts its hello to that origin only. It also tells the worker when the page is hidden. The service worker records which tab holds each MCP session, with the MCP server URL and token the session's plugin uses. A tab holds the session it last announced as connected, until its page announces a disconnect, is hidden, or the tab is closed or replaced. The map lives in chrome.storage.session, so it survives service worker restarts and clears when the browser closes. While a tab holds a session the browser may not discard it automatically, since a discarded tab reloads and loses its MCP connection.
42 lines
858 B
Bash
Executable File
42 lines
858 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# NOTE: this script should be called from the parent directory to
|
|
# properly work
|
|
|
|
SCRIPT_DIR=$(dirname $0);
|
|
URL=${1:-http://localhost:9090}
|
|
|
|
echo "Preparing bundle for types from $URL"
|
|
|
|
set -ex
|
|
|
|
# Ensure clean working directory
|
|
rm -rf dist;
|
|
rm -rf node_modules;
|
|
rm -rf packages/server/dist;
|
|
rm -rf packages/server/node_modules;
|
|
|
|
pushd $SCRIPT_DIR;
|
|
set +e
|
|
./build-types $URL;
|
|
set -e
|
|
popd
|
|
|
|
pnpm -r --filter "!mcp-plugin" --filter "!mcp-browser-extension" install;
|
|
pnpm -r --filter "mcp-server" run build;
|
|
|
|
rsync -avr packages/server/dist/ ./dist/;
|
|
|
|
cp packages/server/package.json ./dist/;
|
|
cp pnpm-lock.yaml ./dist/;
|
|
|
|
touch ./dist/pnpm-workspace.yaml;
|
|
|
|
cat <<EOF | tee ./dist/setup
|
|
#!/usr/bin/env bash
|
|
set -e;
|
|
command -v pnpm >/dev/null || { echo "error: pnpm not found in PATH" >&2; exit 1; };
|
|
pnpm install -P
|
|
EOF
|
|
|
|
chmod +x ./dist/setup;
|