Skip to main content
Glama
samscarrow

Oracle MCP Server

by samscarrow

get_table_constraints

Retrieve primary keys, foreign keys, unique, and check constraints for a specified table in Oracle databases. Specify table name and optionally schema name to streamline database introspection and analysis.

Instructions

Get constraints (primary keys, foreign keys, unique, check) for a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNoSchema name (optional, searches all accessible schemas if not specified)
table_nameYesTable name

Implementation Reference

  • The handler function that implements the get_table_constraints tool. It builds a SQL query to retrieve all types of constraints (P=Primary, U=Unique, R=Foreign Key, C=Check) for the given table, optionally filtered by schema, joins with column info and referenced constraints, and returns formatted JSON results.
    async handleGetTableConstraints(args) { const query = ` SELECT c.owner AS schema_name, c.constraint_name, c.constraint_type, c.status, c.validated, CASE WHEN c.constraint_type = 'C' THEN 'CHECK CONSTRAINT' ELSE NULL END as search_condition, LISTAGG(cc.column_name, ', ') WITHIN GROUP (ORDER BY cc.position) AS columns, r.table_name AS referenced_table, r.constraint_name AS referenced_constraint FROM all_constraints c LEFT JOIN all_cons_columns cc ON c.constraint_name = cc.constraint_name AND c.owner = cc.owner LEFT JOIN all_constraints r ON c.r_constraint_name = r.constraint_name AND c.r_owner = r.owner WHERE c.table_name = :1 ${args.schema ? 'AND c.owner = :2' : ''} GROUP BY c.owner, c.constraint_name, c.constraint_type, c.status, c.validated, r.table_name, r.constraint_name ORDER BY c.owner, CASE c.constraint_type WHEN 'P' THEN 1 WHEN 'U' THEN 2 WHEN 'R' THEN 3 WHEN 'C' THEN 4 ELSE 5 END, c.constraint_name `; const params = [args.table_name.toUpperCase()]; if (args.schema) { params.push(args.schema.toUpperCase()); } const result = await this.executeQuery(query, params); return { content: [ { type: 'text', text: JSON.stringify(result.rows, null, 2) } ] }; }
  • src/index.js:247-264 (registration)
    Tool registration in the list_tools response, defining the tool name, description, and input schema.
    { name: 'get_table_constraints', description: 'Get constraints (primary keys, foreign keys, unique, check) for a table', inputSchema: { type: 'object', properties: { table_name: { type: 'string', description: 'Table name' }, schema: { type: 'string', description: 'Schema name (optional, searches all accessible schemas if not specified)' } }, required: ['table_name'] } },
  • src/index.js:294-295 (registration)
    Switch case in CallToolRequestHandler that routes calls to the get_table_constraints handler.
    case 'get_table_constraints': return await this.handleGetTableConstraints(args);

Other Tools

Related 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/samscarrow/oracle-mcp-server'

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