@gresmcp/mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 fairking
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # gresmcp (`@gresmcp/mcp`)
2
+
3
+ From raw docs to refined answers — Gresy fires your documents into solid Postgres knowledge, entirely local, your MCP.
4
+
5
+ A Postgres-backed **knowledge source (ks) MCP server** for AI tools, with a management CLI.
6
+
7
+ Knowledge is stored in PostgreSQL using `pgvector` (semantic similarity) and `tsvector` (full-text search). Queries are answered with **hybrid search** that fuses both signals via Reciprocal Rank Fusion (RRF). Documents are embedded with an [Ollama](https://ollama.com) embedding model; the model is locked per knowledge source so vector dimensions always stay consistent.
8
+
9
+ - **`gresmcp`** — CLI: create/edit/delete knowledge sources, feed files/folders/url or manual text
10
+ - **`mcp`** — FastMCP server: read-only search/query tools scoped to the knowledge sources you pass on the command line
11
+
12
+ ## Requirements
13
+
14
+ - Node.js >= 20
15
+ - PostgreSQL with the [`pgvector`](https://github.com/pgvector/pgvector) extension installed (default `gres` database and `gres` user `gres` password used in the examples bellow)
16
+ - An [Ollama](https://ollama.com) server with an embedding model pulled (e.g. `ollama pull nomic-embed-text` or `ollama pull bge-m3`)
17
+
18
+ Run `gresmcp check` to verify all of these at once (it also creates the `vector` extension for you if it is missing).
19
+
20
+ ## Install
21
+
22
+ ```sh
23
+ npm install -g @gresmcp/mcp
24
+ ```
25
+
26
+ or use it directly with `npx -y @gresmcp/mcp ...` (MCP server) / `npx -y -p @gresmcp/mcp gresmcp ...` (CLI).
27
+
28
+ ## Configuration
29
+
30
+ Environment variables:
31
+
32
+ | Variable | Default | Description |
33
+ | --- | --- | --- |
34
+ | `GRESMCP_DATABASE_URL` | `postgresql://gres:gres@localhost/gres` | Postgres connection string |
35
+ | `GRESMCP_OLLAMA_URL` | `http://localhost:11434` | Default Ollama base URL |
36
+ | `GRESMCP_KS` | – | Comma-separated ks names for the MCP server (fallback when no arguments are passed) |
37
+
38
+ ## Quickstart
39
+
40
+ ```sh
41
+ # 0. Verify your setup (Node, Postgres, pgvector, schema, Ollama, embedding model)
42
+ gresmcp check --model nomic-embed-text
43
+
44
+ # 1. Create a knowledge source (probes Ollama to validate the model and detect its dimension)
45
+ gresmcp ks create docs --model nomic-embed-text --description "Project documentation"
46
+
47
+ # 2. Feed it
48
+ gresmcp feed docs --path ./docs # a folder (text, markdown, code, html)
49
+ gresmcp feed docs --path ./README.md # a single file
50
+ gresmcp feed docs --text "Note: the API key lives in vault" --title "API keys" --tags secrets
51
+
52
+ # 3. Serve it to your AI tool over MCP
53
+ mcp docs # stdio transport, scoped to the 'docs' knowledge source
54
+ mcp --all # every knowledge source in the database
55
+ mcp docs,wiki --transport http --port 8080 # HTTP streaming on http://localhost:8080/mcp
56
+ ```
57
+
58
+ The database schema is created automatically on first run (`CREATE EXTENSION vector`, `ks` table, one entry table per knowledge source).
59
+
60
+ ## CLI reference
61
+
62
+ ### `gresmcp ks create <name> --model <model> [--url <url>] [--description <text>] [--dim <n>]`
63
+
64
+ Creates a knowledge source. The Ollama server is probed to validate the model and detect the embedding dimension (skip the probe with `--dim`). **The embedding model and dimension are immutable afterwards.**
65
+
66
+ ### `gresmcp ks edit <name> [--url <url>] [--rename <new>] [--description <text>]`
67
+
68
+ Edits a knowledge source. The Ollama server URL, name and description can change; the model cannot.
69
+
70
+ ### `gresmcp ks list [--json]`
71
+
72
+ Lists knowledge sources with model, dimension, URL and entry counts.
73
+
74
+ ### `gresmcp ks delete <name> [--yes]`
75
+
76
+ Deletes a knowledge source and drops its entry table (asks for confirmation unless `--yes`).
77
+
78
+ ### `gresmcp feed <ks> (--path <path> | --text <text> | --stdin) [options]`
79
+
80
+ Feeds data into a knowledge source. Exactly one input of `--path`, `--text` or `--stdin` must be given.
81
+
82
+ | Option | Description |
83
+ | --- | --- |
84
+ | `--path <path>` | File or folder. Folders are walked recursively (skips `node_modules`, `.git`, `dist`, ...). Supported: text, markdown, code files, HTML (converted to Markdown via turndown). Binaries and empty files are skipped with a warning. |
85
+ | `--text <text>` / `--stdin` | Manual entry text (chunked the same way as documents) |
86
+ | `--title <title>` | Title for manual entries |
87
+ | `--source-name <name>` | Source name for manual entries (default `manual`) |
88
+ | `--tags a,b` | Tags stored in metadata, filterable by MCP `search` |
89
+ | `--metadata k=v ...` | Repeatable custom metadata entries |
90
+ | `--url <url>` | Ollama URL override for this run (the model stays the ks's) |
91
+ | `--replace` | Replace all chunks of the same source instead of skipping unchanged ones |
92
+ | `--dry-run` | Parse and chunk only; no embeddings, no writes |
93
+ | `--chunk-size <n>` | Max chunk length in characters (default 1200) |
94
+ | `--overlap <n>` | Chunk overlap in characters (default 180) |
95
+
96
+ Feeding is idempotent: a chunk whose `(source, chunk_index, content hash)` already exists is skipped, so re-running a feed only adds new content. Use `--replace` to force a clean re-ingest of a source.
97
+
98
+ ### `gresmcp init`
99
+
100
+ Explicitly initializes/repairs the schema (runs automatically for every command anyway).
101
+
102
+ ### `gresmcp check [--model <model>] [--url <url>] [--probe] [--json]`
103
+
104
+ Verifies that your environment meets all requirements:
105
+
106
+ | Check | Description |
107
+ | --- | --- |
108
+ | Node | Node.js >= 20 |
109
+ | Postgres | Database reachable at `GRESMCP_DATABASE_URL` |
110
+ | pgvector | Extension installed (created automatically if missing); warns below 0.5.0, which is required for HNSW indexes |
111
+ | schema | `ks` table and every knowledge source's entry table exist (`gresmcp init` repairs them) |
112
+ | Ollama | Server reachable at the configured URL |
113
+ | models | The embedding model of every existing knowledge source (plus `--model`, if given) is pulled at the right URL; `--probe` also embeds a test string to verify the dimension |
114
+
115
+ ```sh
116
+ gresmcp check --model nomic-embed-text
117
+ # ✔ Node v22.14.0 (>= 20 required)
118
+ # ✔ PostgreSQL reachable at postgresql://gres:gres@localhost/gres (PostgreSQL 16.4)
119
+ # ✔ pgvector 0.8.0 installed
120
+ # ✔ schema ready (2 knowledge source(s))
121
+ # ✔ Ollama reachable at http://localhost:11434 (5 model(s))
122
+ # ✔ model 'nomic-embed-text' available at http://localhost:11434 (ks 'docs')
123
+ # all checks passed
124
+ ```
125
+
126
+ The exit code is 1 when any check fails, so it can be used in scripts or CI. `--json` prints the results as machine-readable JSON.
127
+
128
+ ## MCP server reference
129
+
130
+ ```
131
+ mcp <ks1,ks2,...> [--all] [--transport stdio|http] [--port <n>]
132
+ ```
133
+
134
+ The server is **read-only** and hard-scoped to the knowledge sources named at startup; unknown names abort with a helpful message.
135
+
136
+ | Tool | Description |
137
+ | --- | --- |
138
+ | `search` | Hybrid (default) / vector / keyword search. Returns ranked chunks with `[ks] id, score, source#chunk, title` and a snippet. Supports `ks` (array), `mode`, `limit` (1–50, default 8) and `tags` (any-of metadata filter). |
139
+ | `get_entry` | Full content + metadata of one chunk by id. |
140
+ | `list_entries` | Paginated entry list (id, source, title, chunk index, size), optional `source` filter. |
141
+ | `list_sources` | Ingested documents with chunk counts. |
142
+ | `list_ks` | The configured knowledge sources with entry counts. |
143
+
144
+ Hybrid mode fuses pgvector cosine ranking and `ts_rank_cd` full-text ranking with Reciprocal Rank Fusion (`score = Σ 1/(60 + rank)`), so results are comparable across knowledge sources even when they use different embedding models.
145
+
146
+ ## Using with AI tools
147
+
148
+ ### opencode
149
+
150
+ ```json
151
+ {
152
+ "mcp": {
153
+ "gresmcp": {
154
+ "type": "local",
155
+ "command": ["npx", "-y", "@gresmcp/mcp", "ks1,ks2,ks3"],
156
+ "enabled": true
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ With a global install you can use the binary directly: `["mcp", "ks1,ks2"]`. To scope via environment instead of arguments: `"command": ["npx", "-y", "@gresmcp/mcp", "--all"]` or set `GRESMCP_KS=ks1,ks2`.
163
+
164
+ ### Claude Desktop / generic MCP config
165
+
166
+ ```json
167
+ {
168
+ "mcpServers": {
169
+ "gresmcp": {
170
+ "command": "npx",
171
+ "args": ["-y", "@gresmcp/mcp", "ks1,ks2"],
172
+ "env": {
173
+ "GRESMCP_DATABASE_URL": "postgresql://gres:gres@localhost/gres"
174
+ }
175
+ }
176
+ }
177
+ }
178
+ ```
179
+
180
+ ### HTTP transport
181
+
182
+ ```sh
183
+ mcp ks1 --transport http --port 8080
184
+ # MCP endpoint: http://localhost:8080/mcp (health check: /health)
185
+ ```
186
+
187
+ ## Database layout
188
+
189
+ - `ks` — one row per knowledge source: `id`, `name` (unique), `description`, `embedding_model` (immutable), `embedding_dim`, `ollama_url`, timestamps
190
+ - `entry_<uuid>` — one table per knowledge source (per-ks tables allow different vector dimensions across models): `id`, `source`, `title`, `chunk_index`, `content`, `content_hash`, `metadata jsonb`, generated `tsv tsvector`, `embedding vector(dim)`
191
+ - Indexes: `GIN(tsv)`, `HNSW(embedding vector_cosine_ops)`, `btree(source)`
192
+
193
+ ## Development
194
+
195
+ ```sh
196
+ npm install
197
+ npm run build # tsup -> dist/cli.js, dist/mcp.js
198
+ npm run typecheck # tsc --noEmit
199
+ npm test # vitest (DB integration tests skip gracefully when Postgres/pgvector is unavailable)
200
+ ```
201
+
202
+ Release checklist: `npm version <x.y.z> && npm publish --access public` (the scoped package name `@gresmcp/mcp` must be owned by your npm org).
203
+
204
+ ## Contributors
205
+
206
+ gresmcp is built on top of these great projects and tools:
207
+
208
+ | Contributor | Description |
209
+ | --- | --- |
210
+ | [FastMCP](https://gofastmcp.com) | The standard framework for building Model Context Protocol (MCP) servers, clients, and interactive applications (gresmcp uses its TypeScript port) |
211
+ | [Turndown](https://github.com/mixmark-io/turndown) | An HTML to Markdown converter written in JavaScript |
212
+ | [PostgreSQL](https://www.postgresql.org) | The world's most advanced open source database |
213
+ | [Zod](https://zod.dev) | TypeScript-first schema validation library with static type inference |
214
+ | [OpenCode](https://opencode.ai) | The open source AI coding agent |
215
+ | [OpenChamber](https://openchamber.dev) | Agentic development environment for AI coding across desktop, browser, phone, and VS Code |
216
+ | [Ollama](https://ollama.com) | The easiest way to automate your work using open models, while keeping your data safe |
217
+ | [Nano](https://nano.org) | The fast, feeless and eco-friendly digital currency |
218
+ | [NanoGPT](https://nano-gpt.com) | Subscription-free, pay-as-you-go access to AI models |
219
+ | {{ YOU }} | This could be you — issues and PRs welcome at [gitea.com/fairking/gresmcp](https://gitea.com/fairking/gresmcp) |