@shipvo/mcp 0.0.2 → 0.0.4

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
@@ -8,9 +8,9 @@ Lets AI agents (Claude, Cursor, Claude Code, PiPilot…) **use a Shipvo app with
8
8
  "env": { "PN_SIM": "http://localhost:4545", "PN_OWNER_TOKEN": "…optional…" } } } }
9
9
  ```
10
10
 
11
- Start the simulator first (`node sim/server.mjs` in the app, or `shipvo sim` soon). The hosted version at `sim.shipvo.dev` needs no local setup.
11
+ Start the simulator first (`shipvo sim` in the app). The hosted version needs no local setup: `{ "url": "https://<host>/mcp/<key>" }`.
12
12
 
13
- Tools: `list_apps`, `open_app`, `screen`, `tap`, `type`, `scroll`, `back`, `screenshot`, `set_device`, `push_notification`, `device_log`, `end_session`, `owner_describe`, `owner_command`.
13
+ Tools: `list_apps`, `open_app`, `screen`, `tap`, `type`, `scroll`, `back`, `screenshot`, `set_device`, `push_notification`, `notifications`, `open_notification`, `device_log`, `end_session`, `owner_describe`, `owner_command`.
14
14
 
15
15
  Native features work with no phone: the simulated device (see `@shipvo/device`) shows permission dialogs, the camera, the fingerprint prompt, payment prompts, notification banners and the share sheet as real dialogs in the tree; `set_device` decides what the phone has (location, a barcode in view, whether the fingerprint matches, whether a payment is approved, network off).
16
16
 
package/dist/server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  // Shipvo MCP: agents use Shipvo apps with no phone.
3
- // PN_SIM=http://localhost:4545 PN_CONTROL=https://purenative-control.purenative.workers.dev PN_OWNER_TOKEN=... shipvo-mcp
3
+ // PN_SIM=http://localhost:4545 PN_CONTROL=https://api.shipvo.dev PN_OWNER_TOKEN=... shipvo-mcp
4
4
  // Remote (Streamable HTTP, what Claude, ChatGPT, Cursor connect to over the network):
5
5
  // shipvo-mcp --http 8787 with PN_API_KEYS="key1,key2" (Authorization: Bearer <key>) → POST/GET/DELETE /mcp
6
6
  // Tools: list_apps, open_app, screen, tap, type, scroll, back, screenshot, end_session (UI simulator);
@@ -13,7 +13,7 @@ import { randomUUID } from "node:crypto";
13
13
  import { readFileSync } from "node:fs";
14
14
  import { z } from "zod";
15
15
  const SIM = (process.env.PN_SIM ?? "http://localhost:4545").replace(/\/$/, "");
16
- const CONTROL = (process.env.PN_CONTROL ?? "https://purenative-control.purenative.workers.dev").replace(/\/$/, "");
16
+ const CONTROL = (process.env.PN_CONTROL ?? "https://api.shipvo.dev").replace(/\/$/, "");
17
17
  const OWNER_TOKEN = process.env.PN_OWNER_TOKEN ?? "";
18
18
  // Apps this server can open. Hosted: the account's apps. Local: one app served by the simulator.
19
19
  const APPS = process.env.PN_APPS ? JSON.parse(process.env.PN_APPS)
@@ -27,16 +27,37 @@ async function sim(path, body) {
27
27
  const sessions = new Map();
28
28
  const text = (t) => ({ content: [{ type: "text", text: t }] });
29
29
  const result = (sid, r) => { const s = sessions.get(sid); if (s)
30
- s.steps++; return text(r.ok ? (r.screen ?? "") : `Error: ${r.error}\n\nScreen now:\n${r.screen ?? ""}`); };
31
- const need = (sid) => { if (!sessions.has(sid))
32
- throw new Error(`no session "${sid}". Call open_app first.`); };
33
- function makeServer() {
34
- const server = new McpServer({ name: "shipvo", version: "0.0.1" }, { instructions: `You can use Shipvo apps the way a person uses them on a phone, without a phone.
30
+ s.steps++; return text(r.ok ? (r.screen ?? "") : `Error: ${r.error}${/no session/.test(String(r.error)) ? " (sessions expire with the phone; call open_app again)" : ""}\n\nScreen now:\n${r.screen ?? ""}`); };
31
+ // Sessions live in the simulator; this map only tracks step counts. A client may reconnect between calls
32
+ // (ChatGPT does), so an unknown id is forwarded and the simulator answers if it knows it.
33
+ const need = (_sid) => { };
34
+ function makeServer(ctx = {}) {
35
+ const server = new McpServer({ name: "shipvo", version: "0.0.4" }, { instructions: `You can use Shipvo apps the way a person uses them on a phone, without a phone.
35
36
  Call open_app to get a session and the first screen. The screen is an accessibility tree: every button, field and text, with a [ref=eN]. Act with tap/type/scroll/back using refs, and read the screen that comes back each time.
36
37
  Only what is on screen is listed, like a phone: a horizontal product rail shows a few items, so "scroll right" on the rail (its ref) to see more; "scroll down" the page for the rest.
37
38
  System sheets (permission dialogs, the camera, the fingerprint prompt, payment prompts, notification banners, the share sheet) appear in the tree like any other screen: answer them by tapping, as a person would. Use set_device to decide what the phone has (a barcode in front of the camera, a location, whether the fingerprint matches, whether the payment is approved, network off) before the app asks for it.
38
39
  Finish a task by checking the final screen says what you expected (for example "Order placed"). Call end_session when done to get a report.` });
39
- server.tool("list_apps", "Apps this server can open, with what each one does.", {}, async () => text(Object.entries(APPS).map(([id, a]) => `${id}: ${a.name}. ${a.description}`).join("\n")));
40
+ // ctx.app: the app(s) this key opens, comma-separated (the beta app plus any the key owner has registered).
41
+ const keyApps = ctx.app ? ctx.app.split(",").map((s) => s.trim()).filter(Boolean) : null;
42
+ const allowed = (id) => (keyApps ? keyApps.includes(id) : !!APPS[id]);
43
+ server.tool("list_apps", "Apps this server can open, with what each one does. Optional query filters by name, description or category (e.g. 'shop', 'douala').", { query: z.string().optional() }, async ({ query }) => {
44
+ const ids = keyApps ?? Object.keys(APPS);
45
+ const q = (query ?? "").toLowerCase();
46
+ let dir = {};
47
+ try {
48
+ const r = await fetch(`${CONTROL}/apps/public${q ? `?q=${encodeURIComponent(q)}` : ""}`);
49
+ if (r.ok)
50
+ for (const a of (await r.json()).apps)
51
+ dir[a.app_id] = a;
52
+ }
53
+ catch { }
54
+ const lines = ids.map((id) => {
55
+ const d = dir[id] ?? APPS[id];
56
+ const desc = d ? `${d.name}. ${d.description}${"category" in d ? ` [${d.category}]` : ""}` : `published with shipvo`;
57
+ return q && !`${id} ${desc}`.toLowerCase().includes(q) ? null : `${id}: ${desc} (open_app("${id}@latest"))`;
58
+ }).filter(Boolean);
59
+ return text(lines.join("\n") || `no apps match "${query}"`);
60
+ });
40
61
  server.tool("open_app", "Open an app in a fresh phone-sized session and return its first screen.", {
41
62
  app: z.string().describe("App id from list_apps, optionally with a release: 'tide' (local build), 'tide@latest' or 'tide@r13' (the published release phones run)"),
42
63
  session: z.string().optional().describe("Session name (default: generated). One session is one phone."),
@@ -44,13 +65,20 @@ Finish a task by checking the final screen says what you expected (for example "
44
65
  dark: z.boolean().optional().describe("Dark mode"),
45
66
  }, async ({ app, session, seed_cart, dark }) => {
46
67
  const id = app.split("@")[0];
47
- if (!APPS[id])
48
- throw new Error(`unknown app "${id}". Apps: ${Object.keys(APPS).join(", ")}`);
68
+ if (!allowed(id))
69
+ throw new Error(keyApps ? `this key opens: ${keyApps.join(", ")}` : `unknown app "${id}". Apps: ${Object.keys(APPS).join(", ")}`);
70
+ if (ctx.scope === "read")
71
+ throw new Error("this key is read-only: it cannot open sessions");
49
72
  const sid = session ?? `${id}-${Date.now().toString(36)}`;
50
73
  const r = await sim("/session", { session: sid, app, seed_cart, dark });
51
74
  sessions.set(sid, { app: id, steps: 0, startedAt: Date.now() });
52
75
  return text(`session: ${sid}\napp: ${id} release: ${r.release ?? "local"}\n\n${r.screen ?? ""}`);
53
76
  });
77
+ server.tool("list_sessions", "Open simulator sessions (phones) on this server: id, app, release and when each started. Use to resume after a reconnect.", {}, async () => {
78
+ const r = await sim("/sessions", {});
79
+ const rows = (r.sessions ?? []).filter((s) => !keyApps || keyApps.includes(s.app));
80
+ return text(rows.length ? rows.map((s) => `${s.session}: ${s.app} release ${s.release}${s.started_at ? ` since ${s.started_at}` : ""}`).join("\n") : "no open sessions");
81
+ });
54
82
  const sid = z.string().describe("Session from open_app");
55
83
  const ref = z.string().regex(/^e\d+$/).describe("Element ref from the screen, e.g. e42");
56
84
  server.tool("screen", "The current screen as an accessibility tree with refs.", { session: sid }, async ({ session }) => { need(session); return result(session, await sim("/act", { session, action: "screen" })); });
@@ -76,11 +104,13 @@ Finish a task by checking the final screen says what you expected (for example "
76
104
  online: z.boolean().optional(),
77
105
  }, async ({ session, ...device }) => { need(session); return result(session, await sim("/act", { session, action: "set_device", device })); });
78
106
  server.tool("push_notification", "Deliver a push notification to the simulated phone; it appears as a banner the agent can tap.", { session: sid, title: z.string(), body: z.string(), data: z.record(z.unknown()).optional() }, async ({ session, title, body, data }) => { need(session); return result(session, await sim("/act", { session, action: "push_notification", title, body, data })); });
107
+ server.tool("notifications", "The notification shade: notifications delivered to the simulated phone in this session (their banners vanish after 5 s, like a heads-up on a real phone).", { session: sid }, async ({ session }) => { need(session); return text(JSON.stringify((await sim("/act", { session, action: "notifications" })).notifications ?? [], null, 2)); });
108
+ server.tool("open_notification", "Tap a notification from the shade (newest if no id is given): the app handles it exactly as if its banner was tapped.", { session: sid, id: z.string().optional() }, async ({ session, id }) => { need(session); return result(session, await sim("/act", { session, action: "open_notification", id })); });
79
109
  server.tool("device_log", "What the app did with the device in this session: permission prompts and answers, location reads, scans, fingerprint checks, payments, notifications, shares.", { session: sid }, async ({ session }) => { need(session); const r = await sim("/act", { session, action: "device_log" }); return text(JSON.stringify({ note: "Everything here is simulated: no real biometric check or money movement took place.", capabilities: r.capabilities, log: r.log ?? [] }, null, 2)); });
80
110
  server.tool("device_reset", "Put the simulated phone back to a known state (permissions undetermined, default location, nothing in front of the camera, log cleared), optionally with a new profile.", { session: sid, platform: z.enum(["android", "ios"]).optional(), api: z.number().optional() }, async ({ session, ...device }) => { need(session); return result(session, await sim("/act", { session, action: "device_reset", device })); });
81
111
  server.tool("end_session", "Close the session and get a report: steps taken, and the orders the app sent to its backend during the session.", { session: sid }, async ({ session }) => {
82
112
  need(session);
83
- const s = sessions.get(session);
113
+ const s = sessions.get(session) ?? { app: session.split("-")[0], steps: 0, startedAt: Date.now() };
84
114
  sessions.delete(session);
85
115
  let orders = [];
86
116
  try {
@@ -95,9 +125,14 @@ Finish a task by checking the final screen says what you expected (for example "
95
125
  return text(await r.text());
96
126
  });
97
127
  server.tool("owner_command", "Run an owner command against the live app (changes are audited; `publish` makes them live on every phone within seconds).", { app: z.string(), command: z.string(), args: z.record(z.unknown()).optional() }, async ({ app, command, args }) => {
98
- if (!OWNER_TOKEN)
99
- throw new Error("PN_OWNER_TOKEN is not set: owner commands are disabled.");
100
- const r = await fetch(`${CONTROL}/app/${app}/api/command`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${OWNER_TOKEN}` }, body: JSON.stringify({ command, args: args ?? {} }) });
128
+ if (ctx.scope && ctx.scope !== "owner")
129
+ throw new Error(`this key has scope "${ctx.scope}": owner commands need an owner key`);
130
+ if (keyApps && !keyApps.includes(app))
131
+ throw new Error(`this key is for: ${keyApps.join(", ")}`);
132
+ const token = ctx.ownerToken || OWNER_TOKEN;
133
+ if (!token)
134
+ throw new Error("owner commands are not enabled on this server.");
135
+ const r = await fetch(`${CONTROL}/app/${app}/api/command`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${token}` }, body: JSON.stringify({ name: command, args: args ?? {} }) });
101
136
  return text(await r.text());
102
137
  });
103
138
  return server;
@@ -140,8 +175,10 @@ else {
140
175
  transport.onclose = () => { for (const [id, t] of transports)
141
176
  if (t === transport)
142
177
  transports.delete(id); };
143
- // One McpServer per client connection, same tools.
144
- await makeServer().connect(transport);
178
+ // One McpServer per client connection. Behind sim.shipvo.dev the Worker has checked the key and says which
179
+ // app and scope it grants; locally there are no such headers and every app is allowed.
180
+ const scope = req.headers["x-shipvo-scope"];
181
+ await makeServer({ app: req.headers["x-shipvo-app"] || undefined, publicApps: req.headers["x-shipvo-public"] || undefined, scope, ownerToken: req.headers["x-shipvo-owner-token"] || undefined }).connect(transport);
145
182
  }
146
183
  let body = undefined;
147
184
  if (req.method === "POST") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipvo/mcp",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "MCP server that lets AI agents open, see and operate Shipvo apps without a phone: a phone-sized simulator of the real app, plus the app's typed commands and owner API.",