tablas y delete module
This commit is contained in:
@@ -1,65 +1,43 @@
|
||||
import { z } from "zod";
|
||||
import { withAuth, getSessionCredentials } from "../../auth/index.js";
|
||||
import { withAuth, getSessionCredentials, getApiClient } from "../../auth/index.js";
|
||||
import { handleToolError, handleApiResponse } from "../helpers/errorHandler.js";
|
||||
import { AcaiHttpClient } from "../helpers/acaiHttpClient.js";
|
||||
import { withAuthParams } from "../helpers/authSchema.js";
|
||||
import { parseIniMeta } from "./iniParser.js";
|
||||
|
||||
export function registerListTablesTool(server) {
|
||||
server.tool(
|
||||
"list_tables",
|
||||
"List all database tables/schemas and General Sections (tables with 'enlace' field) in the system. Table names returned here are WITHOUT the 'cms_' prefix — use them as-is in all other tool calls. The primary key for all tables is 'num', never 'id'.",
|
||||
withAuthParams({
|
||||
withoutEnlace: z.boolean().default(true).describe("If true, include all tables, not only the ones that are general sections with 'enlace' field"),
|
||||
}),
|
||||
"List all database tables in the project. Table names are WITHOUT 'cms_' prefix — use them as-is in all other tool calls. Primary key is 'num', never 'id'.",
|
||||
withAuthParams({}),
|
||||
{ readOnlyHint: true, destructiveHint: false },
|
||||
withAuth(async ({ withoutEnlace }, extra) => {
|
||||
withAuth(async (params, extra) => {
|
||||
try {
|
||||
console.error(`[list_tables] Tool called with sessionId: ${extra.sessionId}`);
|
||||
console.error(`[list_tables] Getting credentials for session...`);
|
||||
|
||||
const creds = await getSessionCredentials(extra.sessionId);
|
||||
console.error(`[list_tables] Credentials: website=${creds.website}, hasToken=${!!creds.token}, profileName=${creds.profileName}`);
|
||||
|
||||
if (!creds.token) {
|
||||
console.error(`[list_tables] ERROR: No token found for session ${extra.sessionId}!`);
|
||||
return {
|
||||
content: [{
|
||||
type: "text",
|
||||
text: JSON.stringify({
|
||||
error: "No authentication token found for this session. Please login first using login_client tool.",
|
||||
sessionId: extra.sessionId,
|
||||
profileName: creds.profileName
|
||||
}, null, 2)
|
||||
}],
|
||||
isError: true
|
||||
};
|
||||
}
|
||||
|
||||
const response = await AcaiHttpClient.saasPostRequest(
|
||||
{
|
||||
action: 'getSchemaTables',
|
||||
type: 'menu'
|
||||
},
|
||||
creds.token
|
||||
const credentials = await getSessionCredentials(extra.sessionId);
|
||||
const payload = {
|
||||
action_ws: "getTableSchemas",
|
||||
token: credentials.token,
|
||||
tokenHash: credentials.tokenHash,
|
||||
};
|
||||
const response = await AcaiHttpClient.postViewerFunctions(
|
||||
await getApiClient(extra.sessionId),
|
||||
payload
|
||||
);
|
||||
const apiError = handleApiResponse(response.data, 'list_tables');
|
||||
if (apiError) return apiError;
|
||||
|
||||
if (!response.data.success) {
|
||||
const schemas = response.data.schemas || {};
|
||||
const tables = Object.entries(schemas).map(([filename, iniContent]) => {
|
||||
const tableName = filename.replace('.ini.php', '');
|
||||
const meta = parseIniMeta(iniContent);
|
||||
return {
|
||||
content: [{ type: "text", text: "Error getting tables: " + JSON.stringify(response.data) }],
|
||||
isError: true,
|
||||
tableName,
|
||||
menuName: meta.menuName || tableName,
|
||||
menuType: meta.menuType || 'multi',
|
||||
enlace: meta.enlace || null,
|
||||
hasBuilder: iniContent.includes('[builder]'),
|
||||
};
|
||||
}
|
||||
|
||||
// Filter tables based on withoutEnlace parameter
|
||||
const tables = response.data.data.filter(schema =>
|
||||
withoutEnlace ? true : !!schema.enlace
|
||||
).map(table => ({
|
||||
name: table.menuName,
|
||||
tableName: table.tableName,
|
||||
order: table.menuOrder,
|
||||
enlace: table.enlace,
|
||||
hasBuilder: !!table.builder
|
||||
}));
|
||||
});
|
||||
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(tables, null, 2) }],
|
||||
@@ -70,5 +48,3 @@ export function registerListTablesTool(server) {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user