toque en imagenes y filtrado en los esquemas
This commit is contained in:
@@ -12,9 +12,10 @@ export function registerGetTableSchemaTool(server) {
|
||||
withAuthParams({
|
||||
tableName: z.string().describe("Table name without cms_ prefix"),
|
||||
minimal: z.boolean().optional().describe("If true, returns only field names + types + labels"),
|
||||
filterFields: z.string().optional().describe("Filter field names containing these terms (pipe-separated, e.g. 'galeria|foto|image'). Only matching fields are returned. Useful to find the exact field name without loading the full schema."),
|
||||
}),
|
||||
{ readOnlyHint: true, destructiveHint: false },
|
||||
withAuth(async ({ tableName, minimal }, extra) => {
|
||||
withAuth(async ({ tableName, minimal, filterFields }, extra) => {
|
||||
try {
|
||||
const validationError = validateRequired({ tableName }, ['tableName'], 'get_table_schema');
|
||||
if (validationError) return validationError;
|
||||
@@ -45,18 +46,41 @@ export function registerGetTableSchemaTool(server) {
|
||||
|
||||
const parsed = parseIniSchema(iniContent);
|
||||
|
||||
if (minimal) {
|
||||
const minimalSchema = { menuName: parsed.menuName, menuType: parsed.menuType, enlace: parsed.enlace };
|
||||
const minFields = {};
|
||||
for (const [key, value] of Object.entries(parsed.fields || {})) {
|
||||
minFields[key] = { type: value.type };
|
||||
if (value.label) minFields[key].label = value.label;
|
||||
// Filtrar campos si se pasa filterFields (pipe-separated terms)
|
||||
let fields = parsed.fields || {};
|
||||
if (filterFields) {
|
||||
const terms = filterFields.toLowerCase().split("|").map(t => t.trim()).filter(Boolean);
|
||||
const filtered = {};
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
const keyLower = key.toLowerCase();
|
||||
const labelLower = (value.label || "").toLowerCase();
|
||||
if (terms.some(t => keyLower.includes(t) || labelLower.includes(t))) {
|
||||
filtered[key] = value;
|
||||
}
|
||||
}
|
||||
fields = filtered;
|
||||
if (Object.keys(fields).length === 0) {
|
||||
return { content: [{ type: "text", text: JSON.stringify({
|
||||
tableName, filterFields, matches: 0,
|
||||
message: "No fields matching filter. Try broader terms or omit filterFields to see all.",
|
||||
}, null, 2) }] };
|
||||
}
|
||||
minimalSchema.fields = minFields;
|
||||
return { content: [{ type: "text", text: JSON.stringify(minimalSchema, null, 2) }] };
|
||||
}
|
||||
|
||||
return { content: [{ type: "text", text: JSON.stringify(parsed, null, 2) }] };
|
||||
if (minimal || filterFields) {
|
||||
const result = { menuName: parsed.menuName, tableName };
|
||||
const minFields = {};
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
minFields[key] = { type: value.type };
|
||||
if (value.label) minFields[key].label = value.label;
|
||||
if (value.maxUploads) minFields[key].maxUploads = value.maxUploads;
|
||||
}
|
||||
result.fields = minFields;
|
||||
if (filterFields) result.filterFields = filterFields;
|
||||
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
||||
}
|
||||
|
||||
return { content: [{ type: "text", text: JSON.stringify({ ...parsed, fields }, null, 2) }] };
|
||||
} catch (error) {
|
||||
return handleToolError(error, 'get_table_schema', { tableName });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user