@otskit/mcp 0.1.5 → 0.1.7

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="docs/header.png" alt="OTSkit.ts MCP" width="480" />
2
+ <img src="https://raw.githubusercontent.com/OTSkit/OTSkit-MCP/master/docs/header.png" alt="OTSkit.ts MCP" width="480" />
3
3
  </p>
4
4
 
5
5
  # @otskit/mcp
@@ -8,6 +8,8 @@ OpenTimestamps MCP server — stamp, upgrade, and verify Bitcoin timestamps via
8
8
 
9
9
  Exposes a set of tools to any MCP-compatible agent so it can timestamp documents, monitor confirmation status, and verify proofs against the Bitcoin blockchain — all from a conversation.
10
10
 
11
+ > **Note on confirmation times:** After stamping, a proof is `pending` until Bitcoin confirms it. This typically takes **10–60 minutes** but can take **several hours** during network congestion. Use `ots-mcp watch` or `upgrade_timestamp` to monitor. A pending status is not an error.
12
+
11
13
  ## Install
12
14
 
13
15
  ```bash
@@ -38,7 +40,7 @@ Each command writes the MCP entry into the agent's config file, makes a `.bak` b
38
40
  | `ots-mcp backup [dest]` | Backup the SQLite database |
39
41
  | `ots-mcp setup <claude\|codex>` | Configure MCP for an agent |
40
42
 
41
- ## MCP tools exposed to Claude
43
+ ## MCP tools exposed to agents
42
44
 
43
45
  | Tool | Description |
44
46
  |---|---|
@@ -67,10 +69,6 @@ Create `~/.ots-mcp/config.json` to override defaults:
67
69
  ```json
68
70
  {
69
71
  "stamp_enabled": true,
70
- "preserve_enabled": true,
71
- "preserve_whitelist": ["/path/to/allowed/dir"],
72
- "preserve_max_bytes": 104857600,
73
- "preserve_max_files": 10000,
74
72
  "scheduler_interval_minutes": 30,
75
73
  "retry_max_attempts": 20,
76
74
  "calendar_timeout_ms": 10000,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otskit/mcp",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "OpenTimestamps MCP server — stamp, upgrade, verify via AI agents",
5
5
  "type": "module",
6
6
  "engines": {
@@ -20,9 +20,9 @@
20
20
  "test:watch": "vitest"
21
21
  },
22
22
  "dependencies": {
23
- "@otskit/core": "^0.1.0",
24
- "@otskit/client": "^0.1.1",
25
23
  "@modelcontextprotocol/sdk": "^1.29.0",
24
+ "@otskit/client": "^0.1.1",
25
+ "@otskit/core": "^0.1.0",
26
26
  "better-sqlite3": "^12.10.0"
27
27
  },
28
28
  "pnpm": {
@@ -32,8 +32,15 @@
32
32
  ]
33
33
  },
