Files
Jordan Diaz 237dc00379 nah
2026-04-09 20:46:03 +00:00

50 lines
2.3 KiB
JavaScript

import { z } from "zod";
import { 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 },
async (_params, extra) => {
try {
const sessionId = extra?.sessionId || "_default";
const credentials = await getSessionCredentials(sessionId);
if (!credentials || !credentials.web_url) {
return {
content: [{ type: "text", text: "Error: no web_url available. Run select_project first." }],
isError: true,
};
}
// En modo local forzamos http:// porque los certificados SSL de
// los subdominios forge pueden no validar correctamente en
// playwright/fetch/curl desde el container. En produccion se
// mantiene https:// (el sitio real tiene certificado valido).
let webUrl = credentials.web_url;
if (credentials.mode !== "production" && typeof webUrl === "string" && webUrl.startsWith("https://")) {
webUrl = "http://" + webUrl.slice("https://".length);
}
return {
content: [{
type: "text",
text: JSON.stringify({
web_url: webUrl,
api_web_url: credentials.api_web_url || null,
website: credentials.website || null,
note: "Always use web_url for Playwright/fetch. IMPORTANT: Always append ?pruebas=1 to any URL you visit (e.g. web_url + '/?pruebas=1' or web_url + '/servicios/?pruebas=1'). Never use the production domain directly.",
})
}],
};
} catch (error) {
return handleToolError(error, "get_web_url", {});
}
}
);
}