crowdcode-mcp 0.1.2 → 0.2.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.
@@ -0,0 +1,620 @@
1
+ import {
2
+ getConfig,
3
+ loadWallet
4
+ } from "./chunk-SKCQBRTB.js";
5
+ import {
6
+ buildIdentity,
7
+ canonicalReviewPayload,
8
+ normalizePaymentProvider
9
+ } from "./chunk-URCCBSON.js";
10
+
11
+ // src/server.ts
12
+ import { RedactionEngine } from "@crowdcode/redaction";
13
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
14
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
15
+
16
+ // src/attestation.ts
17
+ function withRedactionAttestation(payload, info) {
18
+ return {
19
+ ...payload,
20
+ _redaction: {
21
+ entities_removed: info.entitiesRemoved,
22
+ model_active: info.modelActive
23
+ }
24
+ };
25
+ }
26
+ function toToolResult(payload) {
27
+ return { content: [{ type: "text", text: JSON.stringify(payload) }] };
28
+ }
29
+
30
+ // src/redaction/policy.ts
31
+ var REDACTION_POLICY = {
32
+ request_service: ["service_description", "task_context"],
33
+ review_service: ["reason", "task_context"]
34
+ };
35
+ async function redactArgs(engine, tool, args) {
36
+ const fields = REDACTION_POLICY[tool] ?? [];
37
+ const out = { ...args };
38
+ let entitiesRemoved = 0;
39
+ let modelActive = engine.modelActive;
40
+ for (const field of fields) {
41
+ const value = out[field];
42
+ if (typeof value !== "string" || value === "") continue;
43
+ const result = await engine.redact(value);
44
+ out[field] = result.text;
45
+ entitiesRemoved += result.entitiesRemoved;
46
+ modelActive = result.modelActive;
47
+ }
48
+ return { args: out, entitiesRemoved, modelActive };
49
+ }
50
+
51
+ // src/schemas.ts
52
+ import { z } from "zod";
53
+ var identityShape = {
54
+ service_id: z.string().nullish().describe("Canonical service id (svc_...)"),
55
+ api_endpoint: z.string().nullish().describe("Service API endpoint URL"),
56
+ payment_provider: z.string().nullish().describe("One of: stripe, stripe_payment_link, mppx, x402, manual"),
57
+ payment_target_ref: z.string().nullish().describe("Payment recipient reference (wallet address, account id, ...)"),
58
+ directory_slug: z.string().nullish().describe("Directory slug if known")
59
+ };
60
+ var RATING_DESCRIPTION = "Rating 1-5. Judge the output against the ORIGINAL task you were solving (the task_context): was the response relevant and did it actually help answer that question? 5 = excellent: clear schema, relevant output that answered the original question, fast, clean receipt/proof \u2014 you would reuse it confidently. 4 = works and helped with the task, but with a real schema/docs/latency/output caveat (name it in the reason). 3 = mixed: paid successfully but the response was thin, confusing, needed guesswork, or was not actually relevant or helpful for the task \u2014 a technically valid answer that did not help is a 3 at best. 2 = paid but poor: client error, unclear failure, or hard to use. 1 = paid and broken: server error, unusable output, misleading challenge, or severe reliability problem (e.g. timeout). A service that simply worked well AND helped is a 5 \u2014 do not hedge to 4 without a concrete caveat.";
61
+ var requestServiceShape = {
62
+ service_description: z.string().describe(
63
+ "Specific, reusable capability that a provider could sell as a remote paid API (x402/mppx/Stripe) \u2014 something you could pay for with an HTTP request to someone else's endpoint. Include clear inputs and outputs. Do NOT request local runtime/agent-harness wishes (context management, local compute, IDE features) or one-off task help. Do not include secrets, credentials, or private user data \u2014 free text is additionally redacted locally before it leaves this machine."
64
+ ),
65
+ task_context: z.string().nullish().describe("Optional context about the task that needed this service"),
66
+ requester_wallet: z.string().nullish().describe(
67
+ "EVM 0x address identifying who is asking (rate-limit key). Auto-filled from your local agentcash/X402_PRIVATE_KEY wallet \u2014 only pass it to override."
68
+ )
69
+ };
70
+ var getServiceScoreShape = { ...identityShape };
71
+ var signingPayloadShape = {
72
+ rating: z.number().int().describe(RATING_DESCRIPTION),
73
+ reason: z.string().describe("Review text (redacted locally before hashing)"),
74
+ payment_reference: z.string().describe("Payment reference for this review"),
75
+ ...identityShape,
76
+ auto_sign: z.boolean().nullish().describe(
77
+ "When true, also sign the message with the local wallet and return review_signature + reviewer_wallet. Usually unnecessary: review_service signs automatically."
78
+ )
79
+ };
80
+ var reviewServiceShape = {
81
+ rating: z.number().int().describe(RATING_DESCRIPTION),
82
+ reason: z.string().describe("Review text (redacted locally before sending)"),
83
+ payment_reference: z.string().describe("Unique payment reference"),
84
+ service_id: identityShape.service_id,
85
+ task_context: z.string().nullish(),
86
+ service_name: z.string().nullish(),
87
+ api_endpoint: identityShape.api_endpoint,
88
+ payment_provider: identityShape.payment_provider,
89
+ payment_target_ref: identityShape.payment_target_ref,
90
+ directory_slug: identityShape.directory_slug,
91
+ payment_proof: z.string().nullish().describe(
92
+ "Strongly recommended: the base64 payment-response (x402) or Payment-Receipt (mppx) header string. Omitting it stores the review as UNVERIFIED, which carries half weight in scoring."
93
+ ),
94
+ payment_challenge: z.string().nullish(),
95
+ reviewer_wallet: z.string().nullish().describe("Optional; auto-filled from your local wallet when signing locally"),
96
+ review_signature: z.string().nullish().describe(
97
+ "Optional; crowdcode-mcp signs automatically with your local agentcash/X402_PRIVATE_KEY wallet. A supplied signature always wins."
98
+ ),
99
+ signature_scheme: z.string().default("eip191")
100
+ };
101
+ var MIRRORED_REMOTE_TOOLS = [
102
+ "request_service",
103
+ "get_service_score",
104
+ "review_service"
105
+ ];
106
+
107
+ // src/tools/signing-payload.ts
108
+ function orNull(value) {
109
+ return typeof value === "string" && value !== "" ? value : null;
110
+ }
111
+ async function getReviewSigningPayload(deps, args) {
112
+ let identity;
113
+ try {
114
+ identity = buildIdentity(args);
115
+ } catch (err) {
116
+ return { ok: false, reason: err.message };
117
+ }
118
+ const redacted = await deps.redact(args.reason);
119
+ let score;
120
+ try {
121
+ score = await deps.upstream.call("get_service_score", {
122
+ service_id: identity.service_id,
123
+ api_endpoint: identity.api_endpoint,
124
+ payment_provider: identity.payment_provider,
125
+ payment_target_ref: identity.payment_target_ref,
126
+ directory_slug: identity.directory_slug
127
+ });
128
+ } catch (err) {
129
+ return {
130
+ ok: false,
131
+ reason: `could not reach the CrowdCode backend to resolve the service: ${err.message}`
132
+ };
133
+ }
134
+ let effective = identity;
135
+ if (score.found === true) {
136
+ try {
137
+ effective = buildIdentity({
138
+ service_id: orNull(score.service_id),
139
+ service_name: orNull(score.service_name),
140
+ api_endpoint: identity.api_endpoint ?? orNull(score.canonical_endpoint),
141
+ payment_provider: identity.payment_provider ?? orNull(score.payment_provider),
142
+ payment_target_ref: identity.payment_target_ref ?? orNull(score.payment_target_ref),
143
+ directory_slug: identity.directory_slug ?? orNull(score.directory_slug)
144
+ });
145
+ } catch (err) {
146
+ return { ok: false, reason: err.message };
147
+ }
148
+ } else if (typeof score.reason === "string" && score.reason !== "service not found") {
149
+ return { ok: false, reason: score.reason };
150
+ }
151
+ const message = canonicalReviewPayload({
152
+ identity: effective,
153
+ rating: args.rating,
154
+ reason: redacted.text,
155
+ paymentReference: args.payment_reference
156
+ });
157
+ return {
158
+ ok: true,
159
+ signature_scheme: "eip191",
160
+ message,
161
+ reason: redacted.text,
162
+ identity: {
163
+ service_id: effective.service_id,
164
+ api_endpoint: effective.api_endpoint,
165
+ payment_provider: effective.payment_provider,
166
+ payment_target_ref: effective.payment_target_ref,
167
+ directory_slug: effective.directory_slug
168
+ },
169
+ instructions: "Sign `message` with the reviewer wallet (EIP-191 personal_sign). Then call review_service in this same session, passing this exact `reason` string and every field of `identity` verbatim, plus the same rating and payment_reference.",
170
+ _redaction: {
171
+ entities_removed: redacted.entitiesRemoved,
172
+ model_active: redacted.modelActive
173
+ }
174
+ };
175
+ }
176
+
177
+ // src/tools/sign-review.ts
178
+ var AGENTCASH_INSTALL_COMMAND = "claude mcp add --scope user agentcash -- npx -y agentcash@latest";
179
+ function installWalletNextStep(retryTool) {
180
+ return {
181
+ action: "install_wallet",
182
+ summary: "No local signing wallet found. Install agentcash (or set X402_PRIVATE_KEY) so crowdcode-mcp can sign automatically, then retry " + retryTool + ".",
183
+ command: AGENTCASH_INSTALL_COMMAND,
184
+ link: null,
185
+ retry: { tool: retryTool, after_seconds: null, with: {} }
186
+ };
187
+ }
188
+ function isMachineProvider(value) {
189
+ if (typeof value !== "string") return false;
190
+ try {
191
+ const provider = normalizePaymentProvider(value);
192
+ return provider === "mppx" || provider === "x402";
193
+ } catch {
194
+ return false;
195
+ }
196
+ }
197
+ async function prepareSignedReview(deps, args, wallet) {
198
+ if (!isMachineProvider(args.payment_provider) || args.review_signature) {
199
+ return { args, signed: false };
200
+ }
201
+ const loaded = await loadWallet({
202
+ walletDir: wallet.walletDir,
203
+ autoCreate: wallet.autoCreate,
204
+ env: wallet.env
205
+ });
206
+ if (loaded.source === "none" || loaded.account === null) {
207
+ return {
208
+ args,
209
+ signed: false,
210
+ wallet_source: "none",
211
+ wallet_error: loaded.error,
212
+ next_step: installWalletNextStep("review_service")
213
+ };
214
+ }
215
+ const payload = await getReviewSigningPayload(deps, {
216
+ rating: args.rating,
217
+ reason: String(args.reason ?? ""),
218
+ payment_reference: String(args.payment_reference ?? ""),
219
+ service_id: args.service_id,
220
+ api_endpoint: args.api_endpoint,
221
+ payment_provider: args.payment_provider,
222
+ payment_target_ref: args.payment_target_ref,
223
+ directory_slug: args.directory_slug
224
+ });
225
+ if (payload.ok !== true || typeof payload.message !== "string") {
226
+ return {
227
+ args,
228
+ signed: false,
229
+ wallet_source: loaded.source,
230
+ wallet_created: loaded.created,
231
+ wallet_error: `could not build the signing payload locally: ${String(
232
+ payload.reason ?? "unknown error"
233
+ )}`
234
+ };
235
+ }
236
+ const signature = await loaded.account.signMessage({
237
+ message: payload.message
238
+ });
239
+ const identity = payload.identity;
240
+ return {
241
+ args: {
242
+ ...args,
243
+ // Pass the resolved identity verbatim so the backend rebuilds the exact
244
+ // payload that was just signed.
245
+ service_id: identity.service_id ?? args.service_id,
246
+ api_endpoint: identity.api_endpoint ?? args.api_endpoint,
247
+ payment_provider: identity.payment_provider ?? args.payment_provider,
248
+ payment_target_ref: identity.payment_target_ref ?? args.payment_target_ref,
249
+ directory_slug: identity.directory_slug ?? args.directory_slug,
250
+ reviewer_wallet: loaded.address,
251
+ review_signature: signature,
252
+ signature_scheme: "eip191"
253
+ },
254
+ signed: true,
255
+ wallet_source: loaded.source,
256
+ wallet_created: loaded.created,
257
+ wallet: loaded
258
+ };
259
+ }
260
+ async function resignFromMismatch(prepared, response) {
261
+ if (!prepared.signed || !prepared.wallet?.account) return null;
262
+ if (response.accepted !== false) return null;
263
+ if (typeof response.expected_message !== "string") return null;
264
+ const identity = response.resolved_identity ?? {};
265
+ const signature = await prepared.wallet.account.signMessage({
266
+ message: response.expected_message
267
+ });
268
+ return {
269
+ ...prepared.args,
270
+ service_id: identity.service_id ?? prepared.args.service_id,
271
+ api_endpoint: identity.api_endpoint ?? prepared.args.api_endpoint,
272
+ payment_provider: identity.payment_provider ?? prepared.args.payment_provider,
273
+ payment_target_ref: identity.payment_target_ref ?? prepared.args.payment_target_ref,
274
+ directory_slug: identity.directory_slug ?? prepared.args.directory_slug,
275
+ review_signature: signature
276
+ };
277
+ }
278
+
279
+ // src/upstream.ts
280
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
281
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
282
+ var UpstreamError = class extends Error {
283
+ };
284
+ var UpstreamClient = class {
285
+ constructor(baseUrl, timeoutMs) {
286
+ this.baseUrl = baseUrl;
287
+ this.timeoutMs = timeoutMs;
288
+ }
289
+ baseUrl;
290
+ timeoutMs;
291
+ client = null;
292
+ async connect() {
293
+ if (this.client !== null) return this.client;
294
+ const client = new Client({ name: "crowdcode-mcp-local", version: "0.1.0" });
295
+ const transport = new StreamableHTTPClientTransport(new URL(this.baseUrl));
296
+ await client.connect(transport);
297
+ this.client = client;
298
+ return client;
299
+ }
300
+ async reset() {
301
+ const client = this.client;
302
+ this.client = null;
303
+ if (client !== null) {
304
+ try {
305
+ await client.close();
306
+ } catch {
307
+ }
308
+ }
309
+ }
310
+ async call(name, args) {
311
+ try {
312
+ return await this.callOnce(name, args);
313
+ } catch (err) {
314
+ if (err instanceof UpstreamError) throw err;
315
+ await this.reset();
316
+ return this.callOnce(name, args);
317
+ }
318
+ }
319
+ async callOnce(name, args) {
320
+ const client = await this.connect();
321
+ const result = await client.callTool({ name, arguments: args }, void 0, {
322
+ timeout: this.timeoutMs
323
+ });
324
+ if (result.isError) {
325
+ throw new UpstreamError(
326
+ `backend tool ${name} failed: ${firstText(result.content)}`
327
+ );
328
+ }
329
+ const structured = result.structuredContent;
330
+ if (structured !== void 0 && isRecord(structured)) {
331
+ return structured;
332
+ }
333
+ const text = firstText(result.content);
334
+ try {
335
+ const parsed = JSON.parse(text);
336
+ if (isRecord(parsed)) return parsed;
337
+ } catch {
338
+ }
339
+ throw new UpstreamError(
340
+ `backend tool ${name} returned an unparseable result: ${text.slice(0, 200)}`
341
+ );
342
+ }
343
+ async listToolNames() {
344
+ const client = await this.connect();
345
+ const { tools } = await client.listTools();
346
+ return tools.map((tool) => tool.name);
347
+ }
348
+ };
349
+ function isRecord(value) {
350
+ return typeof value === "object" && value !== null && !Array.isArray(value);
351
+ }
352
+ function firstText(content) {
353
+ if (Array.isArray(content)) {
354
+ for (const item of content) {
355
+ if (isRecord(item) && item.type === "text" && typeof item.text === "string") {
356
+ return item.text;
357
+ }
358
+ }
359
+ }
360
+ return "";
361
+ }
362
+
363
+ // src/server.ts
364
+ function errorPayload(tool, err) {
365
+ const message = err instanceof UpstreamError ? err.message : `could not reach the CrowdCode backend: ${err.message}`;
366
+ const next_step = {
367
+ action: "retry_backend",
368
+ summary: "The CrowdCode backend may be cold-starting (free-tier hosting); retry the same call in ~30 seconds.",
369
+ command: null,
370
+ link: null,
371
+ retry: { tool, after_seconds: 30, with: {} }
372
+ };
373
+ if (tool === "get_service_score") {
374
+ return {
375
+ found: false,
376
+ avg_rating: null,
377
+ num_reviews: 0,
378
+ recent_reviews: [],
379
+ reason: message,
380
+ next_step
381
+ };
382
+ }
383
+ return { accepted: false, reason: message, next_step };
384
+ }
385
+ function withWalletInfo(payload, prepared) {
386
+ const out = { ...payload };
387
+ if (prepared.wallet_source !== void 0) {
388
+ out.wallet_source = prepared.wallet_source;
389
+ }
390
+ if (prepared.wallet_created) out.wallet_created = true;
391
+ if (prepared.wallet_error) out.wallet_error = prepared.wallet_error;
392
+ if (out.next_step === void 0 && prepared.next_step) {
393
+ out.next_step = prepared.next_step;
394
+ }
395
+ return out;
396
+ }
397
+ function createToolHandlers(deps) {
398
+ const { engine, upstream } = deps;
399
+ const config = getConfig();
400
+ const walletOptions = {
401
+ walletDir: deps.wallet?.walletDir ?? config.walletDir,
402
+ autoCreate: deps.wallet?.autoCreate ?? config.walletAutoCreate,
403
+ env: deps.wallet?.env
404
+ };
405
+ const signingDeps = { redact: (text) => engine.redact(text), upstream };
406
+ let onboardingCtaShown = false;
407
+ async function forwardPayload(tool, args) {
408
+ const redacted = await redactArgs(engine, tool, args);
409
+ try {
410
+ const result = await upstream.call(tool, redacted.args);
411
+ return withRedactionAttestation(result, {
412
+ entitiesRemoved: redacted.entitiesRemoved,
413
+ modelActive: redacted.modelActive
414
+ });
415
+ } catch (err) {
416
+ return errorPayload(tool, err);
417
+ }
418
+ }
419
+ return {
420
+ request_service: async (args) => {
421
+ let outgoing = args;
422
+ if (!outgoing.requester_wallet) {
423
+ const wallet = await loadWallet({
424
+ walletDir: walletOptions.walletDir,
425
+ env: walletOptions.env,
426
+ autoCreate: false
427
+ });
428
+ if (wallet.address) {
429
+ outgoing = { ...outgoing, requester_wallet: wallet.address };
430
+ }
431
+ }
432
+ return toToolResult(await forwardPayload("request_service", outgoing));
433
+ },
434
+ get_service_score: async (args) => {
435
+ let payload;
436
+ try {
437
+ payload = await upstream.call("get_service_score", args);
438
+ } catch (err) {
439
+ return toToolResult(errorPayload("get_service_score", err));
440
+ }
441
+ const provider = payload.payment_provider;
442
+ if (!onboardingCtaShown && payload.found === true && (provider === "mppx" || provider === "x402")) {
443
+ const wallet = await loadWallet({
444
+ walletDir: walletOptions.walletDir,
445
+ env: walletOptions.env,
446
+ autoCreate: false
447
+ });
448
+ if (wallet.source === "none") {
449
+ onboardingCtaShown = true;
450
+ payload = {
451
+ ...payload,
452
+ onboarding_cta: {
453
+ message: "This is a paid x402/mppx service and you have no local signing wallet yet. Install agentcash (or set X402_PRIVATE_KEY) so your post-purchase review can be signed and counted.",
454
+ command: installWalletNextStep("review_service").command
455
+ }
456
+ };
457
+ }
458
+ }
459
+ return toToolResult(payload);
460
+ },
461
+ get_review_signing_payload: async (args) => {
462
+ const payload = await getReviewSigningPayload(signingDeps, args);
463
+ if (args.auto_sign !== true || payload.ok !== true) {
464
+ return toToolResult(payload);
465
+ }
466
+ const wallet = await loadWallet(walletOptions);
467
+ if (wallet.source === "none" || wallet.account === null) {
468
+ return toToolResult({
469
+ ...payload,
470
+ wallet_source: "none",
471
+ wallet_error: wallet.error,
472
+ next_step: installWalletNextStep("review_service")
473
+ });
474
+ }
475
+ const signature = await wallet.account.signMessage({
476
+ message: payload.message
477
+ });
478
+ return toToolResult({
479
+ ...payload,
480
+ review_signature: signature,
481
+ reviewer_wallet: wallet.address,
482
+ wallet_source: wallet.source,
483
+ ...wallet.created ? { wallet_created: true } : {}
484
+ });
485
+ },
486
+ review_service: async (args) => {
487
+ const prepared = await prepareSignedReview(signingDeps, args, walletOptions);
488
+ let payload = await forwardPayload("review_service", prepared.args);
489
+ const retryArgs = await resignFromMismatch(prepared, payload);
490
+ if (retryArgs !== null) {
491
+ payload = await forwardPayload("review_service", retryArgs);
492
+ }
493
+ return toToolResult(withWalletInfo(payload, prepared));
494
+ }
495
+ };
496
+ }
497
+ var SERVER_INSTRUCTIONS = [
498
+ "CrowdCode is a shared reputation layer for paid agent services. Use it",
499
+ "whenever a task involves paying for, provisioning, or calling a paid",
500
+ "service \u2014 especially x402 or mppx/MPP services.",
501
+ "",
502
+ "Before spending: call get_service_score on each candidate (prefer",
503
+ "api_endpoint + payment_provider + payment_target_ref, or service_id /",
504
+ "directory_slug). Prefer higher avg_rating, using num_reviews as sample-size",
505
+ "context; with few or no reviews, fall back to price and the spend policy.",
506
+ "",
507
+ "After ANY paid use \u2014 success, slow response, or failure: submit a review.",
508
+ "A slow or broken paid call is not a reason to skip the review; it IS the",
509
+ "review (slowness or breakage goes in the rating and reason). Rate against",
510
+ "the ORIGINAL task you were solving: was the response relevant and did it",
511
+ "actually help answer that question? Fixed scale: 5 = excellent (clear",
512
+ "schema, relevant output that answered the original question, fast, clean",
513
+ "receipt \u2014 would reuse confidently); 4 = helped but a real",
514
+ "schema/docs/latency/output caveat; 3 = paid but response thin, confusing,",
515
+ "needed guesswork, or not actually relevant/helpful for the task (a",
516
+ "technically valid answer that did not help is a 3 at best); 2 = paid but",
517
+ "poor (client error, unclear failure, hard to use); 1 = paid and broken",
518
+ "(server error, unusable output, misleading challenge, timeout/severe",
519
+ "reliability). A service that simply worked well AND helped is a 5 \u2014 do",
520
+ "not hedge to 4 without a concrete caveat.",
521
+ "",
522
+ "Signing is AUTOMATIC: review_service signs with your local wallet",
523
+ "(X402_PRIVATE_KEY, or the agentcash wallet at ~/.agentcash/wallet.json,",
524
+ "auto-created if missing) \u2014 you do not need get_review_signing_payload or",
525
+ "an external signer. Responses include wallet_source (env | agentcash |",
526
+ "none). For x402/mppx, take identity and proofs from the ACTUAL payment,",
527
+ "not a directory listing: payment_reference = the settlement tx hash (x402)",
528
+ "or Payment-Receipt reference (mppx); payment_proof = the base64 response",
529
+ "header string (payment-response for x402, Payment-Receipt for mppx), not",
530
+ "the tx hash or decoded JSON \u2014 payment_proof is OPTIONAL but strongly",
531
+ "encouraged: with it the review counts as a verified purchase (double the",
532
+ "scoring weight of an unverified one); payment_target_ref = the real",
533
+ "on-chain payee (the 402 challenge recipient / Transfer `to`), not a",
534
+ "directory payTo.",
535
+ "",
536
+ "Workflow: 1) get_service_score on each candidate; 2) pay and use the",
537
+ "service; 3) review_service with the payment_reference and (ideally) the",
538
+ "payment_proof header. Reviews are limited to 1 per service per wallet per",
539
+ "24h; failed calls return a next_step object with the exact command or",
540
+ "retry that fixes them \u2014 follow it.",
541
+ "",
542
+ "When no fitting paid service exists, call request_service once with a",
543
+ "specific, reusable capability description (requires a wallet identity,",
544
+ "attached automatically; limited to 5 requests per wallet per 24h). Only",
545
+ "request things a provider could sell as a remote paid API \u2014 the test is:",
546
+ "could you pay for it with an x402/mpp request to someone else's endpoint?",
547
+ "Never runtime or agent-harness wishes (context management, local compute).",
548
+ "Never send secrets or private data \u2014 free-text fields are redacted locally",
549
+ "before anything is sent."
550
+ ].join("\n");
551
+ function buildServer(deps) {
552
+ const server = new McpServer(
553
+ { name: "crowdcode", version: "0.2.0" },
554
+ { instructions: SERVER_INSTRUCTIONS }
555
+ );
556
+ const handlers = createToolHandlers(deps);
557
+ server.registerTool(
558
+ "request_service",
559
+ {
560
+ description: "Capture an unmet, reusable service request for future directory coverage. Use only when no fitting paid or external service exists. Only request capabilities a provider could sell as a remote paid API (x402/mppx/Stripe) \u2014 the test: could you pay for it with an x402/mpp request to someone else's endpoint? Describe a specific capability with clear inputs and outputs, general enough to apply to multiple users. Good: 'resolve a citation like Smith et al. 2019 to the actual paper, or report that it does not exist'; 'semantic search over paywalled full-text academic PDFs returning page-level citations'; 'live versioned registry of current API schemas'. Bad: wishes about your own runtime or harness ('cleaner context', 'more memory', local compute/IDE features) and one-off task help ('fix my CI'). Requires a wallet identity (attached automatically from your local agentcash/X402_PRIVATE_KEY wallet); limited to 5 requests per wallet per 24h. Free-text fields are redacted locally (PII and secrets become [PLACEHOLDER]s) before anything is sent to the shared CrowdCode backend.",
561
+ inputSchema: requestServiceShape
562
+ },
563
+ (args) => handlers.request_service(args)
564
+ );
565
+ server.registerTool(
566
+ "get_service_score",
567
+ {
568
+ description: "Return the average rating, review count, and recent reviews for a service, identified by service_id, api_endpoint, payment target, or directory_slug. Check this before paying for, provisioning, or calling any paid agent service \u2014 especially x402 and mppx/MPP services.",
569
+ inputSchema: getServiceScoreShape
570
+ },
571
+ (args) => handlers.get_service_score(args)
572
+ );
573
+ server.registerTool(
574
+ "get_review_signing_payload",
575
+ {
576
+ description: "Build the exact EIP-191 message for an mppx/x402 review \u2014 usually UNNECESSARY: review_service signs automatically with your local wallet. Use this only for transparency/debugging or when signing with an external wallet. Runs entirely locally: the review reason is redacted on this machine and only its hash enters the payload. Pass auto_sign=true to also sign with the local wallet and get review_signature + reviewer_wallet back. If signing externally, sign `message` VERBATIM (byte-for-byte) with the payer wallet, then call review_service with the returned `reason` and `identity` fields verbatim, in this same session.",
577
+ inputSchema: signingPayloadShape
578
+ },
579
+ (args) => handlers.get_review_signing_payload(args)
580
+ );
581
+ server.registerTool(
582
+ "review_service",
583
+ {
584
+ description: "Submit a review after paying for a service \u2014 call this after EVERY paid x402/mppx use, including slow responses and failures. A bad outcome is not a reason to skip the review; it IS the review: rate 1-2 with the failure in the reason. Rate against the ORIGINAL task you were solving: was the response relevant and did it actually help answer that question? Rating scale: 5 = excellent (clear schema, relevant output that answered the original question, fast, clean receipt \u2014 would reuse confidently); 4 = helped but a real schema/docs/latency/output caveat; 3 = paid but thin/confusing/needed guesswork or not actually relevant/helpful for the task (a technically valid answer that did not help is a 3 at best); 2 = paid but poor (client error, unclear failure, hard to use); 1 = paid and broken (server error, unusable output, misleading challenge, timeout). A service that simply worked well AND helped is a 5 \u2014 do not hedge to 4 without a concrete caveat. SIGNING IS AUTOMATIC: this tool signs with your local agentcash/X402_PRIVATE_KEY wallet (auto-created if missing) \u2014 do not call get_review_signing_payload or sign externally. Get identity and proofs from the ACTUAL payment, not a directory listing: payment_reference = the settlement tx hash (x402) or Payment-Receipt `reference` (mppx); payment_proof = the base64 response header STRING \u2014 `payment-response` for x402, `Payment-Receipt` for mppx \u2014 NOT the tx hash and NOT decoded JSON. payment_proof is OPTIONAL but strongly encouraged: with it the review is a verified purchase (double scoring weight); payment_target_ref = the real payee (the 402 challenge recipient / on-chain Transfer `to`), not a bazaar/directory payTo. If you paid from a different wallet than the local one, pass reviewer_wallet and review_signature yourself (the wallet that SENT the payment \u2014 the ERC-20 Transfer `from`, not the gasless facilitator). Limited to 1 review per service per wallet per 24h. Free-text is redacted locally.",
585
+ inputSchema: reviewServiceShape
586
+ },
587
+ (args) => handlers.review_service(args)
588
+ );
589
+ return server;
590
+ }
591
+ async function warnOnToolDrift(upstream) {
592
+ try {
593
+ const remote = new Set(await upstream.listToolNames());
594
+ const missing = MIRRORED_REMOTE_TOOLS.filter((name) => !remote.has(name));
595
+ if (missing.length > 0) {
596
+ process.stderr.write(
597
+ `crowdcode-mcp: backend no longer advertises: ${missing.join(", ")} \u2014 update the crowdcode-mcp package.
598
+ `
599
+ );
600
+ }
601
+ } catch {
602
+ }
603
+ }
604
+ async function startServer() {
605
+ const config = getConfig();
606
+ const engine = await RedactionEngine.create({
607
+ cacheDir: config.cacheDir,
608
+ enableModel: !config.disableModel
609
+ });
610
+ const upstream = new UpstreamClient(config.backendUrl, config.upstreamTimeoutMs);
611
+ const server = buildServer({ engine, upstream });
612
+ await server.connect(new StdioServerTransport());
613
+ void warnOnToolDrift(upstream);
614
+ }
615
+ export {
616
+ buildServer,
617
+ createToolHandlers,
618
+ startServer
619
+ };
620
+ //# sourceMappingURL=server-GI4ZADCU.js.map