@functional-systems/lambdadb-mcp 0.1.0-dev.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - Prepare `@functional-systems/lambdadb-mcp` and the `lambdadb-mcp` executable for npm/npx distribution under Apache-2.0.
6
+ - Add gated OIDC publishing for develop, rc and stable channels with exact tarball consumer checks.
7
+ - Derive the MCP server version from package metadata and close the process on stdio disconnect or termination.
8
+ - Raise the supported Node.js floor to 22.14.0; verify the minimum and current Node 22/24 LTS.
9
+ - Preserve the existing environment variables, read-only default and explicit write opt-in.
10
+ - Require explicit development-project confirmation before running the optional live smoke.
11
+ - Refresh compatible locked dependencies; the audited dependency tree has no known advisories at validation time.
@@ -0,0 +1,56 @@
1
+ # Contributing
2
+
3
+ ## Branches and validation
4
+
5
+ Create a focused `feat/*` or `fix/*` branch from current `develop`; open PRs with
6
+ `develop` explicitly selected as the base. Keep local credentials and unrelated
7
+ changes outside the PR. Use a dedicated worktree when another checkout is in use.
8
+
9
+ Use Node.js 22.14.0 or newer. CI verifies the exact minimum 22.14.0 and current
10
+ 22.x and 24.x LTS releases. Node 20 is end-of-life and is no longer supported.
11
+ The runtime dependencies permit older Node versions (MCP SDK 1.29.0 declares
12
+ Node >=18), but that is not a promise to support end-of-life runtimes. The
13
+ 22.14.0 floor also aligns with the CLI and npm's OIDC publishing runtime floor.
14
+ See the [Node release schedule](https://nodejs.org/en/about/previous-releases)
15
+ and [npm requirements](https://docs.npmjs.com/trusted-publishers/).
16
+
17
+ ```sh
18
+ npm ci
19
+ npm run check
20
+ npm run test:package
21
+ ```
22
+
23
+ `check` validates package/lock versions, type-checks, builds, and runs local tests.
24
+ `test:package` packs once, checks the actual file inventory, installs without
25
+ lifecycle scripts in a temporary consumer directory, and runs the MCP contracts
26
+ against the installed executable over stdio. An optional tarball argument tests
27
+ an already packed file without rebuilding it. Fixtures use loopback HTTP and
28
+ synthetic credentials; they never call a LambdaDB service. Live verification is
29
+ separate and requires explicit designation of a development project.
30
+
31
+ The `CI` workflow in `.github/workflows/publish.yaml` runs for PRs and pushes to
32
+ `develop`/`main`, manual validation and published GitHub Releases. Require the
33
+ `Node.js 22.14.0`, `Node.js 22` and `Node.js 24` checks in branch protection;
34
+ replace any old `Node 20*` / `Node 22` / `Node 24` check requirements when adopting
35
+ this workflow. Branch protection is an administrator setup step, not configured
36
+ by this change. Validation has read-only permissions and no service credentials.
37
+
38
+ ## Releases and compatibility
39
+
40
+ Keep develop's reviewed base in `X.Y.Z-dev.N` form. Automatic dev publication
41
+ requires separate bootstrap, package-specific npm trust and an explicit repository
42
+ variable; it is initially disabled. PRs and manual workflow runs cannot publish.
43
+ Follow [RELEASING.md](RELEASING.md) for every publication action.
44
+
45
+ Prepare rc/stable metadata on a release branch and review it into `main`. Promote
46
+ with merge commits to preserve main/develop ancestry. When synchronizing main
47
+ back into develop through a PR, include the next dev base. Do not leave stable
48
+ metadata on develop, where automatic version generation requires a dev version.
49
+ Tags, GitHub Releases and bootstrap publication are explicit maintainer actions.
50
+
51
+ Treat environment variables, tool names/schemas, read-only defaults, ref semantics,
52
+ error handling and supported runtimes as public contracts. Document incompatible
53
+ changes and validate the installed artifact. Update package.json and both root
54
+ package-lock.json versions together with `npm version VERSION --no-git-tag-version`.
55
+ Do not use prerelease channels as implicit write opt-in. Pin workflow actions to
56
+ reviewed commit SHAs. Never commit keys, `.env` files or signed URLs.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,289 @@
1
+ # lambdadb-mcp
2
+
3
+ MCP server for LambdaDB using the official TypeScript MCP SDK and the official LambdaDB TypeScript client.
4
+
5
+ ## Scope
6
+
7
+ - Directly calls the LambdaDB data plane
8
+ - Uses a single project-scoped API key from environment variables
9
+ - Defaults to read-only tools
10
+ - Optionally exposes write tools via an environment flag
11
+
12
+ ## Install and run with npm
13
+
14
+ Package: `@functional-systems/lambdadb-mcp`. Executable: `lambdadb-mcp`.
15
+ Requires Node.js >=22.14.0; CI tests the minimum and current Node 22/24 LTS.
16
+
17
+ Publication is being prepared. The following commands become available after the
18
+ maintainer completes [first publication and trust setup](RELEASING.md). Before
19
+ there is a stable release, select `@dev` or an exact published prerelease:
20
+
21
+ ```sh
22
+ npx --yes @functional-systems/lambdadb-mcp@dev
23
+ # After a stable release exists:
24
+ npm install -g @functional-systems/lambdadb-mcp
25
+ lambdadb-mcp
26
+ # Or run without a global installation:
27
+ npx --yes @functional-systems/lambdadb-mcp
28
+ ```
29
+
30
+ Set the environment variables below in your MCP client or securely in the parent
31
+ process. Installed execution reads the environment directly and needs no checkout,
32
+ build, shell script, or `.env.local`. It does not automatically load dotenv files.
33
+ `LAMBDADB_ENV_FILE` belongs to the repository's development launchers only. If you
34
+ prefer a file after global installation, use Node's explicit file loader:
35
+
36
+ ```sh
37
+ node --env-file=/absolute/path/to/mcp.env "$(npm root -g)/@functional-systems/lambdadb-mcp/dist/index.js"
38
+ ```
39
+
40
+ Exported environment values take precedence. Keep credentials out of command
41
+ arguments, source control and logs. Pin an exact published version in MCP client
42
+ configurations for reproducibility. `@dev`, `@rc` and unqualified (`latest`) resolve
43
+ different release channels; installed copies do not update themselves.
44
+
45
+ The server uses stdio: stdout contains only MCP JSON-RPC messages, diagnostics go
46
+ to stderr, and stdin closure/SIGINT/SIGTERM ends the process. Running it without an
47
+ MCP client waits for protocol input. See the [MCP transport specification](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports).
48
+
49
+ ## Project Structure
50
+
51
+ ```text
52
+ src/
53
+ ├─ config/
54
+ │ └─ env.ts
55
+ ├─ lambdadb/
56
+ │ ├─ client.ts
57
+ │ └─ errors.ts
58
+ ├─ server/
59
+ │ └─ createServer.ts
60
+ ├─ tools/
61
+ │ ├─ index.ts
62
+ │ ├─ shared.ts
63
+ │ ├─ read.ts
64
+ │ └─ write.ts
65
+ └─ index.ts
66
+ ```
67
+
68
+ ## Environment Variables
69
+
70
+ ```bash
71
+ LAMBDADB_BASE_URL=https://aws-ap-northeast-2.lambdadb.ai
72
+ LAMBDADB_PROJECT_NAME=my-project
73
+ LAMBDADB_PROJECT_API_KEY=replace-me
74
+ LAMBDADB_MCP_ENABLE_WRITE_TOOLS=false
75
+ ```
76
+
77
+ ## Available Tools
78
+
79
+ Read-only:
80
+
81
+ - `lambdadb_list_collections`
82
+ - `lambdadb_get_collection`
83
+ - `lambdadb_query_collection`
84
+ - `lambdadb_list_docs`
85
+ - `lambdadb_fetch_docs`
86
+
87
+ Optional write tools:
88
+
89
+ - `lambdadb_create_collection`
90
+ - `lambdadb_upsert_docs`
91
+ - `lambdadb_delete_docs`
92
+
93
+ ## API contract and tool inputs
94
+
95
+ The LambdaDB SDK is pinned to `@functional-systems/lambdadb@0.5.1`.
96
+ The tool contract was checked against LambdaDB develop
97
+ [`d1a76659884a9ed09283a0b2e2989897dc799247`](https://github.com/lambdadb/lambdadb/commit/d1a76659884a9ed09283a0b2e2989897dc799247).
98
+ This source revision does not establish which API revision is deployed.
99
+
100
+ - Collection creation requires a nonempty `indexConfigs` and accepts `description`,
101
+ metadata `tags`, `partitionConfig`, and `snapshotRetentionInDays` (1–31).
102
+ The SDK validates individual index configurations and accepts HTTP 201 responses.
103
+ - Query, Fetch, and List accept `ref: { kind: "branch" | "tag" | "alias", name: "..." }`.
104
+ Omitting `ref` reads from `main`. `consistentRead: true` is supported only by
105
+ Query/Fetch with an omitted ref or a direct Branch ref. List has no `consistentRead`.
106
+ - List also accepts `filter`, `fields`, `includeVectors`, and `partitionFilter`.
107
+ The SDK selects the extended POST endpoint when needed and preserves pagination tokens.
108
+ - Upsert/Delete accept an optional `branch`; omitting it writes to `main`.
109
+ Delete requires exactly one of a nonempty `ids` array or `filter`.
110
+ - Unknown top-level inputs and unknown ref fields are rejected, so unsupported
111
+ selectors cannot silently fall back to `main`.
112
+ - List/Get metadata no longer requires the removed `collectionStatus` or an absent
113
+ `dataUpdatedAt`. Epoch-millisecond timestamps are converted by the SDK to `Date`
114
+ and serialized as ISO strings in MCP text results.
115
+
116
+ SDK 0.5.1 already includes the
117
+ [`docsUrl` JSON-array fix](https://github.com/lambdadb/lambdadb-typescript-client/pull/26).
118
+ Query/Fetch/List download top-level document arrays and retain legacy `{ "docs": [...] }`
119
+ support without sending the project API key to the download URL. No additional SDK
120
+ patch is needed for this issue.
121
+
122
+ ## Tests
123
+
124
+ ```bash
125
+ npm ci
126
+ npm run check
127
+ npm run test:package
128
+ ```
129
+
130
+ `check` runs type checking, a build, and the contract tests. Tests connect an MCP
131
+ client to this server and exercise the installed SDK against a local HTTP fixture.
132
+ They cover read-only defaults, write opt-in, List/Get response validation, creation
133
+ HTTP 201, ref/branch forwarding, invalid combinations, pagination, and `docsUrl`
134
+ arrays/errors and local environment-file loading. They do not require credentials
135
+ or create remote collections. `test:package` additionally installs the actual
136
+ tarball in a clean consumer directory and repeats the tool contracts over real
137
+ stdio, checking version identity, config errors, stdout and process termination.
138
+ CI validates Node 22.14.0, current 22.x and 24.x on PRs and pushes to develop/main.
139
+ See [CONTRIBUTING.md](CONTRIBUTING.md) and [RELEASING.md](RELEASING.md) for checks,
140
+ release policy and the initially disabled automatic publication gate.
141
+
142
+ For a live smoke, explicitly designate a disposable **development** project and
143
+ configure its credentials in `.env.local` with `LAMBDADB_MCP_ENABLE_WRITE_TOOLS=true`.
144
+ An existing credential file alone is not permission to test. Then run:
145
+
146
+ ```bash
147
+ LAMBDADB_RUN_LIVE_TESTS=1 LAMBDADB_LIVE_CONFIRM_PROJECT=YOUR_DEV_PROJECT npm run test:live
148
+ ```
149
+
150
+ The live test creates one uniquely named temporary collection, checks real HTTP
151
+ 201/202 responses, metadata, pagination, filters, sorting, and Branch/Tag/Alias
152
+ reads. It writes two 3 MiB documents to force actual `docsUrl` array downloads
153
+ through the MCP tools and checks full payload integrity and download credential
154
+ isolation. It allows up to five minutes for committed visibility, deletes its
155
+ temporary collection in cleanup, and verifies that the collection is absent.
156
+ Branch/Tag/Alias setup and collection cleanup use the SDK directly because these
157
+ operations are not exposed as MCP tools. This test is separate from `npm run check`.
158
+
159
+ If the environment file is outside the worktree:
160
+
161
+ ```bash
162
+ LAMBDADB_ENV_FILE=/absolute/path/to/.env.local LAMBDADB_RUN_LIVE_TESTS=1 LAMBDADB_LIVE_CONFIRM_PROJECT=YOUR_DEV_PROJECT npm run test:live
163
+ ```
164
+
165
+ ## Run from source (development)
166
+
167
+ Use Node.js >=22.14.0. The repository's optional launchers preserve exported
168
+ environment overrides when loading dotenv files with Node's `--env-file`.
169
+
170
+ If you use `nix-direnv`, this repo can provision Node automatically:
171
+
172
+ ```bash
173
+ direnv allow
174
+ ```
175
+
176
+ Or enter the shell directly:
177
+
178
+ ```bash
179
+ nix develop
180
+ ```
181
+
182
+ Then install and build:
183
+
184
+ ```bash
185
+ npm install
186
+ npm run build
187
+ ```
188
+
189
+ For local development, create a `.env.local` file first:
190
+
191
+ ```bash
192
+ cp .env.example .env.local
193
+ ```
194
+
195
+ For local stdio execution:
196
+
197
+ ```bash
198
+ export LAMBDADB_BASE_URL=...
199
+ export LAMBDADB_PROJECT_NAME=...
200
+ export LAMBDADB_PROJECT_API_KEY=...
201
+ npm run start
202
+ ```
203
+
204
+ Or load the local environment file:
205
+
206
+ ```bash
207
+ npm run start:env
208
+ ```
209
+
210
+ To inspect the server in the official MCP Inspector:
211
+
212
+ ```bash
213
+ npm run inspect
214
+ ```
215
+
216
+ `start:env`, `inspect`, and `test:live` use the same file selection:
217
+ `LAMBDADB_ENV_FILE` when set, otherwise `.env.local` if present, otherwise `.env`.
218
+ Only the selected file is loaded. For `start:env` and `test:live`, exported environment
219
+ variables take precedence. Inspector forwards `LAMBDADB_ENV_FILE` and
220
+ `LAMBDADB_MCP_ENABLE_WRITE_TOOLS`; its connection credentials come from the selected file.
221
+ Relative `LAMBDADB_ENV_FILE` paths are resolved from the repository root.
222
+ The Inspector launches `dist/index.js` through this loader and opens its web UI.
223
+ Credentials are read by Node rather than passed as Inspector command-line arguments.
224
+
225
+ To use read-only tools even when the selected file enables writes:
226
+
227
+ ```bash
228
+ LAMBDADB_MCP_ENABLE_WRITE_TOOLS=false npm run inspect
229
+ ```
230
+
231
+ ## Codex Example
232
+
233
+ After the first dev publication, configure the stdio executable:
234
+
235
+ ```toml
236
+ [mcp_servers.lambdadb]
237
+ command = "npx"
238
+ args = ["--yes", "@functional-systems/lambdadb-mcp@dev"]
239
+
240
+ [mcp_servers.lambdadb.env]
241
+ LAMBDADB_BASE_URL = "https://aws-ap-northeast-2.lambdadb.ai"
242
+ LAMBDADB_PROJECT_NAME = "my-project"
243
+ LAMBDADB_PROJECT_API_KEY = "replace-me"
244
+ LAMBDADB_MCP_ENABLE_WRITE_TOOLS = "false"
245
+ ```
246
+
247
+ Use a secure local configuration or the client's environment forwarding facility
248
+ for credentials. Replace `@dev` with an exact published version when pinning.
249
+ The existing source-checkout launcher remains available as
250
+ `bash /absolute/path/to/lambdadb-mcp/scripts/with-env.sh dist/index.js`.
251
+
252
+ ## Claude Desktop Example
253
+
254
+ ```json
255
+ {
256
+ "mcpServers": {
257
+ "lambdadb": {
258
+ "command": "npx",
259
+ "args": ["--yes", "@functional-systems/lambdadb-mcp@dev"],
260
+ "env": {
261
+ "LAMBDADB_BASE_URL": "https://aws-ap-northeast-2.lambdadb.ai",
262
+ "LAMBDADB_PROJECT_NAME": "my-project",
263
+ "LAMBDADB_PROJECT_API_KEY": "replace-me",
264
+ "LAMBDADB_MCP_ENABLE_WRITE_TOOLS": "false"
265
+ }
266
+ }
267
+ }
268
+ }
269
+ ```
270
+
271
+ ## Development Notes
272
+
273
+ - This repo currently assumes `stdio` transport first for local MCP clients.
274
+ - The server is scoped to one configured LambdaDB project per process.
275
+ - Write tools are intentionally disabled by default.
276
+ - `npm run inspect` is the fastest way to validate tool registration, schemas, and live LambdaDB responses during development.
277
+
278
+ ## Documentation Strategy
279
+
280
+ Recommended split:
281
+
282
+ - `lambdadb-mcp`: implementation-oriented source of truth
283
+ - `docs`: user-facing setup, examples, supported tools, troubleshooting
284
+
285
+ That keeps operational details close to code while avoiding product docs drift.
286
+
287
+ ## License
288
+
289
+ Apache-2.0. See [LICENSE](LICENSE).
package/RELEASING.md ADDED
@@ -0,0 +1,180 @@
1
+ # Releasing LambdaDB MCP
2
+
3
+ ## Status and policy
4
+
5
+ This change prepares npm distribution; it does not publish a package, tag a
6
+ release or enable automatic publication. On 2026-09-19, the public registry
7
+ returned E404 for `@functional-systems/lambdadb-mcp`; GitHub had no tags or
8
+ Releases. The current npm account returned E401 for both `npm whoami` and
9
+ `npm org ls functional-systems`, so organization publication rights remain
10
+ unconfirmed. GitHub repository administration is not npm organization membership.
11
+ Check these again before bootstrap; a public E404 is not a name reservation.
12
+
13
+ | Source | Version | Trigger | npm dist-tag |
14
+ | --- | --- | --- | --- |
15
+ | develop | `X.Y.Z-dev.N` | Successful push validation, explicitly enabled | dev |
16
+ | reviewed main history | `X.Y.Z-rc.N` | Published GitHub prerelease `vX.Y.Z-rc.N` | rc |
17
+ | reviewed main history | `X.Y.Z` | Published GitHub release `vX.Y.Z` | latest |
18
+
19
+ Only these canonical forms are accepted, without leading zeroes or build suffixes.
20
+ `package.json` and both root lockfile versions must match. MCP initialize reads
21
+ its version from the installed package.json; there is no second version constant.
22
+ The repository URL must identify this exact public GitHub repository.
23
+
24
+ ## Validation and the publication artifact
25
+
26
+ From a clean checkout of the reviewed candidate with Node >=22.14.0:
27
+
28
+ ```sh
29
+ npm ci
30
+ npm run check
31
+ # Use an output directory outside the checkout.
32
+ mkdir -p /tmp/lambdadb-mcp-release
33
+ npm pack --json --pack-destination /tmp/lambdadb-mcp-release
34
+ # Substitute the exact filename returned by npm pack.
35
+ npm run test:package -- /tmp/lambdadb-mcp-release/functional-systems-lambdadb-mcp-VERSION.tgz
36
+ ```
37
+
38
+ Keep that tarball: publish the same file, never a newly packed directory. The
39
+ workflow performs exactly one pack in its publishing job, validates inventory,
40
+ installs that file without install scripts into a clean temporary directory,
41
+ and tests the installed `lambdadb-mcp` bin. Its hash must remain unchanged during
42
+ testing. Validation matrix jobs also test their own packages; those are not the
43
+ publication artifact. Only compiled JavaScript, package metadata, README,
44
+ CHANGELOG, contribution/release guides and LICENSE are allowed in the actual tarball. The build cleans dist
45
+ first so stale compiled files cannot survive a normal pack.
46
+
47
+ Consumer tests exercise MCP initialize, tools/list and tools/call with loopback
48
+ HTTP fixtures: read-only defaults, write opt-in, ref/branch forwarding, SDK errors,
49
+ docsUrl downloads and credential isolation, version identity, configuration
50
+ failures, protocol-only stdout and termination. They do not prove production
51
+ service behavior or every MCP client UI. Installed dependencies are resolved by
52
+ npm (the package's development lockfile is not a consumer dependency lock).
53
+
54
+ Live tests are optional for PR validation, but release owners must explicitly
55
+ record performed or not performed. They require a designated development project,
56
+ not merely the presence of an existing `.env.local` or credential. See README
57
+ for `LAMBDADB_RUN_LIVE_TESTS=1` and project confirmation. Do not load production
58
+ credentials into package/CI tests. This implementation task did not run live tests.
59
+
60
+ ## First package publication: separate manual bootstrap
61
+
62
+ npm trust configuration requires an existing package. See the official
63
+ [npm trust prerequisites](https://docs.npmjs.com/cli/v11/commands/npm-trust/).
64
+ The TypeScript SDK's or CLI's trust settings do not cover this package.
65
+
66
+ 1. Review and merge preparation, validate a clean reviewed develop candidate,
67
+ and confirm its version is the real bootstrap prerelease `0.1.0-dev.1`.
68
+ 2. Obtain authorization for first publication. An authorized npm
69
+ `functional-systems` organization owner uses interactive `npm login` with MFA,
70
+ then verifies `npm whoami` and `npm org ls functional-systems`. Do not add a
71
+ long-lived npm token to GitHub or the repository.
72
+ 3. Pack once and test the resulting file using the commands above. Publish that
73
+ exact verified file with the interactive account:
74
+
75
+ ```sh
76
+ npm publish /absolute/path/to/functional-systems-lambdadb-mcp-0.1.0-dev.1.tgz --access public --tag dev
77
+ ```
78
+
79
+ 4. Verify version, tarball integrity, dist-tags and a clean consumer install.
80
+ Bootstrap does not carry GitHub Actions provenance. npm can also assign
81
+ `latest` during first publication even with `--tag dev`; inspect actual tags
82
+ and document that state. Until a stable release exists, use an explicit dev
83
+ version/tag and do not advertise unqualified npx as stable. Do not repeat
84
+ bootstrap or republish a used version to fix registry lag.
85
+
86
+ ## Configure package-specific Trusted Publishing
87
+
88
+ After bootstrap, open the npm package's **Settings → Trusted Publisher**:
89
+
90
+ | Setting | Value |
91
+ | --- | --- |
92
+ | Package | `@functional-systems/lambdadb-mcp` |
93
+ | Provider | GitHub Actions |
94
+ | Organization or user | `lambdadb` |
95
+ | Repository | `lambdadb-mcp` |
96
+ | Workflow filename | `publish.yaml` (filename only) |
97
+ | Environment | Empty; the job declares no GitHub Environment |
98
+ | Allowed actions | Enable direct `npm publish` |
99
+
100
+ New trust configurations may default to staged publishing only; that does not
101
+ authorize this workflow's direct publish. If an Environment is added later,
102
+ configure its exact name in npm too. Restrict traditional publishing tokens in
103
+ package settings after setup. Saving trust settings does not validate OIDC;
104
+ only an authorized successful publication does.
105
+
106
+ The workflow uses a GitHub-hosted runner, Node 24, npm >=11.5.1,
107
+ `id-token: write` only in the publication job, public access and provenance.
108
+ It has no npm token secret. See [npm Trusted Publishing](https://docs.npmjs.com/trusted-publishers/).
109
+
110
+ ## Enable automatic dev publication: a separate authorization
111
+
112
+ Leave repository variable `NPM_DEV_PUBLISH_ENABLED` unset or false through
113
+ bootstrap and trust setup. Only after authorizing ongoing develop publication,
114
+ set it to `true` in GitHub **Settings → Secrets and variables → Actions → Variables**.
115
+ This implementation leaves it unset. The next eligible develop push, or a rerun
116
+ of its existing push workflow, can then publish. `workflow_dispatch`, PRs and main
117
+ pushes validate only. Disable the variable to stop future automatic publication;
118
+ do not cancel an in-progress registry write as rollback.
119
+
120
+ The generator reuses the CLI's first-parent strategy: for a reviewed base
121
+ `X.Y.Z-dev.N`, set N to `git rev-list --first-parent --count HEAD` from a full
122
+ checkout. Numbers can have gaps; reruns of the same commit generate the same
123
+ version. Disable force pushes/history rewrites. Generated package/lock versions
124
+ and gitHead exist only in the runner; no version commits, tags or GitHub Releases
125
+ are created for dev builds. Review a new base when starting another release line.
126
+
127
+ Remote develop HEAD is checked before preparation and immediately before the
128
+ write. Stale jobs and versions older than the current channel are skipped.
129
+ All publication jobs share non-cancelling concurrency so registry writes do not
130
+ race. A newer pending job can replace an older pending job; this does not promise
131
+ a package for every rapid merge. Re-run an explicit release if it was superseded
132
+ in the pending queue and still needs publication.
133
+
134
+ ## Explicit rc/stable publication
135
+
136
+ 1. Prepare matching package/lock metadata and a dated
137
+ `## [VERSION] - YYYY-MM-DD` changelog entry on a release branch. Review into
138
+ main and retain validation/live-test status for the candidate.
139
+ 2. Ensure `publish.yaml` exists on the default branch (`main`). The dev push
140
+ path does not require that promotion, but GitHub Release handling does.
141
+ 3. Obtain authorization, tag the verified main commit as `vVERSION`, and publish
142
+ the GitHub Release with `prerelease: true` for rc or `false` for stable.
143
+ Draft releases do not publish. Do not create a dev GitHub Release.
144
+ 4. The workflow validates the release tag, package versions, prerelease flag,
145
+ changelog and ancestry in origin/main; it packs/tests once and publishes the
146
+ exact file to rc/latest with OIDC and provenance. A successful CI run alone
147
+ is not publication evidence. Verify npm and synchronize release changes into
148
+ develop with its next dev base via PR.
149
+
150
+ ## Duplicate prevention, registry lag and recovery
151
+
152
+ Dev, rc and stable use the CLI-derived registry verification path. Before a write,
153
+ only a structured E404 means an absent version; authentication, malformed responses
154
+ and transport failures fail closed. Existing versions must match package name,
155
+ version, gitHead and tarball SHA-512 integrity and already own the selected tag.
156
+ Identical reruns report `already-published`; conflicts or unexpected tag state
157
+ require investigation. Older channel candidates report `superseded` without
158
+ changing tags. rc/dev never intentionally update latest.
159
+
160
+ There is at most one publish request per invocation, with no automatic write
161
+ retry. After an accepted write, read requests share a five-minute monotonic budget,
162
+ 15-second maximum request timeouts, no nested npm fetch retries and sleeps of at
163
+ most ten seconds. E404, HTTP 429/5xx and recognized transient connection errors
164
+ are retried only during post-publication reads. Metadata and tags can propagate
165
+ separately. Artifact conflicts, authentication errors and malformed responses fail.
166
+
167
+ `published-verification-pending` means the write succeeded but reads did not
168
+ converge in the budget. A failed publish request is an uncertain write. In either
169
+ case inspect and retry registry reads first, never immediately republish:
170
+
171
+ ```sh
172
+ npm view @functional-systems/lambdadb-mcp@VERSION version gitHead dist.integrity dist.attestations --json
173
+ npm view @functional-systems/lambdadb-mcp@dev dist-tags --json
174
+ ```
175
+
176
+ Once metadata agrees, an identical rerun skips the write. Verify provenance's
177
+ repository and commit and run a clean consumer smoke. Do not move immutable tags,
178
+ republish a used version, or automatically change dist-tags to recover. Prepare a
179
+ new reviewed patch for a bad release; deprecation and tag changes are explicit
180
+ maintainer actions. No Homebrew, MCP Registry or HTTP hosting is part of this flow.
@@ -0,0 +1,27 @@
1
+ function requireEnv(name, value) {
2
+ if (!value || value.trim() === "") {
3
+ throw new Error(`Missing required environment variable: ${name}`);
4
+ }
5
+ return value.trim();
6
+ }
7
+ function parseBoolean(value, fallback) {
8
+ if (value == null || value.trim() === "") {
9
+ return fallback;
10
+ }
11
+ const normalized = value.trim().toLowerCase();
12
+ if (["1", "true", "yes", "on"].includes(normalized)) {
13
+ return true;
14
+ }
15
+ if (["0", "false", "no", "off"].includes(normalized)) {
16
+ return false;
17
+ }
18
+ throw new Error(`Invalid boolean value: ${value}`);
19
+ }
20
+ export function getEnvConfig(env = process.env) {
21
+ return {
22
+ baseUrl: requireEnv("LAMBDADB_BASE_URL", env.LAMBDADB_BASE_URL),
23
+ projectName: requireEnv("LAMBDADB_PROJECT_NAME", env.LAMBDADB_PROJECT_NAME),
24
+ projectApiKey: requireEnv("LAMBDADB_PROJECT_API_KEY", env.LAMBDADB_PROJECT_API_KEY),
25
+ enableWriteTools: parseBoolean(env.LAMBDADB_MCP_ENABLE_WRITE_TOOLS, false)
26
+ };
27
+ }
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { getEnvConfig } from "./config/env.js";
4
+ import { createServer } from "./server/createServer.js";
5
+ async function main() {
6
+ const config = getEnvConfig();
7
+ const server = createServer(config);
8
+ const transport = new StdioServerTransport();
9
+ await server.connect(transport);
10
+ // A disconnected stdio client owns no further work in this process.
11
+ const shutdown = () => {
12
+ void server.close().finally(() => process.exit(0));
13
+ };
14
+ process.stdin.once("end", shutdown);
15
+ process.once("SIGINT", shutdown);
16
+ process.once("SIGTERM", shutdown);
17
+ }
18
+ main().catch((error) => {
19
+ const message = error instanceof Error ? error.stack ?? error.message : String(error);
20
+ console.error(message);
21
+ process.exit(1);
22
+ });
@@ -0,0 +1,8 @@
1
+ import { LambdaDBClient } from "@functional-systems/lambdadb";
2
+ export function createLambdaDBClient(config) {
3
+ return new LambdaDBClient({
4
+ baseUrl: config.baseUrl,
5
+ projectName: config.projectName,
6
+ projectApiKey: config.projectApiKey
7
+ });
8
+ }
@@ -0,0 +1,14 @@
1
+ export function formatLambdaDBError(error) {
2
+ if (error instanceof Error) {
3
+ return error.message;
4
+ }
5
+ if (typeof error === "string") {
6
+ return error;
7
+ }
8
+ try {
9
+ return JSON.stringify(error, null, 2);
10
+ }
11
+ catch {
12
+ return "Unknown LambdaDB error";
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { registerTools } from "../tools/index.js";
4
+ export function createServer(config) {
5
+ const server = new McpServer({
6
+ name: "lambdadb-mcp",
7
+ version: JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version
8
+ }, {
9
+ instructions: "This server exposes LambdaDB data plane tools for a single configured project. Prefer read-only tools unless write tools are explicitly enabled by the server operator."
10
+ });
11
+ registerTools(server, config);
12
+ return server;
13
+ }
@@ -0,0 +1,8 @@
1
+ import { registerReadTools } from "./read.js";
2
+ import { registerWriteTools } from "./write.js";
3
+ export function registerTools(server, config) {
4
+ registerReadTools(server, config);
5
+ if (config.enableWriteTools) {
6
+ registerWriteTools(server, config);
7
+ }
8
+ }
@@ -0,0 +1,153 @@
1
+ import { z } from "zod";
2
+ import { createLambdaDBClient } from "../lambdadb/client.js";
3
+ import { formatLambdaDBError } from "../lambdadb/errors.js";
4
+ import { fieldsSchema, jsonResult, nameSchema, partitionFilterSchema, readOptions, readRefSchema } from "./shared.js";
5
+ export function registerReadTools(server, config) {
6
+ server.registerTool("lambdadb_list_collections", {
7
+ title: "List Collections",
8
+ description: "List collections in the configured LambdaDB project.",
9
+ annotations: {
10
+ readOnlyHint: true,
11
+ openWorldHint: false
12
+ },
13
+ inputSchema: z.strictObject({
14
+ size: z.number().int().min(1).max(100).optional(),
15
+ pageToken: z.string().optional()
16
+ })
17
+ }, async ({ size, pageToken }) => {
18
+ try {
19
+ const client = createLambdaDBClient(config);
20
+ const result = await client.listCollections({ size, pageToken });
21
+ return jsonResult("Collections listed successfully.", result);
22
+ }
23
+ catch (error) {
24
+ throw new Error(formatLambdaDBError(error));
25
+ }
26
+ });
27
+ server.registerTool("lambdadb_get_collection", {
28
+ title: "Get Collection",
29
+ description: "Get metadata for a specific collection.",
30
+ annotations: {
31
+ readOnlyHint: true,
32
+ openWorldHint: false
33
+ },
34
+ inputSchema: z.strictObject({
35
+ collectionName: nameSchema
36
+ })
37
+ }, async ({ collectionName }) => {
38
+ try {
39
+ const client = createLambdaDBClient(config);
40
+ const result = await client.collection(collectionName).get();
41
+ return jsonResult("Collection metadata loaded successfully.", result);
42
+ }
43
+ catch (error) {
44
+ throw new Error(formatLambdaDBError(error));
45
+ }
46
+ });
47
+ server.registerTool("lambdadb_query_collection", {
48
+ title: "Query Collection",
49
+ description: "Run a search query against a collection and return the matching documents.",
50
+ annotations: {
51
+ readOnlyHint: true,
52
+ openWorldHint: false
53
+ },
54
+ inputSchema: z.strictObject({
55
+ collectionName: nameSchema,
56
+ size: z.number().int().min(1).max(100).optional(),
57
+ query: z.record(z.string(), z.any()),
58
+ ref: readRefSchema.optional(),
59
+ consistentRead: z.boolean().optional().describe("true requires a direct branch ref or omitted ref (main)."),
60
+ includeVectors: z.boolean().optional(),
61
+ // JSON Schema conversion drops RegExp flags; encode case folding in the pattern.
62
+ sort: z.array(z.record(z.string(), z.string().regex(/^([aA][sS][cC]|[dD][eE][sS][cC])$/))).optional(),
63
+ fields: fieldsSchema.optional(),
64
+ partitionFilter: partitionFilterSchema.optional()
65
+ })
66
+ }, async ({ collectionName, size, query, ref, consistentRead, includeVectors, sort, fields, partitionFilter }) => {
67
+ try {
68
+ const client = createLambdaDBClient(config);
69
+ const input = {
70
+ query,
71
+ size,
72
+ ...readOptions(ref, consistentRead),
73
+ includeVectors,
74
+ sort,
75
+ fields,
76
+ partitionFilter
77
+ };
78
+ const result = await client.collection(collectionName).query(input);
79
+ return jsonResult("Collection query completed successfully.", result);
80
+ }
81
+ catch (error) {
82
+ throw new Error(formatLambdaDBError(error));
83
+ }
84
+ });
85
+ server.registerTool("lambdadb_list_docs", {
86
+ title: "List Documents",
87
+ description: "List documents from a collection with pagination support.",
88
+ annotations: {
89
+ readOnlyHint: true,
90
+ openWorldHint: false
91
+ },
92
+ inputSchema: z.strictObject({
93
+ collectionName: nameSchema,
94
+ size: z.number().int().min(1).max(100).optional(),
95
+ pageToken: z.string().optional(),
96
+ ref: readRefSchema.optional(),
97
+ filter: z.record(z.string(), z.any()).optional(),
98
+ fields: fieldsSchema.optional(),
99
+ includeVectors: z.boolean().optional(),
100
+ partitionFilter: partitionFilterSchema.optional()
101
+ })
102
+ }, async ({ collectionName, size, pageToken, ref, filter, fields, includeVectors, partitionFilter }) => {
103
+ try {
104
+ const client = createLambdaDBClient(config);
105
+ const result = await client.collection(collectionName).docs.list({
106
+ size,
107
+ pageToken,
108
+ ref,
109
+ filter,
110
+ fields,
111
+ includeVectors,
112
+ partitionFilter
113
+ });
114
+ return jsonResult("Documents listed successfully.", result);
115
+ }
116
+ catch (error) {
117
+ throw new Error(formatLambdaDBError(error));
118
+ }
119
+ });
120
+ server.registerTool("lambdadb_fetch_docs", {
121
+ title: "Fetch Documents",
122
+ description: "Fetch specific documents from a collection by document ID.",
123
+ annotations: {
124
+ readOnlyHint: true,
125
+ openWorldHint: false
126
+ },
127
+ inputSchema: z.strictObject({
128
+ collectionName: nameSchema,
129
+ ids: z.array(z.string().min(1)).min(1).max(100),
130
+ ref: readRefSchema.optional(),
131
+ consistentRead: z.boolean().optional().describe("true requires a direct branch ref or omitted ref (main)."),
132
+ includeVectors: z.boolean().optional(),
133
+ fields: fieldsSchema.optional(),
134
+ partitionFilter: partitionFilterSchema.optional()
135
+ })
136
+ }, async ({ collectionName, ids, ref, consistentRead, includeVectors, fields, partitionFilter }) => {
137
+ try {
138
+ const client = createLambdaDBClient(config);
139
+ const input = {
140
+ ids,
141
+ ...readOptions(ref, consistentRead),
142
+ includeVectors,
143
+ fields,
144
+ partitionFilter
145
+ };
146
+ const result = await client.collection(collectionName).docs.fetch(input);
147
+ return jsonResult("Documents fetched successfully.", result);
148
+ }
149
+ catch (error) {
150
+ throw new Error(formatLambdaDBError(error));
151
+ }
152
+ });
153
+ }
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ export const nameSchema = z.string().regex(/^[a-zA-Z0-9_-]{3,52}$/);
3
+ export const readRefSchema = z.discriminatedUnion("kind", [
4
+ z.strictObject({ kind: z.literal("branch"), name: nameSchema }),
5
+ z.strictObject({ kind: z.literal("tag"), name: nameSchema }),
6
+ z.strictObject({ kind: z.literal("alias"), name: nameSchema })
7
+ ]);
8
+ const fieldNames = z.array(z.string().min(1)).min(1);
9
+ export const fieldsSchema = z.union([
10
+ z.strictObject({ include: fieldNames, exclude: fieldNames.optional() }),
11
+ z.strictObject({ include: fieldNames.optional(), exclude: fieldNames })
12
+ ]);
13
+ export const partitionFilterSchema = z.strictObject({
14
+ field: z.string().min(1),
15
+ in: z.array(z.string().min(1)).min(1)
16
+ });
17
+ // Preserve the SDK's discriminated input type after enforcing the ref constraint.
18
+ export function readOptions(ref, consistentRead) {
19
+ if (ref && ref.kind !== "branch") {
20
+ if (consistentRead === true) {
21
+ throw new Error("consistentRead=true requires a direct branch ref (or omitted ref for main).");
22
+ }
23
+ return { ref, consistentRead };
24
+ }
25
+ return { ref, consistentRead };
26
+ }
27
+ export function jsonResult(title, data) {
28
+ return {
29
+ content: [
30
+ {
31
+ type: "text",
32
+ text: `${title}\n\n${JSON.stringify(data, null, 2)}`
33
+ }
34
+ ]
35
+ };
36
+ }
@@ -0,0 +1,95 @@
1
+ import { z } from "zod";
2
+ import { createLambdaDBClient } from "../lambdadb/client.js";
3
+ import { formatLambdaDBError } from "../lambdadb/errors.js";
4
+ import { jsonResult, nameSchema, partitionFilterSchema } from "./shared.js";
5
+ export function registerWriteTools(server, config) {
6
+ server.registerTool("lambdadb_create_collection", {
7
+ title: "Create Collection",
8
+ description: "Create a new collection in the configured project.",
9
+ annotations: {
10
+ openWorldHint: false
11
+ },
12
+ inputSchema: z.strictObject({
13
+ collectionName: nameSchema,
14
+ indexConfigs: z.record(z.string(), z.any()).refine((value) => Object.keys(value).length > 0, "indexConfigs must contain at least one field."),
15
+ description: z.string().max(255).optional(),
16
+ tags: z.record(z.string().regex(/^[A-Za-z0-9_.-]{1,63}$/), z.string().min(1).max(127).regex(/^[^:#,]+$/))
17
+ .refine((value) => Object.keys(value).length <= 5, "At most five tags are allowed.")
18
+ .optional(),
19
+ snapshotRetentionInDays: z.number().int().min(1).max(31).optional(),
20
+ partitionConfig: z.strictObject({
21
+ fieldName: z.string().min(1),
22
+ dataType: z.literal("keyword"),
23
+ numPartitions: z.number().int().min(2).max(1024)
24
+ }).optional()
25
+ })
26
+ }, async ({ collectionName, indexConfigs, description, tags, snapshotRetentionInDays, partitionConfig }) => {
27
+ try {
28
+ const client = createLambdaDBClient(config);
29
+ const input = {
30
+ collectionName,
31
+ indexConfigs,
32
+ description,
33
+ tags,
34
+ snapshotRetentionInDays,
35
+ partitionConfig
36
+ };
37
+ const result = await client.createCollection(input);
38
+ return jsonResult("Collection created successfully.", result);
39
+ }
40
+ catch (error) {
41
+ throw new Error(formatLambdaDBError(error));
42
+ }
43
+ });
44
+ server.registerTool("lambdadb_upsert_docs", {
45
+ title: "Upsert Documents",
46
+ description: "Upsert documents into a collection. Keep payloads small enough for the standard API path.",
47
+ annotations: {
48
+ openWorldHint: false
49
+ },
50
+ inputSchema: z.strictObject({
51
+ collectionName: nameSchema,
52
+ docs: z.array(z.record(z.string(), z.any())).min(1),
53
+ branch: nameSchema.optional()
54
+ })
55
+ }, async ({ collectionName, docs, branch }) => {
56
+ try {
57
+ const client = createLambdaDBClient(config);
58
+ const input = { docs, branch };
59
+ const result = await client.collection(collectionName).docs.upsert(input);
60
+ return jsonResult("Documents upserted successfully.", result);
61
+ }
62
+ catch (error) {
63
+ throw new Error(formatLambdaDBError(error));
64
+ }
65
+ });
66
+ server.registerTool("lambdadb_delete_docs", {
67
+ title: "Delete Documents",
68
+ description: "Delete documents using exactly one of ids or filter. Omitted branch targets main.",
69
+ annotations: {
70
+ openWorldHint: false
71
+ },
72
+ inputSchema: z.strictObject({
73
+ collectionName: nameSchema,
74
+ ids: z.array(z.string().min(1)).min(1).optional(),
75
+ filter: z.record(z.string(), z.any()).optional(),
76
+ partitionFilter: partitionFilterSchema.optional(),
77
+ branch: nameSchema.optional()
78
+ })
79
+ }, async ({ collectionName, ids, filter, partitionFilter, branch }) => {
80
+ if ((ids === undefined) === (filter === undefined)) {
81
+ throw new Error("Specify exactly one of ids or filter.");
82
+ }
83
+ try {
84
+ const client = createLambdaDBClient(config);
85
+ const input = ids !== undefined
86
+ ? { ids, partitionFilter, branch }
87
+ : { filter: filter, partitionFilter, branch };
88
+ const result = await client.collection(collectionName).docs.delete(input);
89
+ return jsonResult("Documents deleted successfully.", result);
90
+ }
91
+ catch (error) {
92
+ throw new Error(formatLambdaDBError(error));
93
+ }
94
+ });
95
+ }
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@functional-systems/lambdadb-mcp",
3
+ "version": "0.1.0-dev.1",
4
+ "private": false,
5
+ "description": "MCP server for LambdaDB data plane",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=22.14.0"
9
+ },
10
+ "scripts": {
11
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json && node -e \"require('node:fs').chmodSync('dist/index.js', 0o755)\"",
12
+ "check": "npm run check:version && npm run typecheck && npm test",
13
+ "test": "npm run build && node --test test/*.test.mjs",
14
+ "test:live": "npm run build && bash ./scripts/with-env.sh --test test/integration/live.test.mjs",
15
+ "dev": "tsx watch src/index.ts",
16
+ "inspect": "bash ./scripts/inspect.sh",
17
+ "start": "node dist/index.js",
18
+ "start:env": "bash ./scripts/with-env.sh dist/index.js",
19
+ "typecheck": "tsc --noEmit",
20
+ "prepack": "npm run build",
21
+ "check:version": "node scripts/check-release.mjs",
22
+ "test:package": "node scripts/test-package.mjs"
23
+ },
24
+ "dependencies": {
25
+ "@functional-systems/lambdadb": "0.5.1",
26
+ "@modelcontextprotocol/sdk": "1.29.0",
27
+ "zod": "^4.1.12"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.12.0",
31
+ "tsx": "^4.20.6",
32
+ "typescript": "^5.8.3"
33
+ },
34
+ "bin": {
35
+ "lambdadb-mcp": "dist/index.js"
36
+ },
37
+ "files": [
38
+ "dist/**/*.js",
39
+ "README.md",
40
+ "LICENSE",
41
+ "CHANGELOG.md",
42
+ "CONTRIBUTING.md",
43
+ "RELEASING.md"
44
+ ],
45
+ "license": "Apache-2.0",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/lambdadb/lambdadb-mcp.git"
49
+ },
50
+ "homepage": "https://github.com/lambdadb/lambdadb-mcp#readme",
51
+ "bugs": {
52
+ "url": "https://github.com/lambdadb/lambdadb-mcp/issues"
53
+ },
54
+ "keywords": [
55
+ "lambdadb",
56
+ "mcp",
57
+ "model-context-protocol"
58
+ ],
59
+ "publishConfig": {
60
+ "access": "public",
61
+ "registry": "https://registry.npmjs.org"
62
+ }
63
+ }