diff --git a/apps/mcp-server/index.ts b/apps/mcp-server/index.ts index be333c2..9233d13 100644 --- a/apps/mcp-server/index.ts +++ b/apps/mcp-server/index.ts @@ -7,7 +7,7 @@ import { import axios from "axios"; import * as FormData from "form-data"; -const BACKEND_URL = "http://localhost:3051/api"; +let BACKEND_URL = "http://localhost:3051/api"; const ADMIN_USERNAME = process.env.ADMIN_USERNAME || "admin"; const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD || "homaroma123"; // เปลี่ยนรหัสผ่านตรงนี้ให้ตรงกับ Production ด้วยนะครับ @@ -58,6 +58,17 @@ const server = new Server( server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ + { + name: "set_target_environment", + description: "Switch the target environment for the MCP server (local or production)", + inputSchema: { + type: "object", + properties: { + env: { type: "string", enum: ["local", "production"] } + }, + required: ["env"] + } + }, { name: "ping_backend", description: "Ping the backend to verify connection and authentication", @@ -433,6 +444,24 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { try { switch (request.params.name) { + case "set_target_environment": { + const env = params.env; + if (env === "production") { + BACKEND_URL = "https://api.homaroma.shop/api"; + } else { + BACKEND_URL = "http://localhost:3051/api"; + } + api.defaults.baseURL = BACKEND_URL; + authToken = ""; // reset token so it logs in again on next request + return { + content: [ + { + type: "text", + text: `✅ MCP Server target environment switched to [${env}]. Base URL is now: ${BACKEND_URL}` + } + ] + }; + } case "ping_backend": { const res = await api.get("/products?limit=1"); return { content: [{ type: "text", text: `Connection successful!` }] }; diff --git a/apps/spa/index.html b/apps/spa/index.html index 6ea120b..f6523b2 100644 --- a/apps/spa/index.html +++ b/apps/spa/index.html @@ -7,7 +7,7 @@