@aibtc/mcp-server 1.69.0 → 1.70.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.
@@ -1,329 +0,0 @@
1
- /**
2
- * ERC-8004 Identity and Reputation Tools
3
- *
4
- * These tools provide on-chain agent identity and reputation management:
5
- *
6
- * Identity Tools:
7
- * - register_identity: Register new agent identity on-chain
8
- * - get_identity: Get agent identity info (owner, URI, wallet)
9
- *
10
- * Reputation Tools:
11
- * - give_feedback: Submit feedback for an agent
12
- * - get_reputation: Get aggregated reputation score
13
- *
14
- * Validation Tools:
15
- * - request_validation: Request third-party validation
16
- * - get_validation_status: Check validation request status
17
- * - get_validation_summary: Get validation summary for agent
18
- */
19
- import { z } from "zod";
20
- import { NETWORK, getExplorerTxUrl } from "../config/networks.js";
21
- import { createJsonResponse, createErrorResponse } from "../utils/index.js";
22
- import { getWalletManager } from "../services/wallet-manager.js";
23
- import { Erc8004Service } from "../services/erc8004.service.js";
24
- import { resolveFee } from "../utils/fee.js";
25
- import { sponsoredSchema } from "./schemas.js";
26
- import { normalizeHex, getCallerAddress } from "../utils/erc8004-helpers.js";
27
- const MAX_METADATA_KEY_LENGTH = 128;
28
- const MAX_METADATA_VALUE_BYTES = 512;
29
- export function registerErc8004Tools(server) {
30
- const service = new Erc8004Service(NETWORK);
31
- // ==========================================================================
32
- // Identity Tools
33
- // ==========================================================================
34
- // Register identity
35
- server.registerTool("register_identity", {
36
- description: "Register a new agent identity on-chain using ERC-8004 identity registry. " +
37
- "Returns a transaction ID. Check the transaction result to get the assigned agent ID. " +
38
- "Requires an unlocked wallet.",
39
- inputSchema: {
40
- uri: z
41
- .string()
42
- .optional()
43
- .describe("URI pointing to agent metadata (IPFS, HTTP, etc.). Optional."),
44
- metadata: z
45
- .array(z.object({
46
- key: z.string().max(MAX_METADATA_KEY_LENGTH).describe("Metadata key (max 128 chars)"),
47
- value: z.string().describe("Metadata value as hex string (max 512 bytes)"),
48
- }))
49
- .optional()
50
- .describe("Array of metadata key-value pairs. Values must be hex-encoded buffers. Optional."),
51
- fee: z
52
- .string()
53
- .optional()
54
- .describe('Fee preset ("low", "medium", "high") or micro-STX amount. Optional.'),
55
- sponsored: sponsoredSchema,
56
- },
57
- }, async ({ uri, metadata, fee, sponsored }) => {
58
- try {
59
- const walletManager = getWalletManager();
60
- const account = walletManager.getActiveAccount();
61
- if (!account) {
62
- throw new Error("No active wallet. Please unlock your wallet first.");
63
- }
64
- // Parse metadata if provided
65
- let parsedMetadata;
66
- if (metadata && metadata.length > 0) {
67
- parsedMetadata = metadata.map((m) => {
68
- const normalized = normalizeHex(m.value, `metadata value for key "${m.key}"`);
69
- const buf = Buffer.from(normalized, "hex");
70
- if (buf.length > MAX_METADATA_VALUE_BYTES) {
71
- throw new Error(`metadata value for key "${m.key}" exceeds ${MAX_METADATA_VALUE_BYTES} bytes (got ${buf.length})`);
72
- }
73
- return { key: m.key, value: buf };
74
- });
75
- }
76
- const feeAmount = fee ? await resolveFee(fee, NETWORK, "contract_call") : undefined;
77
- const result = await service.registerIdentity(account, uri, parsedMetadata, feeAmount, sponsored);
78
- return createJsonResponse({
79
- success: true,
80
- txid: result.txid,
81
- message: "Identity registration transaction submitted. " +
82
- "Check transaction result to get your agent ID.",
83
- network: NETWORK,
84
- explorerUrl: getExplorerTxUrl(result.txid, NETWORK),
85
- });
86
- }
87
- catch (error) {
88
- return createErrorResponse(error);
89
- }
90
- });
91
- // Get identity
92
- server.registerTool("get_identity", {
93
- description: "Get agent identity information from ERC-8004 identity registry. " +
94
- "Returns owner address, URI, and wallet address if set.",
95
- inputSchema: {
96
- agentId: z.number().int().min(0).describe("Agent ID to look up"),
97
- },
98
- }, async ({ agentId }) => {
99
- try {
100
- const callerAddress = getCallerAddress();
101
- const identity = await service.getIdentity(agentId, callerAddress);
102
- if (!identity) {
103
- return createJsonResponse({
104
- success: false,
105
- agentId,
106
- message: "Agent ID not found",
107
- });
108
- }
109
- return createJsonResponse({
110
- success: true,
111
- agentId: identity.agentId,
112
- owner: identity.owner,
113
- uri: identity.uri || "(no URI set)",
114
- wallet: identity.wallet || "(no wallet set)",
115
- network: NETWORK,
116
- });
117
- }
118
- catch (error) {
119
- return createErrorResponse(error);
120
- }
121
- });
122
- // ==========================================================================
123
- // Reputation Tools
124
- // ==========================================================================
125
- // Give feedback
126
- server.registerTool("give_feedback", {
127
- description: "Submit feedback for an agent using ERC-8004 reputation registry. " +
128
- "Value is normalized to 18 decimals (WAD) internally for aggregation. " +
129
- "Requires an unlocked wallet.",
130
- inputSchema: {
131
- agentId: z.number().int().min(0).describe("Agent ID to give feedback for"),
132
- value: z
133
- .number()
134
- .int()
135
- .min(0)
136
- .describe("Feedback value (e.g., 5 for 5-star rating)"),
137
- decimals: z
138
- .number()
139
- .int()
140
- .min(0)
141
- .max(18)
142
- .describe("Decimals for the value (e.g., 0 for integer ratings)"),
143
- tag1: z.string().optional().describe("Optional tag 1 (max 64 chars)"),
144
- tag2: z.string().optional().describe("Optional tag 2 (max 64 chars)"),
145
- endpoint: z.string().optional().describe("Optional endpoint URL"),
146
- feedbackUri: z.string().optional().describe("Optional feedback URI"),
147
- feedbackHash: z
148
- .string()
149
- .optional()
150
- .describe("Optional feedback hash as hex string (32 bytes)"),
151
- fee: z
152
- .string()
153
- .optional()
154
- .describe('Fee preset ("low", "medium", "high") or micro-STX amount. Optional.'),
155
- sponsored: sponsoredSchema,
156
- },
157
- }, async ({ agentId, value, decimals, tag1, tag2, endpoint, feedbackUri, feedbackHash, fee, sponsored }) => {
158
- try {
159
- const walletManager = getWalletManager();
160
- const account = walletManager.getActiveAccount();
161
- if (!account) {
162
- throw new Error("No active wallet. Please unlock your wallet first.");
163
- }
164
- const hashBuffer = feedbackHash
165
- ? Buffer.from(normalizeHex(feedbackHash, "feedbackHash", 32), "hex")
166
- : undefined;
167
- const feeAmount = fee ? await resolveFee(fee, NETWORK, "contract_call") : undefined;
168
- const result = await service.giveFeedback(account, agentId, value, decimals, tag1, tag2, endpoint, feedbackUri, hashBuffer, feeAmount, sponsored);
169
- return createJsonResponse({
170
- success: true,
171
- txid: result.txid,
172
- message: "Feedback submitted successfully",
173
- agentId,
174
- value,
175
- decimals,
176
- network: NETWORK,
177
- explorerUrl: getExplorerTxUrl(result.txid, NETWORK),
178
- });
179
- }
180
- catch (error) {
181
- return createErrorResponse(error);
182
- }
183
- });
184
- // Get reputation
185
- server.registerTool("get_reputation", {
186
- description: "Get aggregated reputation summary for an agent from ERC-8004 reputation registry. " +
187
- "Returns average rating as a raw WAD string (18 decimals) and total feedback count.",
188
- inputSchema: {
189
- agentId: z.number().int().min(0).describe("Agent ID to get reputation for"),
190
- },
191
- }, async ({ agentId }) => {
192
- try {
193
- const callerAddress = getCallerAddress();
194
- const reputation = await service.getReputation(agentId, callerAddress);
195
- if (reputation.totalFeedback === 0) {
196
- return createJsonResponse({
197
- success: true,
198
- agentId,
199
- totalFeedback: 0,
200
- summaryValue: "0",
201
- summaryValueDecimals: 0,
202
- message: "No feedback yet for this agent",
203
- network: NETWORK,
204
- });
205
- }
206
- return createJsonResponse({
207
- success: true,
208
- agentId: reputation.agentId,
209
- totalFeedback: reputation.totalFeedback,
210
- summaryValue: reputation.summaryValue,
211
- summaryValueDecimals: reputation.summaryValueDecimals,
212
- network: NETWORK,
213
- });
214
- }
215
- catch (error) {
216
- return createErrorResponse(error);
217
- }
218
- });
219
- // ==========================================================================
220
- // Validation Tools
221
- // ==========================================================================
222
- // Request validation
223
- server.registerTool("request_validation", {
224
- description: "Request third-party validation for an agent using ERC-8004 validation registry. " +
225
- "The validator will be notified and can respond with a 0-100 score. " +
226
- "Requires an unlocked wallet and must be called by agent owner or approved operator.",
227
- inputSchema: {
228
- validator: z.string().describe("Stacks address of the validator"),
229
- agentId: z.number().int().min(0).describe("Agent ID to request validation for"),
230
- requestUri: z.string().describe("URI with validation request details"),
231
- requestHash: z.string().describe("Unique request hash as hex string (32 bytes)"),
232
- fee: z
233
- .string()
234
- .optional()
235
- .describe('Fee preset ("low", "medium", "high") or micro-STX amount. Optional.'),
236
- sponsored: sponsoredSchema,
237
- },
238
- }, async ({ validator, agentId, requestUri, requestHash, fee, sponsored }) => {
239
- try {
240
- const walletManager = getWalletManager();
241
- const account = walletManager.getActiveAccount();
242
- if (!account) {
243
- throw new Error("No active wallet. Please unlock your wallet first.");
244
- }
245
- const normalizedHash = normalizeHex(requestHash, "requestHash", 32);
246
- const hashBuffer = Buffer.from(normalizedHash, "hex");
247
- const feeAmount = fee ? await resolveFee(fee, NETWORK, "contract_call") : undefined;
248
- const result = await service.requestValidation(account, validator, agentId, requestUri, hashBuffer, feeAmount, sponsored);
249
- return createJsonResponse({
250
- success: true,
251
- txid: result.txid,
252
- message: "Validation request submitted successfully",
253
- validator,
254
- agentId,
255
- requestHash,
256
- network: NETWORK,
257
- explorerUrl: getExplorerTxUrl(result.txid, NETWORK),
258
- });
259
- }
260
- catch (error) {
261
- return createErrorResponse(error);
262
- }
263
- });
264
- // Get validation status
265
- server.registerTool("get_validation_status", {
266
- description: "Get the status of a validation request using ERC-8004 validation registry. " +
267
- "Returns validator, agent ID, response score (0-100), and response metadata.",
268
- inputSchema: {
269
- requestHash: z.string().describe("Request hash as hex string (32 bytes)"),
270
- },
271
- }, async ({ requestHash }) => {
272
- try {
273
- const callerAddress = getCallerAddress();
274
- const normalizedHash = normalizeHex(requestHash, "requestHash", 32);
275
- const hashBuffer = Buffer.from(normalizedHash, "hex");
276
- const status = await service.getValidationStatus(hashBuffer, callerAddress);
277
- if (!status) {
278
- return createJsonResponse({
279
- success: false,
280
- requestHash,
281
- message: "Validation request not found",
282
- network: NETWORK,
283
- });
284
- }
285
- return createJsonResponse({
286
- success: true,
287
- requestHash,
288
- validator: status.validator,
289
- agentId: status.agentId,
290
- response: status.response,
291
- responseHash: status.responseHash,
292
- tag: status.tag || "(no tag)",
293
- lastUpdate: status.lastUpdate,
294
- hasResponse: status.hasResponse,
295
- network: NETWORK,
296
- });
297
- }
298
- catch (error) {
299
- return createErrorResponse(error);
300
- }
301
- });
302
- // Get validation summary
303
- server.registerTool("get_validation_summary", {
304
- description: "Get validation summary for an agent using ERC-8004 validation registry. " +
305
- "Returns total validation count and average response score (0-100).",
306
- inputSchema: {
307
- agentId: z.number().int().min(0).describe("Agent ID to get validation summary for"),
308
- },
309
- }, async ({ agentId }) => {
310
- try {
311
- const callerAddress = getCallerAddress();
312
- const summary = await service.getValidationSummary(agentId, callerAddress);
313
- return createJsonResponse({
314
- success: true,
315
- agentId,
316
- count: summary.count,
317
- averageResponse: summary.avgResponse,
318
- message: summary.count === 0
319
- ? "No validations yet for this agent"
320
- : `${summary.count} validation(s) with average score ${summary.avgResponse}/100`,
321
- network: NETWORK,
322
- });
323
- }
324
- catch (error) {
325
- return createErrorResponse(error);
326
- }
327
- });
328
- }
329
- //# sourceMappingURL=erc8004.tools.js.map