@haikit/mcp 0.32.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +60 -1
  2. package/dist/auth.d.ts +151 -0
  3. package/dist/auth.d.ts.map +1 -0
  4. package/dist/auth.js +334 -0
  5. package/dist/auth.js.map +1 -0
  6. package/dist/credential.d.ts +55 -0
  7. package/dist/credential.d.ts.map +1 -0
  8. package/dist/credential.js +62 -0
  9. package/dist/credential.js.map +1 -0
  10. package/dist/errors.d.ts +24 -1
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +3 -0
  13. package/dist/errors.js.map +1 -1
  14. package/dist/index.d.ts +44 -11
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +511 -144
  17. package/dist/index.js.map +1 -1
  18. package/dist/oauth.d.ts +193 -0
  19. package/dist/oauth.d.ts.map +1 -0
  20. package/dist/oauth.js +558 -0
  21. package/dist/oauth.js.map +1 -0
  22. package/dist/postgres.d.ts +25 -0
  23. package/dist/postgres.d.ts.map +1 -0
  24. package/dist/postgres.js +97 -0
  25. package/dist/postgres.js.map +1 -0
  26. package/dist/routes.d.ts +17 -0
  27. package/dist/routes.d.ts.map +1 -0
  28. package/dist/routes.js +228 -0
  29. package/dist/routes.js.map +1 -0
  30. package/dist/seal.d.ts +25 -0
  31. package/dist/seal.d.ts.map +1 -0
  32. package/dist/seal.js +60 -0
  33. package/dist/seal.js.map +1 -0
  34. package/dist/store.d.ts +50 -0
  35. package/dist/store.d.ts.map +1 -0
  36. package/dist/store.js +83 -0
  37. package/dist/store.js.map +1 -0
  38. package/dist/transports.d.ts +17 -3
  39. package/dist/transports.d.ts.map +1 -1
  40. package/dist/transports.js +13 -3
  41. package/dist/transports.js.map +1 -1
  42. package/package.json +6 -2
  43. package/src/auth.ts +466 -0
  44. package/src/credential.ts +78 -0
  45. package/src/errors.ts +26 -2
  46. package/src/index.ts +555 -158
  47. package/src/oauth.ts +659 -0
  48. package/src/postgres.ts +127 -0
  49. package/src/routes.ts +243 -0
  50. package/src/seal.ts +62 -0
  51. package/src/store.ts +118 -0
  52. package/src/transports.ts +34 -4
package/src/errors.ts CHANGED
@@ -10,8 +10,29 @@ import type { ContentBlock } from "@modelcontextprotocol/client";
10
10
  * - `protocol`: the server refused the call, such as for a tool it doesn't
11
11
  * have, or asked for something this client doesn't do.
12
12
  * - `closed`: `close()` was called.
13
+ * - `user`: a server with `auth` had no user to call as, so nothing was sent.
14
+ * - `auth`: the user's credential for the server is missing, was refused, or
15
+ * needs more access. `auth` on the error says which.
13
16
  */
14
- export type McpErrorReason = "args" | "result" | "timeout" | "connection" | "protocol" | "closed";
17
+ export type McpErrorReason = "args" | "result" | "timeout" | "connection" | "protocol" | "closed" | "user" | "auth";
18
+
19
+ /** What a call with reason `auth` needs from the user. */
20
+ export interface McpAuthNeed {
21
+ /**
22
+ * `connect`: the user has no credential for the server, so nothing was sent.
23
+ * `reconnect`: the server refused theirs. `scope`: theirs needs more access.
24
+ */
25
+ readonly kind: "connect" | "reconnect" | "scope";
26
+ /** On `scope`: the scope the server asked for, as its challenge put it. */
27
+ readonly scope?: string;
28
+ /**
29
+ * For an `oauth()` server: the app's connect route for this server and the
30
+ * call's conversation, asking for `scope` if there is one, such as
31
+ * `/mcp/connect/github?conversation=c_123`. For the browser, as a surface's
32
+ * prop: never for the model. Absent for `bearer()` and `sdk()`.
33
+ */
34
+ readonly connect?: string;
35
+ }
15
36
 
16
37
  /**
17
38
  * A call that didn't get a result. The message names only the server and the
@@ -34,11 +55,13 @@ export class McpError extends Error {
34
55
  readonly text: string | undefined;
35
56
  /** A JSON-RPC error's code. */
36
57
  readonly code: number | undefined;
58
+ /** With reason `auth`: what the user's credential needs. */
59
+ readonly auth: McpAuthNeed | undefined;
37
60
 
38
61
  constructor(
39
62
  reason: McpErrorReason,
40
63
  message: string,
41
- detail: { server: string; tool?: string; text?: string; code?: number; cause?: unknown },
64
+ detail: { server: string; tool?: string; text?: string; code?: number; cause?: unknown; auth?: McpAuthNeed },
42
65
  ) {
43
66
  super(message, detail.cause === undefined ? undefined : { cause: detail.cause });
44
67
  this.reason = reason;
@@ -46,6 +69,7 @@ export class McpError extends Error {
46
69
  this.tool = detail.tool;
47
70
  this.text = detail.text;
48
71
  this.code = detail.code;
72
+ this.auth = detail.auth === undefined ? undefined : Object.freeze({ ...detail.auth });
49
73
  }
50
74
  }
51
75