@getciro/mcp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ciro-mcp.js +4 -0
- package/package.json +35 -4
- package/src/server.js +168 -0
- package/README.md +0 -3
package/bin/ciro-mcp.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getciro/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The Ciro MCP server: reads invoices and prepares payments for an agent. It never signs and never holds a key.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Solution Kanu",
|
|
7
|
+
"homepage": "https://github.com/solutiono1/ciro#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/solutiono1/ciro.git",
|
|
11
|
+
"directory": "packages/mcp"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"ciro",
|
|
15
|
+
"invoice",
|
|
16
|
+
"mcp",
|
|
17
|
+
"agent",
|
|
18
|
+
"tusd8"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": {
|
|
22
|
+
"ciro-mcp": "./bin/ciro-mcp.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"bin",
|
|
26
|
+
"src"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=22"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "node --test --test-timeout 120000"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/server.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
|
|
3
|
+
const tools = [
|
|
4
|
+
{
|
|
5
|
+
name: "ciro_check",
|
|
6
|
+
description: "Match a name. Pass invoiceId to match the name locked on that invoice. Pass payee to match the payee's current registration. This does not pay.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
name: { type: "string" },
|
|
11
|
+
payee: { type: "string" },
|
|
12
|
+
invoiceId: { type: "string" },
|
|
13
|
+
},
|
|
14
|
+
required: ["name"],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "ciro_prepare_invoice",
|
|
19
|
+
description: "Prepare an unsigned create-invoice transaction. amount is an integer string of base units (6 decimals). This does not sign.",
|
|
20
|
+
inputSchema: {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
amount: { type: "string" },
|
|
24
|
+
reference: { type: "string" },
|
|
25
|
+
due: { type: "string" },
|
|
26
|
+
},
|
|
27
|
+
required: ["amount", "reference", "due"],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "ciro_prepare_pay",
|
|
32
|
+
description: "Prepare an unsigned pay transaction and report exact, close, or none. A result other than exact has no transaction. This server does not sign and has no paying key.",
|
|
33
|
+
inputSchema: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
id: { type: "string" },
|
|
37
|
+
name: { type: "string" },
|
|
38
|
+
fromAllowance: { type: "boolean" },
|
|
39
|
+
payer: { type: "string" },
|
|
40
|
+
spender: { type: "string" },
|
|
41
|
+
},
|
|
42
|
+
required: ["id", "name"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "ciro_receipt",
|
|
47
|
+
description: "Read the receipt for a paid invoice.",
|
|
48
|
+
inputSchema: {
|
|
49
|
+
type: "object",
|
|
50
|
+
properties: { id: { type: "string" } },
|
|
51
|
+
required: ["id"],
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
function apiBase() {
|
|
57
|
+
return (process.env.CIRO_API_URL ?? "").replace(/\/$/, "");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function send(message) {
|
|
61
|
+
process.stdout.write(`${JSON.stringify(message)}\n`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function callApi(method, pathname, body) {
|
|
65
|
+
const base = apiBase();
|
|
66
|
+
if (!base) return { ok: false, json: { error: "missing_api_url" } };
|
|
67
|
+
const response = await fetch(`${base}${pathname}`, {
|
|
68
|
+
method,
|
|
69
|
+
headers: body ? { "content-type": "application/json" } : undefined,
|
|
70
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
71
|
+
signal: AbortSignal.timeout(30_000),
|
|
72
|
+
});
|
|
73
|
+
const json = await response.json();
|
|
74
|
+
return { ok: response.ok, json };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function withoutSecrets(args) {
|
|
78
|
+
const clean = { ...(args ?? {}) };
|
|
79
|
+
delete clean.privateKey;
|
|
80
|
+
delete clean.key;
|
|
81
|
+
delete clean.mnemonic;
|
|
82
|
+
delete clean.seed;
|
|
83
|
+
return clean;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function callTool(name, args) {
|
|
87
|
+
const clean = withoutSecrets(args);
|
|
88
|
+
if (name === "ciro_check") {
|
|
89
|
+
if (clean.invoiceId !== undefined) {
|
|
90
|
+
return callApi("POST", `/v1/invoices/${clean.invoiceId}/check`, { name: clean.name });
|
|
91
|
+
}
|
|
92
|
+
return callApi("POST", "/v1/check", { payee: clean.payee, name: clean.name });
|
|
93
|
+
}
|
|
94
|
+
if (name === "ciro_prepare_invoice") {
|
|
95
|
+
return callApi("POST", "/v1/tx/invoice", {
|
|
96
|
+
amount: clean.amount,
|
|
97
|
+
reference: clean.reference,
|
|
98
|
+
due: clean.due,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (name === "ciro_prepare_pay") {
|
|
102
|
+
const pathname = clean.fromAllowance ? "/v1/tx/pay-from-allowance" : "/v1/tx/pay";
|
|
103
|
+
const body = { id: clean.id, name: clean.name };
|
|
104
|
+
if (clean.payer) body.payer = clean.payer;
|
|
105
|
+
if (clean.spender) body.spender = clean.spender;
|
|
106
|
+
return callApi("POST", pathname, body);
|
|
107
|
+
}
|
|
108
|
+
if (name === "ciro_receipt") return callApi("GET", `/v1/receipts/${clean.id}`);
|
|
109
|
+
return { ok: false, json: { error: "unknown_tool" } };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function handle(message) {
|
|
113
|
+
const id = message.id;
|
|
114
|
+
const method = message.method;
|
|
115
|
+
if (id === undefined) return;
|
|
116
|
+
if (method === "initialize") {
|
|
117
|
+
send({
|
|
118
|
+
jsonrpc: "2.0",
|
|
119
|
+
id,
|
|
120
|
+
result: {
|
|
121
|
+
protocolVersion: message.params?.protocolVersion ?? "2024-11-05",
|
|
122
|
+
capabilities: { tools: { listChanged: false } },
|
|
123
|
+
serverInfo: { name: "ciro", version: "0.1.0" },
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (method === "ping") {
|
|
129
|
+
send({ jsonrpc: "2.0", id, result: {} });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (method === "tools/list") {
|
|
133
|
+
send({ jsonrpc: "2.0", id, result: { tools } });
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (method === "tools/call") {
|
|
137
|
+
const name = message.params?.name;
|
|
138
|
+
const called = await callTool(name, message.params?.arguments);
|
|
139
|
+
send({
|
|
140
|
+
jsonrpc: "2.0",
|
|
141
|
+
id,
|
|
142
|
+
result: {
|
|
143
|
+
content: [{ type: "text", text: JSON.stringify(called.json) }],
|
|
144
|
+
isError: !called.ok,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
send({ jsonrpc: "2.0", id, error: { code: -32601, message: "method_not_found" } });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function serve() {
|
|
153
|
+
const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
154
|
+
lines.on("line", (line) => {
|
|
155
|
+
if (!line.trim()) return;
|
|
156
|
+
let message;
|
|
157
|
+
try {
|
|
158
|
+
message = JSON.parse(line);
|
|
159
|
+
} catch {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
handle(message).catch(() => {
|
|
163
|
+
if (message.id !== undefined) {
|
|
164
|
+
send({ jsonrpc: "2.0", id: message.id, error: { code: -32000, message: "request_failed" } });
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
package/README.md
DELETED