@shipstatic/mcp 1.0.0-beta.12 → 1.0.0-beta.13

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/dist/call.d.ts CHANGED
@@ -37,6 +37,56 @@ export interface CallOptions {
37
37
  * failure has exactly one published shape, and no schema to keep in step.
38
38
  */
39
39
  structuredContent?: boolean;
40
+ /**
41
+ * Called when the API refuses on CREDENTIAL grounds — and only then.
42
+ *
43
+ * An HTTP transport has an obligation stdio does not: a client learns it
44
+ * must authenticate from a real `401` with a `WWW-Authenticate` header, and
45
+ * ignores that header entirely on a `200`. So a tool error saying "please
46
+ * authenticate" is, on that transport, a dead end — the caller is told
47
+ * something it has no way to act on.
48
+ *
49
+ * This is the seam that lets the transport answer properly, and the
50
+ * decision of WHAT counts as a credential failure stays here, beside the
51
+ * hints, rather than being made a second time by each consumer:
52
+ *
53
+ * - **Authentication** always reports. The credential was absent, malformed,
54
+ * unknown, or expired — the transport cannot tell which, and does not
55
+ * need to.
56
+ * - **Forbidden reports only when it carries `requiredScope`.** That field
57
+ * is the API's own signal that a valid grant simply lacks a permission,
58
+ * which re-consent can fix. Every other refusal on that arm — plan limits,
59
+ * a terminated account, an action no scope can authorize — is a genuine
60
+ * answer to the question asked, and stays an ordinary in-band tool error.
61
+ *
62
+ * The result is unchanged either way: the agent still receives the full
63
+ * text envelope, hints included. This is a notification, not a substitution.
64
+ *
65
+ * Why an observer at all, rather than the transport inspecting the request:
66
+ * peeking at a JSON-RPC body to guess whether a call needs a credential
67
+ * means parsing it twice — on the deploy path, that is tens of megabytes of
68
+ * base64 re-parsed before the size caps run — and it can only ever guess at
69
+ * PRESENCE, so an EXPIRED token would answer in-band and a connected client
70
+ * would never refresh. Reporting what the API actually answered costs
71
+ * nothing and is correct for both.
72
+ */
73
+ onAuthFailure?: (failure: AuthFailure) => void;
74
+ }
75
+ /**
76
+ * What a credential refusal was, in the only two shapes a transport acts on
77
+ * differently.
78
+ *
79
+ * Deliberately not an HTTP status or an RFC 6750 error code: those are the
80
+ * consuming transport's vocabulary, and stdio — which also builds a `call` —
81
+ * has neither. The presence of `requiredScope` is the whole discriminator, so
82
+ * there is no second field restating it.
83
+ */
84
+ export interface AuthFailure {
85
+ /**
86
+ * The scope the grant is missing, from the API's `details.requiredScope`.
87
+ * Absent when the credential itself was refused rather than its permissions.
88
+ */
89
+ requiredScope?: string;
40
90
  }
41
91
  /**
42
92
  * Builds the `call()` wrapper both transports use: SDK promise in, MCP
package/dist/call.js CHANGED
@@ -9,7 +9,7 @@ import { ErrorType, isShipError } from '@shipstatic/ship';
9
9
  * kept equal by review.
10
10
  */
11
11
  export function createCall(options) {
12
- const { hints, structuredContent = false } = options;
12
+ const { hints, structuredContent = false, onAuthFailure } = options;
13
13
  return async function call(fn) {
14
14
  try {
15
15
  const result = await fn();
@@ -28,10 +28,23 @@ export function createCall(options) {
28
28
  };
29
29
  }
30
30
  catch (error) {
31
- return toErrorResult(error, hints);
31
+ return toErrorResult(error, hints, onAuthFailure);
32
32
  }
33
33
  };
34
34
  }
35
+ /**
36
+ * Read the API's `details.requiredScope`, if this refusal carries one.
37
+ *
38
+ * `details` is `unknown` on the wire by design — every arm shapes it
39
+ * differently — so the read is a narrowing rather than a cast, and anything
40
+ * that is not a non-empty string means "no scope was named".
41
+ */
42
+ function requiredScopeOf(details) {
43
+ if (!details || typeof details !== 'object')
44
+ return undefined;
45
+ const scope = details.requiredScope;
46
+ return typeof scope === 'string' && scope ? scope : undefined;
47
+ }
35
48
  function isPlainObject(value) {
36
49
  return typeof value === 'object' && value !== null && !Array.isArray(value);
37
50
  }
@@ -63,14 +76,21 @@ function isPlainObject(value) {
63
76
  * governs success shapes, where the schema-twin objection lives. A failure has
64
77
  * one published shape on every transport.
65
78
  */
66
- function toErrorResult(error, hints) {
79
+ function toErrorResult(error, hints, onAuthFailure) {
67
80
  if (isShipError(error)) {
68
81
  let message = error.message;
69
82
  if (error.isType(ErrorType.Authentication)) {
70
83
  message += `\n\nHint: ${hints.authentication}`;
84
+ onAuthFailure?.({});
71
85
  }
72
86
  if (error.isType(ErrorType.Forbidden)) {
73
87
  message += `\n\nHint: ${hints.forbidden}`;
88
+ // Only a MISSING SCOPE is a credential problem. The same arm carries
89
+ // plan limits and terminated accounts, which re-consenting cannot fix
90
+ // and which the caller should read as the answer it is.
91
+ const requiredScope = requiredScopeOf(error.details);
92
+ if (requiredScope)
93
+ onAuthFailure?.({ requiredScope });
74
94
  }
75
95
  if (error.isType(ErrorType.Validation) && error.details) {
76
96
  message += `\n\nDetails: ${safeStringify(error.details)}`;
package/dist/index.d.ts CHANGED
@@ -60,7 +60,7 @@
60
60
  * extra — because adding an export is the quiet failure: everything published
61
61
  * becomes a breaking change to remove.
62
62
  */
63
- export { type CallFn, type CallOptions, createCall, type ErrorHints } from './call.js';
63
+ export { type AuthFailure, type CallFn, type CallOptions, createCall, type ErrorHints, } from './call.js';
64
64
  export { createServer } from './server.js';
65
65
  export { ACCOUNT_TOOL_NAMES, registerAccountTools } from './tools.js';
66
66
  export { ANNOTATIONS, DESCRIPTION_BLOCKS, INSTRUCTION_BLOCKS, PARAM_DESCRIPTIONS, PUBLIC_EXPIRY, SERVER_NAME, UPLOAD_TOOL_NAME, UPLOAD_TOOL_TITLE, } from './vocabulary.js';
package/dist/index.js CHANGED
@@ -60,7 +60,7 @@
60
60
  * extra — because adding an export is the quiet failure: everything published
61
61
  * becomes a breaking change to remove.
62
62
  */
63
- export { createCall } from './call.js';
63
+ export { createCall, } from './call.js';
64
64
  export { createServer } from './server.js';
65
65
  export { ACCOUNT_TOOL_NAMES, registerAccountTools } from './tools.js';
66
66
  export { ANNOTATIONS, DESCRIPTION_BLOCKS, INSTRUCTION_BLOCKS, PARAM_DESCRIPTIONS, PUBLIC_EXPIRY, SERVER_NAME, UPLOAD_TOOL_NAME, UPLOAD_TOOL_TITLE, } from './vocabulary.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/mcp",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.13",
4
4
  "mcpName": "com.shipstatic/mcp",
5
5
  "description": "ShipStatic MCP — deploy static websites from AI agents. Full toolset incl. custom domains. Free hosted endpoint at mcp.shipstatic.com — no install.",
6
6
  "type": "module",