@onedollarcomputer/odc-mcp 0.3.0 → 0.4.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.
Files changed (2) hide show
  1. package/bin.js +56 -28
  2. package/package.json +1 -1
package/bin.js CHANGED
@@ -35,7 +35,7 @@ const API_ORIGIN = readApiOrigin();
35
35
  // Function below died with the Oct 2026 billing closure (500/503). NOTE: this
36
36
  // is a cloudflared quick-tunnel URL and CHANGES when that tunnel restarts;
37
37
  // read the current one from /data/odc-api/tunnel-api.log on the box.
38
- const MARITIME_API = "https://reaction-icons-lined-delays.trycloudflare.com";
38
+ const MARITIME_API = "https://executives-loop-seattle-aware.trycloudflare.com";
39
39
 
40
40
  const DEFAULT_API =
41
41
  process.env.ODC_CURRICULUM_API ||
@@ -121,7 +121,13 @@ async function api(method, apiPath, { token, body, firebaseIdToken } = {}) {
121
121
  data = { raw: text };
122
122
  }
123
123
  if (!res.ok) {
124
- const err = new Error(data.error || res.statusText || `HTTP ${res.status}`);
124
+ let message = data.error || res.statusText || `HTTP ${res.status}`;
125
+ // Speak agent: a rejected token is a reconnect, not a mystery.
126
+ if (res.status === 401 && token) {
127
+ message =
128
+ "That connection is no longer valid (expired or revoked by the user). Call odc_connect to reconnect — the user approves again with Google.";
129
+ }
130
+ const err = new Error(message);
125
131
  err.status = res.status;
126
132
  err.data = data;
127
133
  // Try next host on network-ish failures only; 4xx from API is final
@@ -138,7 +144,7 @@ async function api(method, apiPath, { token, body, firebaseIdToken } = {}) {
138
144
  if (err && err.status && err.status < 500 && err.status !== 404) throw err;
139
145
  }
140
146
  }
141
- throw lastErr || new Error("All curriculum API hosts failed");
147
+ throw lastErr || new Error("Could not reach the One Dollar Computer service — check the connection and try again in a moment.");
142
148
  }
143
149
 
144
150
  function textResult(obj) {
@@ -165,20 +171,40 @@ function loadProjectBrief() {
165
171
  "Firmware must be complete Simple Rust: use odc::*; fn main() { … }",
166
172
  "Never read_button() / pin 13 / BUTTON — bootloader only",
167
173
  "New projects are private; project_publish is irreversible",
168
- "Pair once with curriculum_pair (Agent → Copy on /project/ or /c/)"
174
+ "Connect once with odc_connect (the user approves with Google); an Agent link from the site with curriculum_pair also works"
169
175
  ],
170
176
  aiDocs
171
177
  };
172
178
  }
173
179
 
174
- const server = new McpServer({
175
- name: "odc-curriculum",
176
- version: "0.3.0"
177
- });
180
+ const server = new McpServer(
181
+ {
182
+ name: "odc-curriculum",
183
+ version: "0.4.0"
184
+ },
185
+ {
186
+ instructions:
187
+ "One Dollar Computer MCP: work with the user's firmware projects (Simple Rust) and curriculum lessons on their One Dollar Computer account. " +
188
+ "Start by checking curriculum_status. If it says paired: false, call odc_connect and show the user the approveUrl — they open it in their own browser, sign in with Google, and approve. Never ask the user for a password, and never fetch the approveUrl yourself. " +
189
+ "Firmware rules: complete Simple Rust programs (use odc::*; fn main), pins by their printed numbers 0–19, LED is pin 19, never pin 13 or read_button() (bootloader only). " +
190
+ "project_publish is irreversible — confirm with the user before calling it. odc_compile needs no pairing. " +
191
+ "If a call answers that the connection is no longer valid, reconnect with odc_connect."
192
+ }
193
+ );
194
+
195
+ // One friendly, consistent answer for every not-connected call: agents
196
+ // should always know the exact next step instead of guessing.
197
+ function notPaired() {
198
+ return textResult({
199
+ ok: false,
200
+ error: "Not connected yet.",
201
+ next: "Call odc_connect — it returns an approval link to show the user (they sign in with Google and approve; a first sign-in creates their account). If the user already gave you an Agent link from the website, call curriculum_pair with it instead."
202
+ });
203
+ }
178
204
 
