brightspace-mcp-server 5.1.19 → 5.1.20

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 @@ import { DEFAULT_CACHE_TTLS } from "./types.js";
7
7
  import { TTLCache } from "./cache.js";
8
8
  import { TokenBucket } from "./rate-limiter.js";
9
9
  import { discoverVersions } from "./version-discovery.js";
10
- import { ApiError, RateLimitError, NetworkError } from "./errors.js";
10
+ import { ApiError, CredentialRejectedError, RateLimitError, NetworkError } from "./errors.js";
11
11
  import { withRetry, isRetryableFailure, retryAfterMsFrom, parseRetryAfter, } from "./retry.js";
12
12
  import { log } from "../utils/logger.js";
13
13
  import { AUTH_COMMAND } from "../utils/commands.js";
@@ -475,7 +475,9 @@ export class D2LApiClient {
475
475
  }
476
476
  log("WARN", "Auto-reauthentication did not produce a valid token");
477
477
  }
478
- throw new ApiError(401, path, this.authExpiredMessage ?? `Session expired. Please re-authenticate via ${AUTH_COMMAND}.`);
478
+ if (this.authExpiredMessage)
479
+ throw new CredentialRejectedError(path, this.authExpiredMessage);
480
+ throw new ApiError(401, path, `Session expired. Please re-authenticate via ${AUTH_COMMAND}.`);
479
481
  }
480
482
  /**
481
483
  * Make one HTTP request. Authentication recovery is shared with raw downloads.
@@ -17,6 +17,19 @@ export class ApiError extends AuthError {
17
17
  this.name = "ApiError";
18
18
  }
19
19
  }
20
+ /**
21
+ * A 401 for a credential pasted into the environment (D2L_ACCESS_TOKEN or
22
+ * D2L_SESSION_COOKIE). No browser sign-in stands behind it, so the user is
23
+ * told how to replace the credential rather than to run the auth command.
24
+ */
25
+ export class CredentialRejectedError extends ApiError {
26
+ guidance;
27
+ constructor(endpoint, guidance) {
28
+ super(401, endpoint, guidance);
29
+ this.guidance = guidance;
30
+ this.name = "CredentialRejectedError";
31
+ }
32
+ }
20
33
  // Generic HTTP error (non-401/429) - semantic alias for ApiError
