Skip to main content
Glama
Yonsn76

MyPos MCP

by Yonsn76

agregarClaveForanea

Adds a foreign key constraint between two existing database tables to enforce referential integrity, ensuring data relationships remain valid by linking local columns to referenced columns.

Instructions

Sigue estas reglas para agregar una clave foránea: PROPÓSITO: Crear una relación (clave foránea) entre dos tablas para mantener la integridad referencial. REGLA: Las tablas y columnas involucradas ya deben existir. PRECAUCIÓN: La operación puede fallar si los datos existentes violan la nueva restricción. USO: Especifica la tabla local, sus columnas, la tabla de referencia y sus columnas. EJEMPLO: "Agrega una clave foránea de cliente_id en ventas referenciando clientes(id)."

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
columnasYesColumnas locales
columnasReferenciaYesColumnas referenciadas
nombreNoNombre de la clave foránea (opcional)
onDeleteNoAcción ON DELETE (ej. CASCADE, SET NULL)
onUpdateNoAcción ON UPDATE (ej. CASCADE, SET NULL)
tablaYesTabla que tendrá la clave foránea
tablaReferenciaYesTabla referenciada

Implementation Reference

  • Handler function that constructs and executes the SQL ALTER TABLE statement to add a foreign key constraint, handling optional constraint name, ON DELETE, and ON UPDATE actions.
      async ({ tabla, columnas, tablaReferencia, columnasReferencia, nombre, onDelete, onUpdate }) => {
        try {
          if (!tabla || !columnas || !tablaReferencia || !columnasReferencia) {
            return { isError: true, content: [{ type: 'text', text: 'Debes proporcionar tabla, columnas, tablaReferencia y columnasReferencia.' }] };
          }
          const nombreFK = nombre ? `CONSTRAINT ${quoteIdent(nombre)} ` : '';
          const cols = columnas.map(quoteIdent).join(', ');
          const refCols = columnasReferencia.map(quoteIdent).join(', ');
          let sql = `ALTER TABLE ${quoteIdent(tabla)} ADD ${nombreFK}FOREIGN KEY (${cols}) REFERENCES ${quoteIdent(tablaReferencia)} (${refCols})`;
          if (onDelete) sql += ` ON DELETE ${onDelete}`;
          if (onUpdate) sql += ` ON UPDATE ${onUpdate}`;
          await query_runner.runQuery(sql);
          return { content: [{ type: 'text', text: 'Clave foránea agregada exitosamente.' }] };
        } catch (e) {
          return { isError: true, content: [{ type: 'text', text: 'Error al agregar clave foránea: ' + (e.message || e) }] };
        }
      }
    );
  • Zod input schema defining parameters for the foreign key addition: local table and columns, referenced table and columns, optional name, onDelete, onUpdate.
    {
      tabla: z.string().describe('Tabla que tendrá la clave foránea'),
      columnas: z.array(z.string()).describe('Columnas locales'),
      tablaReferencia: z.string().describe('Tabla referenciada'),
      columnasReferencia: z.array(z.string()).describe('Columnas referenciadas'),
      nombre: z.string().optional().describe('Nombre de la clave foránea (opcional)'),
      onDelete: z.string().optional().describe('Acción ON DELETE (ej. CASCADE, SET NULL)'),
      onUpdate: z.string().optional().describe('Acción ON UPDATE (ej. CASCADE, SET NULL)'),
    },
  • mcp_server.js:684-718 (registration)
    MCP server.tool registration for 'agregarClaveForanea' tool, including description, input schema, and inline handler implementation.
    server.tool(
      'agregarClaveForanea',
      'Sigue estas reglas para agregar una clave foránea:\n'
      + 'PROPÓSITO: Crear una relación (clave foránea) entre dos tablas para mantener la integridad referencial.\n'
      + 'REGLA: Las tablas y columnas involucradas ya deben existir.\n'
      + 'PRECAUCIÓN: La operación puede fallar si los datos existentes violan la nueva restricción.\n'
      + 'USO: Especifica la tabla local, sus columnas, la tabla de referencia y sus columnas.\n'
      + 'EJEMPLO: "Agrega una clave foránea de cliente_id en ventas referenciando clientes(id)."',
      {
        tabla: z.string().describe('Tabla que tendrá la clave foránea'),
        columnas: z.array(z.string()).describe('Columnas locales'),
        tablaReferencia: z.string().describe('Tabla referenciada'),
        columnasReferencia: z.array(z.string()).describe('Columnas referenciadas'),
        nombre: z.string().optional().describe('Nombre de la clave foránea (opcional)'),
        onDelete: z.string().optional().describe('Acción ON DELETE (ej. CASCADE, SET NULL)'),
        onUpdate: z.string().optional().describe('Acción ON UPDATE (ej. CASCADE, SET NULL)'),
      },
      async ({ tabla, columnas, tablaReferencia, columnasReferencia, nombre, onDelete, onUpdate }) => {
        try {
          if (!tabla || !columnas || !tablaReferencia || !columnasReferencia) {
            return { isError: true, content: [{ type: 'text', text: 'Debes proporcionar tabla, columnas, tablaReferencia y columnasReferencia.' }] };
          }
          const nombreFK = nombre ? `CONSTRAINT ${quoteIdent(nombre)} ` : '';
          const cols = columnas.map(quoteIdent).join(', ');
          const refCols = columnasReferencia.map(quoteIdent).join(', ');
          let sql = `ALTER TABLE ${quoteIdent(tabla)} ADD ${nombreFK}FOREIGN KEY (${cols}) REFERENCES ${quoteIdent(tablaReferencia)} (${refCols})`;
          if (onDelete) sql += ` ON DELETE ${onDelete}`;
          if (onUpdate) sql += ` ON UPDATE ${onUpdate}`;
          await query_runner.runQuery(sql);
          return { content: [{ type: 'text', text: 'Clave foránea agregada exitosamente.' }] };
        } catch (e) {
          return { isError: true, content: [{ type: 'text', text: 'Error al agregar clave foránea: ' + (e.message || e) }] };
        }
      }
    );
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes critical behavioral traits: the prerequisite that tables/columns must exist, the potential failure due to data violations, and the action of creating a foreign key constraint. However, it doesn't mention side effects like performance impact or transaction behavior, leaving some gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with labeled sections (PROPÓSITO, REGLA, PRECAUCIÓN, USO, EJEMPLO), making it easy to scan. It's concise with no redundant sentences, though the example could be integrated more smoothly. Every sentence adds value, such as clarifying prerequisites and risks.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation with 7 parameters, no annotations, no output schema), the description is reasonably complete. It covers purpose, rules, cautions, usage, and an example. However, it lacks details on return values or error handling, which would be helpful since there's no output schema. It compensates well but isn't fully exhaustive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 7 parameters. The description adds minimal parameter semantics beyond the schema—it mentions 'tabla local' (local table), 'columnas' (columns), 'tabla de referencia' (reference table), and 'columnas referenciadas' (referenced columns) in the USO section, but doesn't provide additional context like format examples (beyond the general example) or explain optional parameters like 'nombre' (name). Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states the purpose as 'Crear una relación (clave foránea) entre dos tablas para mantener la integridad referencial' (Create a relationship between two tables to maintain referential integrity). This is specific (verb+resource+goal) and clearly distinguishes it from sibling tools like 'crearTabla' (create table) or 'agregarColumna' (add column) by focusing on establishing foreign key constraints.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage rules: 'REGLA: Las tablas y columnas involucradas ya deben existir' (Rule: The involved tables and columns must already exist) and 'PRECAUCIÓN: La operación puede fallar si los datos existentes violan la nueva restricción' (Caution: The operation may fail if existing data violates the new constraint). It also includes an example and specifies when to use it for foreign key creation, distinguishing it from alternatives like 'eliminarClaveForanea' (delete foreign key).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Yonsn76/MyPos-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server