gogcli-mcp-classroom 4.3.0 → 4.5.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.
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "metadata": {
9
9
  "description": "Extended Google Classroom for Claude via gogcli — auth + full Classroom support (courses, rosters, coursework, submissions, announcements, topics, invitations)",
10
- "version": "4.3.0"
10
+ "version": "4.5.0"
11
11
  },
12
12
  "plugins": [
13
13
  {
@@ -15,7 +15,7 @@
15
15
  "displayName": "gogcli (Classroom)",
16
16
  "source": "./",
17
17
  "description": "Extended Google Classroom for Claude via gogcli — auth + full Classroom support (courses, rosters, coursework, submissions, announcements, topics, invitations)",
18
- "version": "4.3.0",
18
+ "version": "4.5.0",
19
19
  "author": {
20
20
  "name": "Chris Hall"
21
21
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gogcli-mcp-classroom",
3
3
  "displayName": "gogcli (Classroom)",
4
- "version": "4.3.0",
4
+ "version": "4.5.0",
5
5
  "description": "Extended Google Classroom for Claude via gogcli — auth + full Classroom support (courses, rosters, coursework, submissions, announcements, topics, invitations)",
6
6
  "author": {
7
7
  "name": "Chris Hall",
package/dist/index.js CHANGED
@@ -37,6 +37,33 @@ var storage2 = new AsyncLocalStorage2();
37
37
  function withCallerCapabilities(capabilities, fn) {
38
38
  return capabilities ? storage2.run(capabilities, fn) : fn();
39
39
  }
40
+ function currentCallerCapabilities() {
41
+ return storage2.getStore();
42
+ }
43
+ var ENVELOPE_CAPABILITIES_KEY = "io.modelcontextprotocol/clientCapabilities";
44
+ var ELICITATION_MODES = ["form", "url"];
45
+ function isRecord(value) {
46
+ return typeof value === "object" && value !== null && !Array.isArray(value);
47
+ }
48
+ function callerCapabilities(ctx) {
49
+ const envelope = isRecord(ctx) && isRecord(ctx.mcpReq) ? ctx.mcpReq.envelope : void 0;
50
+ if (isRecord(envelope)) {
51
+ const declared = envelope[ENVELOPE_CAPABILITIES_KEY];
52
+ if (isRecord(declared))
53
+ return declared;
54
+ }
55
+ return currentCallerCapabilities();
56
+ }
57
+ function callerAcceptsFormElicitation(ctx) {
58
+ const capabilities = callerCapabilities(ctx);
59
+ if (!capabilities)
60
+ return void 0;
61
+ const elicitation = capabilities.elicitation;
62
+ if (!isRecord(elicitation))
63
+ return false;
64
+ const namedModes = ELICITATION_MODES.filter((mode) => mode in elicitation);
65
+ return namedModes.length === 0 || namedModes.includes("form");
66
+ }
40
67
 
41
68
  // ../../node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
42
69
  var __create = Object.create;
@@ -24101,6 +24128,37 @@ var inputRequired = Object.assign(buildInputRequired, {
24101
24128
  return { method: "roots/list" };
24102
24129
  }
24103
24130
  });
24131
+ function acceptedContent(responses, key, schema) {
24132
+ const view = inputResponse(responses, key);
24133
+ if (view.kind !== "elicit" || view.action !== "accept" || view.content === void 0) return void 0;
24134
+ if (schema === void 0) return view.content;
24135
+ const outcome = schema["~standard"].validate(view.content);
24136
+ if (outcome instanceof Promise) throw new TypeError("acceptedContent(responses, key, schema) requires a synchronously-validating schema");
24137
+ return outcome.issues === void 0 ? outcome.value : void 0;
24138
+ }
24139
+ function inputResponse(responses, key) {
24140
+ if (responses === void 0 || typeof responses !== "object" || responses === null) return { kind: "missing" };
24141
+ const entry = responses[key];
24142
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return { kind: "missing" };
24143
+ const candidate = entry;
24144
+ if (candidate["action"] === "accept" || candidate["action"] === "decline" || candidate["action"] === "cancel") {
24145
+ const content = candidate["content"];
24146
+ return {
24147
+ kind: "elicit",
24148
+ action: candidate["action"],
24149
+ ...content !== null && typeof content === "object" && !Array.isArray(content) && { content }
24150
+ };
24151
+ }
24152
+ if (Array.isArray(candidate["roots"])) return {
24153
+ kind: "roots",
24154
+ roots: candidate["roots"]
24155
+ };
24156
+ if (typeof candidate["role"] === "string" && candidate["content"] !== void 0) return {
24157
+ kind: "sampling",
24158
+ result: candidate
24159
+ };
24160
+ return { kind: "missing" };
24161
+ }
24104
24162
  var REQUEST_STATE_ONLY_LEG_PACING_MS = 250;
24105
24163
  function inputRequiredRoundsExceededMessage(method, maxRounds) {
24106
24164
  return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
@@ -34148,14 +34206,14 @@ function serveStdio(factory, options = {}) {
34148
34206
  return false;
34149
34207
  };
34150
34208
  const answerLegacyRejection = (request, reason, requestedVersion) => {
34151
- const rejection2 = modernOnlyStrictRejection({
34209
+ const rejection3 = modernOnlyStrictRejection({
34152
34210
  kind: "legacy",
34153
34211
  reason,
34154
34212
  ...requestedVersion !== void 0 && { requestedVersion }
34155
34213
  }, SUPPORTED_MODERN_PROTOCOL_VERSIONS);
34156
- if (rejection2 === void 0) return Promise.resolve();
34157
- reportError(/* @__PURE__ */ new Error(`Rejected 2025-era request on a modern-only stdio connection (${rejection2.cell}): ${rejection2.message}`));
34158
- return writeErrorResponse(request.id, rejection2.code, rejection2.message, rejection2.data);
34214
+ if (rejection3 === void 0) return Promise.resolve();
34215
+ reportError(/* @__PURE__ */ new Error(`Rejected 2025-era request on a modern-only stdio connection (${rejection3.cell}): ${rejection3.message}`));
34216
+ return writeErrorResponse(request.id, rejection3.code, rejection3.message, rejection3.data);
34159
34217
  };
34160
34218
  const onInstanceClosed = (channel) => {
34161
34219
  if (closing || channel === discarding) return;
@@ -34458,6 +34516,11 @@ function walk(value, keep, drop) {
34458
34516
  }
34459
34517
 
34460
34518
  // ../../node_modules/@chrischall/mcp-utils/dist/response/index.js
34519
+ function textResult(data) {
34520
+ return {
34521
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
34522
+ };
34523
+ }
34461
34524
  function rawTextResult(text) {
34462
34525
  return { content: [{ type: "text", text }] };
34463
34526
  }
@@ -34468,6 +34531,416 @@ function errorResult(message) {
34468
34531
  };
34469
34532
  }
34470
34533
 
34534
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirmation.js
34535
+ import { createHash, createHmac, timingSafeEqual } from "node:crypto";
34536
+
34537
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/canonical.js
34538
+ function canonicalJson(value) {
34539
+ if (value === null || typeof value === "string" || typeof value === "boolean")
34540
+ return JSON.stringify(value);
34541
+ if (value === void 0)
34542
+ return "null";
34543
+ if (typeof value === "number")
34544
+ return Number.isFinite(value) ? JSON.stringify(value) : `{"$num":"${String(value)}"}`;
34545
+ if (typeof value === "bigint")
34546
+ return `{"$bigint":"${value.toString()}"}`;
34547
+ if (typeof value === "function" || typeof value === "symbol") {
34548
+ throw new TypeError(`confirmation: cannot bind a ${typeof value} argument value.`);
34549
+ }
34550
+ if (Array.isArray(value))
34551
+ return `[${value.map(canonicalJson).join(",")}]`;
34552
+ if (value instanceof Date) {
34553
+ return `{"$date":${JSON.stringify(Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString())}}`;
34554
+ }
34555
+ if (ArrayBuffer.isView(value)) {
34556
+ const bytes = Buffer.from(value.buffer, value.byteOffset, value.byteLength);
34557
+ return `{"$bytes":${JSON.stringify(bytes.toString("base64"))}}`;
34558
+ }
34559
+ if (value instanceof ArrayBuffer)
34560
+ return `{"$bytes":${JSON.stringify(Buffer.from(value).toString("base64"))}}`;
34561
+ if (value instanceof Map) {
34562
+ const entries2 = [...value.entries()].map(([k, v]) => `[${canonicalJson(k)},${canonicalJson(v)}]`).sort();
34563
+ return `{"$map":[${entries2.join(",")}]}`;
34564
+ }
34565
+ if (value instanceof Set) {
34566
+ return `{"$set":[${[...value].map(canonicalJson).sort().join(",")}]}`;
34567
+ }
34568
+ const proto = Object.getPrototypeOf(value);
34569
+ if (proto !== Object.prototype && proto !== null) {
34570
+ throw new TypeError("confirmation: cannot bind a non-plain object argument value (class instance).");
34571
+ }
34572
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
34573
+ return `{${entries.map(([k, v]) => `${JSON.stringify(escapeKey(k))}:${canonicalJson(v)}`).join(",")}}`;
34574
+ }
34575
+ function escapeKey(key) {
34576
+ return key.startsWith("$") ? `$${key}` : key;
34577
+ }
34578
+
34579
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirmation.js
34580
+ var DEFAULT_REQUEST_KEY = "confirmation";
34581
+ var DEFAULT_CONFIRMATION_LABEL = "Confirm this action should proceed.";
34582
+ var UNSUPPORTED_NOTE = "Nothing was done because this client cannot show a confirmation prompt (it declares no MCP elicitation capability), and this action is never taken without one";
34583
+ var STATE_PREFIX = "mcpu.confirm.v1.";
34584
+ function bindingKey(binding) {
34585
+ if (binding.ttlSeconds !== void 0 && !(Number.isFinite(binding.ttlSeconds) && binding.ttlSeconds > 0)) {
34586
+ throw new RangeError("requireConfirmation: binding.ttlSeconds must be a finite number greater than 0.");
34587
+ }
34588
+ const key = typeof binding.key === "string" ? Buffer.from(binding.key, "utf8") : Buffer.from(binding.key);
34589
+ if (key.length < 32) {
34590
+ throw new RangeError("requireConfirmation: binding.key must be at least 32 bytes.");
34591
+ }
34592
+ return key;
34593
+ }
34594
+ function commitment(action, args) {
34595
+ return createHash("sha256").update(`${action}\0${canonicalJson(args)}`).digest("base64url");
34596
+ }
34597
+ function mintState(key, action, binding) {
34598
+ const exp = Math.floor(Date.now() / 1e3) + (binding.ttlSeconds ?? 600);
34599
+ const body = Buffer.from(JSON.stringify({ c: commitment(action, binding.args), exp })).toString("base64url");
34600
+ const mac3 = createHmac("sha256", key).update(`${STATE_PREFIX}${body}`).digest("base64url");
34601
+ return `${STATE_PREFIX}${body}.${mac3}`;
34602
+ }
34603
+ function verifyState(key, action, binding, state) {
34604
+ if (typeof state !== "string" || !state.startsWith(STATE_PREFIX))
34605
+ return false;
34606
+ const rest = state.slice(STATE_PREFIX.length);
34607
+ const dot = rest.indexOf(".");
34608
+ if (dot < 0)
34609
+ return false;
34610
+ const body = rest.slice(0, dot);
34611
+ const mac3 = Buffer.from(rest.slice(dot + 1), "base64url");
34612
+ const expected = createHmac("sha256", key).update(`${STATE_PREFIX}${body}`).digest();
34613
+ if (mac3.length !== expected.length || !timingSafeEqual(mac3, expected))
34614
+ return false;
34615
+ let payload;
34616
+ try {
34617
+ payload = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
34618
+ } catch {
34619
+ return false;
34620
+ }
34621
+ if (typeof payload.exp !== "number" || payload.exp * 1e3 <= Date.now())
34622
+ return false;
34623
+ const want = Buffer.from(commitment(action, binding.args));
34624
+ const got = Buffer.from(typeof payload.c === "string" ? payload.c : "");
34625
+ return got.length === want.length && timingSafeEqual(got, want);
34626
+ }
34627
+ function echoedState(ctx) {
34628
+ const accessor = ctx.mcpReq.requestState;
34629
+ return typeof accessor === "function" ? accessor() : void 0;
34630
+ }
34631
+ function requireConfirmation(ctx, options) {
34632
+ const requestKey = options.requestKey ?? DEFAULT_REQUEST_KEY;
34633
+ const key = options.binding ? bindingKey(options.binding) : void 0;
34634
+ const confirmationSchema = external_exports.object({
34635
+ confirmed: external_exports.boolean().describe(options.confirmationLabel ?? DEFAULT_CONFIRMATION_LABEL)
34636
+ });
34637
+ const ask = () => {
34638
+ const preview = {
34639
+ action: options.action,
34640
+ ...options.details === void 0 ? {} : { details: options.details }
34641
+ };
34642
+ return inputRequired({
34643
+ inputRequests: {
34644
+ [requestKey]: inputRequired.elicit({
34645
+ message: `${options.message}
34646
+ ${JSON.stringify(preview, null, 2)}`,
34647
+ requestedSchema: confirmationSchema
34648
+ })
34649
+ },
34650
+ ...key && options.binding ? { requestState: mintState(key, options.action, options.binding) } : {}
34651
+ });
34652
+ };
34653
+ const response = inputResponse(ctx.mcpReq.inputResponses, requestKey);
34654
+ const accepted = acceptedContent(ctx.mcpReq.inputResponses, requestKey, confirmationSchema);
34655
+ if (response.kind === "missing") {
34656
+ if (callerAcceptsFormElicitation(ctx) === false) {
34657
+ return textResult({
34658
+ confirmed: false,
34659
+ dispatched: false,
34660
+ action: options.action,
34661
+ reason: "confirmation-unsupported",
34662
+ note: options.unsupportedNote ? `${UNSUPPORTED_NOTE}. ${options.unsupportedNote}` : `${UNSUPPORTED_NOTE}.`
34663
+ });
34664
+ }
34665
+ return ask();
34666
+ }
34667
+ if (response.kind === "elicit" && response.action === "accept" && accepted?.confirmed === true) {
34668
+ if (key && options.binding) {
34669
+ const state = echoedState(ctx);
34670
+ if (state === void 0 || state === null) {
34671
+ return errorResult(`Confirmation for ${options.action} was accepted, but the retry carried no requestState, so it cannot be checked against the prompt that was shown. Nothing was done. The likely cause is that the MCP client or host does not round-trip requestState (it must echo the requestState from the input_required result back on the retry); asking again would loop.`);
34672
+ }
34673
+ if (!verifyState(key, options.action, options.binding, state))
34674
+ return ask();
34675
+ }
34676
+ return void 0;
34677
+ }
34678
+ return textResult({
34679
+ confirmed: false,
34680
+ cancelled: true,
34681
+ action: options.action,
34682
+ note: "Nothing was changed because the confirmation was declined, cancelled, or left unchecked."
34683
+ });
34684
+ }
34685
+
34686
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-token.js
34687
+ import { createHash as createHash2, createHmac as createHmac2, randomBytes, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
34688
+ function createSpentTokenStore() {
34689
+ const spent2 = /* @__PURE__ */ new Map();
34690
+ return {
34691
+ has: (nonce) => spent2.has(nonce),
34692
+ add: (nonce, exp) => {
34693
+ spent2.set(nonce, exp);
34694
+ },
34695
+ prune: (now) => {
34696
+ for (const [nonce, exp] of spent2)
34697
+ if (exp < now)
34698
+ spent2.delete(nonce);
34699
+ },
34700
+ clear: () => spent2.clear(),
34701
+ get size() {
34702
+ return spent2.size;
34703
+ }
34704
+ };
34705
+ }
34706
+ var PROCESS_SPENT = createSpentTokenStore();
34707
+ var PREFIX = "mcpu.token.v1.";
34708
+ var DEFAULT_TTL_SECONDS = 600;
34709
+ function tokenKey(key) {
34710
+ const bytes = typeof key === "string" ? Buffer.from(key, "utf8") : Buffer.from(key);
34711
+ if (bytes.length < 32)
34712
+ throw new RangeError("confirm token: key must be at least 32 bytes.");
34713
+ return bytes;
34714
+ }
34715
+ function ttlOf(ttlSeconds) {
34716
+ if (ttlSeconds === void 0)
34717
+ return DEFAULT_TTL_SECONDS;
34718
+ if (!(Number.isFinite(ttlSeconds) && ttlSeconds > 0)) {
34719
+ throw new RangeError("confirm token: ttlSeconds must be a finite number greater than 0.");
34720
+ }
34721
+ return ttlSeconds;
34722
+ }
34723
+ function sign(key, body) {
34724
+ return createHmac2("sha256", key).update(`${PREFIX}${body}`).digest();
34725
+ }
34726
+ function hashConfirmPayload(payload) {
34727
+ return createHash2("sha256").update(canonicalJson(payload)).digest("base64url");
34728
+ }
34729
+ function issueConfirmToken(key, binding, options = {}) {
34730
+ const k = tokenKey(key);
34731
+ const now = options.now ?? Date.now();
34732
+ const exp = now + ttlOf(options.ttlSeconds) * 1e3;
34733
+ const claims = {
34734
+ t: binding.tool,
34735
+ ...binding.account === void 0 ? {} : { a: binding.account },
34736
+ g: binding.target,
34737
+ ...binding.revision === void 0 ? {} : { r: binding.revision },
34738
+ h: binding.payloadHash,
34739
+ exp,
34740
+ n: randomBytes(16).toString("base64url")
34741
+ };
34742
+ const body = Buffer.from(JSON.stringify(claims), "utf8").toString("base64url");
34743
+ return { token: `${PREFIX}${body}.${sign(k, body).toString("base64url")}`, expiresAt: new Date(exp).toISOString() };
34744
+ }
34745
+ function parseClaims(body) {
34746
+ try {
34747
+ const claims = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
34748
+ return claims && typeof claims === "object" ? claims : void 0;
34749
+ } catch {
34750
+ return void 0;
34751
+ }
34752
+ }
34753
+ function verifyConfirmToken(key, token, binding, options = {}) {
34754
+ const k = tokenKey(key);
34755
+ const now = options.now ?? Date.now();
34756
+ const spent2 = options.spent ?? PROCESS_SPENT;
34757
+ spent2.prune(now);
34758
+ if (!token.startsWith(PREFIX))
34759
+ return { ok: false, error: "TOKEN_INVALID" };
34760
+ const rest = token.slice(PREFIX.length);
34761
+ const dot = rest.indexOf(".");
34762
+ const body = dot < 0 ? "" : rest.slice(0, dot);
34763
+ const mac3 = Buffer.from(dot < 0 ? "" : rest.slice(dot + 1), "base64url");
34764
+ const expected = sign(k, body);
34765
+ if (!body || mac3.length !== expected.length || !timingSafeEqual2(mac3, expected))
34766
+ return { ok: false, error: "TOKEN_INVALID" };
34767
+ const claims = parseClaims(body);
34768
+ if (!claims)
34769
+ return { ok: false, error: "TOKEN_INVALID" };
34770
+ if (claims.t !== binding.tool || claims.a !== binding.account || claims.g !== binding.target) {
34771
+ return { ok: false, error: "TOKEN_INVALID" };
34772
+ }
34773
+ if (spent2.has(claims.n))
34774
+ return { ok: false, error: "TOKEN_REUSED" };
34775
+ if (now > claims.exp)
34776
+ return { ok: false, error: "TOKEN_EXPIRED" };
34777
+ if (claims.r !== binding.revision)
34778
+ return { ok: false, error: "DRAFT_CHANGED", reason: "revision-changed" };
34779
+ if (claims.h !== binding.payloadHash)
34780
+ return { ok: false, error: "DRAFT_CHANGED", reason: "payload-changed" };
34781
+ spent2.add(claims.n, claims.exp);
34782
+ return { ok: true };
34783
+ }
34784
+ var CONFIRM_TOKEN_INSTRUCTION = "Show this preview to the user verbatim and proceed only after they explicitly approve in chat. Then call again with confirmToken.";
34785
+ var confirmTokenParam = external_exports.string().optional().describe(`ONLY for the two-step confirmation fallback (a client without MCP elicitation). The confirmToken from this same tool's phase-1 "confirmation-required" response, passed back ONLY after the user has seen that preview and explicitly approved it in chat \u2014 never on the first call, never invented, never reused. Call again with the same arguments. Ignored when the client supports elicitation.`);
34786
+ var TOKEN_ERROR_NOTE = {
34787
+ TOKEN_EXPIRED: "Nothing was sent or changed: the confirmToken expired. Call again WITHOUT confirmToken for a fresh preview, and ask the user to approve it again.",
34788
+ TOKEN_REUSED: "Nothing was sent or changed by this call: this confirmToken was already used, and one approval acts once. If doing it again is really intended, call again WITHOUT confirmToken and get a new approval.",
34789
+ TOKEN_INVALID: "Nothing was sent or changed: this confirmToken was not issued by this server for this tool, account and target (or the server has restarted since). Call again WITHOUT confirmToken for a fresh preview and approval."
34790
+ };
34791
+ var CHANGED_NOTE = {
34792
+ "revision-changed": "Nothing was sent or changed: the target was edited since the user approved it (its version rotated), so what would happen is not what they saw.",
34793
+ "payload-changed": "Nothing was sent or changed: what would happen no longer matches what the user approved."
34794
+ };
34795
+ function isToolResult(value) {
34796
+ return Array.isArray(value.content);
34797
+ }
34798
+ function rejection2(data) {
34799
+ return { ...textResult({ status: "confirmation-rejected", confirmed: false, dispatched: false, ...data }), isError: true };
34800
+ }
34801
+ async function tokenConfirmation(action, fb) {
34802
+ const subject = await fb.subject();
34803
+ if (isToolResult(subject))
34804
+ return subject;
34805
+ const binding = {
34806
+ tool: fb.tool,
34807
+ ...fb.account === void 0 ? {} : { account: fb.account },
34808
+ target: subject.target,
34809
+ ...subject.revision === void 0 ? {} : { revision: subject.revision },
34810
+ payloadHash: hashConfirmPayload(subject.payload)
34811
+ };
34812
+ const phaseOne = () => {
34813
+ const { token, expiresAt } = issueConfirmToken(fb.key, binding, { ttlSeconds: fb.ttlSeconds });
34814
+ return {
34815
+ action,
34816
+ preview: subject.preview,
34817
+ confirmToken: token,
34818
+ expiresAt,
34819
+ ttlSeconds: ttlOf(fb.ttlSeconds),
34820
+ instruction: fb.instruction ?? CONFIRM_TOKEN_INSTRUCTION
34821
+ };
34822
+ };
34823
+ if (!fb.confirmToken) {
34824
+ return textResult({ status: "confirmation-required", confirmed: false, dispatched: false, ...phaseOne() });
34825
+ }
34826
+ const verdict = verifyConfirmToken(fb.key, fb.confirmToken, binding, { spent: fb.spent });
34827
+ if (verdict.ok)
34828
+ return void 0;
34829
+ if (verdict.error === "DRAFT_CHANGED") {
34830
+ return rejection2({
34831
+ error: "DRAFT_CHANGED",
34832
+ reason: verdict.reason,
34833
+ note: `${CHANGED_NOTE[verdict.reason]} The current preview and a fresh confirmToken are below.`,
34834
+ ...phaseOne()
34835
+ });
34836
+ }
34837
+ return rejection2({ error: verdict.error, action, note: TOKEN_ERROR_NOTE[verdict.error] });
34838
+ }
34839
+ async function requireConfirmationWithFallback(ctx, options) {
34840
+ const { tokenFallback, ...confirmation } = options;
34841
+ if (tokenFallback && callerAcceptsFormElicitation(ctx) === false) {
34842
+ return tokenConfirmation(options.action, tokenFallback);
34843
+ }
34844
+ return requireConfirmation(ctx, confirmation);
34845
+ }
34846
+
34847
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-env.js
34848
+ import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
34849
+
34850
+ // ../../node_modules/@chrischall/mcp-utils/dist/config/index.js
34851
+ import { homedir } from "node:os";
34852
+ import { isAbsolute, join, resolve } from "node:path";
34853
+ var PLACEHOLDER_RE = /^\$\{[^}]*\}$/;
34854
+ function readEnvVar(key, opts = {}) {
34855
+ const env = opts.env ?? process.env;
34856
+ const raw = env[key];
34857
+ if (typeof raw === "string") {
34858
+ const trimmed = raw.trim();
34859
+ if (trimmed.length > 0 && trimmed !== "undefined" && trimmed !== "null" && !PLACEHOLDER_RE.test(trimmed)) {
34860
+ return trimmed;
34861
+ }
34862
+ }
34863
+ return opts.default;
34864
+ }
34865
+ var TRUE_TOKENS = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
34866
+ var FALSE_TOKENS = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
34867
+ function parseBoolEnv(key, opts = {}) {
34868
+ const fallback = opts.default ?? false;
34869
+ const raw = readEnvVar(key, { env: opts.env });
34870
+ if (raw === void 0)
34871
+ return fallback;
34872
+ const token = raw.toLowerCase();
34873
+ if (TRUE_TOKENS.has(token))
34874
+ return true;
34875
+ if (FALSE_TOKENS.has(token))
34876
+ return false;
34877
+ return fallback;
34878
+ }
34879
+ function expandPath(p) {
34880
+ let expanded = p;
34881
+ if (p === "~") {
34882
+ expanded = homedir();
34883
+ } else if (p.startsWith("~/")) {
34884
+ expanded = join(homedir(), p.slice(2));
34885
+ }
34886
+ return isAbsolute(expanded) ? expanded : resolve(expanded);
34887
+ }
34888
+
34889
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-env.js
34890
+ var MODES = /* @__PURE__ */ new Set(["ask-user", "auto", "refuse"]);
34891
+ var DEFAULT_TTL_SECONDS2 = 600;
34892
+ var warned = /* @__PURE__ */ new Set();
34893
+ function readConfirmMode(env = process.env) {
34894
+ const raw = readEnvVar("MCP_CONFIRM_MODE", { env })?.trim().toLowerCase();
34895
+ if (!raw)
34896
+ return "ask-user";
34897
+ if (MODES.has(raw))
34898
+ return raw;
34899
+ if (!warned.has(raw)) {
34900
+ warned.add(raw);
34901
+ process.stderr.write(`MCP_CONFIRM_MODE="${raw}" is not one of ask-user, auto, refuse; treating it as refuse.
34902
+ `);
34903
+ }
34904
+ return "refuse";
34905
+ }
34906
+ function confirmTtlFromEnv(env = process.env) {
34907
+ const raw = readEnvVar("MCP_CONFIRM_TTL_SECONDS", { env })?.trim();
34908
+ return raw && /^[1-9]\d*$/.test(raw) ? Number(raw) : DEFAULT_TTL_SECONDS2;
34909
+ }
34910
+ var processKey;
34911
+ function confirmKeyFromEnv(env = process.env) {
34912
+ const secret = readEnvVar("MCP_CONFIRM_SECRET", { env });
34913
+ if (secret)
34914
+ return createHash3("sha256").update(secret, "utf8").digest();
34915
+ processKey ??= randomBytes2(32);
34916
+ return processKey;
34917
+ }
34918
+ var CONFIRM_TOKEN_AUTO_INSTRUCTION = "Nothing has been done yet. Review this preview; if it is what was intended, call again with the same arguments plus confirmToken. (This server runs with MCP_CONFIRM_MODE=auto, so the user's approval in chat is not required.)";
34919
+ var REFUSE_HINT = "Set MCP_CONFIRM_MODE=ask-user on the server to allow two-step confirmation instead.";
34920
+ function confirmationFromEnv(options) {
34921
+ const { tool, account, confirmToken, subject, instruction, spent: spent2, env = process.env, ...confirmation } = options;
34922
+ const mode = readConfirmMode(env);
34923
+ if (mode === "refuse") {
34924
+ return {
34925
+ ...confirmation,
34926
+ unsupportedNote: confirmation.unsupportedNote ? `${confirmation.unsupportedNote} ${REFUSE_HINT}` : REFUSE_HINT
34927
+ };
34928
+ }
34929
+ return {
34930
+ ...confirmation,
34931
+ tokenFallback: {
34932
+ key: confirmKeyFromEnv(env),
34933
+ tool,
34934
+ ...account === void 0 ? {} : { account },
34935
+ ...confirmToken === void 0 ? {} : { confirmToken },
34936
+ subject,
34937
+ ttlSeconds: confirmTtlFromEnv(env),
34938
+ instruction: mode === "auto" ? CONFIRM_TOKEN_AUTO_INSTRUCTION : instruction ?? CONFIRM_TOKEN_INSTRUCTION,
34939
+ ...spent2 === void 0 ? {} : { spent: spent2 }
34940
+ }
34941
+ };
34942
+ }
34943
+
34471
34944
  // ../../node_modules/@chrischall/mcp-utils/dist/server/index.js
34472
34945
  var SERVER_PROTOCOL_VERSIONS = Object.freeze([
34473
34946
  "2026-07-28",
@@ -34643,45 +35116,6 @@ function runMcp(opts) {
34643
35116
  return handle;
34644
35117
  }
34645
35118
 
34646
- // ../../node_modules/@chrischall/mcp-utils/dist/config/index.js
34647
- import { homedir } from "node:os";
34648
- import { isAbsolute, join, resolve } from "node:path";
34649
- var PLACEHOLDER_RE = /^\$\{[^}]*\}$/;
34650
- function readEnvVar(key, opts = {}) {
34651
- const env = opts.env ?? process.env;
34652
- const raw = env[key];
34653
- if (typeof raw === "string") {
34654
- const trimmed = raw.trim();
34655
- if (trimmed.length > 0 && trimmed !== "undefined" && trimmed !== "null" && !PLACEHOLDER_RE.test(trimmed)) {
34656
- return trimmed;
34657
- }
34658
- }
34659
- return opts.default;
34660
- }
34661
- var TRUE_TOKENS = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
34662
- var FALSE_TOKENS = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
34663
- function parseBoolEnv(key, opts = {}) {
34664
- const fallback = opts.default ?? false;
34665
- const raw = readEnvVar(key, { env: opts.env });
34666
- if (raw === void 0)
34667
- return fallback;
34668
- const token = raw.toLowerCase();
34669
- if (TRUE_TOKENS.has(token))
34670
- return true;
34671
- if (FALSE_TOKENS.has(token))
34672
- return false;
34673
- return fallback;
34674
- }
34675
- function expandPath(p) {
34676
- let expanded = p;
34677
- if (p === "~") {
34678
- expanded = homedir();
34679
- } else if (p.startsWith("~/")) {
34680
- expanded = join(homedir(), p.slice(2));
34681
- }
34682
- return isAbsolute(expanded) ? expanded : resolve(expanded);
34683
- }
34684
-
34685
35119
  // ../../node_modules/@chrischall/mcp-utils/dist/fs/confine.js
34686
35120
  import { existsSync, realpathSync } from "node:fs";
34687
35121
  import { dirname, isAbsolute as isAbsolute2, relative, resolve as resolve2, sep } from "node:path";
@@ -34763,9 +35197,9 @@ function offsetAt(instant, tz) {
34763
35197
  const w = wallPartsIn(instant, tz);
34764
35198
  const asUTC = Date.UTC(w.year, w.month - 1, w.day, w.hour, w.minute, w.second, instant.getUTCMilliseconds());
34765
35199
  const minutes = Math.round((asUTC - instant.getTime()) / 6e4);
34766
- const sign = minutes < 0 ? "-" : "+";
35200
+ const sign2 = minutes < 0 ? "-" : "+";
34767
35201
  const abs = Math.abs(minutes);
34768
- return `${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
35202
+ return `${sign2}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
34769
35203
  }
34770
35204
  function wallPartsIn(instant, tz) {
34771
35205
  const parts = new Intl.DateTimeFormat("en-US", {
@@ -35550,6 +35984,52 @@ function formatAuthHealth(raw, now) {
35550
35984
  return accounts.map((a) => formatOneAccountHealth(a, now)).join("\n\n");
35551
35985
  }
35552
35986
 
35987
+ // ../gogcli-mcp/src/send-confirm-token.ts
35988
+ var spent = createSpentTokenStore();
35989
+ function confirmSpentStore() {
35990
+ return spent;
35991
+ }
35992
+
35993
+ // ../gogcli-mcp/src/dispatch-confirmation.ts
35994
+ var BODY_PREVIEW_MAX = 2048;
35995
+ function bodyPreview(text) {
35996
+ if (!text) return void 0;
35997
+ if (text.length <= BODY_PREVIEW_MAX) return text;
35998
+ return `${text.slice(0, BODY_PREVIEW_MAX)}\u2026 [${text.length - BODY_PREVIEW_MAX} more characters not shown]`;
35999
+ }
36000
+ var CONFIRM_ACTION_INSTRUCTION = CONFIRM_TOKEN_INSTRUCTION;
36001
+ var CONFIRM_FALLBACK_DESCRIPTION = ' If the client cannot show that prompt (no MCP elicitation, e.g. claude.ai), a two-step flow applies instead: call WITHOUT confirmToken and nothing is sent or changed \u2014 the result has status "confirmation-required", the full preview and a confirmToken. Follow its instruction (by default: show the preview to the user verbatim and only after they explicitly approve it in chat, call again with the SAME arguments plus confirmToken). The tool re-reads what it would act on and refuses (DRAFT_CHANGED, with a fresh preview and token) if it changed; TOKEN_EXPIRED / TOKEN_REUSED / TOKEN_INVALID also do nothing. A server set to MCP_CONFIRM_MODE=refuse refuses instead.';
36002
+ function gatedElsewhere(what, via, does, tool) {
36003
+ return `${what} ${does} and is not available through ${via}. Use ${tool}, which asks the user to confirm.`;
36004
+ }
36005
+ function hasCommandWord(args, words) {
36006
+ return args.find((a) => words.has(a.toLowerCase()));
36007
+ }
36008
+ async function requireDispatchConfirmation(ctx, options) {
36009
+ const { action, fallback } = options;
36010
+ const confirmation = {
36011
+ action,
36012
+ message: options.message,
36013
+ details: options.details,
36014
+ confirmationLabel: options.confirmationLabel,
36015
+ ...options.unsupportedNote ? { unsupportedNote: options.unsupportedNote } : {}
36016
+ };
36017
+ if (!fallback) return requireConfirmationWithFallback(ctx, confirmation);
36018
+ return requireConfirmationWithFallback(ctx, confirmationFromEnv({
36019
+ ...confirmation,
36020
+ tool: fallback.tool,
36021
+ account: fallback.account ?? readEnvVar("GOG_ACCOUNT") ?? "",
36022
+ confirmToken: fallback.confirmToken,
36023
+ subject: fallback.subject,
36024
+ instruction: fallback.instruction ?? CONFIRM_ACTION_INSTRUCTION,
36025
+ spent: confirmSpentStore()
36026
+ }));
36027
+ }
36028
+ function resultText(result) {
36029
+ const first = result.content[0];
36030
+ return first && first.type === "text" && typeof first.text === "string" ? first.text : "{}";
36031
+ }
36032
+
35553
36033
  // ../gogcli-mcp/src/tools/auth.ts
35554
36034
  var AUTH_RUN_SUBCOMMANDS = ["list", "status", "services", "remove", "alias"];
35555
36035
  function registerAuthToolsWith(server, defaultServices) {
@@ -35715,6 +36195,39 @@ var attachInlineParam = external_exports.array(inlineAttachmentSchema).optional(
35715
36195
  );
35716
36196
 
35717
36197
  // ../gogcli-mcp/src/tools/classroom.ts
36198
+ var CLASSROOM_CREATE_WORDS = /* @__PURE__ */ new Set(["create", "add", "new"]);
36199
+ var CLASSROOM_GATED = {
36200
+ announcements: { does: "posts to a class", tool: "gog_classroom_announcements_create" },
36201
+ announcement: { does: "posts to a class", tool: "gog_classroom_announcements_create" },
36202
+ ann: { does: "posts to a class", tool: "gog_classroom_announcements_create" },
36203
+ invitations: { does: "invites someone to a class", tool: "gog_classroom_invitations_create" },
36204
+ invitation: { does: "invites someone to a class", tool: "gog_classroom_invitations_create" },
36205
+ invites: { does: "invites someone to a class", tool: "gog_classroom_invitations_create" }
36206
+ };
36207
+ function vetClassroomRun(subcommand, args) {
36208
+ const sub = subcommand.toLowerCase();
36209
+ const gated = Object.hasOwn(CLASSROOM_GATED, sub) ? CLASSROOM_GATED[sub] : void 0;
36210
+ if (!gated) return void 0;
36211
+ const word = hasCommandWord(args, CLASSROOM_CREATE_WORDS);
36212
+ return word ? gatedElsewhere(`gog classroom ${sub} ${word.toLowerCase()}`, "gog_classroom_run", gated.does, gated.tool) : void 0;
36213
+ }
36214
+ async function readCourse(courseId, account, runner = runOrDiagnose) {
36215
+ const got = await runner(["classroom", "courses", "get", pos(courseId)], { account });
36216
+ if (got.isError) return { error: got };
36217
+ let course;
36218
+ try {
36219
+ course = JSON.parse(resultText(got))?.course;
36220
+ } catch {
36221
+ course = void 0;
36222
+ }
36223
+ return {
36224
+ course: {
36225
+ id: courseId,
36226
+ ...typeof course?.name === "string" ? { name: course.name } : {},
36227
+ ...typeof course?.section === "string" ? { section: course.section } : {}
36228
+ }
36229
+ };
36230
+ }
35718
36231
  function registerClassroomTools(server) {
35719
36232
  server.registerTool("gog_classroom_courses_list", {
35720
36233
  description: "List Google Classroom courses.",
@@ -35997,19 +36510,42 @@ function registerClassroomTools(server) {
35997
36510
  return runOrDiagnose(["classroom", "announcements", "get", pos(courseId), pos(announcementId)], { account });
35998
36511
  });
35999
36512
  server.registerTool("gog_classroom_announcements_create", {
36000
- description: "Create an announcement in a Google Classroom course.",
36513
+ description: "Create an announcement in a Google Classroom course. Unless state is DRAFT (which students cannot see), this reads the course and asks the MCP host to show the user a confirmation prompt with the class, the full text and when it publishes; nothing is posted unless they accept. To stage one without asking, pass state DRAFT." + CONFIRM_FALLBACK_DESCRIPTION,
36001
36514
  annotations: { destructiveHint: true },
36002
36515
  inputSchema: external_exports.object({
36003
36516
  courseId: external_exports.string().describe("Course ID"),
36004
36517
  text: external_exports.string().describe("Announcement text"),
36005
- state: external_exports.enum(["PUBLISHED", "DRAFT"]).optional().describe("State"),
36518
+ state: external_exports.enum(["PUBLISHED", "DRAFT"]).optional().describe("State (DRAFT is visible only to teachers and needs no confirmation)"),
36006
36519
  scheduled: external_exports.string().optional().describe("Scheduled publish time"),
36007
- account: accountParam
36520
+ account: accountParam,
36521
+ confirmToken: confirmTokenParam
36008
36522
  })
36009
- }, async ({ courseId, text, state, scheduled, account }) => {
36523
+ }, async ({ courseId, text, state, scheduled, account, confirmToken }, ctx) => {
36010
36524
  const args = ["classroom", "announcements", "create", pos(courseId), `--text=${text}`];
36011
36525
  if (state) args.push(`--state=${state}`);
36012
36526
  if (scheduled) args.push(`--scheduled=${scheduled}`);
36527
+ if (state !== "DRAFT") {
36528
+ const read = await readCourse(courseId, account);
36529
+ if (read.error) return read.error;
36530
+ const publishes = scheduled ? `at ${scheduled}` : "immediately";
36531
+ const confirmation = await requireDispatchConfirmation(ctx, {
36532
+ action: "classroom.announcement-create",
36533
+ message: "Review and confirm this Classroom announcement:",
36534
+ confirmationLabel: "Confirm that this announcement should be posted to the class.",
36535
+ details: { course: read.course, publishes, textPreview: bodyPreview(text) },
36536
+ unsupportedNote: "Create it with state DRAFT instead; the user can review and post it from Classroom.",
36537
+ fallback: {
36538
+ tool: "gog_classroom_announcements_create",
36539
+ account,
36540
+ confirmToken,
36541
+ subject: () => {
36542
+ const view = { course: read.course, publishes, text };
36543
+ return { target: courseId, payload: view, preview: view };
36544
+ }
36545
+ }
36546
+ });
36547
+ if (confirmation) return confirmation;
36548
+ }
36013
36549
  return runOrDiagnose(args, { account });
36014
36550
  });
36015
36551
  server.registerTool("gog_classroom_topics_list", {
@@ -36099,6 +36635,7 @@ function registerClassroomTools(server) {
36099
36635
  registerRunTool(server, {
36100
36636
  service: "classroom",
36101
36637
  examples: '"guardians", "materials", "guardian-invitations"',
36638
+ vet: vetClassroomRun,
36102
36639
  note: "Covers anything not wrapped by the dedicated tools (guardians, guardian-invitations, materials, coursework assignees, announcement assignees, etc.)."
36103
36640
  });
36104
36641
  }
@@ -36124,7 +36661,7 @@ var replySchema = {
36124
36661
  signatureFile: external_exports.string().optional().describe("Append a local signature file (plain text or HTML), read on the gog server"),
36125
36662
  account: accountParam
36126
36663
  };
36127
- var sendReplySchema = external_exports.object(replySchema);
36664
+ var sendReplySchema = external_exports.object({ ...replySchema, confirmToken: confirmTokenParam });
36128
36665
 
36129
36666
  // ../gogcli-mcp/src/tools/sheets.ts
36130
36667
  var cellValueParam = external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean(), external_exports.null()]);
@@ -36136,7 +36673,7 @@ var failIfNotEmptyParam = external_exports.boolean().optional().describe(
36136
36673
  );
36137
36674
 
36138
36675
  // ../gogcli-mcp/src/server.ts
36139
- var VERSION = true ? "4.3.0" : "0.0.0";
36676
+ var VERSION = true ? "4.5.0" : "0.0.0";
36140
36677
 
36141
36678
  // ../gogcli-mcp/src/bootstrap-auth.ts
36142
36679
  import { join as join5 } from "node:path";
@@ -36173,12 +36710,12 @@ async function bootstrapGogAuth(env = process.env, options = {}) {
36173
36710
  const [clientId, clientSecret, refreshToken, account] = values;
36174
36711
  const { spawner } = options;
36175
36712
  try {
36176
- const { createHash } = await import("node:crypto");
36713
+ const { createHash: createHash4 } = await import("node:crypto");
36177
36714
  const { mkdir, readFile, writeFile, chmod } = await import("node:fs/promises");
36178
36715
  const home = options.home ?? (await import("node:os")).homedir();
36179
36716
  const dir = join5(home, ".gogcli-mcp");
36180
36717
  const marker = join5(dir, AUTH_BOOTSTRAP_MARKER);
36181
- const fingerprint = createHash("sha256").update(values.join("\0")).digest("hex");
36718
+ const fingerprint = createHash4("sha256").update(values.join("\0")).digest("hex");
36182
36719
  const previous = await readFile(marker, "utf8").catch(() => void 0);
36183
36720
  if (previous === fingerprint && await accountListed(account, spawner)) return "present";
36184
36721
  await run(
@@ -36470,15 +37007,33 @@ function registerExtraClassroomTools(server) {
36470
37007
  return runOrDiagnose(["classroom", "topics", "delete", pos(courseId), pos(topicId), "--force"], { account });
36471
37008
  });
36472
37009
  server.registerTool("gog_classroom_invitations_create", {
36473
- description: "Create an invitation to a Google Classroom course.",
37010
+ description: "Create an invitation to a Google Classroom course \u2014 Classroom emails the invitee. Reads the course and asks the MCP host to show the user a confirmation prompt with the class, the invitee and the role; nothing is sent unless they accept." + CONFIRM_FALLBACK_DESCRIPTION,
36474
37011
  annotations: { destructiveHint: true },
36475
37012
  inputSchema: external_exports.object({
36476
37013
  courseId: external_exports.string().describe("Course ID"),
36477
37014
  userId: external_exports.string().describe("User ID to invite"),
36478
37015
  role: external_exports.enum(["STUDENT", "TEACHER", "OWNER"]).describe("Role for the invited user"),
36479
- account: accountParam
37016
+ account: accountParam,
37017
+ confirmToken: confirmTokenParam
36480
37018
  })
36481
- }, async ({ courseId, userId, role, account }) => {
37019
+ }, async ({ courseId, userId, role, account, confirmToken }, ctx) => {
37020
+ const read = await readCourse(courseId, account, runOrDiagnose);
37021
+ if (read.error) return read.error;
37022
+ const invitation = { course: read.course, invitee: userId, role };
37023
+ const confirmation = await requireDispatchConfirmation(ctx, {
37024
+ action: "classroom.invitation-create",
37025
+ message: role === "OWNER" ? "Review and confirm this Classroom invitation \u2014 it offers OWNERSHIP of the course:" : "Review and confirm this Classroom invitation:",
37026
+ confirmationLabel: "Confirm that this invitation should be sent now.",
37027
+ details: invitation,
37028
+ unsupportedNote: "Ask the user to invite them from Classroom.",
37029
+ fallback: {
37030
+ tool: "gog_classroom_invitations_create",
37031
+ account,
37032
+ confirmToken,
37033
+ subject: () => ({ target: `${courseId}/${userId}`, payload: invitation, preview: invitation })
37034
+ }
37035
+ });
37036
+ if (confirmation) return confirmation;
36482
37037
  return runOrDiagnose(["classroom", "invitations", "create", pos(courseId), pos(userId), `--role=${role}`], { account });
36483
37038
  });
36484
37039
  server.registerTool("gog_classroom_invitations_delete", {
package/manifest.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifest_version": "0.3",
4
4
  "name": "gogcli-mcp-classroom",
5
5
  "display_name": "gogcli (Classroom)",
6
- "version": "4.3.0",
6
+ "version": "4.5.0",
7
7
  "description": "Extended Google Classroom for Claude via gogcli — auth + full Classroom support (courses, rosters, coursework, submissions, announcements, topics, invitations)",
8
8
  "author": {
9
9
  "name": "Chris Hall",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gogcli-mcp-classroom",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "mcpName": "io.github.chrischall/gogcli-mcp-classroom",
5
5
  "description": "Extended Google Classroom MCP server via gogcli — auth + full Classroom support",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
@@ -24,7 +24,7 @@
24
24
  "test:coverage": "vitest run --coverage"
25
25
  },
26
26
  "dependencies": {
27
- "@chrischall/mcp-utils": "^2.4.0",
27
+ "@chrischall/mcp-utils": "^2.6.0",
28
28
  "@modelcontextprotocol/server": "^2.0.0",
29
29
  "zod": "^4.6.1"
30
30
  },
package/server.json CHANGED
@@ -7,12 +7,12 @@
7
7
  "source": "github",
8
8
  "subfolder": "packages/gogcli-mcp-classroom"
9
9
  },
10
- "version": "4.3.0",
10
+ "version": "4.5.0",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "gogcli-mcp-classroom",
15
- "version": "4.3.0",
15
+ "version": "4.5.0",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  },
@@ -1,6 +1,6 @@
1
1
  import { McpServer } from '@modelcontextprotocol/server';
2
2
  import { z } from 'zod';
3
- import { accountParam, runOrDiagnose, pos } from '../../../gogcli-mcp/src/lib.js';
3
+ import { accountParam, runOrDiagnose, pos, readCourse, requireDispatchConfirmation, CONFIRM_FALLBACK_DESCRIPTION, confirmTokenParam } from '../../../gogcli-mcp/src/lib.js';
4
4
  import type { GogArg } from '../../../gogcli-mcp/src/lib.js';
5
5
 
6
6
  const courseState = z.enum(['ACTIVE', 'ARCHIVED', 'PROVISIONED', 'DECLINED', 'SUSPENDED']);
@@ -286,15 +286,37 @@ export function registerExtraClassroomTools(server: McpServer): void {
286
286
  });
287
287
 
288
288
  server.registerTool('gog_classroom_invitations_create', {
289
- description: 'Create an invitation to a Google Classroom course.',
289
+ description: 'Create an invitation to a Google Classroom course — Classroom emails the invitee. Reads the course '
290
+ + 'and asks the MCP host to show the user a confirmation prompt with the class, the invitee and the role; '
291
+ + 'nothing is sent unless they accept.' + CONFIRM_FALLBACK_DESCRIPTION,
290
292
  annotations: { destructiveHint: true },
291
293
  inputSchema: z.object({
292
294
  courseId: z.string().describe('Course ID'),
293
295
  userId: z.string().describe('User ID to invite'),
294
296
  role: z.enum(['STUDENT', 'TEACHER', 'OWNER']).describe('Role for the invited user'),
295
297
  account: accountParam,
298
+ confirmToken: confirmTokenParam,
296
299
  }),
297
- }, async ({ courseId, userId, role, account }) => {
300
+ }, async ({ courseId, userId, role, account, confirmToken }, ctx) => {
301
+ const read = await readCourse(courseId, account, runOrDiagnose);
302
+ if (read.error) return read.error;
303
+ const invitation = { course: read.course, invitee: userId, role };
304
+ const confirmation = await requireDispatchConfirmation(ctx, {
305
+ action: 'classroom.invitation-create',
306
+ message: role === 'OWNER'
307
+ ? 'Review and confirm this Classroom invitation — it offers OWNERSHIP of the course:'
308
+ : 'Review and confirm this Classroom invitation:',
309
+ confirmationLabel: 'Confirm that this invitation should be sent now.',
310
+ details: invitation,
311
+ unsupportedNote: 'Ask the user to invite them from Classroom.',
312
+ fallback: {
313
+ tool: 'gog_classroom_invitations_create',
314
+ account,
315
+ confirmToken,
316
+ subject: () => ({ target: `${courseId}/${userId}`, payload: invitation, preview: invitation }),
317
+ },
318
+ });
319
+ if (confirmation) return confirmation;
298
320
  return runOrDiagnose(['classroom', 'invitations', 'create', pos(courseId), pos(userId), `--role=${role}`], { account });
299
321
  });
300
322
 
@@ -1,4 +1,4 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
2
  import { registerExtraClassroomTools } from '../../src/tools/classroom-extra.js';
3
3
  import * as lib from '../../../gogcli-mcp/src/lib.js';
4
4
  import { createTestHarness, type TestHarness } from '@chrischall/mcp-utils/test';
@@ -15,10 +15,15 @@ vi.mock('../../../gogcli-mcp/src/lib.js', async (importOriginal) => {
15
15
 
16
16
  let harness: TestHarness;
17
17
 
18
+ // MCP_CONFIRM_MODE is read per call; a test that sets it must not leak it.
19
+ afterEach(() => { delete process.env.MCP_CONFIRM_MODE; });
20
+
18
21
  beforeEach(async () => {
19
22
  vi.clearAllMocks();
20
23
  vi.mocked(lib.runOrDiagnose).mockResolvedValue(rawTextResult('{}'));
21
- harness = await createTestHarness(registerExtraClassroomTools);
24
+ harness = await createTestHarness(registerExtraClassroomTools, {
25
+ elicitation: async () => ({ action: 'accept', content: { confirmed: true } }),
26
+ });
22
27
  });
23
28
 
24
29
  describe('gog_classroom_courses_create', () => {
@@ -249,6 +254,57 @@ describe('gog_classroom_topics_delete', () => {
249
254
  });
250
255
 
251
256
  describe('gog_classroom_invitations_create', () => {
257
+ const COURSE = rawTextResult(JSON.stringify({ course: { id: 'c1', name: 'Algebra II' } }));
258
+
259
+ it('reads the course and prompts with the class, invitee and role', async () => {
260
+ vi.mocked(lib.runOrDiagnose).mockResolvedValue(COURSE);
261
+ let message = '';
262
+ const h = await createTestHarness(registerExtraClassroomTools, {
263
+ elicitation: async (r) => { message = r.params.message; return { action: 'decline' }; },
264
+ });
265
+ await h.callTool('gog_classroom_invitations_create', { courseId: 'c1', userId: 'kid@example.com', role: 'OWNER' });
266
+ expect(message).toMatch(/OWNERSHIP/);
267
+ expect(JSON.parse(message.split('\n').slice(1).join('\n')).details)
268
+ .toEqual({ course: { id: 'c1', name: 'Algebra II' }, invitee: 'kid@example.com', role: 'OWNER' });
269
+ expect(lib.runOrDiagnose).toHaveBeenCalledWith(['classroom', 'courses', 'get', pos('c1')], { account: undefined });
270
+ expect(lib.runOrDiagnose).not.toHaveBeenCalledWith(
271
+ ['classroom', 'invitations', 'create', pos('c1'), pos('kid@example.com'), '--role=OWNER'], { account: undefined });
272
+ });
273
+
274
+ it('refuses a client that cannot be prompted', async () => {
275
+
276
+ process.env.MCP_CONFIRM_MODE = 'refuse';
277
+ vi.mocked(lib.runOrDiagnose).mockResolvedValue(COURSE);
278
+ const h = await createTestHarness(registerExtraClassroomTools);
279
+ const r = JSON.parse((await h.callTool('gog_classroom_invitations_create', { courseId: 'c1', userId: 'u1', role: 'STUDENT' })).content[0]!.text as string);
280
+ expect(r).toMatchObject({ reason: 'confirmation-unsupported', action: 'classroom.invitation-create' });
281
+ expect(r.note).toMatch(/invite them from Classroom/);
282
+ });
283
+
284
+ it('token fallback: phase 1 previews, phase 2 invites', async () => {
285
+ const ORIGINAL = { ...process.env };
286
+ process.env.MCP_CONFIRM_MODE = 'ask-user';
287
+ try {
288
+ vi.mocked(lib.runOrDiagnose).mockResolvedValue(COURSE);
289
+ const h = await createTestHarness(registerExtraClassroomTools);
290
+ const args = { courseId: 'c1', userId: 'u1', role: 'STUDENT' as const };
291
+ const p1 = JSON.parse((await h.callTool('gog_classroom_invitations_create', args)).content[0]!.text as string);
292
+ expect(p1.preview).toEqual({ course: { id: 'c1', name: 'Algebra II' }, invitee: 'u1', role: 'STUDENT' });
293
+ await h.callTool('gog_classroom_invitations_create', { ...args, confirmToken: p1.confirmToken });
294
+ expect(lib.runOrDiagnose).toHaveBeenCalledWith(
295
+ ['classroom', 'invitations', 'create', pos('c1'), pos('u1'), '--role=STUDENT'], { account: undefined });
296
+ } finally {
297
+ process.env = ORIGINAL;
298
+ }
299
+ });
300
+
301
+ it('returns a failed course read without inviting', async () => {
302
+ vi.mocked(lib.runOrDiagnose).mockResolvedValue({ content: [{ type: 'text', text: 'Error: not found' }], isError: true });
303
+ const r = await harness.callTool('gog_classroom_invitations_create', { courseId: 'c1', userId: 'u1', role: 'STUDENT' });
304
+ expect(r.isError).toBe(true);
305
+ expect(lib.runOrDiagnose).toHaveBeenCalledTimes(1);
306
+ });
307
+
252
308
  it('calls runOrDiagnose with courseId, userId, role', async () => {
253
309
  await harness.callTool('gog_classroom_invitations_create', { courseId: 'c1', userId: 'u1', role: 'STUDENT' });
254
310
  expect(lib.runOrDiagnose).toHaveBeenCalledWith(