Tool get_web_url: devuelve URL correcta del proyecto para fetch/playwright
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
39
mcp-server/tools/project/getWebUrl.js
Normal file
39
mcp-server/tools/project/getWebUrl.js
Normal file
@@ -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", {});
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { registerSaveProjectStylesTool } from "./saveStyles.js";
|
||||
import { registerGetWebUrlTool } from "./getWebUrl.js";
|
||||
|
||||
export function registerProjectTools(server) {
|
||||
registerSaveProjectStylesTool(server);
|
||||
registerGetWebUrlTool(server);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user