Skip to main content
Glama
devopam

MCPg - Production-grade PostgreSQL MCP Server

Generate SQLAlchemy models

generate_sqlalchemy_models
Read-only

Generates a SQLAlchemy 2.0 declarative models file from a PostgreSQL schema, including tables, columns with native types, primary keys, single-column foreign keys, unique 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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaYes
databaseNoOptional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior5/5

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

The description is consistent with the readOnlyHint annotation, as it only reads the schema and emits code. It adds detailed behavioral context beyond annotations, specifying which SQLAlchemy features are covered (Mapped[T], mapped_column, ForeignKey, etc.) and explicitly documenting the composite FK gap. This provides full transparency for the agent.

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

Conciseness5/5

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

The description is a single, well-structured paragraph. The first sentence states the purpose, followed by details on coverage and a known gap, and ends with the output format. Every sentence earns its place; no unnecessary wording.

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 the tool's complexity (generating code from a schema) and the presence of an output schema, the description is complete. It covers what the tool generates, what is supported, and what is not. The agent has enough information to decide whether this tool meets its needs without needing to invoke it blindly.

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?

The input schema already describes the 'database' parameter well ('Optional: target a configured secondary...'). The tool description adds no further per-parameter guidance; it implicitly explains that 'schema' is the database schema to read. With 50% schema description coverage, the description does not compensate for the undocumented 'schema' parameter, so it adds marginal value.

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 clearly states the tool reads a PostgreSQL schema and generates a SQLAlchemy 2.0 declarative models file. It specifies the output format and covers tables, columns, types, keys, constraints, defaults, and enums, while noting a known gap (composite FKs). This distinguishes it from sibling tools that generate other ORM schemas (e.g., Prisma, Drizzle, Ecto).

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

Usage Guidelines3/5

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

The description implies this tool is for generating SQLAlchemy models from a PostgreSQL schema but does not explicitly state when to use it vs. alternatives like generate_prisma_schema or generate_diesel_schema. It notes a limitation (composite FKs are a v1 gap) but provides no exclusion criteria or guidance on when not to use it.

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/devopam/MCPg'

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