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

MCPg - Production-grade PostgreSQL MCP Server

Migrate vector to halfvec

migrate_vector_to_halfvec
Read-only

Generate an ordered DDL plan to convert a pgvector vector(N) column to halfvec(N), halving element storage, with index drop/recreate and rollback SQL.

Instructions

Generate a DDL plan that converts a pgvector vector(N) column to halfvec(N) — halving per-element storage (4 → 2 bytes) with typically negligible recall impact at d ≥ 768. Reads the column's current type + dimension from the catalog, finds every index on the column, and emits an ordered migration_sql plan: DROP each affected index, ALTER COLUMN to halfvec(N) via a USING cast, then recreate each index with its halfvec opclass. Also returns a mirror rollback_sql that restores the original vector(N) type plus the original index definitions. Nothing is executed — feed the plan through the shadow-migration workflow (prepare_migration / validate_migration_schema) before applying. Returns already_halfvec=true (and an empty plan) when the column is already halfvec, and refuses any index whose opclass has no halfvec sibling rather than rewriting it incorrectly. Requires the vector extension.

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>",
      "table": "<table>",
      "column": "<column>"
    },
    "name": "migrate_vector_to_halfvec"
  }
}

Input Schema

NameRequiredDescriptionDefault
tableYes
columnYes
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
notesYes
indexesYes
availableYes
dimensionYes
row_countYes
column_typeYes
rollback_sqlYes
migration_sqlYes
already_halfvecYes
estimated_total_bytes_savedYes
estimated_bytes_per_row_afterYes
estimated_bytes_per_row_beforeYes

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.1/5.0
Behavior5/5

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

Annotations declare readOnlyHint=true, and the description reinforces this with 'Nothing is executed' rather than contradicting it. Beyond annotations it discloses the ordered plan contents (drop indexes, ALTER with USING cast, recreate with halfvec opclass), the rollback mirror, the already_halfvec=true edge case, refusal of opclasses with no halfvec sibling, and the vector-extension prerequisite.

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 purpose and mechanism, then edges into safeguards and prerequisites. Every clause carries information, though the long em-dash-and-parenthetical sentences make it denser than necessary.

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?

An output schema exists, so the description's return-value discussion (migration_sql, rollback_sql, already_halfvec) is bonus rather than obligation. For a plan-generating DDL tool with mutation implications, the safety and sequencing guidance is complete; only the unexplained identifier parameters leave a gap.

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

Parameters2/5

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

Schema description coverage is 25% — only `database` is documented, and that is in the schema, not the description. The description never explains how `schema`, `table`, and `column` identify the target, nor how the column's dimension is resolved, so it fails to compensate for the low coverage.

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 and resource with scope: 'Generate a DDL plan that converts a pgvector vector(N) column to halfvec(N)', including the storage and recall rationale. An agent can distinguish this from siblings like recommend_vector_quantization or tune_vector_index without opening any 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 says nothing is executed and directs the plan through the shadow-migration workflow (prepare_migration / validate_migration_schema) before applying, which is clear when-to-use context. It does not name a sibling to use *instead* when halfvec is inappropriate, so it falls short of full when/when-not routing.

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