179
205
  server.tool(
180
206
  "curriculum_pair",
181
- "Connect to ODC (curriculum lessons AND firmware projects). Pass the Agent link from /c/ or /project/ (while signed in). REQUIRED: call this tool — do NOT fetch the URL as a webpage, do NOT scrape onedollarcomputer.com, do NOT create local files. After pairing: for lessons use curriculum_agent_brief; for firmware projects use project_brief then project_get / project_update. Board firmware must be Simple Rust (use odc::*;).",
207
+ "Connect with an Agent link the user copied from the website (the manual alternative — most users should just use odc_connect, which needs no link). Pass the full link or its code. Do NOT fetch the link as a webpage and do NOT scrape the site. After pairing: curriculum_agent_brief for lessons, project_brief for firmware projects.",
182
208
  {
183
209
  connect_url_or_code: z.string().describe("Full Agent link or the connect code")
184
210
  },
@@ -253,7 +279,7 @@ server.tool(
253
279
  "odc_connect",
254
280
  "Connect this agent to the user's One Dollar Computer account — the EASY first-time flow (no link to copy from the site). Call this tool, then show the user the approveUrl from the result: they open it in any browser, sign in with Google (a first sign-in creates their account), and approve. This tool waits for the approval and stores the pairing token itself. Do NOT fetch the approveUrl as a webpage. After connecting: for lessons use curriculum_agent_brief; for firmware projects use project_brief then project_get / project_update. Board firmware must be Simple Rust (use odc::*;).",
255
281
  {
256
- wait_seconds: z.number().optional().describe("How long to wait for the user to approve (default 300, max 600). If the wait ends first, the result is status pending with the approveUrl — show it to the user and call odc_connect again later is NOT needed; the same tool can be called again to keep waiting only while the link is fresh (10 minutes).")
282
+ wait_seconds: z.number().optional().describe("How long to wait for the user to approve (default 300, max 600). If the wait ends first, the result is status pending with the approveUrl — show it to the user and call odc_connect again later is NOT needed; the same tool can be called again to keep waiting only while the link is fresh (30 minutes).")
257
283
  },
258
284
  async ({ wait_seconds }) => {
259
285
  const waitMs = Math.min(Math.max(Number(wait_seconds ?? 300) || 0, 0), 600) * 1000;
@@ -314,7 +340,7 @@ server.tool(
314
340
  status: "pending",
315
341
  approveUrl,
316
342
  message:
317
- "Not approved yet. Show the user this approveUrl: they open it in any browser, sign in with Google, and approve. The link stays fresh for 10 minutes from the start of this call."
343
+ "Not approved yet. Show the user this approveUrl: they open it in any browser, sign in with Google, and approve. The link stays fresh for 30 minutes from the start of this call."
318
344
  });
319
345
  }
320
346
  );
