@agentpickup/mcp 0.2.0 → 0.3.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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # @agentpickup/mcp
2
2
 
3
3
  An MCP server for [agentPickup](https://github.com/dav3trad3r/agentpickup) shops. It lets an AI agent find
4
- pickup shops near its user, see what they sell, order, pay in USDC over x402, and hand its user the QR they
5
- show at the counter to collect.
4
+ pickup shops near its user, see what they sell, order, pay by card or in USDC over x402, and hand its user the
5
+ QR they show at the counter to collect.
6
6
 
7
7
  ## Tools
8
8
 
@@ -14,6 +14,10 @@ show at the counter to collect.
14
14
  | `pay_order` | Pays the order's x402 link from your wallet and returns the pass link. With no wallet set up, returns the price and pay link instead |
15
15
  | `order_status` | Waiting for payment, paid, ready, collected or expired |
16
16
  | `get_pickup_pass` | Fetches the pass link, pickup code and QR again by signing in as the paying wallet (Sign-In-With-X) |
17
+ | `start_group_order` | Starts a group order (a coffee run) with a closing time; returns the code to share and a key to close it early |
18
+ | `join_group_order` | Adds the user's items to a group order by its code; pay the share with `pay_order` before it closes |
19
+ | `group_order_status` | Who's in, what they ordered, who has paid, and whether the shop's order is ready or collected |
20
+ | `close_group_order` | Closes a group order early, as its organiser; the shop gets one combined order and the organiser its QR |
17
21
 
18
22
  ## Use it
19
23
 
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { type Fetch, type Payer } from "./wallet.js";
3
- export declare const VERSION = "0.2.0";
3
+ export declare const VERSION = "0.3.1";
4
4
  export interface PickupMcpOptions {
5
5
  /** The agentPickup shop this server orders from. */
6
6
  shopUrl: string;
@@ -11,6 +11,11 @@ export interface PickupMcpOptions {
11
11
  allowOtherShops?: boolean;
12
12
  /** An agentPickup directory (<host>/directory/v1/shops). Adds find_shops: shops near someone that sell what they want. */
13
13
  directoryUrl?: string;
14
+ /**
15
+ * Shops on other hosts a hosted server may still order from, such as agentPickup shops its directory has checked.
16
+ * Called with the shop's base URL.
17
+ */
18
+ trustedShop?: (shopBase: string) => boolean | Promise<boolean>;
14
19
  /** How requests reach the shop. Defaults to global fetch; a shop hosting its own server passes its app's fetch. */
15
20
  fetch?: Fetch;
16
21
  /** The wallet that pays. Without one, pay_order returns the price and pay link for another x402 client. */
package/dist/server.js CHANGED
@@ -4,16 +4,20 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
4
  import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
5
5
  import { z } from "zod";
6
6
  import { errorOf, usd } from "./wallet.js";
7
- export const VERSION = "0.2.0";
7
+ export const VERSION = "0.3.1";
8
8
  class ToolError extends Error {
9
9
  }
10
10
  const INSTRUCTIONS = `agentPickup lets you buy things online for the user to collect in person.
11
11
  0. find_shops (when available): shops near the user that sell what they want. Pass a shop's shop_url to the other tools.
12
12
  1. get_shop: see what the shop sells, its pickup location and how it takes payment.
13
13
  2. create_pickup_order: needs the user's email, where the shop sends the pickup QR.
14
- 3. pay_order: pays from the configured wallet in USDC over x402. Confirm the items and total with the user first.
14
+ 3. pay_order: pays from the configured wallet in USDC over x402. Where the shop takes cards, payment: "card" on
15
+ create_pickup_order gives a checkout link for the user to pay on instead. Confirm the items and total with the user first.
15
16
  4. Give the user the pass link and pickup code. They show the QR at the counter to collect.
16
- get_pickup_pass fetches the pass again later; order_status says whether it's ready or collected.`;
17
+ get_pickup_pass fetches the pass again later; order_status says whether it's ready or collected.
18
+ Group orders (a coffee run): start_group_order gives a code to share; each person's agent calls join_group_order and
19
+ pays its own share with pay_order; at closing time the shop gets one combined order and the organiser gets its QR.
20
+ group_order_status shows who's in; close_group_order closes it early.`;
17
21
  const money = (cents, currency) => new Intl.NumberFormat("en-US", { style: "currency", currency: currency.toUpperCase() }).format(cents / 100);
18
22
  const reply = (summary, data) => ({
19
23
  content: [{ type: "text", text: `${summary}\n\n${JSON.stringify(data, null, 2)}` }],
@@ -28,7 +32,7 @@ export function createPickupMcpServer(opts) {
28
32
  const homeUrl = new URL(opts.shopUrl);
29
33
  const home = shopBase(homeUrl);
30
34
  const doFetch = opts.fetch ?? ((req) => fetch(req));
31
- function shopFor(shopUrl) {
35
+ async function shopFor(shopUrl) {
32
36
  if (!shopUrl)
33
37
  return home;
34
38
  let url;
@@ -41,11 +45,14 @@ export function createPickupMcpServer(opts) {
41
45
  // Shops on this server's own host: the home shop and its venues.
42
46
  if (url.origin === homeUrl.origin)
43
47
  return shopBase(url);
44
- if (!opts.allowOtherShops)
45
- throw new ToolError(`This server orders from shops on ${homeUrl.origin} only.`);
46
- if (url.protocol !== "https:" && url.hostname !== "localhost")
47
- throw new ToolError("Shops must be served over https.");
48
- return shopBase(url);
48
+ if (opts.allowOtherShops || opts.trustedShop) {
49
+ if (url.protocol !== "https:" && url.hostname !== "localhost")
50
+ throw new ToolError("Shops must be served over https.");
51
+ if (opts.allowOtherShops || (await opts.trustedShop(shopBase(url))))
52
+ return shopBase(url);
53
+ throw new ToolError(`This server orders from shops on ${homeUrl.origin} and agentPickup shops its directory lists.`);
54
+ }
55
+ throw new ToolError(`This server orders from shops on ${homeUrl.origin} only.`);
49
56
  }
50
57
  async function call(shop, path, init) {
51
58
  const res = await doFetch(new Request(`${shop}${path}`, init));
@@ -105,6 +112,8 @@ export function createPickupMcpServer(opts) {
105
112
  s.distanceKm !== undefined ? `${s.distanceKm} km` : null,
106
113
  s.openNow === true ? "open now" : s.openNow === false ? "closed now" : null,
107
114
  s.testOnly ? "test shop, no real money" : null,
115
+ s.source?.kind === "listed" ? `listed by ${s.source.domain}` : null,
116
+ s.order?.via === "ucp" ? "orders through its UCP checkout" : s.order?.via === "web" ? "orders on its own website" : null,
108
117
  ].filter(Boolean);
109
118
  const items = s.items.slice(0, 3).map((i) => `${i.name} ${money(i.priceCents, s.currency)}`).join(", ");
110
119
  return `- ${s.name}${facts.length ? ` (${facts.join(", ")})` : ""}${s.location.address ? `, ${s.location.address}` : ""}${items ? `: ${items}` : ""}`;
@@ -118,6 +127,10 @@ export function createPickupMcpServer(opts) {
118
127
  openNow: s.openNow,
119
128
  testOnly: s.testOnly,
120
129
  payments: { x402: s.payments.x402?.network ?? null, test: s.payments.test },
130
+ listedBy: s.source?.kind === "listed" ? s.source.domain : null,
131
+ // agentpickup: use get_shop and create_pickup_order. ucp or web: order there instead.
132
+ orderVia: s.order?.via ?? "agentpickup",
133
+ ...(s.order?.via === "ucp" ? { ucpProfile: s.order.profile } : s.order?.via === "web" ? { orderUrl: s.order.url } : {}),
121
134
  items: s.items.map((i) => ({ id: i.id, name: i.name, price: money(i.priceCents, s.currency) })),
122
135
  moreItems: Math.max(0, s.itemCount - s.items.length),
123
136
  })),
@@ -130,7 +143,7 @@ export function createPickupMcpServer(opts) {
130
143
  inputSchema: { ...shopArg },
131
144
  annotations: { readOnlyHint: true, openWorldHint: true },
132
145
  }, guarded(async (args) => {
133
- const shop = shopFor(args.shop_url);
146
+ const shop = await shopFor(args.shop_url);
134
147
  const data = await call(shop, "/api/catalog");
135
148
  const merchant = data.merchant;
136
149
  const currency = String(data.currency ?? "usd");
@@ -141,33 +154,47 @@ export function createPickupMcpServer(opts) {
141
154
  description: i.description,
142
155
  }));
143
156
  const payments = data.payments;
157
+ const cards = Boolean(payments.square || payments.card);
158
+ const ways = [
159
+ ...(payments.x402 ? [`USDC over x402 on ${payments.x402.network}, paid by the agent`] : []),
160
+ ...(cards ? ["cards, paid by the user on a checkout link"] : []),
161
+ ...(payments.test ? ["test payments, with no money moving"] : []),
162
+ ];
144
163
  return reply(`${merchant.name}${merchant.location?.name ? `, collect at ${merchant.location.name}` : ""}. ` +
145
- (payments.x402
146
- ? `Takes USDC over x402 on ${payments.x402.network}.`
147
- : payments.test
164
+ (!ways.length
165
+ ? "Doesn't take agent payments."
166
+ : ways.length === 1 && payments.test
148
167
  ? "A test shop: orders are marked paid without money moving."
149
- : "Doesn't take agent payments."), { shop, merchant: merchant.name, location: merchant.location, currency, items, x402: payments.x402 ?? null, test: Boolean(payments.test) });
168
+ : `Takes ${ways.join("; ")}.`), { shop, merchant: merchant.name, location: merchant.location, currency, items, x402: payments.x402 ?? null, cards, test: Boolean(payments.test) });
150
169
  }));
151
170
  server.registerTool("create_pickup_order", {
152
171
  title: "Order for pickup",
153
172
  description: "Create an order to collect in person. Returns the order id and total; pay it with pay_order. " +
154
- "The shop emails the pickup QR to `email` once it's paid.",
173
+ "The shop emails the pickup QR to `email` once it's paid. Where the shop takes cards, `payment: \"card\"` " +
174
+ "returns a checkout link for the user to pay on instead.",
155
175
  inputSchema: {
156
176
  items: z
157
177
  .array(z.object({ id: z.string().describe("Item id from get_shop"), qty: z.number().int().min(1).max(20) }))
158
178
  .min(1),
159
179
  email: z.string().email().describe("The user's email. The pickup QR goes here."),
160
180
  name: z.string().max(100).optional().describe("Name for the order, shown to staff"),
181
+ payment: z
182
+ .enum(["agent", "card"])
183
+ .optional()
184
+ .describe("Who pays: agent (USDC over x402, or a test payment at a test shop) or card (the user pays on a checkout link). Default: agent where the shop takes it, else card."),
161
185
  ...shopArg,
162
186
  },
163
187
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
164
188
  }, guarded(async (args) => {
165
- const shop = shopFor(args.shop_url);
166
- // Pay over x402 where the shop takes it; a test shop marks the order paid straight away.
189
+ const shop = await shopFor(args.shop_url);
190
+ // The agent pays over x402 where the shop takes it, a test shop marks the order paid straight away, and a
191
+ // shop that takes cards gives the user a checkout link.
167
192
  const { payments } = (await call(shop, "/api/catalog"));
168
- const rail = payments.x402 ? "x402" : payments.test ? "test" : null;
193
+ const agentRail = payments.x402 ? "x402" : payments.test ? "test" : null;
194
+ const cardRail = payments.square ? "square" : payments.card ? "card" : null;
195
+ const rail = args.payment === "card" ? cardRail : args.payment === "agent" ? agentRail : (agentRail ?? cardRail);
169
196
  if (!rail)
170
- throw new ToolError("This shop doesn't take agent payments.");
197
+ throw new ToolError(args.payment === "card" ? "This shop doesn't take cards." : "This shop doesn't take agent payments.");
171
198
  const data = await call(shop, "/api/orders", {
172
199
  method: "POST",
173
200
  headers: { "Content-Type": "application/json" },
@@ -179,6 +206,10 @@ export function createPickupMcpServer(opts) {
179
206
  return reply(`Test order ${order.id}: ${order.items.map((i) => `${i.qty}× ${i.name}`).join(", ")}, ${money(order.totalCents, order.currency)}, ` +
180
207
  `marked paid with no money moving. The shop emails ${args.email} the receipt and pickup QR; the pass is at ${next.passUrl}.`, { shop, orderId: order.id, status: order.status, test: true, total: money(order.totalCents, order.currency), items: order.items, passUrl: next.passUrl });
181
208
  }
209
+ if (rail === "square" || rail === "card") {
210
+ return reply(`Order ${order.id}: ${order.items.map((i) => `${i.qty}× ${i.name}`).join(", ")}, ${money(order.totalCents, order.currency)}. ` +
211
+ `Give the user this link to pay by card: ${next.url}. Once they've paid, the shop emails ${args.email} the receipt and pickup QR.`, { shop, orderId: order.id, total: money(order.totalCents, order.currency), items: order.items, payBy: "card", checkoutUrl: next.url, collectBy: order.collectBy });
212
+ }
182
213
  return reply(`Order ${order.id}: ${order.items.map((i) => `${i.qty}× ${i.name}`).join(", ")}, ${money(order.totalCents, order.currency)}. ` +
183
214
  `Confirm with the user, then call pay_order.`, { shop, orderId: order.id, total: money(order.totalCents, order.currency), items: order.items, payUrl: next.url, collectBy: order.collectBy });
184
215
  }));
@@ -190,7 +221,15 @@ export function createPickupMcpServer(opts) {
190
221
  inputSchema: { order_id: z.string(), ...shopArg },
191
222
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
192
223
  }, guarded(async (args) => {
193
- const shop = shopFor(args.shop_url);
224
+ const shop = await shopFor(args.shop_url);
225
+ const status = (await call(shop, `/api/orders/${encodeURIComponent(args.order_id)}`));
226
+ if (status.order.rail === "square" || status.order.rail === "card") {
227
+ if (status.order.status !== "awaiting_payment")
228
+ return reply(`Order ${args.order_id} is already paid (${status.order.status}).`, { orderId: args.order_id, status: status.order.status });
229
+ return reply(status.checkoutUrl
230
+ ? `This order is paid by card: give the user ${status.checkoutUrl} to pay on.`
231
+ : "This order is paid by card, on the checkout link create_pickup_order returned.", { orderId: args.order_id, payBy: "card", checkoutUrl: status.checkoutUrl ?? null });
232
+ }
194
233
  const payUrl = `${shop}/api/orders/${encodeURIComponent(args.order_id)}/pay`;
195
234
  if (!opts.payer) {
196
235
  const res = await doFetch(new Request(payUrl, { method: "POST" }));
@@ -216,7 +255,7 @@ export function createPickupMcpServer(opts) {
216
255
  inputSchema: { order_id: z.string(), ...shopArg },
217
256
  annotations: { readOnlyHint: true, openWorldHint: true },
218
257
  }, guarded(async (args) => {
219
- const shop = shopFor(args.shop_url);
258
+ const shop = await shopFor(args.shop_url);
220
259
  const { order } = (await call(shop, `/api/orders/${encodeURIComponent(args.order_id)}`));
221
260
  const words = {
222
261
  awaiting_payment: "is waiting for payment",
@@ -236,13 +275,97 @@ export function createPickupMcpServer(opts) {
236
275
  }, guarded(async (args) => {
237
276
  if (!opts.payer)
238
277
  throw new ToolError("No wallet is set up here. The pass was emailed to the buyer when the order was paid.");
239
- const shop = shopFor(args.shop_url);
278
+ const shop = await shopFor(args.shop_url);
240
279
  const res = await opts.payer.signIn(`${shop}/api/orders/${encodeURIComponent(args.order_id)}/pass`, doFetch);
241
280
  if (!res.ok)
242
281
  throw new ToolError(await errorOf(res, `The shop answered ${res.status}.`));
243
282
  const pass = (await res.json());
244
283
  return reply(`Pickup pass: ${pass.passUrl}, pickup code ${pass.pickupCode}.`, pass);
245
284
  }));
285
+ const closesIn = (g) => {
286
+ const minutes = Math.max(0, Math.round((g.closesAt - Date.now()) / 60_000));
287
+ return g.status === "open" ? `closes in ${minutes} min` : g.status === "sent" ? "closed and sent to the shop" : "cancelled";
288
+ };
289
+ const groupSummary = (g) => {
290
+ const paid = g.members.filter((m) => m.status !== "awaiting_payment" && m.status !== "cancelled");
291
+ return `${g.title} (code ${g.code}), ${closesIn(g)}: ${paid.length} of ${g.members.length} paid, ${money(g.paidCents, g.currency)} so far.`;
292
+ };
293
+ server.registerTool("start_group_order", {
294
+ title: "Start a group order",
295
+ description: "Start a group order (a coffee run) at a shop. Returns a code to share: each person's agent joins with it and pays for " +
296
+ "their own items. When it closes, the shop gets one combined order and the organiser is emailed its pickup QR.",
297
+ inputSchema: {
298
+ organiser_name: z.string().min(1).max(60).describe("Who collects, shown to staff"),
299
+ organiser_email: z.string().email().describe("Where the group's pickup QR goes"),
300
+ title: z.string().max(60).optional().describe('e.g. "Friday coffee run"'),
301
+ closes_in_minutes: z.number().int().min(5).max(240).optional().describe("Default 15"),
302
+ ...shopArg,
303
+ },
304
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
305
+ }, guarded(async (args) => {
306
+ const shop = await shopFor(args.shop_url);
307
+ const data = (await call(shop, "/api/groups", {
308
+ method: "POST",
309
+ headers: { "Content-Type": "application/json" },
310
+ body: JSON.stringify({ name: args.organiser_name, email: args.organiser_email, title: args.title, closesInMinutes: args.closes_in_minutes }),
311
+ }));
312
+ return reply(`Started ${data.group.title}: share code ${data.group.code}. Everyone's agent joins with join_group_order and the code; it ${closesIn(data.group)}. ` +
313
+ `Keep organiser_key to close it early.`, { shop, code: data.group.code, closesAt: data.group.closesAt, organiser_key: data.organiserKey });
314
+ }));
315
+ server.registerTool("join_group_order", {
316
+ title: "Join a group order",
317
+ description: "Add the user's items to a group order with its code. Returns the order id; pay it with pay_order before the group closes. " +
318
+ "The organiser collects everything, so the user gets a receipt, not a QR.",
319
+ inputSchema: {
320
+ code: z.string().min(4).max(12).describe("The group's code"),
321
+ items: z.array(z.object({ id: z.string().describe("Item id from get_shop"), qty: z.number().int().min(1).max(20) })).min(1),
322
+ email: z.string().email().describe("The user's email, for their receipt"),
323
+ name: z.string().min(1).max(60).describe("The user's name, shown to staff on their items"),
324
+ ...shopArg,
325
+ },
326
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
327
+ }, guarded(async (args) => {
328
+ const shop = await shopFor(args.shop_url);
329
+ const { payments } = (await call(shop, "/api/catalog"));
330
+ const rail = payments.x402 ? "x402" : payments.test ? "test" : null;
331
+ if (!rail)
332
+ throw new ToolError("This shop doesn't take agent payments.");
333
+ const data = (await call(shop, `/api/groups/${encodeURIComponent(args.code)}/orders`, {
334
+ method: "POST",
335
+ headers: { "Content-Type": "application/json" },
336
+ body: JSON.stringify({ items: args.items, email: args.email, name: args.name, rail }),
337
+ }));
338
+ const what = `${data.order.items.map((i) => `${i.qty}× ${i.name}`).join(", ")}, ${money(data.order.totalCents, data.order.currency)}`;
339
+ return reply(rail === "test"
340
+ ? `Added to ${data.group.title}: ${what}, paid with a test payment (no money moved). ${data.group.organiser} collects it.`
341
+ : `Added to ${data.group.title}: ${what}. Confirm with the user, then pay it with pay_order (order ${data.order.id}) before the group closes.`, { shop, orderId: data.order.id, group: groupSummary(data.group), payUrl: data.next.url ?? null, test: rail === "test" });
342
+ }));
343
+ server.registerTool("group_order_status", {
344
+ title: "Check a group order",
345
+ description: "Who's in a group order, what they ordered, who has paid, and whether it has closed and been collected.",
346
+ inputSchema: { code: z.string().min(4).max(12), ...shopArg },
347
+ annotations: { readOnlyHint: true, openWorldHint: true },
348
+ }, guarded(async (args) => {
349
+ const shop = await shopFor(args.shop_url);
350
+ const { group } = (await call(shop, `/api/groups/${encodeURIComponent(args.code)}`));
351
+ return reply(groupSummary(group) + (group.combined ? ` The shop's order is ${group.combined.status}.` : ""), group);
352
+ }));
353
+ server.registerTool("close_group_order", {
354
+ title: "Close a group order now",
355
+ description: "Close a group order early, as its organiser. Unpaid shares are left out; the shop gets the rest as one order.",
356
+ inputSchema: { code: z.string().min(4).max(12), organiser_key: z.string().min(8), ...shopArg },
357
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
358
+ }, guarded(async (args) => {
359
+ const shop = await shopFor(args.shop_url);
360
+ const { group } = (await call(shop, `/api/groups/${encodeURIComponent(args.code)}/close`, {
361
+ method: "POST",
362
+ headers: { "Content-Type": "application/json" },
363
+ body: JSON.stringify({ organiserKey: args.organiser_key }),
364
+ }));
365
+ return reply(group.status === "sent"
366
+ ? `Closed: ${groupSummary(group)} The shop has the combined order, and ${group.organiser}'s pickup QR is on its way by email.`
367
+ : `Closed with nobody paid, so the group order was cancelled.`, group);
368
+ }));
246
369
  return server;
247
370
  }
248
371
  /** A Streamable HTTP endpoint (stateless, JSON responses) for hosting the server, e.g. at /mcp. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentpickup/mcp",
3
- "version": "0.2.0",
4
- "description": "MCP server for agentPickup: let an AI agent find pickup shops near its user, order, pay over x402, and hand its user the QR to collect in person.",
3
+ "version": "0.3.1",
4
+ "description": "MCP server for agentPickup: let an AI agent find pickup shops near its user, order, pay by card or in USDC over x402, and hand its user the QR to collect in person.",
5
5
  "mcpName": "io.github.dav3trad3r/agentpickup",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",