34
34
  "devDependencies": {
35
+ "@semantic-release/changelog": "^6",
36
+ "@semantic-release/commit-analyzer": "^13.0.0",
37
+ "@semantic-release/git": "^10",
38
+ "@semantic-release/github": "^12.0.8",
39
+ "@semantic-release/npm": "^13.1.5",
40
+ "@semantic-release/release-notes-generator": "^14.0.0",
35
41
  "@types/better-sqlite3": "^7.6.13",
36
42
  "@types/node": "^22.0.0",
43
+ "semantic-release": "^25.0.3",
37
44
  "tsup": "^8.3.5",
38
45
  "typescript": "^5.6.3",
39
46
  "vitest": "^2.1.4"
@@ -1,123 +0,0 @@
1
- // src/config.ts
2
- import { readFileSync, existsSync, mkdirSync } from "fs";
3
- import { join } from "path";
4
- import { homedir } from "os";
5
- function getDataDir() {
6
- return process.env.OTS_MCP_DATA_DIR ?? join(homedir(), ".ots-mcp");
7
- }
8
- var DEFAULTS = {
9
- stamp_enabled: true,
10
- preserve_enabled: true,
11
- preserve_whitelist: [],
12
- preserve_max_bytes: 104857600,
13
- preserve_max_files: 1e4,
14
- scheduler_interval_minutes: 30,
15
- calendar_timeout_ms: 1e4,
16
- calendar_max_response_bytes: 1048576,
17
- retry_max_attempts: 20,
18
- log_file: join(getDataDir(), "ots-mcp.log"),
19
- calendars: [
20
- "https://alice.btc.calendar.opentimestamps.org",
21
- "https://bob.btc.calendar.opentimestamps.org",
22
- "https://finney.calendar.eternitywall.com",
23
- "https://btc.calendar.catallaxy.com"
24
- ],
25
- esplora_url: "https://blockstream.info/api"
26
- };
27
- function loadConfig() {
28
- const dir = getDataDir();
29
- mkdirSync(dir, { recursive: true });
30
- const configPath = join(dir, "config.json");
31
- if (!existsSync(configPath)) return { ...DEFAULTS };
32
- const raw = JSON.parse(readFileSync(configPath, "utf8"));
33
- return { ...DEFAULTS, ...raw };
34
- }
35
-
36
- // src/db/index.ts
37
- import DatabaseConstructor from "better-sqlite3";
38
- import { join as join2 } from "path";
39
- import { mkdirSync as mkdirSync2, statSync } from "fs";
40
-
41
- // src/db/schema.ts
42
- function initDb(db) {
43
- db.pragma("journal_mode = WAL");
44
- db.pragma("busy_timeout = 5000");
45
- db.pragma("foreign_keys = ON");
46
- runMigrations(db);
47
- }
48
- function runMigrations(db) {
49
- const version = db.pragma("user_version", { simple: true });
50
- if (version < 1) migrateTo1(db);
51
- }
52
- function migrateTo1(db) {
53
- db.transaction(() => {
54
- db.exec(`
55
- CREATE TABLE IF NOT EXISTS stamps (
56
- id TEXT PRIMARY KEY,
57
- hash TEXT NOT NULL,
58
- status TEXT NOT NULL,
59
- created_at TEXT NOT NULL,
60
- confirmed_at TEXT,
61
- bitcoin_block INTEGER,
62
- bitcoin_time TEXT,
63
- proof_path TEXT,
64
- archive_path TEXT,
65
- last_attempt_at TEXT,
66
- attempt_count INTEGER NOT NULL DEFAULT 0,
67
- last_error TEXT,
68
- next_retry_at TEXT,
69
- metadata TEXT
70
- );
71
- CREATE INDEX IF NOT EXISTS idx_stamps_hash ON stamps(hash);
72
- CREATE INDEX IF NOT EXISTS idx_stamps_status ON stamps(status);
73
-
74
- CREATE TABLE IF NOT EXISTS operations_log (
75
- id INTEGER PRIMARY KEY AUTOINCREMENT,
76
- stamp_id TEXT NOT NULL REFERENCES stamps(id),
77
- action TEXT NOT NULL,
78
- result TEXT NOT NULL,
79
- error_msg TEXT,
80
- calendar_uri TEXT,
81
- response_time_ms INTEGER,
82
- created_at TEXT NOT NULL
83
- );
84
- CREATE INDEX IF NOT EXISTS idx_oplog_stamp_id ON operations_log(stamp_id);
85
- CREATE INDEX IF NOT EXISTS idx_oplog_created ON operations_log(created_at);
86
- `);
87
- db.pragma("user_version = 1");
88
- })();
89
- }
90
-
91
- // src/db/index.ts
92
- var _db = null;
93
- function getDb() {
94
- if (_db) return _db;
95
- const dir = getDataDir();
96
- mkdirSync2(dir, { recursive: true });
97
- _db = new DatabaseConstructor(join2(dir, "db.sqlite"));
98
- initDb(_db);
99
- reconcileOrphans(_db);
100
- return _db;
101
- }
102
- function backupDb(destPath) {
103
- getDb().backup(destPath);
104
- }
105
- function reconcileOrphans(db) {
106
- const pending = db.prepare(
107
- `SELECT id, proof_path FROM stamps WHERE status = 'pending' AND proof_path IS NOT NULL`
108
- ).all();
109
- for (const row of pending) {
110
- try {
111
- statSync(row.proof_path);
112
- } catch {
113
- db.prepare(`UPDATE stamps SET status = 'failed', last_error = ? WHERE id = ?`).run("proof file missing on disk", row.id);
114
- }
115
- }
116
- }
117
-
118
- export {
119
- getDataDir,
120
- loadConfig,
121
- getDb,
122
- backupDb
123
- };
@@ -1,250 +0,0 @@
1
- import {
2
- getDataDir
3
- } from "./chunk-4ZDPWS7C.js";
4
- import {
5
- writeAtomic
6
- } from "./chunk-YFSUDT24.js";
7
-
8
- // src/tools/create-timestamp.ts
9
- import { mkdirSync } from "fs";
10
- import { join } from "path";
11
- import { randomUUID } from "crypto";
12
- import { OpenTimestampsClient } from "@otskit/client";
13
-
14
- // src/db/stamps.ts
15
- function insertStamp(db, params) {
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);
21
- return getStamp(db, params.id);
22
- }
23
- function getStamp(db, id) {
24
- return db.prepare("SELECT * FROM stamps WHERE id = ?").get(id) ?? null;
25
- }
26
- function updateStampStatus(db, id, params) {
27
- const fields = [];
28
- const values = [];
29
- const add = (col, val) => {
30
- fields.push(`${col} = ?`);
31
- values.push(val);
32
- };
33
- if (params.status !== void 0) add("status", params.status);
34
- if (params.bitcoin_block !== void 0) add("bitcoin_block", params.bitcoin_block);
35
- if (params.bitcoin_time !== void 0) add("bitcoin_time", params.bitcoin_time);
36
- if (params.confirmed_at !== void 0) add("confirmed_at", params.confirmed_at);
37
- if (params.last_error !== void 0) add("last_error", params.last_error);
38
- if (params.attempt_count !== void 0) add("attempt_count", params.attempt_count);
39
- if (params.last_attempt_at !== void 0) add("last_attempt_at", params.last_attempt_at);
40
- if (params.next_retry_at !== void 0) add("next_retry_at", params.next_retry_at);
41
- if (fields.length === 0) return;
42
- values.push(id);
43
- db.prepare(`UPDATE stamps SET ${fields.join(", ")} WHERE id = ?`).run(...values);
44
- }
45
- function listStamps(db, params) {
46
- const conds = [];
47
- const vals = [];
48
- if (params.status) {
49
- conds.push("status = ?");
50
- vals.push(params.status);
51
- }
52
- if (params.older_than_hours) {
53
- const cutoff = new Date(Date.now() - params.older_than_hours * 36e5).toISOString();
54
- conds.push("created_at < ?");
55
- vals.push(cutoff);
56
- }
57
- const where = conds.length ? `WHERE ${conds.join(" AND ")}` : "";
58
- const total = db.prepare(`SELECT COUNT(*) as n FROM stamps ${where}`).get(...vals).n;
59
- const items = db.prepare(
60
- `SELECT * FROM stamps ${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`
61
- ).all(...vals, params.limit, params.offset);
62
- return { items, total };
63
- }
64
-
65
- // src/db/operations-log.ts
66
- function logOperation(db, params) {
67
- db.prepare(`
68
- INSERT INTO operations_log (stamp_id, action, result, error_msg, calendar_uri, response_time_ms, created_at)
69
- VALUES (?, ?, ?, ?, ?, ?, ?)
70
- `).run(
71
- params.stamp_id,
72
- params.action,
73
- params.result,
74
- params.error_msg ?? null,
75
- params.calendar_uri ?? null,
76
- params.response_time_ms ?? null,
77
- (/* @__PURE__ */ new Date()).toISOString()
78
- );
79
- }
80
-
81
- // src/tools/create-timestamp.ts
82
- var HEX64 = /^[0-9a-f]{64}$/i;
83
- async function createTimestamp(input, db, config) {
84
- if (!HEX64.test(input.hash)) {
85
- return { error: "invalid_hash", details: "hash must be 64 hex characters (SHA-256)" };
86
- }
87
- const normalizedHash = input.hash.toLowerCase();
88
- const client = new OpenTimestampsClient({
89
- calendars: config.calendars,
90
- resilience: { timeout: config.calendar_timeout_ms }
91
- });
92
- const t0 = Date.now();
93
- let proofBuffer;
94
- try {
95
- proofBuffer = await client.stamp(normalizedHash);
96
- } catch (e) {
97
- return { error: "calendar_error", details: String(e) };
98
- }
99
- const responseTimeMs = Date.now() - t0;
100
- const id = randomUUID();
101
- const proofDir = join(getDataDir(), "proofs");
102
- mkdirSync(proofDir, { recursive: true });
103
- const proofPath = join(proofDir, `${id}.ots`);
104
- try {
105
- writeAtomic(proofPath, proofBuffer);
106
- } catch (e) {
107
- return { error: "storage_error", details: String(e) };
108
- }
109
- const record = insertStamp(db, { id, hash: normalizedHash, proof_path: proofPath });
110
- logOperation(db, { stamp_id: id, action: "stamp", result: "success", response_time_ms: responseTimeMs });
111
- return {
112
- id: record.id,
113
- hash: record.hash,
114
- status: "pending",
115
- calendars: config.calendars,
116
- created_at: record.created_at,
117
- proof_path: proofPath
118
- };
119
- }
120
-
121
- // src/tools/upgrade-timestamp.ts
122
- import { readFileSync } from "fs";
123
- import { OpenTimestampsClient as OpenTimestampsClient2, UpgradeError } from "@otskit/client";
124
- import { DetachedTimestampFile } from "@otskit/core";
125
- function checkBitcoinConfirmation(bytes) {
126
- try {
127
- const proof = DetachedTimestampFile.deserialize(new Uint8Array(bytes));
128
- const attestations = proof.timestamp.getAttestations();
129
- const bitcoin = attestations.filter((a) => a.kind === "bitcoin");
130
- if (bitcoin.length > 0) {
131
- const block = Math.min(...bitcoin.map((a) => a.height));
132
- return { confirmed: true, block };
133
- }
134
- return { confirmed: false };
135
- } catch {
136
- return { confirmed: false };
137
- }
138
- }
139
- function nextRetryAt(attemptCount) {
140
- const base = Math.min(3e4 * Math.pow(2, attemptCount), 36e5);
141
- const jitter = Math.random() * 0.2 * base;
142
- return new Date(Date.now() + base + jitter).toISOString();
143
- }
144
- async function upgradeTimestamp(input, db, config) {
145
- const record = getStamp(db, input.id);
146
- if (!record) return { error: "not_found", details: `No stamp with id ${input.id}` };
147
- if (!record.proof_path) return { error: "storage_error", details: "No proof_path on record" };
148
- const proofBefore = readFileSync(record.proof_path);
149
- const client = new OpenTimestampsClient2({
150
- calendars: config.calendars,
151
- resilience: { timeout: config.calendar_timeout_ms }
152
- });
153
- const now = (/* @__PURE__ */ new Date()).toISOString();
154
- const newAttemptCount = record.attempt_count + 1;
155
- const next = nextRetryAt(newAttemptCount);
156
- let upgraded;
157
- try {
158
- upgraded = await client.upgrade(proofBefore);
159
- } catch (e) {
160
- if (e instanceof UpgradeError) {
161
- updateStampStatus(db, input.id, { last_attempt_at: now, attempt_count: newAttemptCount, next_retry_at: next });
162
- logOperation(db, { stamp_id: input.id, action: "upgrade", result: "pending" });
163
- return { id: input.id, status: "pending", attempt_count: newAttemptCount, last_attempt_at: now, next_retry_at: next };
164
- }
165
- updateStampStatus(db, input.id, { last_attempt_at: now, attempt_count: newAttemptCount, last_error: String(e), next_retry_at: next });
166
- logOperation(db, { stamp_id: input.id, action: "upgrade", result: "failed", error_msg: String(e) });
167
- return { error: "calendar_error", details: String(e) };
168
- }
169
- writeAtomic(record.proof_path, upgraded);
170
- const { confirmed, block } = checkBitcoinConfirmation(upgraded);
171
- if (confirmed && block !== void 0) {
172
- const bitcoinTime = now;
173
- updateStampStatus(db, input.id, {
174
- status: "confirmed",
175
- bitcoin_block: block,
176
- bitcoin_time: bitcoinTime,
177
- confirmed_at: now,
178
- last_attempt_at: now,
179
- attempt_count: newAttemptCount
180
- });
181
- logOperation(db, { stamp_id: input.id, action: "upgrade", result: "success" });
182
- return { id: input.id, status: "confirmed", bitcoin_block: block, bitcoin_time: bitcoinTime, proof_path: record.proof_path };
183
- }
184
- updateStampStatus(db, input.id, { last_attempt_at: now, attempt_count: newAttemptCount, next_retry_at: next });
185
- logOperation(db, { stamp_id: input.id, action: "upgrade", result: "pending" });
186
- return { id: input.id, status: "pending", attempt_count: newAttemptCount, last_attempt_at: now, next_retry_at: next };
187
- }
188
-
189
- // src/tools/verify-timestamp.ts
190
- import { readFileSync as readFileSync2 } from "fs";
191
- import { OpenTimestampsClient as OpenTimestampsClient3 } from "@otskit/client";
192
- async function verifyTimestamp(input, db, config) {
193
- const record = getStamp(db, input.id);
194
- if (!record) return { error: "not_found", details: `No stamp with id ${input.id}` };
195
- if (!record.proof_path) return { error: "storage_error", details: "No proof_path on record" };
196
- let proofBytes;
197
- try {
198
- proofBytes = readFileSync2(record.proof_path);
199
- } catch (e) {
200
- return { error: "storage_error", details: String(e) };
201
- }
202
- const client = new OpenTimestampsClient3({
203
- calendars: config.calendars,
204
- resilience: { timeout: config.calendar_timeout_ms }
205
- });
206
- let result;
207
- try {
208
- result = await client.verify(proofBytes, record.hash);
209
- } catch (e) {
210
- logOperation(db, { stamp_id: input.id, action: "verify", result: "failed", error_msg: String(e) });
211
- return { status: "network_error", hash: record.hash, details: String(e) };
212
- }
213
- if (!result.valid) {
214
- if (result.error?.includes("No Bitcoin attestation")) {
215
- logOperation(db, { stamp_id: input.id, action: "verify", result: "pending" });
216
- return { status: "pending", hash: record.hash, calendars: config.calendars };
217
- }
218
- if (result.error?.toLowerCase().includes("invalid") || result.error?.toLowerCase().includes("corrupt")) {
219
- logOperation(db, { stamp_id: input.id, action: "verify", result: "failed", error_msg: result.error });
220
- return { status: "invalid", hash: record.hash, reason: result.error ?? "unknown" };
221
- }
222
- logOperation(db, { stamp_id: input.id, action: "verify", result: "failed", error_msg: result.error });
223
- return { status: "unknown", hash: record.hash };
224
- }
225
- logOperation(db, { stamp_id: input.id, action: "verify", result: "success" });
226
- return {
227
- status: "confirmed",
228
- hash: record.hash,
229
- bitcoin_block: result.blockHeight,
230
- bitcoin_time: new Date(result.timestamp * 1e3).toISOString()
231
- };
232
- }
233
-
234
- // src/tools/list-pending.ts
235
- function listPending(input, db, _config) {
236
- return listStamps(db, {
237
- status: input.status ?? "pending",
238
- limit: Math.min(input.limit ?? 50, 200),
239
- offset: input.offset ?? 0,
240
- older_than_hours: input.older_than_hours
241
- });
242
- }
243
-
244
- export {
245
- getStamp,
246
- createTimestamp,
247
- upgradeTimestamp,
248
- verifyTimestamp,
249
- listPending
250
- };
@@ -1,24 +0,0 @@
1
- // src/utils.ts
2
- import { execFileSync } from "child_process";
3
- import { writeFileSync, renameSync } from "fs";
4
- function which(cmd) {
5
- try {
6
- const out = execFileSync(
7
- process.platform === "win32" ? "where" : "which",
8
- [cmd]
9
- ).toString().trim();
10
- return out.split("\n")[0] ?? null;
11
- } catch {
12
- return null;
13
- }
14
- }
15
- function writeAtomic(dest, data) {
16
- const tmp = dest + ".tmp";
17
- writeFileSync(tmp, data);
18
- renameSync(tmp, dest);
19
- }
20
-
21
- export {
22
- which,
23
- writeAtomic
24
- };
@@ -1,54 +0,0 @@
1
- // src/setup/claude.ts
2
- import { readFileSync, writeFileSync, copyFileSync, mkdirSync, existsSync } from "fs";
3
- import { join } from "path";
4
- import { homedir } from "os";
5
- function getConfigPath() {
6
- if (process.platform === "win32") {
7
- return join(process.env.APPDATA ?? "", "Claude", "claude_desktop_config.json");
8
- } else if (process.platform === "darwin") {
9
- return join(homedir(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
10
- } else {
11
- return join(homedir(), ".config", "Claude", "claude_desktop_config.json");
12
- }
13
- }
14
- function setupClaude() {
15
- const configPath = getConfigPath();
16
- const configDir = join(configPath, "..");
17
- if (!existsSync(configDir)) {
18
- mkdirSync(configDir, { recursive: true });
19
- }
20
- let config = {};
21
- if (existsSync(configPath)) {
22
- try {
23
- config = JSON.parse(readFileSync(configPath, "utf8"));
24
- } catch {
25
- process.stderr.write(` Aviso: no se pudo parsear la config existente, se crear\xE1 nueva.
26
- `);
27
- }
28
- const existing = config.mcpServers ?? {};
29
- if ("otskit" in existing) {
30
- process.stdout.write(` ots-mcp ya est\xE1 configurado en ${configPath}
31
- `);
32
- process.stdout.write(` No se hizo ning\xFAn cambio.
33
- `);
34
- return;
35
- }
36
- const backupPath = configPath + ".bak";
37
- copyFileSync(configPath, backupPath);
38
- process.stdout.write(` Backup guardado en ${backupPath}
39
- `);
40
- }
41
- const mcpServers = config.mcpServers ?? {};
42
- mcpServers["otskit"] = { command: "npx", args: ["-y", "@otskit/mcp", "serve"] };
43
- config.mcpServers = mcpServers;
44
- writeFileSync(configPath, JSON.stringify(config, null, 2), "utf8");
45
- process.stdout.write(`OTSkit MCP configurado para Claude Desktop
46
- `);
47
- process.stdout.write(` Config: ${configPath}
48
- `);
49
- process.stdout.write(` Reinicia Claude Desktop para aplicar los cambios.
50
- `);
51
- }
52
- export {
53
- setupClaude
54
- };
@@ -1,98 +0,0 @@
1
- import {
2
- createTimestamp,
3
- listPending,
4
- upgradeTimestamp,
5
- verifyTimestamp
6
- } from "./chunk-55NLVWDQ.js";
7
- import {
8
- backupDb,
9
- getDb,
10
- loadConfig
11
- } from "./chunk-4ZDPWS7C.js";
12
- import "./chunk-YFSUDT24.js";
13
-
14
- // src/cli.ts
15
- async function runCli(command, args) {
16
- const config = loadConfig();
17
- const db = getDb();
18
- switch (command) {
19
- case "stamp": {
20
- const hash = args[0];
21
- if (!hash) {
22
- process.stderr.write("Usage: ots-mcp stamp <sha256-hash>\n");
23
- process.exit(1);
24
- }
25
- const result = await createTimestamp({ hash }, db, config);
26
- if ("error" in result) {
27
- process.stderr.write(`Error: ${result.error} \u2014 ${result.details}
28
- `);
29
- process.exit(1);
30
- }
31
- process.stdout.write(JSON.stringify(result, null, 2) + "\n");
32
- break;
33
- }
34
- case "upgrade": {
35
- const id = args[0];
36
- if (!id) {
37
- process.stderr.write("Usage: ots-mcp upgrade <id>\n");
38
- process.exit(1);
39
- }
40
- const result = await upgradeTimestamp({ id }, db, config);
41
- if ("error" in result) {
42
- process.stderr.write(`Error: ${result.error} \u2014 ${result.details}
43
- `);
44
- process.exit(1);
45
- }
46
- process.stdout.write(JSON.stringify(result, null, 2) + "\n");
47
- break;
48
- }
49
- case "verify": {
50
- const id = args[0];
51
- if (!id) {
52
- process.stderr.write("Usage: ots-mcp verify <id>\n");
53
- process.exit(1);
54
- }
55
- const result = await verifyTimestamp({ id }, db, config);
56
- if ("error" in result) {
57
- process.stderr.write(`Error: ${result.error} \u2014 ${result.details}
58
- `);
59
- process.exit(1);
60
- }
61
- process.stdout.write(JSON.stringify(result, null, 2) + "\n");
62
- break;
63
- }
64
- case "list": {
65
- const status = args[0] ?? "pending";
66
- const result = listPending({ status }, db, config);
67
- process.stdout.write(JSON.stringify(result, null, 2) + "\n");
68
- break;
69
- }
70
- case "check-pending": {
71
- const { items } = listPending({ status: "pending", limit: 200 }, db, config);
72
- process.stderr.write(`Processing ${items.length} pending stamps...
73
- `);
74
- for (const record of items) {
75
- const result = await upgradeTimestamp({ id: record.id }, db, config);
76
- const statusStr = "status" in result ? result.status : `error:${result.error}`;
77
- process.stderr.write(`${record.id.slice(0, 8)}: ${statusStr}
78
- `);
79
- }
80
- process.exit(0);
81
- }
82
- case "backup": {
83
- const dest = args[0] ?? `ots-mcp-backup-${Date.now()}.sqlite`;
84
- backupDb(dest);
85
- process.stdout.write(`Backup saved to ${dest}
86
- `);
87
- break;
88
- }
89
- case "scheduler": {
90
- const { runScheduler } = await import("./scheduler-YF6WMSR4.js");
91
- await runScheduler(args);
92
- break;
93
- }
94
- }
95
- }
96
- export {
97
- runCli
98
- };
@@ -1,41 +0,0 @@
1
- // src/setup/codex.ts
2
- import { readFileSync, writeFileSync, copyFileSync, mkdirSync, existsSync } from "fs";
3
- import { join } from "path";
4
- import { homedir } from "os";
5
- var BLOCK = `
6
- [mcp_servers.ots-mcp]
7
- command = "npx"
8
- args = ["-y", "@otskit/mcp", "serve"]
9
- `;
10
- function setupCodex() {
11
- const configPath = join(homedir(), ".codex", "config.toml");
12
- const configDir = join(configPath, "..");
13
- if (!existsSync(configDir)) {
14
- mkdirSync(configDir, { recursive: true });
15
- }
16
- let content = "";
17
- if (existsSync(configPath)) {
18
- content = readFileSync(configPath, "utf8");
19
- if (content.includes("[mcp_servers.ots-mcp]")) {
20
- process.stdout.write(` ots-mcp ya est\xE1 configurado en ${configPath}
21
- `);
22
- process.stdout.write(` No se hizo ning\xFAn cambio.
23
- `);
24
- return;
25
- }
26
- const backupPath = configPath + ".bak";
27
- copyFileSync(configPath, backupPath);
28
- process.stdout.write(` Backup guardado en ${backupPath}
29
- `);
30
- }
31
- writeFileSync(configPath, content.trimEnd() + "\n" + BLOCK, "utf8");
32
- process.stdout.write(`OTSkit MCP configurado para Codex
33
- `);
34
- process.stdout.write(` Config: ${configPath}
35
- `);
36
- process.stdout.write(` Reinicia Codex para aplicar los cambios.
37
- `);
38
- }
39
- export {
40
- setupCodex
41
- };
package/dist/index.js DELETED
@@ -1,74 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/index.ts
4
- var [, , command, ...args] = process.argv;
5
- if (!command || command === "--help" || command === "help") {
6
- process.stderr.write(`Usage: ots-mcp <command>
7
- Commands:
8
- serve Start MCP server (stdio transport)
9
- setup <target> Configure MCP for an agent (claude | codex)
10
- watch [interval] Watch pending stamps in real-time (default: 5 min)
11
- stamp <hash> Stamp a SHA-256 hash
12
- upgrade <id> Upgrade a pending stamp
13
- verify <id> Verify a stamp
14
- list [status] List stamps (default: pending)
15
- check-pending Run pending upgrades (for scheduler)
16
- backup [dest] Backup the SQLite database
17
- scheduler Manage OS scheduler (install|remove|status)
18
- `);
19
- process.exit(command ? 0 : 1);
20
- }
21
- switch (command) {
22
- case "serve": {
23
- const { runServer } = await import("./server-Q7XYIZRY.js");
24
- await runServer();
25
- break;
26
- }
27
- case "setup": {
28
- const target = args[0];
29
- if (!target || target !== "claude" && target !== "codex") {
30
- process.stderr.write(`Usage: ots-mcp setup <claude|codex>
31
- `);
32
- process.exit(1);
33
- }
34
- if (target === "claude") {
35
- const { setupClaude } = await import("./claude-QTEB3Z5V.js");
36
- setupClaude();
37
- } else {
38
- const { setupCodex } = await import("./codex-P7EDO5GY.js");
39
- setupCodex();
40
- }
41
- break;
42
- }
43
- case "install-claude": {
44
- const { installClaude } = await import("./install-claude-UKSS65BW.js");
45
- installClaude();
46
- break;
47
- }
48
- case "watch": {
49
- const { watchPending } = await import("./watch-7NPUWR6I.js");
50
- const parsed = args[0] ? parseInt(args[0], 10) : NaN;
51
- const interval = isNaN(parsed) || parsed < 1 ? 5 : parsed;
52
- if (args[0] && (isNaN(parsed) || parsed < 1))
53
- process.stderr.write(`Argumento inv\xE1lido "${args[0]}", usando intervalo por defecto: 5 min
54
- `);
55
- await watchPending(interval);
56
- break;
57
- }
58
- case "stamp":
59
- case "upgrade":
60
- case "verify":
61
- case "list":
62
- case "check-pending":
63
- case "backup":
64
- case "scheduler": {
65
- const { runCli } = await import("./cli-ZD2OP45N.js");
66
- await runCli(command, args);
67
- break;
68
- }
69
- default: {
70
- process.stderr.write(`Unknown command: ${command}. Run 'ots-mcp help' for usage.
71
- `);
72
- process.exit(1);
73
- }
74
- }
@@ -1,37 +0,0 @@
1
- import {
2
- which
3
- } from "./chunk-YFSUDT24.js";
4
-
5
- // src/scheduler/install.ts
6
- import { execFileSync } from "child_process";
7
- import { writeFileSync } from "fs";
8
- async function installScheduler(args) {
9
- const intervalIdx = args.indexOf("--interval");
10
- const interval = intervalIdx !== -1 ? parseInt(args[intervalIdx + 1] ?? "30") : 30;
11
- const bin = which("ots-mcp") ?? process.argv[1];
12
- if (process.platform === "win32") {
13
- const xmlPath = `${process.env.TEMP}\\ots-mcp-task.xml`;
14
- writeFileSync(xmlPath, `<?xml version="1.0"?>
15
- <Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
16
- <Triggers><TimeTrigger>
17
- <Repetition><Interval>PT${interval}M</Interval><StopAtDurationEnd>false</StopAtDurationEnd></Repetition>
18
- <StartBoundary>2020-01-01T00:00:00</StartBoundary><Enabled>true</Enabled>
19
- </TimeTrigger></Triggers>
20
- <Actions><Exec>
21
- <Command>${bin}</Command>
22
- <Arguments>check-pending</Arguments>
23
- </Exec></Actions>
24
- </Task>`);
25
- execFileSync("schtasks", ["/create", "/tn", "ots-mcp-check-pending", "/xml", xmlPath, "/f"]);
26
- process.stdout.write(`Scheduler installed: runs every ${interval} minutes
27
- `);
28
- } else {
29
- process.stdout.write(`Add to crontab (run: crontab -e):
30
- `);
31
- process.stdout.write(`*/${interval} * * * * "${bin}" check-pending
32
- `);
33
- }
34
- }
35
- export {
36
- installScheduler
37
- };
@@ -1,44 +0,0 @@
1
- // src/install-claude.ts
2
- import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
3
- import { join } from "path";
4
- function getConfigPath() {
5
- if (process.platform === "win32") {
6
- return join(process.env.APPDATA ?? "", "Claude", "claude_desktop_config.json");
7
- } else if (process.platform === "darwin") {
8
- return join(process.env.HOME ?? "", "Library", "Application Support", "Claude", "claude_desktop_config.json");
9
- } else {
10
- return join(process.env.HOME ?? "", ".config", "Claude", "claude_desktop_config.json");
11
- }
12
- }
13
- function installClaude() {
14
- const configPath = getConfigPath();
15
- const configDir = join(configPath, "..");
16
- if (!existsSync(configDir)) {
17
- mkdirSync(configDir, { recursive: true });
18
- }
19
- let config = {};
20
- if (existsSync(configPath)) {
21
- try {
22
- config = JSON.parse(readFileSync(configPath, "utf8"));
23
- } catch {
24
- process.stderr.write(`Warning: could not parse existing config, creating new one
25
- `);
26
- }
27
- }
28
- const mcpServers = config.mcpServers ?? {};
29
- mcpServers["otskit"] = {
30
- command: "npx",
31
- args: ["-y", "@otskit/mcp", "serve"]
32
- };
33
- config.mcpServers = mcpServers;
34
- writeFileSync(configPath, JSON.stringify(config, null, 2), "utf8");
35
- process.stdout.write(`\u2713 OTSkit MCP installed in Claude Desktop
36
- `);
37
- process.stdout.write(` Config: ${configPath}
38
- `);
39
- process.stdout.write(` Restart Claude Desktop to apply changes.
40
- `);
41
- }
42
- export {
43
- installClaude
44
- };
@@ -1,17 +0,0 @@
1
- // src/scheduler/remove.ts
2
- import { execFileSync } from "child_process";
3
- async function removeScheduler() {
4
- if (process.platform === "win32") {
5
- try {
6
- execFileSync("schtasks", ["/delete", "/tn", "ots-mcp-check-pending", "/f"]);
7
- process.stdout.write("Scheduler task removed\n");
8
- } catch {
9
- process.stderr.write("Task not found or could not be removed\n");
10
- }
11
- } else {
12
- process.stdout.write("Remove the ots-mcp entry from crontab: crontab -e\n");
13
- }
14
- }
15
- export {
16
- removeScheduler
17
- };
@@ -1,27 +0,0 @@
1
- // src/scheduler/index.ts
2
- async function runScheduler(args) {
3
- const [sub, ...rest] = args;
4
- switch (sub) {
5
- case "install": {
6
- const { installScheduler } = await import("./install-BUSOMBB2.js");
7
- await installScheduler(rest);
8
- break;
9
- }
10
- case "remove": {
11
- const { removeScheduler } = await import("./remove-BGFQRDX3.js");
12
- await removeScheduler();
13
- break;
14
- }
15
- case "status": {
16
- const { statusScheduler } = await import("./status-M6A2RG7G.js");
17
- await statusScheduler();
18
- break;
19
- }
20
- default:
21
- process.stderr.write("Usage: ots-mcp scheduler install [--interval N] | remove | status\n");
22
- process.exit(1);
23
- }
24
- }
25
- export {
26
- runScheduler
27
- };
@@ -1,220 +0,0 @@
1
- import {
2
- createTimestamp,
3
- getStamp,
4
- listPending,
5
- upgradeTimestamp,
6
- verifyTimestamp
7
- } from "./chunk-55NLVWDQ.js";
8
- import {
9
- getDb,
10
- loadConfig
11
- } from "./chunk-4ZDPWS7C.js";
12
- import "./chunk-YFSUDT24.js";
13
-
14
- // src/server.ts
15
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
16
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
17
- import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
18
-
19
- // src/tools/inspect-timestamp.ts
20
- import { readFileSync, statSync } from "fs";
21
- import { DetachedTimestampFile } from "@otskit/core";
22
- function inspectTimestamp(input, db, _config) {
23
- const record = getStamp(db, input.id);
24
- if (!record) return { error: "not_found", details: `No stamp with id ${input.id}` };
25
- if (!record.proof_path) return { error: "proof_missing", details: "No proof file on record" };
26
- let proofBytes;
27
- let proofSize;
28
- try {
29
- proofSize = statSync(record.proof_path).size;
30
- proofBytes = readFileSync(record.proof_path);
31
- } catch {
32
- return { error: "proof_missing", details: `Cannot read proof: ${record.proof_path}` };
33
- }
34
- let attestationCount = 0;
35
- let hasBitcoin = false;
36
- let bitcoinBlock = null;
37
- try {
38
- const proof = DetachedTimestampFile.deserialize(new Uint8Array(proofBytes));
39
- const attestations = proof.timestamp.getAttestations();
40
- attestationCount = attestations.length;
41
- hasBitcoin = attestations.some((a) => a.kind === "bitcoin");
42
- if (hasBitcoin) {
43
- const blocks = attestations.filter((a) => a.kind === "bitcoin").map((a) => a.height);
44
- bitcoinBlock = blocks.length > 0 ? Math.min(...blocks) : null;
45
- }
46
- } catch {
47
- }
48
- return {
49
- id: record.id,
50
- hash: record.hash,
51
- status: record.status,
52
- created_at: record.created_at,
53
- proof_path: record.proof_path,
54
- proof_size_bytes: proofSize,
55
- attestation_count: attestationCount,
56
- has_bitcoin_confirmation: hasBitcoin,
57
- bitcoin_block: bitcoinBlock
58
- };
59
- }
60
-
61
- // src/tools/watch-window.ts
62
- import { exec } from "child_process";
63
- function openWatchWindow(intervalMinutes = 5) {
64
- const minutes = Math.max(1, Math.floor(intervalMinutes));
65
- const cmd = `start powershell.exe -NoExit -Command "ots-mcp watch ${minutes}"`;
66
- let errorMsg;
67
- exec(cmd, { shell: "cmd" }, (err) => {
68
- if (err) errorMsg = err.message;
69
- });
70
- return { opened: true, interval_minutes: minutes, ...errorMsg ? { error: errorMsg } : {} };
71
- }
72
-
73
- // src/tool-definitions.ts
74
- var TOOL_DEFINITIONS = [
75
- {
76
- name: "create_timestamp",
77
- description: "Stamps a SHA-256 hash against public OpenTimestamps calendars. IMPORTANT: the digest is sent to external calendar servers (alice.btc, bob.btc, finney, catallaxy).",
78
- inputSchema: {
79
- type: "object",
80
- properties: { hash: { type: "string", description: "SHA-256 hex digest (64 chars)" } },
81
- required: ["hash"]
82
- },
83
- annotations: {
84
- readOnlyHint: false,
85
- destructiveHint: false,
86
- idempotentHint: false,
87
- openWorldHint: true
88
- }
89
- },
90
- {
91
- name: "upgrade_timestamp",
92
- description: "Checks if a pending stamp has been confirmed in Bitcoin. Use the id returned by create_timestamp.",
93
- inputSchema: {
94
- type: "object",
95
- properties: { id: { type: "string", description: "UUID from the stamp record" } },
96
- required: ["id"]
97
- },
98
- annotations: {
99
- readOnlyHint: false,
100
- destructiveHint: false,
101
- idempotentHint: true,
102
- openWorldHint: true
103
- }
104
- },
105
- {
106
- name: "verify_timestamp",
107
- description: "Verifies a stamp against Bitcoin. Does NOT affirm document authorship or truth \u2014 only proves the hash existed before a given Bitcoin block.",
108
- inputSchema: {
109
- type: "object",
110
- properties: { id: { type: "string", description: "UUID from the stamp record" } },
111
- required: ["id"]
112
- },
113
- annotations: {
114
- readOnlyHint: true,
115
- destructiveHint: false,
116
- idempotentHint: true,
117
- openWorldHint: true
118
- }
119
- },
120
- {
121
- name: "inspect_timestamp",
122
- description: "Shows the contents of a stored proof file without making any network calls. Useful for debugging: returns size, parsed attestations, and confirmation status from the proof itself.",
123
- inputSchema: {
124
- type: "object",
125
- properties: { id: { type: "string", description: "UUID from the stamp record" } },
126
- required: ["id"]
127
- },
128
- annotations: {
129
- readOnlyHint: true,
130
- destructiveHint: false,
131
- idempotentHint: true,
132
- openWorldHint: false
133
- }
134
- },
135
- {
136
- name: "list_pending",
137
- description: "Lists stamp records with status and retry info.",
138
- inputSchema: {
139
- type: "object",
140
- properties: {
141
- status: { type: "string", enum: ["pending", "confirmed", "failed", "timeout"] },
142
- limit: { type: "number", maximum: 200 },
143
- offset: { type: "number" },
144
- older_than_hours: { type: "number" }
145
- }
146
- },
147
- annotations: {
148
- readOnlyHint: true,
149
- destructiveHint: false,
150
- idempotentHint: true,
151
- openWorldHint: false
152
- }
153
- },
154
- {
155
- name: "watch",
156
- description: "Opens a new terminal window that monitors pending stamps in real-time, polling at the given interval. The window stays open so the user can watch progress.",
157
- inputSchema: {
158
- type: "object",
159
- properties: {
160
- interval_minutes: { type: "number", description: "Polling interval in minutes (default: 5, minimum: 1)" }
161
- }
162
- },
163
- annotations: {
164
- readOnlyHint: true,
165
- destructiveHint: false,
166
- idempotentHint: false,
167
- openWorldHint: false
168
- }
169
- }
170
- ];
171
-
172
- // src/server.ts
173
- async function runServer() {
174
- const config = loadConfig();
175
- const db = getDb();
176
- const server = new Server(
177
- { name: "ots-mcp", version: "0.1.0" },
178
- { capabilities: { tools: {} } }
179
- );
180
- server.setRequestHandler(ListToolsRequestSchema, async () => ({
181
- tools: TOOL_DEFINITIONS
182
- }));
183
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
184
- const { name, arguments: args } = request.params;
185
- try {
186
- let result;
187
- switch (name) {
188
- case "create_timestamp":
189
- result = await createTimestamp(args, db, config);
190
- break;
191
- case "upgrade_timestamp":
192
- result = await upgradeTimestamp(args, db, config);
193
- break;
194
- case "verify_timestamp":
195
- result = await verifyTimestamp(args, db, config);
196
- break;
197
- case "inspect_timestamp":
198
- result = inspectTimestamp(args, db, config);
199
- break;
200
- case "list_pending":
201
- result = listPending(args, db, config);
202
- break;
203
- case "watch":
204
- result = openWatchWindow(args?.interval_minutes);
205
- break;
206
- default:
207
- return { content: [{ type: "text", text: JSON.stringify({ error: "unknown_tool", tool: name }) }], isError: true };
208
- }
209
- const isError = Boolean(result && typeof result === "object" && "error" in result);
210
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], isError };
211
- } catch (e) {
212
- return { content: [{ type: "text", text: JSON.stringify({ error: "internal_error", details: String(e) }) }], isError: true };
213
- }
214
- });
215
- const transport = new StdioServerTransport();
216
- await server.connect(transport);
217
- }
218
- export {
219
- runServer
220
- };
@@ -1,17 +0,0 @@
1
- // src/scheduler/status.ts
2
- import { execFileSync } from "child_process";
3
- async function statusScheduler() {
4
- if (process.platform === "win32") {
5
- try {
6
- const out = execFileSync("schtasks", ["/query", "/tn", "ots-mcp-check-pending", "/fo", "LIST"]).toString();
7
- process.stdout.write(out + "\n");
8
- } catch {
9
- process.stdout.write("Scheduler task not found\n");
10
- }
11
- } else {
12
- process.stdout.write("Check with: crontab -l | grep ots-mcp\n");
13
- }
14
- }
15
- export {
16
- statusScheduler
17
- };
@@ -1,41 +0,0 @@
1
- import {
2
- getDb,
3
- loadConfig
4
- } from "./chunk-4ZDPWS7C.js";
5
-
6
- // src/tools/watch.ts
7
- async function watchPending(intervalMinutes = 5) {
8
- const config = loadConfig();
9
- const db = getDb(config);
10
- process.stdout.write(`Watching pending stamps every ${intervalMinutes} min. Ctrl+C to stop.
11
-
12
- `);
13
- function tick() {
14
- const rows = db.prepare(
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();
18
- process.stdout.write(`${now()} \u2014 ${rows.length} pendientes, ${confirmed.n} confirmados
19
- `);
20
- for (const row of rows) {
21
- process.stdout.write(` ${row.id.slice(0, 8)} ${row.status} (${row.attempt_count} intentos)
22
- `);
23
- }
24
- if (rows.length === 0) {
25
- process.stdout.write(` (ning\xFAn sello pendiente)
26
- `);
27
- }
28
- process.stdout.write("\n");
29
- }
30
- function now() {
31
- return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
32
- }
33
- function loop() {
34
- tick();
35
- setTimeout(loop, Math.max(6e4, intervalMinutes * 60 * 1e3));
36
- }
37
- loop();
38
- }
39
- export {
40
- watchPending
41
- };