@beggar-bot/mcp 0.0.0-stage → 0.1.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/README.md +14 -2
- package/package.json +34 -4
- package/src/index.js +63 -0
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @beggar-bot/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Source: [https://github.com/beggar-bot-x402/beggar-bot-connectors/tree/main/packages/mcp](https://github.com/beggar-bot-x402/beggar-bot-connectors/tree/main/packages/mcp)
|
|
4
|
+
|
|
5
|
+
Talk to the live Beggar Bot MCP at `https://beggar-bot-demand.beggarbot.workers.dev/mcp` (streamable HTTP). Each JSON-RPC call that hits a paid tool is retried with an x402 payment signed by the **buyer's** wallet.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { BeggarBotMcp } from "@beggar-bot/mcp";
|
|
9
|
+
|
|
10
|
+
const mcp = new BeggarBotMcp({ signer });
|
|
11
|
+
const tools = await mcp.listTools();
|
|
12
|
+
const result = await mcp.callTool("token_price", { token: "ETH" }); // actual MCP tool names may differ; or use HTTP catalog via the sibling packages
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`initialize` and `tools/list` are attempted first; if the server 402s them, the same buyer signer pays.
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beggar-bot/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Thin MCP client for Beggar Bot's remote streamable-HTTP server at /mcp. x402 payment is signed by the buyer's wallet.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@beggar-bot/x402-client": "^0.1.1"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20"
|
|
19
|
+
},
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "Beggar Bot",
|
|
22
|
+
"email": "beggarbot@mail.grokbot.com"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/beggar-bot-x402/beggar-bot-connectors.git",
|
|
30
|
+
"directory": "packages/mcp"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/beggar-bot-x402/beggar-bot-connectors/tree/main/packages/mcp#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/beggar-bot-x402/beggar-bot-connectors/issues"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { paidRequest, DEFAULT_BASE_URL, asSigner, X402Error } from "@beggar-bot/x402-client";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_MCP_PATH = "/mcp";
|
|
4
|
+
|
|
5
|
+
export class BeggarBotMcp {
|
|
6
|
+
constructor({ signer, baseUrl = DEFAULT_BASE_URL, mcpPath = DEFAULT_MCP_PATH, fetchImpl, maxUsd } = {}) {
|
|
7
|
+
this.signer = asSigner(signer);
|
|
8
|
+
this.baseUrl = baseUrl;
|
|
9
|
+
this.mcpPath = mcpPath;
|
|
10
|
+
this.fetchImpl = fetchImpl;
|
|
11
|
+
this.maxUsd = maxUsd;
|
|
12
|
+
this._id = 0;
|
|
13
|
+
this.session = null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async rpc(method, params = {}, { extraHeaders } = {}) {
|
|
17
|
+
const id = ++this._id;
|
|
18
|
+
const body = { jsonrpc: "2.0", id, method, params };
|
|
19
|
+
const { ok, status, data, payment } = await paidRequest(this.mcpPath, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
body,
|
|
22
|
+
signer: this.signer,
|
|
23
|
+
baseUrl: this.baseUrl,
|
|
24
|
+
fetchImpl: this.fetchImpl,
|
|
25
|
+
maxUsd: this.maxUsd,
|
|
26
|
+
headers: { accept: "application/json, text/event-stream", ...(extraHeaders || {}) },
|
|
27
|
+
});
|
|
28
|
+
if (!ok) {
|
|
29
|
+
throw new X402Error(`MCP ${method} failed with HTTP ${status}`, { data, payment, status });
|
|
30
|
+
}
|
|
31
|
+
// streamable HTTP may return a JSON-RPC object or SSE; tests and this client expect JSON
|
|
32
|
+
if (data && data.error) {
|
|
33
|
+
throw new X402Error(`MCP ${method} JSON-RPC error: ${data.error.message || JSON.stringify(data.error)}`, { data, payment });
|
|
34
|
+
}
|
|
35
|
+
return { result: data?.result, raw: data, payment };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async initialize() {
|
|
39
|
+
const { result, payment } = await this.rpc("initialize", {
|
|
40
|
+
protocolVersion: "2025-03-26",
|
|
41
|
+
capabilities: {},
|
|
42
|
+
clientInfo: { name: "beggar-bot-mcp-client", version: "0.1.0" },
|
|
43
|
+
});
|
|
44
|
+
this.session = result;
|
|
45
|
+
return { result, payment };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async listTools() {
|
|
49
|
+
const { result, payment } = await this.rpc("tools/list", {});
|
|
50
|
+
return { tools: result?.tools || [], payment };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async callTool(name, args = {}, { meta } = {}) {
|
|
54
|
+
const params = { name, arguments: args };
|
|
55
|
+
if (meta) params._meta = meta;
|
|
56
|
+
const { result, payment } = await this.rpc("tools/call", params);
|
|
57
|
+
return { result, payment };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createBeggarBotMcp(opts) {
|
|
62
|
+
return new BeggarBotMcp(opts);
|
|
63
|
+
}
|