mcp tablas

This commit is contained in:
Jordan Diaz
2026-04-25 08:51:17 +00:00
parent 62239cb0a5
commit e84a36c83d
17 changed files with 535 additions and 497 deletions

View File

@@ -0,0 +1,52 @@
import { pythonPost } from "../helpers/pythonServerClient.js";
import { getCurrentProjectInfo } from "../files/helpers.js";
/**
* Llama a un endpoint /api/schema/* del server Python.
*
* Todas las schema-tools comparten el mismo contrato:
* - Resolver projectSlug desde la sesion actual.
* - POST al endpoint con { project, ...body }.
* - Mapear respuesta a formato MCP conservando warnings/schema/etc.
*
* No validamos payloads aqui: la responsabilidad es del caller (zod) y
* del backend Python (validaciones fuertes + proxy al PHP).
*
* @param {string} endpoint - Path relativo, ej: "/api/schema/create-table"
* @param {object} body - Campos especificos de la tool (sin `project`)
* @returns {Promise<{mcp: object}>} Respuesta lista para devolver desde la tool
*/
export async function callSchemaEndpoint(endpoint, body) {
const { projectSlug } = getCurrentProjectInfo();
const result = await pythonPost(endpoint, { project: projectSlug, ...body });
// success=false -> error con los campos utiles del backend (error,
// warnings, recordCount, dataCount, ...) preservados para el LLM.
if (!result || result.success === false) {
const { success: _s, ...rest } = result || {};
return {
mcp: {
content: [{
type: "text",
text: JSON.stringify({
success: false,
error: (result && result.error) || "Schema endpoint returned no success",
...rest,
}, null, 2),
}],
isError: true,
},
};
}
// success=true -> devolvemos el payload completo (incluye warnings,
// schema, recordCount, etc. cuando el backend los adjunta).
return {
mcp: {
content: [{
type: "text",
text: JSON.stringify(result, null, 2),
}],
},
};
}