cambios mcp remoto

This commit is contained in:
Jordan Diaz
2026-04-17 20:03:02 +00:00
parent d41a94b57d
commit 2ac01acd61
15 changed files with 344 additions and 123 deletions

View File

@@ -1,9 +1,31 @@
import axios from "axios";
import path from "path";
import { LOCAL_SERVER_URL, getLocalServerHeaders } from "../../config/index.js";
import { getCurrentSessionId } from "../../utils/sessionContext.js";
import { getMcpSessionCredentials } from "../../auth/credentials.js";
import { resolveCurrentAcaiUser } from "../helpers/sessionHelpers.js";
/**
* Resuelve `project_dir` para la tool en curso.
*
* Orden de precedencia:
* 1. AsyncLocalStorage (mcpSessionId) -> credenciales de la sesion HTTP
* 2. process.env.ACAI_PROJECT_DIR (modo stdio / fallback legacy)
*
* Devuelve string vacio si no hay forma de resolverlo — el caller decide
* como manejar el error.
*/
export function resolveCurrentProjectDir() {
const sessionId = getCurrentSessionId();
if (sessionId) {
const creds = getMcpSessionCredentials(sessionId);
if (creds?.project_dir) return creds.project_dir;
}
return process.env.ACAI_PROJECT_DIR || "";
}
export function getCurrentProjectInfo() {
const projectDir = process.env.ACAI_PROJECT_DIR || "";
const projectDir = resolveCurrentProjectDir();
if (!projectDir) {
throw new Error("ACAI_PROJECT_DIR not set");
}
@@ -15,6 +37,11 @@ export function getCurrentProjectInfo() {
export async function callLocalFileEndpoint(method, endpoint, payload = null, query = null) {
const headers = getLocalServerHeaders();
// Inyectar X-Acai-User cuando hay sesion HTTP activa: permite que los
// endpoints autenticados del server Python identifiquen al usuario sin
// depender de Authorization Basic.
const acaiUser = resolveCurrentAcaiUser();
if (acaiUser) headers["X-Acai-User"] = acaiUser;
if (method === "GET") {
const response = await axios.get(`${LOCAL_SERVER_URL}${endpoint}`, {
params: query || undefined,