Skip to main content
Glama
MCPg - Production-grade PostgreSQL MCP Server

MCPg - Production-grade PostgreSQL MCP Server

Generate SQLAlchemy models

generate_sqlalchemy_models
Read-only

Reads a PostgreSQL schema and emits SQLAlchemy 2.0 declarative models, covering tables, columns, primary keys, foreign keys, constraints, defaults, and enums.

Instructions

Read a PostgreSQL schema and emit a SQLAlchemy 2.0 declarative models file (DeclarativeBase + Mapped[T] + mapped_column). Covers tables, columns with PG-native types (incl. jsonb via sqlalchemy.dialects.postgresql.JSONB), primary keys, single-column FKs via ForeignKey(), unique constraints (column-level + composite via table_args), defaults, and enums (emitted as Python enum.Enum classes). Composite FKs are a documented v1 gap. Returns the rendered Python models.py source as a single string. Schema/table/column names must be plain identifiers ([A-Za-z_][A-Za-z0-9_]*); delimited names (hyphens, spaces, mixed-case-only) are not supported here because they become source identifiers in generated code — use SQL tools (export_table, dump_database) for those objects. See docs/identifier-policy.md.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "schema": "<schema>"
    },
    "name": "generate_sqlalchemy_models"
  }
}

Input Schema

NameRequiredDescriptionDefault
schemaYes
databaseNoOptional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.8.4
    • changedInput schema / properties / database / description
      Previous value: -"Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids."New value: +"Optional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected."
  2. First observedv0.6.8

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already mark it read-only and closed-world, and the description adds substantial behavior beyond that: it enumerates exactly what is covered (jsonb via JSONB, single-column FKs, composite uniques via __table_args__, enums as Python Enum classes), discloses the v1 limitation ('Composite FKs are a documented v1 gap'), and states the return type ('rendered Python models.py source as a single string'). This is exactly the kind of scope-and-limitation disclosure the annotations cannot carry.

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?

Front-loaded with the core action and artifact, and every clause carries information (capability list, gap disclosure, return type, identifier policy, alternative tool). It is dense to the point of being a run-on with many parentheticals, which slightly hurts scanability, but no sentence is wasted.

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

Completeness5/5

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

Given an output schema exists, the description need not explain return values, yet it does note the return is a single source string. Combined with the coverage list, the v1 composite-FK gap, the identifier constraint, and the alternative-tool routing, an agent has everything needed to call this correctly and to know when the call will be rejected.

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

Parameters4/5

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

Schema description coverage is 50% (only `database` is documented inline; `schema` has no description in the schema), so the description has to compensate. It does partially, by constraining the form of schema/table/column names to plain identifiers and pointing to docs/identifier-policy.md, and by explaining the fallback for delimited names. It still never says what the `schema` argument selects relative to the `database` argument, which is a real residual gap.

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?

States a specific verb+resource+output artifact: 'Read a PostgreSQL schema and emit a SQLAlchemy 2.0 declarative models file (DeclarativeBase + Mapped[T] + mapped_column)'. This cleanly separates it from the many sibling codegen tools (generate_prisma_schema, generate_drizzle_schema, generate_diesel_schema, generate_jooq_config) without needing the schema.

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

Usage Guidelines4/5

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

Explicitly names when NOT to use it ('delimited names ... are not supported here ... use SQL tools (export_table, dump_database)'), and names the supported feature set that defines the appropriate scope. It does not explicitly route an agent among the sibling ORM generators (Prisma/Drizzle/Diesel), though the output language makes that largely self-evident.

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

Deploy Server

Other Tools