@otskit/mcp 0.6.0 → 0.6.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 OTSkit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -10,6 +10,8 @@
10
10
  [![TypeScript](https://img.shields.io/badge/TypeScript-6-blue.svg)](https://www.typescriptlang.org/)
11
11
  [![Node ≥20](https://img.shields.io/badge/node-%3E%3D20-brightgreen)](https://nodejs.org)
12
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
13
+ [![Glama](https://glama.ai/mcp/servers/OTSkit/OTSkit-MCP/badges/score.svg)](https://glama.ai/mcp/servers/OTSkit/OTSkit-MCP)
14
+ [![OTSkit-MCP MCP server](https://glama.ai/mcp/servers/OTSkit/OTSkit-MCP/badges/card.svg)](https://glama.ai/mcp/servers/OTSkit/OTSkit-MCP)
13
15
 
14
16
  OpenTimestamps MCP server — stamp, upgrade, and verify Bitcoin timestamps via AI agents.
15
17
 
@@ -105,4 +107,4 @@ npm test # run tests
105
107
  - [`@otskit/core`](https://github.com/AlexAlves87/otskit-core) — OpenTimestamps core logic
106
108
  - [`@otskit/client`](https://github.com/AlexAlves87/otskit-client) — OTS calendar client
107
109
  - [`@modelcontextprotocol/sdk`](https://github.com/modelcontextprotocol/typescript-sdk) — MCP SDK
108
- - `better-sqlite3` — local database
110
+ - `node-sqlite3-wasm` — local database (pure WASM, no native compilation)
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getDataDir
3
- } from "./chunk-4ZDPWS7C.js";
3
+ } from "./chunk-R2HGDQWP.js";
4
4
  import {
5
5
  writeAtomic
6
6
  } from "./chunk-YFSUDT24.js";
@@ -14,14 +14,15 @@ import { OpenTimestampsClient } from "@otskit/client";
14
14
  // src/db/stamps.ts
15
15
  function insertStamp(db, params) {
16
16
  const now = (/* @__PURE__ */ new Date()).toISOString();
17
- db.prepare(`
18
- INSERT INTO stamps (id, hash, status, created_at, proof_path, archive_path, attempt_count, metadata)
19
- VALUES (?, ?, 'pending', ?, ?, ?, 0, ?)
20
- `).run(params.id, params.hash, now, params.proof_path, params.archive_path ?? null, params.metadata ?? null);
17
+ db.run(
18
+ `INSERT INTO stamps (id, hash, status, created_at, proof_path, archive_path, attempt_count, metadata)
19
+ VALUES (?, ?, 'pending', ?, ?, ?, 0, ?)`,
20
+ [params.id, params.hash, now, params.proof_path, params.archive_path ?? null, params.metadata ?? null]
21
+ );
21
22
  return getStamp(db, params.id);
22
23
  }
23
24
  function getStamp(db, id) {
24
- return db.prepare("SELECT * FROM stamps WHERE id = ?").get(id) ?? null;
25
+ return db.get("SELECT * FROM stamps WHERE id = ?", [id]) ?? null;
25
26
  }
26
27
  function updateStampStatus(db, id, params) {
27
28
  const fields = [];
@@ -40,7 +41,7 @@ function updateStampStatus(db, id, params) {
40
41
  if (params.next_retry_at !== void 0) add("next_retry_at", params.next_retry_at);
41
42
  if (fields.length === 0) return;
42
43
  values.push(id);
43
- db.prepare(`UPDATE stamps SET ${fields.join(", ")} WHERE id = ?`).run(...values);
44
+ db.run(`UPDATE stamps SET ${fields.join(", ")} WHERE id = ?`, values);
44
45
  }
45
46
  function listStamps(db, params) {
46
47
  const conds = [];
@@ -59,26 +60,29 @@ function listStamps(db, params) {
59
60
  vals.push((/* @__PURE__ */ new Date()).toISOString());
60
61
  }
61
62
  const where = conds.length ? `WHERE ${conds.join(" AND ")}` : "";
62
- const total = db.prepare(`SELECT COUNT(*) as n FROM stamps ${where}`).get(...vals).n;
63
- const items = db.prepare(
64
- `SELECT * FROM stamps ${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`
65
- ).all(...vals, params.limit, params.offset);
63
+ const countParams = vals.length ? vals : void 0;
64
+ const total = db.get(`SELECT COUNT(*) as n FROM stamps ${where}`, countParams).n;
65
+ const items = db.all(
66
+ `SELECT * FROM stamps ${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`,
67
+ [...vals, params.limit, params.offset]
68
+ );
66
69
  return { items, total };
67
70
  }
68
71
 
69
72
  // src/db/operations-log.ts
70
73
  function logOperation(db, params) {
71
- db.prepare(`
72
- INSERT INTO operations_log (stamp_id, action, result, error_msg, calendar_uri, response_time_ms, created_at)
73
- VALUES (?, ?, ?, ?, ?, ?, ?)
74
- `).run(
75
- params.stamp_id,
76
- params.action,
77
- params.result,
78
- params.error_msg ?? null,
79
- params.calendar_uri ?? null,
80
- params.response_time_ms ?? null,
81
- (/* @__PURE__ */ new Date()).toISOString()
74
+ db.run(
75
+ `INSERT INTO operations_log (stamp_id, action, result, error_msg, calendar_uri, response_time_ms, created_at)
76
+ VALUES (?, ?, ?, ?, ?, ?, ?)`,
77
+ [
78
+ params.stamp_id,
79
+ params.action,
80
+ params.result,
81
+ params.error_msg ?? null,
82
+ params.calendar_uri ?? null,
83
+ params.response_time_ms ?? null,
84
+ (/* @__PURE__ */ new Date()).toISOString()
85
+ ]
82
86
  );
83
87
  }
84
88
 
@@ -34,23 +34,23 @@ function loadConfig() {
34
34
  }
35
35
 
36
36
  // src/db/index.ts
37
- import DatabaseConstructor from "better-sqlite3";
37
+ import { createRequire } from "module";
38
38
  import { join as join2 } from "path";
39
39
  import { mkdirSync as mkdirSync2, statSync } from "fs";
40
40
 
41
41
  // src/db/schema.ts
42
42
  function initDb(db) {
43
- db.pragma("journal_mode = WAL");
44
- db.pragma("busy_timeout = 5000");
45
- db.pragma("foreign_keys = ON");
43
+ db.exec("PRAGMA busy_timeout = 5000");
44
+ db.exec("PRAGMA foreign_keys = ON");
46
45
  runMigrations(db);
47
46
  }
48
47
  function runMigrations(db) {
49
- const version = db.pragma("user_version", { simple: true });
50
- if (version < 1) migrateTo1(db);
48
+ const row = db.get("PRAGMA user_version");
49
+ if (row.user_version < 1) migrateTo1(db);
51
50
  }
52
51
  function migrateTo1(db) {
53
- db.transaction(() => {
52
+ db.exec("BEGIN");
53
+ try {
54
54
  db.exec(`
55
55
  CREATE TABLE IF NOT EXISTS stamps (
56
56
  id TEXT PRIMARY KEY,
@@ -84,33 +84,43 @@ function migrateTo1(db) {
84
84
  CREATE INDEX IF NOT EXISTS idx_oplog_stamp_id ON operations_log(stamp_id);
85
85
  CREATE INDEX IF NOT EXISTS idx_oplog_created ON operations_log(created_at);
86
86
  `);
87
- db.pragma("user_version = 1");
88
- })();
87
+ db.exec("PRAGMA user_version = 1");
88
+ db.exec("COMMIT");
89
+ } catch (e) {
90
+ db.exec("ROLLBACK");
91
+ throw e;
92
+ }
89
93
  }
90
94
 
91
95
  // src/db/index.ts
96
+ var _require = createRequire(import.meta.url);
97
+ var { Database } = _require("node-sqlite3-wasm");
92
98
  var _db = null;
93
99
  function getDb() {
94
100
  if (_db) return _db;
95
101
  const dir = getDataDir();
96
102
  mkdirSync2(dir, { recursive: true });
97
- _db = new DatabaseConstructor(join2(dir, "db.sqlite"));
103
+ _db = new Database(join2(dir, "db.sqlite"));
98
104
  initDb(_db);
99
105
  reconcileOrphans(_db);
100
106
  return _db;
101
107
  }
102
108
  function backupDb(destPath) {
103
- getDb().backup(destPath);
109
+ const escaped = destPath.replace(/'/g, "''");
110
+ getDb().exec(`VACUUM INTO '${escaped}'`);
104
111
  }
105
112
  function reconcileOrphans(db) {
106
- const pending = db.prepare(
113
+ const pending = db.all(
107
114
  `SELECT id, proof_path FROM stamps WHERE status = 'pending' AND proof_path IS NOT NULL`
108
- ).all();
115
+ );
109
116
  for (const row of pending) {
110
117
  try {
111
118
  statSync(row.proof_path);
112
119
  } catch {
113
- db.prepare(`UPDATE stamps SET status = 'failed', last_error = ? WHERE id = ?`).run("proof file missing on disk", row.id);
120
+ db.run(
121
+ `UPDATE stamps SET status = 'failed', last_error = ? WHERE id = ?`,
122
+ ["proof file missing on disk", row.id]
123
+ );
114
124
  }
115
125
  }
116
126
  }
@@ -3,12 +3,12 @@ import {
3
3
  listPending,
4
4
  upgradeTimestamp,
5
5
  verifyTimestamp
6
- } from "./chunk-OMNHFTJW.js";
6
+ } from "./chunk-EJNN5HXO.js";
7
7
  import {
8
8
  backupDb,
9
9
  getDb,
10
10
  loadConfig
11
- } from "./chunk-4ZDPWS7C.js";
11
+ } from "./chunk-R2HGDQWP.js";
12
12
  import "./chunk-YFSUDT24.js";
13
13
 
14
14
  // src/cli.ts
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ Commands:
20
20
  }
21
21
  switch (command) {
22
22
  case "serve": {
23
- const { runServer } = await import("./server-NNUGQ5WQ.js");
23
+ const { runServer } = await import("./server-ATWAFTPU.js");
24
24
  await runServer();
25
25
  break;
26
26
  }
@@ -49,7 +49,7 @@ switch (command) {
49
49
  break;
50
50
  }
51
51
  case "watch": {
52
- const { watchPending } = await import("./watch-7NPUWR6I.js");
52
+ const { watchPending } = await import("./watch-JD5XLLTV.js");
53
53
  const parsed = args[0] ? parseInt(args[0], 10) : NaN;
54
54
  const interval = isNaN(parsed) || parsed < 1 ? 5 : parsed;
55
55
  if (args[0] && (isNaN(parsed) || parsed < 1))
@@ -65,7 +65,7 @@ switch (command) {
65
65
  case "check-pending":
66
66
  case "backup":
67
67
  case "scheduler": {
68
- const { runCli } = await import("./cli-D7G2H6UT.js");
68
+ const { runCli } = await import("./cli-4QMQ3NIC.js");
69
69
  await runCli(command, args);
70
70
  break;
71
71
  }
@@ -4,11 +4,11 @@ import {
4
4
  listPending,
5
5
  upgradeTimestamp,
6
6
  verifyTimestamp
7
- } from "./chunk-OMNHFTJW.js";
7
+ } from "./chunk-EJNN5HXO.js";
8
8
  import {
9
9
  getDb,
10
10
  loadConfig
11
- } from "./chunk-4ZDPWS7C.js";
11
+ } from "./chunk-R2HGDQWP.js";
12
12
  import "./chunk-YFSUDT24.js";
13
13
 
14
14
  // src/server.ts
@@ -272,6 +272,13 @@ async function runServer() {
272
272
  return { content: [{ type: "text", text: JSON.stringify({ error: "internal_error", details: String(e) }) }], isError: true };
273
273
  }
274
274
  });
275
+ const exit = () => {
276
+ db.close();
277
+ process.exit(0);
278
+ };
279
+ process.stdin.on("close", exit);
280
+ process.on("SIGTERM", exit);
281
+ process.on("SIGINT", exit);
275
282
  const transport = new StdioServerTransport();
276
283
  await server.connect(transport);
277
284
  }
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  getDb,
3
3
  loadConfig
4
- } from "./chunk-4ZDPWS7C.js";
4
+ } from "./chunk-R2HGDQWP.js";
5
5
 
6
6
  // src/tools/watch.ts
7
7
  async function watchPending(intervalMinutes = 5) {
8
8
  const config = loadConfig();
9
- const db = getDb(config);
9
+ const db = getDb();
10
10
  process.stdout.write(`Watching pending stamps every ${intervalMinutes} min. Ctrl+C to stop.
11
11
 
12
12
  `);
13
13
  function tick() {
14
- const rows = db.prepare(
14
+ const rows = db.all(
15
15
  `SELECT id, hash, status, attempt_count, bitcoin_block, confirmed_at FROM stamps WHERE status != 'confirmed' ORDER BY created_at DESC`
16
- ).all();
17
- const confirmed = db.prepare(`SELECT COUNT(*) as n FROM stamps WHERE status = 'confirmed'`).get();
16
+ );
17
+ const confirmed = db.get(`SELECT COUNT(*) as n FROM stamps WHERE status = 'confirmed'`);
18
18
  process.stdout.write(`${now()} \u2014 ${rows.length} pendientes, ${confirmed.n} confirmados
19
19
  `);
20
20
  for (const row of rows) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@otskit/mcp",
3
3
  "mcpName": "io.github.AlexAlves87/otskit-mcp",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "license": "MIT",
6
6
  "description": "OpenTimestamps MCP server — stamp, upgrade, verify via AI agents",
7
7
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "dist"
22
22
  ],
23
23
  "scripts": {
24
- "build": "tsup src/index.ts --format esm --clean",
24
+ "build": "tsup src/index.ts --format esm --clean --external node-sqlite3-wasm",
25
25
  "dev": "tsup src/index.ts --format esm --watch",
26
26
  "test": "vitest run",
27
27
  "test:watch": "vitest"
@@ -30,11 +30,10 @@
30
30
  "@modelcontextprotocol/sdk": "^1.29.0",
31
31
  "@otskit/client": "^0.2.0",
32
32
  "@otskit/core": "^0.1.0",
33
- "better-sqlite3": "^12.10.0"
33
+ "node-sqlite3-wasm": "0.8.57"
34
34
  },
35
35
  "pnpm": {
36
36
  "onlyBuiltDependencies": [
37
- "better-sqlite3",
38
37
  "esbuild"
39
38
  ]
40
39
  },
@@ -46,7 +45,6 @@
46
45
  "@semantic-release/github": "^12.0.8",
47
46
  "@semantic-release/npm": "^13.1.5",
48
47
  "@semantic-release/release-notes-generator": "^14.0.0",
49
- "@types/better-sqlite3": "^7.6.13",
50
48
  "@types/node": "^25.9.1",
51
49
  "semantic-release": "^25.0.3",
52
50
  "tsup": "^8.3.5",