@otskit/mcp 0.5.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
 
@@ -58,6 +60,8 @@ Each command writes the MCP entry into the agent's config file, makes a `.bak` b
58
60
  | `inspect_timestamp` | Inspect a stored proof file without network calls |
59
61
  | `list_pending` | List stamps with status, retry count, and filters |
60
62
  | `watch` | Open a terminal window monitoring pending stamps in real-time |
63
+ | `hash_file` | Compute the SHA-256 of a local file and return it as a 64-char hex string (no network calls) |
64
+ | `stamp_file` | Compute SHA-256 of a local file and stamp it on Bitcoin in one step |
61
65
 
62
66
  ## Data directory
63
67
 
@@ -103,4 +107,4 @@ npm test # run tests
103
107
  - [`@otskit/core`](https://github.com/AlexAlves87/otskit-core) — OpenTimestamps core logic
104
108
  - [`@otskit/client`](https://github.com/AlexAlves87/otskit-client) — OTS calendar client
105
109
  - [`@modelcontextprotocol/sdk`](https://github.com/modelcontextprotocol/typescript-sdk) — MCP SDK
106
- - `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-6QAYMGCK.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
@@ -80,6 +80,20 @@ async function stampFile(input, db, config) {
80
80
  return createTimestamp({ hash }, db, config);
81
81
  }
82
82
 
83
+ // src/tools/hash-file.ts
84
+ import { hashFile } from "@otskit/client";
85
+ async function hashFileTool(input) {
86
+ try {
87
+ const buf = await hashFile(input.path);
88
+ return { hash: buf.toString("hex") };
89
+ } catch (e) {
90
+ if (e?.code === "ENOENT") {
91
+ return { error: "file_not_found", details: `File not found: ${input.path}` };
92
+ }
93
+ throw e;
94
+ }
95
+ }
96
+
83
97
  // src/tool-definitions.ts
84
98
  var TOOL_DEFINITIONS = [
85
99
  {
@@ -161,6 +175,21 @@ var TOOL_DEFINITIONS = [
161
175
  openWorldHint: false
162
176
  }
163
177
  },
178
+ {
179
+ name: "hash_file",
180
+ description: "Computes the SHA-256 hash of a local file and returns it as a 64-character hex string. No network calls \u2014 pure local operation.",
181
+ inputSchema: {
182
+ type: "object",
183
+ properties: { path: { type: "string", description: "Absolute path to the file" } },
184
+ required: ["path"]
185
+ },
186
+ annotations: {
187
+ readOnlyHint: true,
188
+ destructiveHint: false,
189
+ idempotentHint: true,
190
+ openWorldHint: false
191
+ }
192
+ },
164
193
  {
165
194
  name: "stamp_file",
166
195
  description: "Stamps a file against public OpenTimestamps calendars. Computes SHA-256 of the file and stamps it on Bitcoin. IMPORTANT: the digest is sent to external calendar servers (alice.btc, bob.btc, finney, catallaxy).",
@@ -225,6 +254,9 @@ async function runServer() {
225
254
  case "list_pending":
226
255
  result = listPending(args, db, config);
227
256
  break;
257
+ case "hash_file":
258
+ result = await hashFileTool(args);
259
+ break;
228
260
  case "stamp_file":
229
261
  result = await stampFile(args, db, config);
230
262
  break;
@@ -240,6 +272,13 @@ async function runServer() {
240
272
  return { content: [{ type: "text", text: JSON.stringify({ error: "internal_error", details: String(e) }) }], isError: true };
241
273
  }
242
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);
243
282
  const transport = new StdioServerTransport();
244
283
  await server.connect(transport);
245
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.5.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,20 +21,19 @@
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"
28
28
  },
29
29
  "dependencies": {
30
30
  "@modelcontextprotocol/sdk": "^1.29.0",
31
- "@otskit/client": "^0.1.1",
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",