Initial commit

This commit is contained in:
Jordan
2026-04-01 23:16:45 +01:00
commit bc4199aed2
201 changed files with 25612 additions and 0 deletions

102
mcp-server/config/index.js Normal file
View File

@@ -0,0 +1,102 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import dotenv from "dotenv";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load .env from server directory
dotenv.config({ path: path.join(__dirname, '..', '.env') });
export const CONFIG_FILE_PATH =
process.env.ACAI_CONFIG_PATH ||
path.join(__dirname, "..", "..", "mcp-config.json");
export const MCP_PORT = Number(process.env.MCP_PORT || 3000);
export const MONITOR_PORT = Number(process.env.MCP_MONITOR_PORT || 4545);
export const MONITOR_DISABLED =
String(process.env.MCP_MONITOR_DISABLED || "").toLowerCase() === "1" ||
String(process.env.MCP_MONITOR_DISABLED || "").toLowerCase() === "true";
export const JWT_SECRET =
process.env.MCP_JWT_SECRET ||
process.env.JWT_SECRET ||
"change_me_in_env";
if (JWT_SECRET === "change_me_in_env") {
console.warn("[config] WARNING: JWT_SECRET is using the default value. Set MCP_JWT_SECRET or JWT_SECRET in your .env file for production.");
}
export const LOCAL_SERVER_URL = process.env.LOCAL_SERVER_URL || 'http://localhost:29871';
// Auth headers para llamadas internas al server Python
export function getLocalServerHeaders() {
const headers = { "Content-Type": "application/json" };
// En Forge, usar X-Acai-Token para auth interna
const token = process.env.ACAI_TOKEN || "";
const website = process.env.ACAI_WEBSITE || "";
if (token && website) {
headers["X-Acai-Token"] = token;
headers["X-Acai-Website"] = website;
}
return headers;
}
export const SAAS_URL = "https://ws.cocosolution.com/api/schemas/";
export const CMS_URL = "https://acai.cms.cocosolution.com";
const selectProfile = (config) => {
if (!config || typeof config !== "object") {
return null;
}
if (config.token && config.website) {
return { ...config, profileName: config.profileName || "default" };
}
const profiles = config.profiles || {};
const profileKey =
process.env.ACAI_PROFILE ||
config.defaultProfile ||
Object.keys(profiles)[0];
if (profileKey && profiles[profileKey]) {
return {
...profiles[profileKey],
profileName: profileKey,
};
}
return null;
};
export const loadLocalConfigProfile = () => {
if (!fs.existsSync(CONFIG_FILE_PATH)) {
return null;
}
try {
const raw = fs.readFileSync(CONFIG_FILE_PATH, "utf-8");
const parsed = JSON.parse(raw);
return selectProfile(parsed);
} catch (error) {
console.error(`[config] Could not read ${CONFIG_FILE_PATH}: ${error.message}`);
return null;
}
};
export const applyProfileToEnv = (profile) => {
if (!profile) {
return;
}
if (!process.env.ACAI_TOKEN && profile.token) {
process.env.ACAI_TOKEN = profile.token;
}
if (!process.env.ACAI_TOKEN_HASH && profile.tokenHash) {
process.env.ACAI_TOKEN_HASH = profile.tokenHash;
}
if (!process.env.ACAI_WEBSITE && profile.website) {
process.env.ACAI_WEBSITE = profile.website;
}
console.error(`[config] Loaded Acai profile '${profile.profileName}' from ${CONFIG_FILE_PATH}`);
};