gitmyhub

pg_mcp_server

Python ★ 0 updated 2mo ago

Local PostgreSQL Internals Assistant with Ollama, pgvector, and MCP

A local, offline MCP server that lets you ask plain language questions about PostgreSQL's C source code, answered by a local LLM.

PythonPostgreSQLpgvectorOllamaFastMCPsetup: hardcomplexity 4/5

This project is a local, offline assistant for exploring PostgreSQL's internal C source code by asking plain language questions instead of digging through the codebase by hand. It runs entirely on your own machine, with no API costs and no internet connection needed once set up, and connects to code editors like Zed and VSCode through the Model Context Protocol, or MCP.

Under the hood it combines a few pieces: ctags and cscope provide exact symbol lookups such as who calls a function or where something is defined, while a vector database extension called pgvector, running inside a local Postgres 18 database, holds semantic search embeddings for tens of thousands of chunks of the PostgreSQL source code. A local embedding model turns questions and code into those vectors, and a small local language model, run through Ollama, uses the matched source snippets to write an answer grounded in the real code rather than guessing.

Three tools are exposed to your editor's AI agent panel: one that performs a full retrieval and answer cycle, one that just returns the raw matching source code chunks, and one that does exact symbol lookups using cscope. Setting it up involves installing Ollama and pulling two local models, installing the pgvector extension, creating a database and loading its schema, building the ctags and cscope index over a local copy of the PostgreSQL source, indexing everything into the database with a provided script, and finally pointing your editor's MCP configuration at the server script.

The author notes the local seven billion parameter model is good for explaining how code works but not for deep architecture decisions, where a larger hosted model would do better, and that the indexer needs to be rerun after upgrading to a newer PostgreSQL source version. The project is released under the MIT license.

Where it fits