@onedollarcomputer/odc-mcp 0.0.0-stage → 0.3.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.
- package/AGENT_LESSONS.md +149 -0
- package/README.md +16 -2
- package/api-origin.json +3 -0
- package/bin.js +784 -0
- package/package.json +23 -4
package/AGENT_LESSONS.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Learn Physical AI — lesson authoring (One Dollar Computer)
|
|
2
|
+
|
|
3
|
+
For **agents** (Codex, Cursor MCP, curl) building **Physical AI** curriculum.
|
|
4
|
+
Teachers only paste the Agent link and describe the Physical AI lesson in natural language.
|
|
5
|
+
|
|
6
|
+
## Non-negotiable rule
|
|
7
|
+
|
|
8
|
+
**Teaching UI is free. Firmware is not.**
|
|
9
|
+
|
|
10
|
+
- You may invent any HTML5 experience the instructor wants (slides, game, block-like UI, quiz, “keyboard”, robot metaphor, …).
|
|
11
|
+
- If the lesson uses the **One Dollar Computer** (virtual board or real Upload), you **must** also produce **complete Simple Rust** that compiles with the existing ODC toolchain.
|
|
12
|
+
- Do **not** invent a second compiler language for the board. Blockly / Python-in-the-page / custom DSLs are **only** pedagogy; the board path is always Rust.
|
|
13
|
+
|
|
14
|
+
Canonical firmware shape:
|
|
15
|
+
|
|
16
|
+
```rust
|
|
17
|
+
use odc::*;
|
|
18
|
+
|
|
19
|
+
fn main() {
|
|
20
|
+
// …
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Full coding rules: https://onedollarcomputer.com/editor/AI_DOCS.txt
|
|
25
|
+
Platform: https://onedollarcomputer.com/specification/ (v1.004 **R2**)
|
|
26
|
+
|
|
27
|
+
### Firmware constraints (short)
|
|
28
|
+
|
|
29
|
+
| Do | Don’t |
|
|
30
|
+
|----|--------|
|
|
31
|
+
| Pins **0..=19** only | MCU pads (`PD6`, `PC0`, …) |
|
|
32
|
+
| Refer to pins by the **printed board number** only — the only numbering | Using a connector contact number as a pin's name (e.g. "RJ45-2") — contacts 1-8 are printed at the port only to land the RJ45 cable; they are the **same** board pins |
|
|
33
|
+
| `LED` = 19; GPIO for I/O | Treat pin **13** / `BUTTON` as student input |
|
|
34
|
+
| `pin_set` / `led_on` / `delay` | `read_button()`, `pin_input(BUTTON)` |
|
|
35
|
+
| One complete `fn main()` | Partial snippets as the only firmware |
|
|
36
|
+
|
|
37
|
+
GPIO-capable for lessons: `0–9`, `12`, `14–15`, `19`. **Pin 13 is not for lessons.** Power/GND/NC are not GPIO.
|
|
38
|
+
|
|
39
|
+
### Physical button & HID (read before inventing input lessons)
|
|
40
|
+
|
|
41
|
+
**Canonical:** https://onedollarcomputer.com/docs/BUTTON.md
|
|
42
|
+
|
|
43
|
+
| Fact | Implication for lessons |
|
|
44
|
+
|------|-------------------------|
|
|
45
|
+
| The **physical** ODC button only **enters the bootloader** so Upload (WebHID) works | Do **not** teach “press the board button → LED on” as firmware |
|
|
46
|
+
| User firmware that touches pin **13** / `read_button()` can **break HID reflash** | Never emit that code in curriculum Rust |
|
|
47
|
+
| A **virtual button in HTML** can teach if/else in the browser | That is pedagogy only — it does **not** drive the real computer |
|
|
48
|
+
| Live browser ↔ board control via HID (page button → LED, or page reading the physical button) | **Not ready** — do not promise or build lessons that need it yet |
|
|
49
|
+
|
|
50
|
+
**Safe next lesson after blink:** LED timing / blink codes (“Light Signals”) in HTML + matching Simple Rust on the board — no button, no HID messaging.
|
|
51
|
+
|
|
52
|
+
**If the instructor wants input → decision → output:** simulate in HTML5, or use an **external** switch on a free GPIO (e.g. pin 0). Say clearly that the onboard button is for **bootloader / Upload**, not the exercise.
|
|
53
|
+
|
|
54
|
+
## How to put a lesson together (MCP)
|
|
55
|
+
|
|
56
|
+
Tools: `curriculum_pair` → `curriculum_agent_brief` → `curriculum_create_lesson` (or list/get) → `curriculum_update_lesson`.
|
|
57
|
+
|
|
58
|
+
| Tool | Use |
|
|
59
|
+
|------|-----|
|
|
60
|
+
| `curriculum_create_lesson` | **New** lesson — requires `title`; optional overview, steps, `html[]`, links, … Returns `{ id, siteUrl }` |
|
|
61
|
+
| `curriculum_update_lesson` | Patch an existing lesson by `lesson_id` |
|
|
62
|
+
| `curriculum_list_lessons` / `curriculum_get_lesson` | Read |
|
|
63
|
+
|
|
64
|
+
Useful fields (create + update):
|
|
65
|
+
|
|
66
|
+
| Field | Use |
|
|
67
|
+
|-------|-----|
|
|
68
|
+
| `title`, `overview`, `materials[]`, `steps[]` | Lesson text |
|
|
69
|
+
| `html[]` | `{ "title": "…", "html": "<!doctype html>…" }` — **interactive teaching UI** |
|
|
70
|
+
| `links[]` | Editor / emulator / docs links |
|
|
71
|
+
| `photos[]`, `videos[]` | Media |
|
|
72
|
+
|
|
73
|
+
**Prefer `curriculum_create_lesson`** for new work — do not overwrite unrelated lessons.
|
|
74
|
+
|
|
75
|
+
### Always when the board is involved
|
|
76
|
+
|
|
77
|
+
1. **`html[]`** — the experience (whatever the instructor asked for).
|
|
78
|
+
2. **`steps[]` (or overview)** — include a clear section **Firmware (Simple Rust)** with the **full** Rust source in a fenced `rust` code block (copy-paste ready for the editor).
|
|
79
|
+
3. **`links[]`** — at least the Editor: `https://onedollarcomputer.com/editor/`
|
|
80
|
+
Optional: Spec / AI docs. Emulator only when the lesson actually uses Lab → Simulate.
|
|
81
|
+
|
|
82
|
+
Students compile/load via the **editor** (Compile / Upload) or open **Lab → Simulate** with a project. The lesson HTML teaches; the Rust is what becomes the `.bin`.
|
|
83
|
+
|
|
84
|
+
### HTML tips
|
|
85
|
+
|
|
86
|
+
- Prefer a full mini-document: `<!doctype html><html>…</html>` inside each `html` string.
|
|
87
|
+
- Keep scripts self-contained (no secrets, no Firebase service keys).
|
|
88
|
+
- **Contrast:** titles and body text must be readable. On light backgrounds use dark text (`#0f172a` / `#334155`). Never pale gray/lavender titles on white. On dark panels use light text (`#f8fafc`).
|
|
89
|
+
- Prefer CSS variables or solid hex colors with clear contrast; avoid near-white on white.
|
|
90
|
+
- Link to `/editor/` when firmware is part of the lesson.
|
|
91
|
+
- Emulator iframe embed is optional (advanced): `/emulator/r2/?embed=1` — see `web/emulator/r2/README.md`.
|
|
92
|
+
|
|
93
|
+
## Minimal blink example (Rust that must compile)
|
|
94
|
+
|
|
95
|
+
```rust
|
|
96
|
+
use odc::*;
|
|
97
|
+
|
|
98
|
+
fn main() {
|
|
99
|
+
loop {
|
|
100
|
+
led_on();
|
|
101
|
+
delay(500);
|
|
102
|
+
led_off();
|
|
103
|
+
delay(500);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Put this (or the lesson’s real firmware) in **steps** under **Firmware (Simple Rust)**. Put any creative HTML in **`html[]`**.
|
|
109
|
+
|
|
110
|
+
## Do / don’t for agents
|
|
111
|
+
|
|
112
|
+
## How agents work from the platform (all agents)
|
|
113
|
+
|
|
114
|
+
Instructors use **Agent → Copy** on `/c/`. That paste is **complete**:
|
|
115
|
+
|
|
116
|
+
- Bearer token (pairing already done)
|
|
117
|
+
- Rules inline (no need to fetch this file or the site)
|
|
118
|
+
- Sandbox-safe API hosts first (`*.run.app`, then `*.web.app`)
|
|
119
|
+
|
|
120
|
+
Optional: `GET {API}/brief` on the same API host returns the contract as JSON (no auth).
|
|
121
|
+
|
|
122
|
+
If MCP `odc-curriculum` is connected, use it. Otherwise HTTP tools against the API hosts in the Copy are enough.
|
|
123
|
+
|
|
124
|
+
### Sandbox / Codex (403 host_not_allowed)
|
|
125
|
+
|
|
126
|
+
Do **not** require fetching `onedollarcomputer.com` / `odc.rs`. Do **not** use blocked-host `curl`.
|
|
127
|
+
|
|
128
|
+
API hosts (try in order):
|
|
129
|
+
|
|
130
|
+
1. `https://curriculumagent-mhrupl2ima-uc.a.run.app`
|
|
131
|
+
2. `https://odc-files-api.web.app`
|
|
132
|
+
3. `https://api.onedollarcomputer.com`
|
|
133
|
+
|
|
134
|
+
Then `GET /brief`, `GET/POST /lessons`, `PATCH /lessons/:id` with `Authorization: Bearer …`.
|
|
135
|
+
|
|
136
|
+
**Do**
|
|
137
|
+
|
|
138
|
+
- Prefer the platform Copy paste; update lessons on the site (not local `outputs/*.html` files).
|
|
139
|
+
- Match the instructor’s preferred teaching style in HTML5.
|
|
140
|
+
- Emit **valid ODC Rust** whenever hardware or the virtual board is part of the story.
|
|
141
|
+
|
|
142
|
+
**Don’t**
|
|
143
|
+
|
|
144
|
+
- Scrape the connect URL as a webpage for lesson content.
|
|
145
|
+
- Send Blockly / JS / Python / asm **to** the cloud compiler as `language`.
|
|
146
|
+
- Use chip pad names or invent pin numbers outside 0–19.
|
|
147
|
+
- Use the **physical button** / `read_button()` / pin **13** as lesson input.
|
|
148
|
+
- Promise browser ↔ board HID sync (not validated yet).
|
|
149
|
+
- Confuse an HTML “virtual button” with the real ODC button.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# odc MCP (curriculum + projects)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stdio MCP for One Dollar Computer — curriculum lessons **and** firmware projects.
|
|
4
|
+
|
|
5
|
+
See [../README.md](../README.md) for pair flow and Cursor/`mcp.json` setup.
|
|
6
|
+
|
|
7
|
+
**Pair once:** Agent → **Copy** on `/c/` or `/project/` → `curriculum_pair` with that link (MCP server name: `odc-curriculum`).
|
|
8
|
+
|
|
9
|
+
**Projects:** `project_brief` → `project_list` / `project_create` / `project_get` / `project_update` / `project_publish` / `project_fork`
|
|
10
|
+
**Lessons:** `curriculum_agent_brief` → `curriculum_create_lesson` / `curriculum_update_lesson` / …
|
|
11
|
+
|
|
12
|
+
**Hardware:** physical button (pin 13) = bootloader / Upload only — never `read_button()`. See [../../docs/BUTTON.md](../../docs/BUTTON.md).
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install
|
|
16
|
+
node bin.js # normally launched by the MCP host (Cursor: .cursor/mcp.json)
|
|
17
|
+
```
|
package/api-origin.json
ADDED
package/bin.js
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* One Dollar Computer — Curriculum MCP (stdio)
|
|
4
|
+
*
|
|
5
|
+
* Env:
|
|
6
|
+
* ODC_CURRICULUM_API — default production Cloud Function URL
|
|
7
|
+
* ODC_AGENT_TOKEN — optional; otherwise ~/.config/odc/curriculum-agent.json
|
|
8
|
+
*/
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import crypto from "node:crypto";
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import os from "node:os";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
|
|
18
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
// api-origin.json ships inside the npm package; the repo layout keeps it one
|
|
20
|
+
// level up. Resolve either, and never crash at startup if it is missing.
|
|
21
|
+
function readApiOrigin() {
|
|
22
|
+
for (const p of [
|
|
23
|
+
path.join(__dirname, "api-origin.json"),
|
|
24
|
+
path.join(__dirname, "..", "api-origin.json"),
|
|
25
|
+
]) {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(fs.readFileSync(p, "utf8")).url;
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
return "https://api.onedollarcomputer.com";
|
|
31
|
+
}
|
|
32
|
+
const API_ORIGIN = readApiOrigin();
|
|
33
|
+
|
|
34
|
+
// Maritime agent box port of curriculumAgent (2026-11-23) — the Google Cloud
|
|
35
|
+
// Function below died with the Oct 2026 billing closure (500/503). NOTE: this
|
|
36
|
+
// is a cloudflared quick-tunnel URL and CHANGES when that tunnel restarts;
|
|
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";
|
|
39
|
+
|
|
40
|
+
const DEFAULT_API =
|
|
41
|
+
process.env.ODC_CURRICULUM_API ||
|
|
42
|
+
process.env.ODC_CURRICULUM_API_FALLBACK ||
|
|
43
|
+
MARITIME_API;
|
|
44
|
+
|
|
45
|
+
const API_FALLBACKS = [
|
|
46
|
+
MARITIME_API,
|
|
47
|
+
DEFAULT_API,
|
|
48
|
+
"https://curriculumagent-mhrupl2ima-uc.a.run.app",
|
|
49
|
+
"https://odc-files-api.web.app",
|
|
50
|
+
API_ORIGIN,
|
|
51
|
+
"https://api.onedollarcomputer.com"
|
|
52
|
+
].filter((v, i, a) => v && a.indexOf(v) === i);
|
|
53
|
+
|
|
54
|
+
const RTDB_URL =
|
|
55
|
+
process.env.ODC_RTDB_URL ||
|
|
56
|
+
"https://odc-files-default-rtdb.firebaseio.com";
|
|
57
|
+
|
|
58
|
+
const TOKEN_PATH = path.join(os.homedir(), ".config", "odc", "curriculum-agent.json");
|
|
59
|
+
|
|
60
|
+
const AGENT_LESSONS_PATHS = [
|
|
61
|
+
path.join(__dirname, "AGENT_LESSONS.md"),
|
|
62
|
+
path.join(__dirname, "..", "AGENT_LESSONS.md"),
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
function loadAgentLessonsBrief() {
|
|
66
|
+
for (const p of AGENT_LESSONS_PATHS) {
|
|
67
|
+
try {
|
|
68
|
+
return fs.readFileSync(p, "utf8");
|
|
69
|
+
} catch {}
|
|
70
|
+
}
|
|
71
|
+
return "See https://onedollarcomputer.com/c/AGENT_LESSONS.md (HTML free; firmware must be Simple Rust).";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function loadStore() {
|
|
75
|
+
try {
|
|
76
|
+
return JSON.parse(fs.readFileSync(TOKEN_PATH, "utf8"));
|
|
77
|
+
} catch {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function saveStore(data) {
|
|
83
|
+
fs.mkdirSync(path.dirname(TOKEN_PATH), { recursive: true });
|
|
84
|
+
fs.writeFileSync(TOKEN_PATH, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getToken() {
|
|
88
|
+
return process.env.ODC_AGENT_TOKEN || loadStore().token || null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function extractCode(input) {
|
|
92
|
+
const s = String(input || "").trim();
|
|
93
|
+
if (!s) return null;
|
|
94
|
+
try {
|
|
95
|
+
const u = new URL(s);
|
|
96
|
+
return u.searchParams.get("connect") || u.searchParams.get("code") || s;
|
|
97
|
+
} catch {
|
|
98
|
+
return s;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function api(method, apiPath, { token, body, firebaseIdToken } = {}) {
|
|
103
|
+
const headers = { Accept: "application/json" };
|
|
104
|
+
if (body) headers["Content-Type"] = "application/json";
|
|
105
|
+
if (firebaseIdToken) headers.Authorization = `Bearer ${firebaseIdToken}`;
|
|
106
|
+
else if (token) headers.Authorization = `Bearer ${token}`;
|
|
107
|
+
|
|
108
|
+
let lastErr = null;
|
|
109
|
+
for (const base of API_FALLBACKS) {
|
|
110
|
+
try {
|
|
111
|
+
const res = await fetch(`${base}${apiPath}`, {
|
|
112
|
+
method,
|
|
113
|
+
headers,
|
|
114
|
+
body: body ? JSON.stringify(body) : undefined
|
|
115
|
+
});
|
|
116
|
+
const text = await res.text();
|
|
117
|
+
let data;
|
|
118
|
+
try {
|
|
119
|
+
data = text ? JSON.parse(text) : {};
|
|
120
|
+
} catch {
|
|
121
|
+
data = { raw: text };
|
|
122
|
+
}
|
|
123
|
+
if (!res.ok) {
|
|
124
|
+
const err = new Error(data.error || res.statusText || `HTTP ${res.status}`);
|
|
125
|
+
err.status = res.status;
|
|
126
|
+
err.data = data;
|
|
127
|
+
// Try next host on network-ish failures only; 4xx from API is final
|
|
128
|
+
if (res.status >= 500 || res.status === 404) {
|
|
129
|
+
lastErr = err;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
return data;
|
|
135
|
+
} catch (err) {
|
|
136
|
+
lastErr = err;
|
|
137
|
+
// fetch failed (DNS / blocked / network) → try next host
|
|
138
|
+
if (err && err.status && err.status < 500 && err.status !== 404) throw err;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
throw lastErr || new Error("All curriculum API hosts failed");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function textResult(obj) {
|
|
145
|
+
return {
|
|
146
|
+
content: [{ type: "text", text: typeof obj === "string" ? obj : JSON.stringify(obj, null, 2) }]
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const AI_DOCS_PATH = path.join(__dirname, "..", "..", "editor", "AI_DOCS.txt");
|
|
151
|
+
|
|
152
|
+
function loadProjectBrief() {
|
|
153
|
+
let aiDocs = "";
|
|
154
|
+
try {
|
|
155
|
+
aiDocs = fs.readFileSync(AI_DOCS_PATH, "utf8");
|
|
156
|
+
} catch {
|
|
157
|
+
aiDocs = "See https://onedollarcomputer.com/editor/AI_DOCS.txt";
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
docsUrl: "https://onedollarcomputer.com/editor/AI_DOCS.txt",
|
|
161
|
+
buttonWarning: "https://onedollarcomputer.com/docs/BUTTON.md",
|
|
162
|
+
editorUrl: "https://onedollarcomputer.com/editor/",
|
|
163
|
+
emulatorUrl: "https://onedollarcomputer.com/emulator/r2/",
|
|
164
|
+
rules: [
|
|
165
|
+
"Firmware must be complete Simple Rust: use odc::*; fn main() { … }",
|
|
166
|
+
"Never read_button() / pin 13 / BUTTON — bootloader only",
|
|
167
|
+
"New projects are private; project_publish is irreversible",
|
|
168
|
+
"Pair once with curriculum_pair (Agent → Copy on /project/ or /c/)"
|
|
169
|
+
],
|
|
170
|
+
aiDocs
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const server = new McpServer({
|
|
175
|
+
name: "odc-curriculum",
|
|
176
|
+
version: "0.3.0"
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
server.tool(
|
|
180
|
+
"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::*;).",
|
|
182
|
+
{
|
|
183
|
+
connect_url_or_code: z.string().describe("Full Agent link or the connect code")
|
|
184
|
+
},
|
|
185
|
+
async ({ connect_url_or_code }) => {
|
|
186
|
+
const code = extractCode(connect_url_or_code);
|
|
187
|
+
if (!code) return textResult({ error: "Missing link — copy Agent from /c/ while signed in." });
|
|
188
|
+
|
|
189
|
+
const connectUrl = `https://odc.rs/c/?connect=${encodeURIComponent(code)}`;
|
|
190
|
+
const deadline = Date.now() + 3 * 60 * 1000;
|
|
191
|
+
let last = "pending";
|
|
192
|
+
|
|
193
|
+
while (Date.now() < deadline) {
|
|
194
|
+
let st = null;
|
|
195
|
+
try {
|
|
196
|
+
const res = await fetch(
|
|
197
|
+
`${RTDB_URL}/curriculum/agentPairing/${encodeURIComponent(code)}.json`
|
|
198
|
+
);
|
|
199
|
+
if (res.ok) {
|
|
200
|
+
const row = await res.json();
|
|
201
|
+
if (row) {
|
|
202
|
+
st = {
|
|
203
|
+
status: row.status,
|
|
204
|
+
token: row.tokenPending || null
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} catch {
|
|
209
|
+
/* ignore */
|
|
210
|
+
}
|
|
211
|
+
if (!st) {
|
|
212
|
+
try {
|
|
213
|
+
st = await api("GET", `/pair/status?code=${encodeURIComponent(code)}`);
|
|
214
|
+
} catch (err) {
|
|
215
|
+
st = { status: "error", error: err.message };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
last = st.status || last;
|
|
220
|
+
if (st.token) {
|
|
221
|
+
saveStore({
|
|
222
|
+
token: st.token,
|
|
223
|
+
api: DEFAULT_API,
|
|
224
|
+
pairedAt: new Date().toISOString()
|
|
225
|
+
});
|
|
226
|
+
return textResult({
|
|
227
|
+
ok: true,
|
|
228
|
+
status: "connected",
|
|
229
|
+
message:
|
|
230
|
+
"Connected. Call curriculum_agent_brief (lessons) or project_brief (firmware). Same token: project_list / project_create / project_update / project_publish. HTML5 teaching UI is free; board firmware must be complete Simple Rust (use odc::*;).",
|
|
231
|
+
brief: "curriculum_agent_brief | project_brief",
|
|
232
|
+
create: "curriculum_create_lesson | project_create",
|
|
233
|
+
docs: "https://onedollarcomputer.com/c/AGENT_LESSONS.md",
|
|
234
|
+
projectDocs: "https://onedollarcomputer.com/editor/AI_DOCS.txt",
|
|
235
|
+
connectUrl
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (st.status === "denied" || st.status === "expired" || st.status === "unknown") {
|
|
239
|
+
return textResult({ ok: false, status: st.status, connectUrl });
|
|
240
|
+
}
|
|
241
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
242
|
+
}
|
|
243
|
+
return textResult({
|
|
244
|
+
ok: false,
|
|
245
|
+
status: last,
|
|
246
|
+
message: "Could not connect. Ask the instructor to copy a fresh Agent link from /c/ (signed in), then paste it here.",
|
|
247
|
+
connectUrl
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
server.tool(
|
|
253
|
+
"odc_connect",
|
|
254
|
+
"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
|
+
{
|
|
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).")
|
|
257
|
+
},
|
|
258
|
+
async ({ wait_seconds }) => {
|
|
259
|
+
const waitMs = Math.min(Math.max(Number(wait_seconds ?? 300) || 0, 0), 600) * 1000;
|
|
260
|
+
const verifier = crypto.randomBytes(32).toString("base64url");
|
|
261
|
+
const verifierHash = crypto.createHash("sha256").update(verifier).digest("hex");
|
|
262
|
+
|
|
263
|
+
let start;
|
|
264
|
+
try {
|
|
265
|
+
start = await api("POST", "/pair/agent-start", { body: { verifierHash } });
|
|
266
|
+
} catch (err) {
|
|
267
|
+
return textResult({ ok: false, error: `Could not start the connection: ${err.message}` });
|
|
268
|
+
}
|
|
269
|
+
const { code, approveUrl } = start;
|
|
270
|
+
if (!code || !approveUrl) {
|
|
271
|
+
return textResult({ ok: false, error: "Connection start did not return a code and approval link.", raw: start });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const deadline = Date.now() + waitMs;
|
|
275
|
+
let last = "pending";
|
|
276
|
+
for (;;) {
|
|
277
|
+
let st = null;
|
|
278
|
+
try {
|
|
279
|
+
st = await api(
|
|
280
|
+
"GET",
|
|
281
|
+
`/pair/agent-status?code=${encodeURIComponent(code)}&verifier=${encodeURIComponent(verifier)}`
|
|
282
|
+
);
|
|
283
|
+
} catch (err) {
|
|
284
|
+
st = { status: "error", error: err.message };
|
|
285
|
+
}
|
|
286
|
+
last = st.status || last;
|
|
287
|
+
if (st.token) {
|
|
288
|
+
saveStore({
|
|
289
|
+
token: st.token,
|
|
290
|
+
api: DEFAULT_API,
|
|
291
|
+
pairedAt: new Date().toISOString()
|
|
292
|
+
});
|
|
293
|
+
return textResult({
|
|
294
|
+
ok: true,
|
|
295
|
+
status: "connected",
|
|
296
|
+
approveUrl,
|
|
297
|
+
message:
|
|
298
|
+
"Connected. Call curriculum_agent_brief (lessons) or project_brief (firmware). Same token: project_list / project_create / project_update / project_publish. HTML5 teaching UI is free; board firmware must be complete Simple Rust (use odc::*;).",
|
|
299
|
+
brief: "curriculum_agent_brief | project_brief",
|
|
300
|
+
create: "curriculum_create_lesson | project_create",
|
|
301
|
+
docs: "https://onedollarcomputer.com/c/AGENT_LESSONS.md",
|
|
302
|
+
projectDocs: "https://onedollarcomputer.com/editor/AI_DOCS.txt"
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
if (st.status === "denied" || st.status === "expired" || st.status === "unknown") {
|
|
306
|
+
return textResult({ ok: false, status: st.status, approveUrl });
|
|
307
|
+
}
|
|
308
|
+
if (Date.now() >= deadline) break;
|
|
309
|
+
await new Promise((r) => setTimeout(r, Math.min(1500, Math.max(deadline - Date.now(), 0))));
|
|
310
|
+
if (Date.now() >= deadline) break;
|
|
311
|
+
}
|
|
312
|
+
return textResult({
|
|
313
|
+
ok: false,
|
|
314
|
+
status: "pending",
|
|
315
|
+
approveUrl,
|
|
316
|
+
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."
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
const BUILDS_DIR = path.join(os.homedir(), ".config", "odc", "builds");
|
|
323
|
+
|
|
324
|
+
async function rtdb(method, rtdbPath, body) {
|
|
325
|
+
const res = await fetch(`${RTDB_URL}${rtdbPath}`, {
|
|
326
|
+
method,
|
|
327
|
+
headers: body ? { "Content-Type": "application/json" } : undefined,
|
|
328
|
+
body: body ? JSON.stringify(body) : undefined
|
|
329
|
+
});
|
|
330
|
+
const text = await res.text();
|
|
331
|
+
let data = null;
|
|
332
|
+
try {
|
|
333
|
+
data = text ? JSON.parse(text) : null;
|
|
334
|
+
} catch {
|
|
335
|
+
data = null;
|
|
336
|
+
}
|
|
337
|
+
if (!res.ok) {
|
|
338
|
+
const err = new Error(`RTDB ${method} ${rtdbPath}: HTTP ${res.status} ${text.slice(0, 300)}`);
|
|
339
|
+
err.status = res.status;
|
|
340
|
+
throw err;
|
|
341
|
+
}
|
|
342
|
+
return data;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Same hash the web editor and the compile workers use: SHA-1 of the
|
|
346
|
+
// comment-stripped, whitespace-collapsed source (editor getCodeHash /
|
|
347
|
+
// worker code_hash). Lets the worker serve identical code from cache.
|
|
348
|
+
function codeHash(source) {
|
|
349
|
+
const cleaned = String(source)
|
|
350
|
+
.replace(/\/\/.*$/gm, "")
|
|
351
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
352
|
+
.replace(/\s+/g, " ")
|
|
353
|
+
.trim();
|
|
354
|
+
return crypto.createHash("sha1").update(cleaned, "utf8").digest("hex");
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
server.tool(
|
|
358
|
+
"odc_compile",
|
|
359
|
+
"Compile complete Simple Rust firmware (use odc::*;) for the One Dollar Computer on the cloud compile service — the same queue the web editor uses. Returns the compiled binary saved as a local .bin file (ready for odc_flash when available, or the web editor's Upload). No pairing needed: compilation is stateless. If project_id is given, the code is written to that editor project first (like pressing Compile in the editor); otherwise a throwaway project id is used. Compile errors are returned word-for-word from the compiler — show them to the user and fix the code. Never use pin 13 / read_button() (bootloader only); LED is pin 19.",
|
|
360
|
+
{
|
|
361
|
+
source: z.string().describe("Complete Simple Rust program: use odc::*; fn main() { … }"),
|
|
362
|
+
project_id: z.string().optional().describe("Editor project id to compile in place (optional)"),
|
|
363
|
+
timeout_seconds: z.number().optional().describe("Max seconds to wait for the compile (default 180, max 300)"),
|
|
364
|
+
save_to: z.string().optional().describe("Local path for the .bin (default ~/.config/odc/builds/<project_id>.bin)")
|
|
365
|
+
},
|
|
366
|
+
async ({ source, project_id, timeout_seconds, save_to }) => {
|
|
367
|
+
if (!source || !source.trim()) {
|
|
368
|
+
return textResult({ ok: false, error: "No code to compile." });
|
|
369
|
+
}
|
|
370
|
+
if (source.length > 65536) {
|
|
371
|
+
return textResult({ ok: false, error: "Code is too large (max 65536 characters)." });
|
|
372
|
+
}
|
|
373
|
+
const id =
|
|
374
|
+
project_id ||
|
|
375
|
+
`mcp${Date.now().toString(36)}${crypto.randomBytes(3).toString("hex")}`;
|
|
376
|
+
const hash = codeHash(source);
|
|
377
|
+
const submittedAt = Date.now();
|
|
378
|
+
const nowIso = new Date(submittedAt).toISOString();
|
|
379
|
+
const codeNode = {
|
|
380
|
+
content: source,
|
|
381
|
+
binaryHash: hash,
|
|
382
|
+
language: "rust",
|
|
383
|
+
lastModified: nowIso,
|
|
384
|
+
timestamp: submittedAt,
|
|
385
|
+
size: source.length,
|
|
386
|
+
compilationStatus: "pending",
|
|
387
|
+
compilationRequested: true,
|
|
388
|
+
compilationRequestedAt: nowIso
|
|
389
|
+
};
|
|
390
|
+
try {
|
|
391
|
+
await rtdb("PUT", `/projects/${encodeURIComponent(id)}/code.json`, codeNode);
|
|
392
|
+
await rtdb("PUT", `/compileQueue/${encodeURIComponent(id)}.json`, {
|
|
393
|
+
requestedAt: nowIso,
|
|
394
|
+
binaryHash: hash
|
|
395
|
+
});
|
|
396
|
+
} catch (err) {
|
|
397
|
+
return textResult({ ok: false, project_id: id, error: `Could not submit the compile: ${err.message}` });
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const deadline = Date.now() + Math.min(Math.max(Number(timeout_seconds ?? 180) || 180, 10), 300) * 1000;
|
|
401
|
+
let lastStatus = "pending";
|
|
402
|
+
let resubmitted = false;
|
|
403
|
+
let submittedMs = submittedAt;
|
|
404
|
+
while (Date.now() < deadline) {
|
|
405
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
406
|
+
let node = null;
|
|
407
|
+
try {
|
|
408
|
+
node = await rtdb("GET", `/projects/${encodeURIComponent(id)}/code.json`);
|
|
409
|
+
} catch {
|
|
410
|
+
/* transient — keep waiting */
|
|
411
|
+
}
|
|
412
|
+
if (!node) continue;
|
|
413
|
+
lastStatus = node.compilationStatus || lastStatus;
|
|
414
|
+
const updatedMs = Date.parse(node.compilationUpdatedAt || "") || 0;
|
|
415
|
+
const fresh = updatedMs >= submittedMs - 5000;
|
|
416
|
+
if (!fresh) continue;
|
|
417
|
+
// Known two-worker race: a worker that loses a job mid-flight can
|
|
418
|
+
// overwrite the real result with "worker error (job dropped)".
|
|
419
|
+
// That is not a compile verdict — resubmit once and keep waiting.
|
|
420
|
+
if (
|
|
421
|
+
node.compilationStatus === "error" &&
|
|
422
|
+
String(node.compilationError || "").includes("job dropped") &&
|
|
423
|
+
!resubmitted
|
|
424
|
+
) {
|
|
425
|
+
resubmitted = true;
|
|
426
|
+
submittedMs = Date.now();
|
|
427
|
+
const retryIso = new Date(submittedMs).toISOString();
|
|
428
|
+
try {
|
|
429
|
+
await rtdb("PUT", `/projects/${encodeURIComponent(id)}/code.json`, {
|
|
430
|
+
...codeNode,
|
|
431
|
+
lastModified: retryIso,
|
|
432
|
+
timestamp: submittedMs,
|
|
433
|
+
compilationRequestedAt: retryIso
|
|
434
|
+
});
|
|
435
|
+
await rtdb("PUT", `/compileQueue/${encodeURIComponent(id)}.json`, {
|
|
436
|
+
requestedAt: retryIso,
|
|
437
|
+
binaryHash: hash
|
|
438
|
+
});
|
|
439
|
+
} catch {
|
|
440
|
+
/* fall through — the loop will time out with a clear message */
|
|
441
|
+
}
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (node.compilationStatus === "success" && node.binary) {
|
|
445
|
+
const raw = Buffer.from(node.binary, "base64");
|
|
446
|
+
const outPath = save_to || path.join(BUILDS_DIR, `${id}.bin`);
|
|
447
|
+
try {
|
|
448
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
449
|
+
fs.writeFileSync(outPath, raw);
|
|
450
|
+
} catch (err) {
|
|
451
|
+
return textResult({
|
|
452
|
+
ok: true,
|
|
453
|
+
project_id: id,
|
|
454
|
+
binarySize: raw.length,
|
|
455
|
+
binaryHash: node.binaryHash || hash,
|
|
456
|
+
binaryBase64: node.binary,
|
|
457
|
+
warning: `Compiled OK but could not save the .bin locally: ${err.message}`,
|
|
458
|
+
editorUrl: `https://onedollarcomputer.com/editor/?projectID=${encodeURIComponent(id)}`
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
return textResult({
|
|
462
|
+
ok: true,
|
|
463
|
+
project_id: id,
|
|
464
|
+
binarySize: raw.length,
|
|
465
|
+
binaryHash: node.binaryHash || hash,
|
|
466
|
+
binaryFile: outPath,
|
|
467
|
+
fromCache: !!(node.compilationResult && node.compilationResult.cache),
|
|
468
|
+
message: `Compiled OK — ${raw.length} bytes. Binary saved to ${outPath}. Load it onto the computer with odc_flash when available, or open the editor project and press Upload.`,
|
|
469
|
+
editorUrl: `https://onedollarcomputer.com/editor/?projectID=${encodeURIComponent(id)}`
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
if (node.compilationStatus === "error") {
|
|
473
|
+
return textResult({
|
|
474
|
+
ok: false,
|
|
475
|
+
project_id: id,
|
|
476
|
+
error: String(node.compilationError || "Compile failed").slice(0, 4000),
|
|
477
|
+
editorUrl: `https://onedollarcomputer.com/editor/?projectID=${encodeURIComponent(id)}`
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return textResult({
|
|
482
|
+
ok: false,
|
|
483
|
+
project_id: id,
|
|
484
|
+
status: lastStatus,
|
|
485
|
+
error: "Compile did not finish in time. The job stays queued — try odc_compile again in a moment (identical code is served from cache)."
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
);
|
|
489
|
+
|
|
490
|
+
server.registerTool(
|
|
491
|
+
"curriculum_status",
|
|
492
|
+
{
|
|
493
|
+
description: "Show whether an agent token is stored and the API base URL."
|
|
494
|
+
},
|
|
495
|
+
async () => {
|
|
496
|
+
const token = getToken();
|
|
497
|
+
return textResult({
|
|
498
|
+
paired: !!token,
|
|
499
|
+
api: DEFAULT_API,
|
|
500
|
+
tokenPath: TOKEN_PATH,
|
|
501
|
+
tokenPreview: token ? `${token.slice(0, 16)}…` : null
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
);
|
|
505
|
+
|
|
506
|
+
server.registerTool(
|
|
507
|
+
"curriculum_agent_brief",
|
|
508
|
+
{
|
|
509
|
+
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."
|
|
511
|
+
},
|
|
512
|
+
async () => textResult({
|
|
513
|
+
docsUrl: "https://onedollarcomputer.com/c/AGENT_LESSONS.md",
|
|
514
|
+
aiDocsUrl: "https://onedollarcomputer.com/editor/AI_DOCS.txt",
|
|
515
|
+
emulatorUrl: "https://onedollarcomputer.com/emulator/r2/",
|
|
516
|
+
editorUrl: "https://onedollarcomputer.com/editor/",
|
|
517
|
+
markdown: loadAgentLessonsBrief()
|
|
518
|
+
})
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
server.registerTool(
|
|
522
|
+
"curriculum_list_lessons",
|
|
523
|
+
{
|
|
524
|
+
description: "List curriculum lessons for the paired account."
|
|
525
|
+
},
|
|
526
|
+
async () => {
|
|
527
|
+
const token = getToken();
|
|
528
|
+
if (!token) {
|
|
529
|
+
return textResult({
|
|
530
|
+
error: "Not paired. Ask the user for a Connect agent link, then call curriculum_pair."
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
const data = await api("GET", "/lessons", { token });
|
|
534
|
+
return textResult(data);
|
|
535
|
+
}
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
server.tool(
|
|
539
|
+
"curriculum_create_lesson",
|
|
540
|
+
"Create a NEW curriculum lesson for the paired instructor. Requires title. Optional: overview, materials[], steps[], html[], links[], photos[], videos[]. Put teaching UI in html[]; if the board is used, put complete Simple Rust in steps under 'Firmware (Simple Rust)'. Returns { id, siteUrl }.",
|
|
541
|
+
{
|
|
542
|
+
title: z.string(),
|
|
543
|
+
overview: z.string().optional(),
|
|
544
|
+
materials: z.array(z.string()).optional(),
|
|
545
|
+
steps: z.array(z.string()).optional(),
|
|
546
|
+
photos: z.array(z.object({ url: z.string() })).optional(),
|
|
547
|
+
videos: z.array(z.object({ url: z.string() })).optional(),
|
|
548
|
+
html: z.array(z.object({
|
|
549
|
+
title: z.string().optional(),
|
|
550
|
+
html: z.string()
|
|
551
|
+
})).optional(),
|
|
552
|
+
links: z.array(z.object({ label: z.string().optional(), url: z.string() })).optional()
|
|
553
|
+
},
|
|
554
|
+
async (args) => {
|
|
555
|
+
const token = getToken();
|
|
556
|
+
if (!token) {
|
|
557
|
+
return textResult({ error: "Not paired. Use curriculum_pair first." });
|
|
558
|
+
}
|
|
559
|
+
const body = { title: args.title };
|
|
560
|
+
if (args.overview !== undefined) body.overview = args.overview;
|
|
561
|
+
if (args.materials !== undefined) body.materials = args.materials;
|
|
562
|
+
if (args.steps !== undefined) body.steps = args.steps;
|
|
563
|
+
if (args.photos !== undefined) body.photos = args.photos;
|
|
564
|
+
if (args.videos !== undefined) body.videos = args.videos;
|
|
565
|
+
if (args.html !== undefined) body.html = args.html;
|
|
566
|
+
if (args.links !== undefined) body.links = args.links;
|
|
567
|
+
const data = await api("POST", "/lessons", { token, body });
|
|
568
|
+
return textResult(data);
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
server.tool(
|
|
573
|
+
"curriculum_get_lesson",
|
|
574
|
+
"Get one curriculum lesson (title + body) by id.",
|
|
575
|
+
{
|
|
576
|
+
lesson_id: z.string()
|
|
577
|
+
},
|
|
578
|
+
async ({ lesson_id }) => {
|
|
579
|
+
const token = getToken();
|
|
580
|
+
if (!token) {
|
|
581
|
+
return textResult({ error: "Not paired. Use curriculum_pair first." });
|
|
582
|
+
}
|
|
583
|
+
const data = await api("GET", `/lessons/${encodeURIComponent(lesson_id)}`, { token });
|
|
584
|
+
return textResult(data);
|
|
585
|
+
}
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
server.tool(
|
|
589
|
+
"curriculum_update_lesson",
|
|
590
|
+
"Update a curriculum lesson. Fields: overview, materials[], steps[], photos, videos, html[], links. Put interactive teaching UI in html[] ({ title?, html }). If the lesson uses the ODC board or virtual board, also put complete Simple Rust (use odc::*; fn main) in steps under 'Firmware (Simple Rust)'. Teaching metaphor is free; compiler input is always Rust. See curriculum_agent_brief.",
|
|
591
|
+
{
|
|
592
|
+
lesson_id: z.string(),
|
|
593
|
+
title: z.string().optional(),
|
|
594
|
+
overview: z.string().optional(),
|
|
595
|
+
materials: z.array(z.string()).optional(),
|
|
596
|
+
steps: z.array(z.string()).optional(),
|
|
597
|
+
photos: z.array(z.object({ url: z.string() })).optional(),
|
|
598
|
+
videos: z.array(z.object({ url: z.string() })).optional(),
|
|
599
|
+
html: z.array(z.object({
|
|
600
|
+
title: z.string().optional(),
|
|
601
|
+
html: z.string()
|
|
602
|
+
})).optional(),
|
|
603
|
+
games: z.array(z.object({
|
|
604
|
+
title: z.string().optional(),
|
|
605
|
+
html: z.string()
|
|
606
|
+
})).optional(),
|
|
607
|
+
gameHtml: z.union([
|
|
608
|
+
z.string(),
|
|
609
|
+
z.array(z.object({
|
|
610
|
+
title: z.string().optional(),
|
|
611
|
+
html: z.string()
|
|
612
|
+
}))
|
|
613
|
+
]).optional(),
|
|
614
|
+
links: z.array(z.object({ label: z.string().optional(), url: z.string() })).optional()
|
|
615
|
+
},
|
|
616
|
+
async (args) => {
|
|
617
|
+
const token = getToken();
|
|
618
|
+
if (!token) {
|
|
619
|
+
return textResult({ error: "Not paired. Use curriculum_pair first." });
|
|
620
|
+
}
|
|
621
|
+
const body = {};
|
|
622
|
+
if (args.title !== undefined) body.title = args.title;
|
|
623
|
+
if (args.overview !== undefined) body.overview = args.overview;
|
|
624
|
+
if (args.materials !== undefined) body.materials = args.materials;
|
|
625
|
+
if (args.steps !== undefined) body.steps = args.steps;
|
|
626
|
+
if (args.photos !== undefined) body.photos = args.photos;
|
|
627
|
+
if (args.videos !== undefined) body.videos = args.videos;
|
|
628
|
+
if (args.html !== undefined) body.html = args.html;
|
|
629
|
+
else if (args.games !== undefined) body.html = args.games;
|
|
630
|
+
if (args.gameHtml !== undefined) {
|
|
631
|
+
body.html = typeof args.gameHtml === "string"
|
|
632
|
+
? [{ html: args.gameHtml }]
|
|
633
|
+
: args.gameHtml;
|
|
634
|
+
}
|
|
635
|
+
if (args.links !== undefined) body.links = args.links;
|
|
636
|
+
const data = await api("PATCH", `/lessons/${encodeURIComponent(args.lesson_id)}`, {
|
|
637
|
+
token,
|
|
638
|
+
body
|
|
639
|
+
});
|
|
640
|
+
return textResult(data);
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
server.registerTool(
|
|
645
|
+
"project_brief",
|
|
646
|
+
{
|
|
647
|
+
description:
|
|
648
|
+
"Firmware project authoring contract (Simple Rust, pin 13 warning, publish rules). Call after curriculum_pair before project_create / project_update."
|
|
649
|
+
},
|
|
650
|
+
async () => textResult(loadProjectBrief())
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
server.registerTool(
|
|
654
|
+
"project_list",
|
|
655
|
+
{
|
|
656
|
+
description: "List firmware projects for the paired account (private and public)."
|
|
657
|
+
},
|
|
658
|
+
async () => {
|
|
659
|
+
const token = getToken();
|
|
660
|
+
if (!token) {
|
|
661
|
+
return textResult({ error: "Not paired. Use curriculum_pair first (Agent → Copy on /project/)." });
|
|
662
|
+
}
|
|
663
|
+
const data = await api("GET", "/projects", { token });
|
|
664
|
+
return textResult(data);
|
|
665
|
+
}
|
|
666
|
+
);
|
|
667
|
+
|
|
668
|
+
server.registerTool(
|
|
669
|
+
"project_create",
|
|
670
|
+
{
|
|
671
|
+
description:
|
|
672
|
+
"Create a NEW private firmware project. Requires name. Optional code (complete Simple Rust: use odc::*; fn main). Publish separately with project_publish (irreversible). Returns { id, slug, editorUrl }.",
|
|
673
|
+
inputSchema: {
|
|
674
|
+
name: z.string(),
|
|
675
|
+
code: z.string().optional()
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
async (args) => {
|
|
679
|
+
const token = getToken();
|
|
680
|
+
if (!token) {
|
|
681
|
+
return textResult({ error: "Not paired. Use curriculum_pair first." });
|
|
682
|
+
}
|
|
683
|
+
const body = { name: args.name };
|
|
684
|
+
if (args.code !== undefined) body.code = args.code;
|
|
685
|
+
const data = await api("POST", "/projects", { token, body });
|
|
686
|
+
return textResult(data);
|
|
687
|
+
}
|
|
688
|
+
);
|
|
689
|
+
|
|
690
|
+
server.registerTool(
|
|
691
|
+
"project_get",
|
|
692
|
+
{
|
|
693
|
+
description: "Get one firmware project (meta + code) by id. Owner can read private; public projects readable by any paired agent.",
|
|
694
|
+
inputSchema: {
|
|
695
|
+
project_id: z.string()
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
async ({ project_id }) => {
|
|
699
|
+
const token = getToken();
|
|
700
|
+
if (!token) {
|
|
701
|
+
return textResult({ error: "Not paired. Use curriculum_pair first." });
|
|
702
|
+
}
|
|
703
|
+
const data = await api("GET", `/projects/${encodeURIComponent(project_id)}`, { token });
|
|
704
|
+
return textResult(data);
|
|
705
|
+
}
|
|
706
|
+
);
|
|
707
|
+
|
|
708
|
+
server.registerTool(
|
|
709
|
+
"project_update",
|
|
710
|
+
{
|
|
711
|
+
description:
|
|
712
|
+
"Update a firmware project you own (name and/or code). Optional file id for multi-code projects (e.g. send, receive). Code must be complete Simple Rust (use odc::*;). Never read_button() / pin 13. Cannot unpublish.",
|
|
713
|
+
inputSchema: {
|
|
714
|
+
project_id: z.string(),
|
|
715
|
+
name: z.string().optional(),
|
|
716
|
+
code: z.string().optional(),
|
|
717
|
+
file: z.string().optional().describe("File id within the project (default: active / main)"),
|
|
718
|
+
file_name: z.string().optional().describe("Display name when creating/updating a file")
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
async (args) => {
|
|
722
|
+
const token = getToken();
|
|
723
|
+
if (!token) {
|
|
724
|
+
return textResult({ error: "Not paired. Use curriculum_pair first." });
|
|
725
|
+
}
|
|
726
|
+
const body = {};
|
|
727
|
+
if (args.name !== undefined) body.name = args.name;
|
|
728
|
+
if (args.code !== undefined) body.code = args.code;
|
|
729
|
+
if (args.file !== undefined) body.file = args.file;
|
|
730
|
+
if (args.file_name !== undefined) body.fileName = args.file_name;
|
|
731
|
+
const data = await api("PATCH", `/projects/${encodeURIComponent(args.project_id)}`, {
|
|
732
|
+
token,
|
|
733
|
+
body
|
|
734
|
+
});
|
|
735
|
+
return textResult(data);
|
|
736
|
+
}
|
|
737
|
+
);
|
|
738
|
+
|
|
739
|
+
server.registerTool(
|
|
740
|
+
"project_publish",
|
|
741
|
+
{
|
|
742
|
+
description:
|
|
743
|
+
"Make a project public at onedollarcomputer.com/{username}/{slug}. IRREVERSIBLE — cannot make it private again.",
|
|
744
|
+
inputSchema: {
|
|
745
|
+
project_id: z.string()
|
|
746
|
+
}
|
|
747
|
+
},
|
|
748
|
+
async ({ project_id }) => {
|
|
749
|
+
const token = getToken();
|
|
750
|
+
if (!token) {
|
|
751
|
+
return textResult({ error: "Not paired. Use curriculum_pair first." });
|
|
752
|
+
}
|
|
753
|
+
const data = await api("POST", `/projects/${encodeURIComponent(project_id)}/publish`, {
|
|
754
|
+
token,
|
|
755
|
+
body: {}
|
|
756
|
+
});
|
|
757
|
+
return textResult(data);
|
|
758
|
+
}
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
server.registerTool(
|
|
762
|
+
"project_fork",
|
|
763
|
+
{
|
|
764
|
+
description:
|
|
765
|
+
"Copy a public project to the paired account (stays private until project_publish). Records who copied from whom.",
|
|
766
|
+
inputSchema: {
|
|
767
|
+
project_id: z.string()
|
|
768
|
+
}
|
|
769
|
+
},
|
|
770
|
+
async ({ project_id }) => {
|
|
771
|
+
const token = getToken();
|
|
772
|
+
if (!token) {
|
|
773
|
+
return textResult({ error: "Not paired. Use curriculum_pair first." });
|
|
774
|
+
}
|
|
775
|
+
const data = await api("POST", `/projects/${encodeURIComponent(project_id)}/fork`, {
|
|
776
|
+
token,
|
|
777
|
+
body: {}
|
|
778
|
+
});
|
|
779
|
+
return textResult(data);
|
|
780
|
+
}
|
|
781
|
+
);
|
|
782
|
+
|
|
783
|
+
const transport = new StdioServerTransport();
|
|
784
|
+
await server.connect(transport);
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onedollarcomputer/odc-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "MCP server for One Dollar Computer \u2014 curriculum lessons and firmware projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"odc-mcp": "./bin.js"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
14
|
+
"zod": "^3.24.2"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"bin.js",
|
|
18
|
+
"api-origin.json",
|
|
19
|
+
"AGENT_LESSONS.md",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
}
|
|
25
|
+
}
|