From 30a62d9a1d3c125a5f5a5dd290e5f2a307e9539f Mon Sep 17 00:00:00 2001 From: Jordan Diaz Date: Mon, 6 Apr 2026 19:33:39 +0000 Subject: [PATCH] Tool get_web_url: devuelve URL correcta del proyecto para fetch/playwright Co-Authored-By: Claude Opus 4.6 (1M context) --- docs/knowledge-index-base.md | 5 ++-- mcp-server/tools/project/getWebUrl.js | 39 +++++++++++++++++++++++++++ mcp-server/tools/project/index.js | 2 ++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 mcp-server/tools/project/getWebUrl.js diff --git a/docs/knowledge-index-base.md b/docs/knowledge-index-base.md index d077d73..803e96f 100644 --- a/docs/knowledge-index-base.md +++ b/docs/knowledge-index-base.md @@ -5,10 +5,9 @@ This is an Acai CMS website project. Follow these instructions when working with ## Environment - The site runs in Docker. The development URL is provided via `ACAI_WEB_URL` environment variable (e.g. `https://username_domain.forge.acaisuite.com/`) -- **ALWAYS use `ACAI_WEB_URL` for fetch, Playwright, and any HTTP request.** This is the local development copy. -- **NEVER navigate to the production domain** (e.g. `keepsailing.es`, `tienda.com`). The production site is NOT your development environment. Only use the forge URL. +- **Before using fetch or Playwright, call the `get_web_url` tool** to get the correct development URL. Never hardcode or guess URLs. +- **NEVER navigate to the production domain** (e.g. `keepsailing.es`, `tienda.com`). The production site is NOT your development environment. - **NEVER use localhost:8080** — that does not resolve in this environment. -- If `ACAI_WEB_URL` is not available, check the `.acai` file for `local_web_url`. ## Project Structure diff --git a/mcp-server/tools/project/getWebUrl.js b/mcp-server/tools/project/getWebUrl.js new file mode 100644 index 0000000..c33cbdc --- /dev/null +++ b/mcp-server/tools/project/getWebUrl.js @@ -0,0 +1,39 @@ +import { z } from "zod"; +import { withAuth, getSessionCredentials } from "../../auth/index.js"; +import { handleToolError } from "../helpers/errorHandler.js"; +import { withAuthParams } from "../helpers/authSchema.js"; + +export function registerGetWebUrlTool(server) { + server.tool( + "get_web_url", + `Get the correct URL for the project's development website. Always use this URL for fetch, Playwright, or any HTTP request to the site. Never guess or use production domains.`, + withAuthParams({}), + { readOnlyHint: true, destructiveHint: false }, + withAuth(async (_params, extra) => { + try { + const credentials = await getSessionCredentials(extra.sessionId); + + if (!credentials || !credentials.web_url) { + return { + content: [{ type: "text", text: "Error: no web_url available. Run select_project first." }], + isError: true, + }; + } + + return { + content: [{ + type: "text", + text: JSON.stringify({ + web_url: credentials.web_url, + api_web_url: credentials.api_web_url || null, + website: credentials.website || null, + note: "Always use web_url for Playwright/fetch. Never use the production domain directly.", + }) + }], + }; + } catch (error) { + return handleToolError(error, "get_web_url", {}); + } + }) + ); +} diff --git a/mcp-server/tools/project/index.js b/mcp-server/tools/project/index.js index 438ebf7..e11b10a 100644 --- a/mcp-server/tools/project/index.js +++ b/mcp-server/tools/project/index.js @@ -1,5 +1,7 @@ import { registerSaveProjectStylesTool } from "./saveStyles.js"; +import { registerGetWebUrlTool } from "./getWebUrl.js"; export function registerProjectTools(server) { registerSaveProjectStylesTool(server); + registerGetWebUrlTool(server); }