21
34
  export class HttpError extends ApiError {
22
35
  constructor(status, endpoint, message, responseBody, cause) {
@@ -12,5 +12,5 @@ export { discoverVersions } from "./version-discovery.js";
12
12
  export { TTLCache } from "./cache.js";
13
13
  export { TokenBucket } from "./rate-limiter.js";
14
14
  // Errors
15
- export { ApiError, RateLimitError, NetworkError } from "./errors.js";
15
+ export { ApiError, CredentialRejectedError, RateLimitError, NetworkError } from "./errors.js";
16
16
  export { DEFAULT_CACHE_TTLS } from "./types.js";
@@ -6,7 +6,7 @@
6
6
  import { DEFAULT_CACHE_TTLS } from "../api/index.js";
7
7
  import { fetchAllItems } from "../api/paginate.js";
8
8
  import { GetAnnouncementsSchema, } from "./schemas.js";
9
- import { toolResponse, toolResponseWithNotice, sanitizeError, isAuthUnavailable, authPendingNotice } from "./tool-helpers.js";
9
+ import { toolResponse, toolResponseWithNotice, sanitizeError, isAuthUnavailable, authPendingNotice, throwIfCredentialRejected } from "./tool-helpers.js";
10
10
  import { log } from "../utils/logger.js";
11
11
  import { applyCourseFilter } from "../utils/course-filter.js";
12
12
  import { matchesModifiedSince } from "../utils/modified-since.js";
@@ -150,6 +150,7 @@ export function registerGetAnnouncements(server, apiClient, config) {
150
150
  // answered, so the result says so instead of reporting zero
151
151
  // announcements as if that were a real measurement.
152
152
  if (isAuthUnavailable(error)) {
153
+ throwIfCredentialRejected(error);
153
154
  log("DEBUG", `get_announcements: sign-in pending for course ${courseId}`, error);
154
155
  const notice = "Sign-in to Brightspace is still in progress, so announcements for this course " +
155
156
  `could not be fetched yet. ${authPendingNotice(error)} Call get_announcements again ` +
@@ -250,6 +251,8 @@ export function registerGetAnnouncements(server, apiClient, config) {
250
251
  // always a bare array — a shape change would break every existing
251
252
  // caller — so a pending course adds a second content block carrying
252
253
  // the notice instead of changing content[0].
254
+ if (pending.length > 0)
255
+ throwIfCredentialRejected(pending[0].authError);
253
256
  if (!modifiedSince) {
254
257
  if (pending.length === 0)
255
258
  return arrayPage(announcements, pagination);
@@ -6,7 +6,7 @@
6
6
  import { DEFAULT_CACHE_TTLS } from "../api/index.js";
7
7
  import { fetchAllItems, fetchAllObjects } from "../api/paginate.js";
8
8
  import { GetAssignmentsSchema } from "./schemas.js";
9
- import { toolResponse, sanitizeError, isAuthUnavailable, authPendingNotice } from "./tool-helpers.js";
9
+ import { toolResponse, sanitizeError, isAuthUnavailable, authPendingNotice, throwIfCredentialRejected } from "./tool-helpers.js";
10
10
  import { convertHtmlToMarkdown } from "../utils/html-converter.js";
11
11
  import { log } from "../utils/logger.js";
12
12
  import { applyCourseFilter } from "../utils/course-filter.js";
@@ -892,6 +892,7 @@ export function registerGetAssignments(server, apiClient, config) {
892
892
  // keep working — with authPending/notice added for callers that
893
893
  // want to tell "no assignments" apart from "couldn't check".
894
894
  if (isAuthUnavailable(error)) {
895
+ throwIfCredentialRejected(error);
895
896
  log("DEBUG", `get_assignments: sign-in pending for course ${courseId}`, error);
896
897
  return toolResponse({
897
898
  courseId,
@@ -983,6 +984,7 @@ export function registerGetAssignments(server, apiClient, config) {
983
984
  ],
984
985
  };
985
986
  if (pending.length > 0) {
987
+ throwIfCredentialRejected(pending[0].authError);
986
988
  response.authPending = true;
987
989
  response.unavailableCourseIds = pending.map((c) => c.courseId);
988
990
  response.notice =
@@ -4,7 +4,7 @@
4
4
  * Licensed under MIT — see LICENSE file for details.
5
5
  */
6
6
  import { GetCalendarEventsSchema } from "./schemas.js";
7
- import { toolResponse, toolResponseWithNotice, errorResponse, sanitizeError, isAuthUnavailable, authPendingNotice } from "./tool-helpers.js";
7
+ import { toolResponse, toolResponseWithNotice, errorResponse, sanitizeError, isAuthUnavailable, authPendingNotice, throwIfCredentialRejected } from "./tool-helpers.js";
8
8
  import { log } from "../utils/logger.js";
9
9
  import { resolveCourses } from "./resolve-courses.js";
10
10
  import { fetchCourseCalendarEvents } from "./calendar-events.js";
@@ -67,6 +67,7 @@ export function registerGetCalendarEvents(server, apiClient, config) {
67
67
  // which names which course ids are unavailable.
68
68
  const notices = [];
69
69
  if (pendingCourseIds.length > 0) {
70
+ throwIfCredentialRejected(firstAuthError);
70
71
  notices.push("Sign-in to Brightspace is still in progress, so calendar events for " +
71
72
  `${pendingCourseIds.length} course(s) (${pendingCourseIds.join(", ")}) could not be fetched ` +
72
73
  `yet. ${authPendingNotice(firstAuthError)} Call get_calendar_events again once sign-in finishes.`);
@@ -6,7 +6,7 @@
6
6
  import { DEFAULT_CACHE_TTLS } from "../api/index.js";
7
7
  import { fetchAllItems, fetchAllObjects } from "../api/paginate.js";
8
8
  import { GetMyGradesSchema, } from "./schemas.js";
9
- import { toolResponse, sanitizeError, errorResponse, isAuthUnavailable, authPendingNotice, } from "./tool-helpers.js";
9
+ import { toolResponse, sanitizeError, errorResponse, isAuthUnavailable, authPendingNotice, throwIfCredentialRejected, } from "./tool-helpers.js";
10
10
  import { log } from "../utils/logger.js";
11
11
  import { applyCourseFilter } from "../utils/course-filter.js";
12
12
  import { gradebookUrl, quizUrl } from "../utils/deep-links.js";
@@ -115,6 +115,7 @@ export function registerGetMyGrades(server, apiClient, config) {
115
115
  // working — with authPending/notice added for callers that want
116
116
  // to tell "no grades" apart from "couldn't check".
117
117
  if (isAuthUnavailable(error)) {
118
+ throwIfCredentialRejected(error);
118
119
  log("DEBUG", `get_my_grades: sign-in pending for course ${courseId}`, error);
119
120
  return toolResponse({
120
121
  courseId,
@@ -260,6 +261,7 @@ export function registerGetMyGrades(server, apiClient, config) {
260
261
  };
261
262
  const notices = [];
262
263
  if (pending.length > 0) {
264
+ throwIfCredentialRejected(pending[0].authError);
263
265
  response.authPending = true;
264
266
  response.unavailableCourseIds = pending.map((c) => c.courseId);
265
267
  notices.push("Sign-in to Brightspace is still in progress, so grades for " +
@@ -6,7 +6,7 @@
6
6
  import { DEFAULT_CACHE_TTLS } from "../api/index.js";
7
7
  import { fetchAllObjects } from "../api/paginate.js";
8
8
  import { GetRosterSchema, } from "./schemas.js";
9
- import { toolResponse, sanitizeError, isAuthUnavailable, authPendingNotice } from "./tool-helpers.js";
9
+ import { toolResponse, sanitizeError, isAuthUnavailable, authPendingNotice, throwIfCredentialRejected } from "./tool-helpers.js";
10
10
  import { log } from "../utils/logger.js";
11
11
  // Purdue-specific role IDs. These are institution-specific values.
12
12
  // If using at another institution, you may need to adjust these.
@@ -80,6 +80,8 @@ export function registerGetRoster(server, apiClient) {
80
80
  // roster that lost its TAs to a pending sign-in should still show
81
81
  // the instructor it already has.
82
82
  authFailure = [instructorResult, taResult].find((r) => r.status === "rejected" && isAuthUnavailable(r.reason));
83
+ if (authFailure)
84
+ throwIfCredentialRejected(authFailure.reason);
83
85
  // Merge results
84
86
  if (instructorResult.status === "fulfilled") {
85
87
  allUsers.push(...instructorResult.value);
@@ -169,6 +171,7 @@ export function registerGetRoster(server, apiClient) {
169
171
  // authPending/notice added for callers that want to tell "empty
170
172
  // roster" apart from "couldn't check".
171
173
  if (isAuthUnavailable(error)) {
174
+ throwIfCredentialRejected(error);
172
175
  log("DEBUG", `get_roster: sign-in pending for course ${courseId}`, error);
173
176
  return toolResponse({
174
177
  courseId,
@@ -6,7 +6,7 @@
6
6
  import { DEFAULT_CACHE_TTLS } from "../api/index.js";
7
7
  import { fetchAllObjects } from "../api/paginate.js";
8
8
  import { GetUpcomingDueDatesSchema, } from "./schemas.js";
9
- import { toolResponse, toolResponseWithNotice, sanitizeError, isAuthUnavailable, authPendingNotice } from "./tool-helpers.js";
9
+ import { toolResponse, toolResponseWithNotice, sanitizeError, isAuthUnavailable, authPendingNotice, throwIfCredentialRejected } from "./tool-helpers.js";
10
10
  import { log } from "../utils/logger.js";
11
11
  import { quizUrl, discussionUrl } from "../utils/deep-links.js";
12
12
  import { assignmentLinkResolver } from "./assignment-links.js";
@@ -242,6 +242,7 @@ export function registerGetUpcomingDueDates(server, apiClient, config) {
242
242
  if (pendingCourseIds.length === 0) {
243
243
  return toolResponse(upcoming);
244
244
  }
245
+ throwIfCredentialRejected(firstAuthError);
245
246
  return toolResponseWithNotice(upcoming, "Sign-in to Brightspace is still in progress, so upcoming due dates for " +
246
247
  `${pendingCourseIds.length} course(s) (${pendingCourseIds.join(", ")}) could not be fetched ` +
247
248
  `yet. ${authPendingNotice(firstAuthError)} Call get_upcoming_due_dates again once sign-in finishes.`);
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { ZodError } from "zod";
7
7
  import { ApiError, RateLimitError, NetworkError } from "../api/index.js";
8
- import { TokenRefreshError } from "../api/errors.js";
8
+ import { CredentialRejectedError, TokenRefreshError } from "../api/errors.js";
9
9
  import { AuthProcessError } from "../auth/auth-runner.js";
10
10
  import { log } from "../utils/logger.js";
11
11
  import { AUTH_COMMAND } from "../utils/commands.js";
@@ -226,6 +226,16 @@ export function authPendingNotice(error) {
226
226
  return "Authentication expired. Auto-reauthentication was attempted but failed. " +
227
227
  `Please run \`${AUTH_COMMAND}\` in your terminal, then try again.`;
228
228
  }
229
+ /**
230
+ * A rejected pasted credential (D2L_ACCESS_TOKEN or D2L_SESSION_COOKIE) never
231
+ * recovers by waiting, unlike a pending sign-in. Tools call this before
232
+ * reporting "sign-in is still in progress", so the whole call fails instead
233
+ * and sanitizeError tells the user how to replace the credential.
234
+ */
235
+ export function throwIfCredentialRejected(error) {
236
+ if (error instanceof CredentialRejectedError)
237
+ throw error;
238
+ }
229
239
  /**
230
240
  * Sanitize errors for user-friendly messages
231
241
  *
@@ -263,6 +273,9 @@ function describeError(error) {
263
273
  if (error.status === 404) {
264
274
  return errorResponse("Resource not found. The course or item may not exist, or you may not have access.");
265
275
  }
276
+ if (error instanceof CredentialRejectedError) {
277
+ return errorResponse(error.guidance);
278
+ }
266
279
  if (error.status === 401) {
267
280
  // A stale install is a common cause of sign-in failing, so this is the
268
281
  // one error worth attaching the update notice to.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brightspace-mcp-server",
3
- "version": "5.1.19",
3
+ "version": "5.1.20",
4
4
  "mcpName": "io.github.RohanMuppa/brightspace",
5
5
  "description": "MCP server for Brightspace (D2L). Check grades, due dates, assignments, announcements, syllabus, rosters and more via Claude, ChatGPT, Cursor, Windsurf, or any MCP client.",
6
6
  "type": "module",