cambios mcp remoto
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user