@@ -490,16 +516,20 @@ server.tool(
490
516
  server.registerTool(
491
517
  "curriculum_status",
492
518
  {
493
- description: "Show whether an agent token is stored and the API base URL."
519
+ description: "Check the connection state: whether this agent is connected to a One Dollar Computer account, and which API it talks to. Call this first when unsure — it never changes anything."
494
520
  },
495
521
  async () => {
496
522
  const token = getToken();
497
- return textResult({
523
+ const out = {
498
524
  paired: !!token,
499
525
  api: DEFAULT_API,
500
526
  tokenPath: TOKEN_PATH,
501
527
  tokenPreview: token ? `${token.slice(0, 16)}…` : null
502
- });
528
+ };
529
+ if (!token) {
530
+ out.next = "Call odc_connect — it returns an approval link to show the user (they sign in with Google and approve).";
531
+ }
532
+ return textResult(out);
503
533
  }
504
534
  );
505
535
 
@@ -507,7 +537,7 @@ server.registerTool(
507
537
  "curriculum_agent_brief",
508
538
  {
509
539
  description:
510
- "Return the curriculum authoring contract: HTML5 teaching UI is free; board firmware must be Simple Rust (use odc::*;). Call after curriculum_pair before writing lessons."
540
+ "Return the curriculum authoring contract: HTML5 teaching UI is free; board firmware must be Simple Rust (use odc::*;). Call after connecting (odc_connect or curriculum_pair) before writing lessons."
511
541
  },
512
542
  async () => textResult({
513
543
  docsUrl: "https://onedollarcomputer.com/c/AGENT_LESSONS.md",
@@ -526,9 +556,7 @@ server.registerTool(
526
556
  async () => {
527
557
  const token = getToken();
528
558
  if (!token) {
529
- return textResult({
530
- error: "Not paired. Ask the user for a Connect agent link, then call curriculum_pair."
531
- });
559
+ return notPaired();
532
560
  }
533
561
  const data = await api("GET", "/lessons", { token });
534
562
  return textResult(data);
@@ -554,7 +582,7 @@ server.tool(
554
582
  async (args) => {
555
583
  const token = getToken();
556
584
  if (!token) {
557
- return textResult({ error: "Not paired. Use curriculum_pair first." });
585
+ return notPaired();
558
586
  }
559
587
  const body = { title: args.title };
560
588
  if (args.overview !== undefined) body.overview = args.overview;
@@ -578,7 +606,7 @@ server.tool(
578
606
  async ({ lesson_id }) => {
579
607
  const token = getToken();
580
608
  if (!token) {
581
- return textResult({ error: "Not paired. Use curriculum_pair first." });
609
+ return notPaired();
582
610
  }
583
611
  const data = await api("GET", `/lessons/${encodeURIComponent(lesson_id)}`, { token });
584
612
  return textResult(data);
@@ -616,7 +644,7 @@ server.tool(
616
644
  async (args) => {
617
645
  const token = getToken();
618
646
  if (!token) {
619
- return textResult({ error: "Not paired. Use curriculum_pair first." });
647
+ return notPaired();
620
648
  }
621
649
  const body = {};
622
650
  if (args.title !== undefined) body.title = args.title;
@@ -645,7 +673,7 @@ server.registerTool(
645
673
  "project_brief",
646
674
  {
647
675
  description:
648
- "Firmware project authoring contract (Simple Rust, pin 13 warning, publish rules). Call after curriculum_pair before project_create / project_update."
676
+ "Firmware project authoring contract (Simple Rust, pin 13 warning, publish rules). Call after connecting (odc_connect or curriculum_pair) before project_create / project_update."
649
677
  },
650
678
  async () => textResult(loadProjectBrief())
651
679
  );
@@ -658,7 +686,7 @@ server.registerTool(
658
686
  async () => {
659
687
  const token = getToken();
660
688
  if (!token) {
661
- return textResult({ error: "Not paired. Use curriculum_pair first (Agent → Copy on /project/)." });
689
+ return notPaired();
662
690
  }
663
691
  const data = await api("GET", "/projects", { token });
664
692
  return textResult(data);
@@ -678,7 +706,7 @@ server.registerTool(
678
706
  async (args) => {
679
707
  const token = getToken();
680
708
  if (!token) {
681
- return textResult({ error: "Not paired. Use curriculum_pair first." });
709
+ return notPaired();
682
710
  }
683
711
  const body = { name: args.name };
684
712
  if (args.code !== undefined) body.code = args.code;
@@ -698,7 +726,7 @@ server.registerTool(
698
726
  async ({ project_id }) => {
699
727
  const token = getToken();
700
728
  if (!token) {
701
- return textResult({ error: "Not paired. Use curriculum_pair first." });
729
+ return notPaired();
702
730
  }
703
731
  const data = await api("GET", `/projects/${encodeURIComponent(project_id)}`, { token });
704
732
  return textResult(data);
@@ -721,7 +749,7 @@ server.registerTool(
721
749
  async (args) => {
722
750
  const token = getToken();
723
751
  if (!token) {
724
- return textResult({ error: "Not paired. Use curriculum_pair first." });
752
+ return notPaired();
725
753
  }
726
754
  const body = {};
727
755
  if (args.name !== undefined) body.name = args.name;
@@ -748,7 +776,7 @@ server.registerTool(
748
776
  async ({ project_id }) => {
749
777
  const token = getToken();
750
778
  if (!token) {
751
- return textResult({ error: "Not paired. Use curriculum_pair first." });
779
+ return notPaired();
752
780
  }
753
781
  const data = await api("POST", `/projects/${encodeURIComponent(project_id)}/publish`, {
754
782
  token,
@@ -770,7 +798,7 @@ server.registerTool(
770
798
  async ({ project_id }) => {
771
799
  const token = getToken();
772
800
  if (!token) {
773
- return textResult({ error: "Not paired. Use curriculum_pair first." });
801
+ return notPaired();
774
802
  }
775
803
  const data = await api("POST", `/projects/${encodeURIComponent(project_id)}/fork`, {
776
804
  token,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onedollarcomputer/odc-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "MCP server for One Dollar Computer \u2014 curriculum lessons and firmware projects",
5
5
  "type": "module",
6
6
  "bin": {