@aidenhq/sdk 0.5.7 → 0.5.9

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 (73) hide show
  1. package/dist/assets/page-kit.js +13 -33
  2. package/dist/src/attribution.d.ts +0 -4
  3. package/dist/src/attribution.js +1 -9
  4. package/dist/src/box-bundle.d.ts +1 -5
  5. package/dist/src/box-bundle.js +2 -9
  6. package/dist/src/caller.d.ts +0 -2
  7. package/dist/src/caller.js +2 -6
  8. package/dist/src/checks.d.ts +9 -52
  9. package/dist/src/checks.js +10 -53
  10. package/dist/src/churn.d.ts +2 -12
  11. package/dist/src/churn.js +3 -17
  12. package/dist/src/closed-event.d.ts +0 -1
  13. package/dist/src/closed-event.js +1 -5
  14. package/dist/src/executor.d.ts +6 -7
  15. package/dist/src/executor.js +2 -8
  16. package/dist/src/face-kit.js +1 -4
  17. package/dist/src/fence.d.ts +2 -10
  18. package/dist/src/fence.js +4 -15
  19. package/dist/src/for-others.d.ts +0 -1
  20. package/dist/src/for-others.js +1 -5
  21. package/dist/src/instance-details.d.ts +1 -7
  22. package/dist/src/instance-details.js +4 -16
  23. package/dist/src/instance-paths.d.ts +1 -6
  24. package/dist/src/instance-paths.js +2 -11
  25. package/dist/src/judge.d.ts +3 -21
  26. package/dist/src/judge.js +5 -25
  27. package/dist/src/kernel-client.d.ts +0 -1
  28. package/dist/src/kernel-client.js +3 -12
  29. package/dist/src/kit.d.ts +0 -3
  30. package/dist/src/kit.js +0 -3
  31. package/dist/src/maintained-repos.d.ts +5 -22
  32. package/dist/src/maintained-repos.js +7 -23
  33. package/dist/src/number-setting.d.ts +0 -2
  34. package/dist/src/number-setting.js +1 -6
  35. package/dist/src/owner-day.d.ts +0 -4
  36. package/dist/src/owner-day.js +1 -8
  37. package/dist/src/paperclip.d.ts +0 -3
  38. package/dist/src/paperclip.js +1 -7
  39. package/dist/src/pass-rule.d.ts +0 -2
  40. package/dist/src/pass-rule.js +2 -10
  41. package/dist/src/provider.d.ts +1 -7
  42. package/dist/src/provider.js +2 -8
  43. package/dist/src/quality.d.ts +0 -10
  44. package/dist/src/quality.js +2 -12
  45. package/dist/src/repeat.d.ts +1 -6
  46. package/dist/src/repeat.js +2 -10
  47. package/dist/src/responses.d.ts +1 -8
  48. package/dist/src/responses.js +3 -13
  49. package/dist/src/reviewer.d.ts +3 -1
  50. package/dist/src/reviewer.js +1 -1
  51. package/dist/src/selector.d.ts +1 -11
  52. package/dist/src/selector.js +1 -6
  53. package/dist/src/source-store.d.ts +4 -26
  54. package/dist/src/source-store.js +5 -30
  55. package/dist/src/task-state-types.d.ts +3 -18
  56. package/dist/src/task-state-types.js +1 -3
  57. package/dist/src/teammate-name.d.ts +0 -1
  58. package/dist/src/teammate-name.js +2 -6
  59. package/dist/src/tiers.d.ts +1 -11
  60. package/dist/src/tiers.js +4 -14
  61. package/dist/src/tools-client.d.ts +3 -13
  62. package/dist/src/tools-client.js +7 -28
  63. package/dist/src/types.d.ts +0 -2
  64. package/dist/src/types.js +1 -2
  65. package/dist/src/url-setting.d.ts +0 -1
  66. package/dist/src/url-setting.js +1 -4
  67. package/dist/src/vendor/needs.d.ts +1 -7
  68. package/dist/src/vendor/needs.js +3 -12
  69. package/dist/src/vendor/oauth.d.ts +6 -35
  70. package/dist/src/vendor/oauth.js +12 -37
  71. package/dist/src/vendor/proxy.d.ts +5 -27
  72. package/dist/src/vendor/proxy.js +42 -114
  73. package/package.json +1 -1
@@ -1,25 +1,16 @@
1
- // The one answer a connection gives when only the owner can fix why a call can't be served (spec 2026-11-20 connect on first
2
- // use §1): an MCP isError result whose structuredContent is { error: "needs_owner", need }. The kernel's tool proxy reads it
3
- // before fencing, records the connection as down, and decides who hears about it (the owner, in the conversation they asked
4
- // in, or the daily digest); the agent gets the kernel's own fixed words, never this text. Import-free; every module imports it from
5
- // npm (@aidenhq/sdk/vendor/needs) at an exact pin.
1
+ // The one answer a connection gives when only the owner can fix why a call can't be served: an MCP isError result with structuredContent { error: "needs_owner", need }. The kernel's tool proxy reads it before fencing, records the connection down and decides who hears (the owner in the conversation, or the digest); the agent gets the kernel's fixed words, never this text.
2
+ // Import-free; modules import it from npm (@aidenhq/sdk/vendor/needs) at an exact pin.
6
3
  /** The causes only the owner can fix. A vendor that is down or a rate limit is a plain error, never a need. */
7
4
  export const OWNER_CAUSES = ["not_connected", "expired", "scope", "sso", "restricted"];
8
- /** The tool result a connection answers when only the owner can fix it. */
9
5
  export function needsOwner(need) {
10
6
  return { isError: true, content: [{ type: "text", text: need.detail }], structuredContent: { error: "needs_owner", need } };
11
7
  }
12
- /**
13
- * The `_meta` key a connection sets on a successful answer its sign-in served. Only such an answer clears the connection's down
14
- * state in the kernel: a tool that works signed out (a prefilled link) proves nothing about the sign-in.
15
- */
8
+ /** The `_meta` key set on a successful answer its sign-in served: only such an answer clears the connection's down state (a tool that works signed out proves nothing). */
16
9
  export const SIGNED_IN = "aidenhq/signed_in";
17
- /** Marks a result as served by the connection's sign-in (SIGNED_IN); `account` names whose it was, for a multi-account one. */
18
10
  export function signedIn(result, account) {
19
11
  const meta = result._meta;
20
12
  return { ...result, _meta: { ...(meta && typeof meta === "object" ? meta : {}), [SIGNED_IN]: account || true } };
21
13
  }
22
- /** Whether a tools/call result is a success the connection's sign-in served. */
23
14
  export function servedSignedIn(result) {
24
15
  const r = result;
25
16
  const v = r && typeof r === "object" && r.isError !== true && r._meta && typeof r._meta === "object" ? r._meta[SIGNED_IN] : undefined;
@@ -3,7 +3,6 @@ export interface AuthStatus {
3
3
  state: "missing" | "ok" | "expired" | "unknown" | "none";
4
4
  since: string;
5
5
  detail?: string;
6
- /** The scopes the vendor granted at the last sign-in. */
7
6
  scope?: string;
8
7
  /** Signs in by a pasted value (a service token), never a browser sign-in: the board's Connect asks for it while not ok. */
9
8
  paste?: boolean;
@@ -12,14 +11,12 @@ export declare class AuthError extends Error {
12
11
  }
13
12
  export declare class SignInError extends Error {
14
13
  }
15
- /** The board's sign-in: which scopes the owner may pick (and the ones pre-selected), then the round trip. */
16
14
  export interface SignInFlow {
17
15
  /** `target`: the account or new client a sign-in is for, whose own scopes are pre-selected (a connection with several). */
18
16
  scopes(target?: SignInTarget): Promise<{
19
17
  supported: string[];
20
18
  recommended: string[];
21
19
  }>;
22
- /** `target`: for a connection with several accounts, the one to reconnect, or the client a new one signs in with. */
23
20
  start(redirectUri: string, scopes?: string[], target?: SignInTarget): Promise<{
24
21
  url: string;
25
22
  }>;
@@ -30,7 +27,6 @@ export interface SignInTarget {
30
27
  account?: string;
31
28
  client_id?: string;
32
29
  }
33
- /** A device sign-in (RFC 8628) as the board shows it: the code to type on the vendor's page, and how it is going. */
34
30
  export interface DeviceStart {
35
31
  user_code: string;
36
32
  verification_uri: string;
@@ -42,16 +38,12 @@ export interface DeviceState {
42
38
  state: "idle" | "pending" | "ok" | "expired" | "denied" | "cancelled" | "failed";
43
39
  detail?: string;
44
40
  }
45
- /**
46
- * A sign-in for a server without a browser (GitHub, like `gh`): start asks the vendor for a code, and this service polls for the
47
- * token itself until it lands, the code expires or the board cancels. One at a time: a new start cancels the one before.
48
- */
41
+ /** Sign-in without a browser (GitHub, like `gh`): start asks for a code, this service polls until the token lands, the code expires or the board cancels; a new start cancels the previous. */
49
42
  export interface DeviceFlow {
50
43
  start(onSignedIn?: () => void): Promise<DeviceStart>;
51
44
  state(): DeviceState;
52
45
  cancel(): void;
53
46
  }
54
- /** What the proxy needs from a sign-in: the headers for an upstream request, a refresh after a refusal, and its state. */
55
47
  export interface Auth {
56
48
  headers(): Promise<Record<string, string>>;
57
49
  refresh(): Promise<void>;
@@ -60,23 +52,18 @@ export interface Auth {
60
52
  check?(): Promise<void>;
61
53
  /** Whether the vendor refuses the current token right now (its own cheap authenticated read): a 401 or a refused refresh proves nothing alone. Absent: the connection can't tell. */
62
54
  refused?(): Promise<boolean>;
63
- /** How many sign-ins this connection has completed: a refresh keeps it, a new sign-in (a different account or grant) bumps it, so a
64
- * caller can tell a token the same sign-in refreshed from one a different sign-in replaced. Absent: the connection can't tell. */
55
+ /** Completed sign-ins: a refresh keeps it, a new sign-in bumps it, so callers can tell a refreshed token from a replaced one. Absent: can't tell. */
65
56
  signInCount?(): number;
66
57
  mark(state: "ok" | "expired", detail?: string): void;
67
58
  signedIn(): boolean;
68
59
  signIn?: SignInFlow;
69
60
  device?: DeviceFlow;
70
- /** Signs one account out (a connection with several): the board's per-account Disconnect. */
71
61
  disconnect?(account?: string): Promise<void>;
72
62
  }
73
- /** A connection that signs in to nothing (a local server), with fixed headers. */
74
63
  export declare function staticAuth(headers?: Record<string, string>): Auth;
75
64
  export interface OAuthOptions {
76
- /** The vendor's name in messages ("Glean"). */
77
65
  name: string;
78
66
  mcpUrl: string;
79
- /** token.json and client.json live here. */
80
67
  stateDir: string;
81
68
  /** Sent on every upstream request and on discovery's probe (Grafana Cloud: x-grafana-url). */
82
69
  headers?: Record<string, string>;
@@ -92,10 +79,7 @@ export interface OAuthOptions {
92
79
  authorize: string;
93
80
  token: string;
94
81
  };
95
- /**
96
- * `supported`: the scopes the owner may pick when the vendor doesn't list them (an empty list: never ask for scopes).
97
- * `recommended`: the ones pre-selected (default: all of them). `separator`: how they are joined (default a space).
98
- */
82
+ /** `supported`: scopes the owner may pick when the vendor doesn't list them (empty: never ask); `recommended`: pre-selected (default all); `separator`: join (default a space). */
99
83
  scopes?: {
100
84
  supported?: string[];
101
85
  recommended?: string[];
@@ -105,10 +89,7 @@ export interface OAuthOptions {
105
89
  resource?: false;
106
90
  /** A vendor's token answer in the standard shape (Slack nests the user token under authed_user). */
107
91
  tokenAnswer?: (json: Record<string, unknown>) => Record<string, unknown>;
108
- /**
109
- * Sign in by device code (RFC 8628) instead of a redirect: `endpoint` is the vendor's device authorization endpoint, the token
110
- * endpoint is `endpoints.token` (else discovered). An empty `client_id` is a sign-in not configured yet.
111
- */
92
+ /** Sign in by device code (RFC 8628): `endpoint` is the device authorization endpoint, the token endpoint is `endpoints.token` (else discovered); empty `client_id`: not configured yet. */
112
93
  device?: {
113
94
  endpoint: string;
114
95
  client_id: string;
@@ -124,10 +105,7 @@ export interface OAuthOptions {
124
105
  /** Where the token lives (default: token.json in `stateDir`): a connection with several accounts keeps one per account. */
125
106
  store?: TokenStore;
126
107
  }
127
- /**
128
- * Where a sign-in's token is kept. `read` answers the same object until `write` replaces it, so a refresh can tell that a
129
- * new sign-in saved a token meanwhile; a `write` that throws (a sign-in for another account) saves nothing.
130
- */
108
+ /** Where a sign-in's token is kept. `read` returns the same object until `write` replaces it, so a refresh can tell a new sign-in saved meanwhile; a throwing `write` saves nothing. */
131
109
  export interface TokenStore {
132
110
  read(): StoredToken | undefined;
133
111
  write(t: StoredToken): void;
@@ -144,22 +122,15 @@ export interface StoredToken {
144
122
  client_secret?: string;
145
123
  token_endpoint?: string;
146
124
  resource?: string;
147
- /** The whole MCP address it was issued for (query included). */
148
125
  endpoint?: string;
149
- /** The authorization server that issued it. */
150
126
  issuer?: string;
151
127
  /** sha256 of the extra headers it was issued under (Grafana Cloud's stack); absent without any. */
152
128
  tenant?: string;
153
129
  [extra: string]: unknown;
154
130
  }
155
- /** A redirect this sign-in may send: a loopback callback (a tunnel), or a callback on the board's https origin. */
156
131
  export declare function redirectAllowed(redirectUri: string, boardUrl?: string): boolean;
157
132
  /** A private, loopback, link-local or shared address: never a vendor's sign-in server. */
158
133
  export declare function privateAddress(ip: string): boolean;
159
- /**
160
- * fetch for the OAuth calls (discovery names hosts the vendor chose): https only, each connection's address checked as the socket
161
- * opens (TLS still verifies the name), and no redirect followed.
162
- */
134
+ /** fetch for OAuth calls: https only, each connection's address checked as the socket opens (TLS still verifies the name), no redirects. */
163
135
  export declare const publicFetch: typeof fetch;
164
- /** The owner's OAuth sign-in to a vendor's MCP server. */
165
136
  export declare function oauth(o: OAuthOptions): Auth;
@@ -1,17 +1,8 @@
1
- // How a vendor MCP connection (src/vendor/proxy.ts) reaches its upstream as the owner: OAuth 2.1 with PKCE, started from
2
- // the board (its Connect sends the browser here and back to the board's callback, at its https address or on loopback), with the scopes the owner picks
3
- // there. The client is registered dynamically (RFC 7591) or is one the owner made in the vendor (HubSpot, Slack). Only this
4
- // service sees the tokens: the pair lives in /state/token.json (0600), refreshed here, rotated pairs written back atomically.
5
- // A saved token is bound to what it was issued for: the whole MCP address (`endpoint`, query included: a tenant may live
6
- // there), the RFC 8707 `resource`, the extra headers that pick a tenant (`tenant`, a hash) and its issuer. A changed address or
7
- // tenant reads as signed out ("Connect again"), so a token never reaches an endpoint it wasn't issued for; a token saved before
8
- // binding keeps working while its resource matches and no tenant header applies. A refresh answer never rewrites those
9
- // fields or where the next refresh goes. Discovery takes only https endpoints (http on loopback, for tests), metadata whose
10
- // issuer names itself and a resource on the MCP server's origin; no request here follows a redirect or reaches a private
11
- // network address.
12
- //
13
- // Every module imports it from npm (@aidenhq/sdk/vendor/oauth) at an exact pin: a change here needs a version bump in package.json,
14
- // which is what publishes it.
1
+ // OAuth 2.1 + PKCE sign-in for a vendor MCP connection (proxy.ts) as the owner, started from the board (callback at its https address or loopback). The client is registered dynamically (RFC 7591) or is one the owner made in the vendor (HubSpot, Slack).
2
+ // Only this service sees tokens: /state/token.json (0600), refreshed here, rotated pairs written back atomically.
3
+ // A token is bound to its MCP address (query included), RFC 8707 `resource`, tenant headers (hash) and issuer: a change reads as signed out so a token never reaches an endpoint it wasn't issued for; a pre-binding token works while its resource matches and no tenant header applies. A refresh answer never rewrites those fields or the next refresh's target.
4
+ // Discovery takes only https endpoints (http on loopback for tests), metadata whose issuer names itself and a resource on the MCP server's origin; no request follows a redirect or reaches a private address.
5
+ // Modules import it from npm (@aidenhq/sdk/vendor/oauth) at an exact pin: a change here needs a package.json version bump, which publishes it.
15
6
  import { createHash, randomBytes } from "node:crypto";
16
7
  import { lookup } from "node:dns";
17
8
  import { request } from "node:https";
@@ -22,7 +13,6 @@ export class AuthError extends Error {
22
13
  }
23
14
  export class SignInError extends Error {
24
15
  }
25
- /** A connection that signs in to nothing (a local server), with fixed headers. */
26
16
  export function staticAuth(headers = {}) {
27
17
  const since = new Date().toISOString();
28
18
  return { headers: async () => headers, refresh: async () => { }, status: () => ({ state: "none", since }), mark: () => { }, signedIn: () => true, signInCount: () => 0 };
@@ -46,7 +36,6 @@ export function fileStore(path) {
46
36
  };
47
37
  }
48
38
  const LOOPBACK = /^http:\/\/(127\.0\.0\.1|localhost)(:\d+)?\/[\w/-]*$/;
49
- /** A redirect this sign-in may send: a loopback callback (a tunnel), or a callback on the board's https origin. */
50
39
  export function redirectAllowed(redirectUri, boardUrl = process.env.BOARD_URL ?? "") {
51
40
  if (LOOPBACK.test(redirectUri))
52
41
  return true;
@@ -81,10 +70,7 @@ const publicLookup = (host, opts, done) => lookup(host, { ...opts, all: true },
81
70
  return done(new SignInError(`refused ${host}: it resolves to a private network address`), "", 0);
82
71
  return opts.all ? done(null, list) : done(null, list[0].address, list[0].family);
83
72
  });
84
- /**
85
- * fetch for the OAuth calls (discovery names hosts the vendor chose): https only, each connection's address checked as the socket
86
- * opens (TLS still verifies the name), and no redirect followed.
87
- */
73
+ /** fetch for OAuth calls: https only, each connection's address checked as the socket opens (TLS still verifies the name), no redirects. */
88
74
  export const publicFetch = (input, init) => new Promise((resolve, reject) => {
89
75
  const url = new URL(String(input instanceof Request ? input.url : input));
90
76
  if (url.protocol !== "https:" || (isIP(url.hostname.replace(/^\[|\]$/g, "")) && privateAddress(url.hostname.replace(/^\[|\]$/g, ""))))
@@ -104,31 +90,26 @@ export const publicFetch = (input, init) => new Promise((resolve, reject) => {
104
90
  req.on("error", reject);
105
91
  req.end(body);
106
92
  });
107
- /** The owner's OAuth sign-in to a vendor's MCP server. */
108
93
  export function oauth(o) {
109
94
  const fetchImpl = o.fetchImpl ?? publicFetch;
110
95
  const store = o.store ?? fileStore(join(o.stateDir, "token.json"));
111
96
  const clientPath = join(o.stateDir, "client.json");
112
97
  // The resource a token is for (RFC 8707): the MCP endpoint without its query (Atlassian's ?tools=all).
113
- // No address yet (a cleared setting): no resource, and the connection reads as not set up rather than failing.
98
+ // No address (cleared setting): no resource; reads as not set up.
114
99
  const resourceOf = () => { if (o.resource === false || !URL.canParse(o.mcpUrl))
115
100
  return undefined; const u = new URL(o.mcpUrl); return u.origin + u.pathname; };
116
101
  // The tenant a token is for: the extra headers sent with it (Grafana Cloud's x-grafana-url), hashed; none without any.
117
102
  const tenantOf = () => (o.headers && Object.keys(o.headers).length ? createHash("sha256").update(JSON.stringify(Object.entries(o.headers).map(([k, v]) => [k.toLowerCase(), v]).sort())).digest("hex") : undefined);
118
- // The saved token while it is bound to this connection's resource and tenant, exactly. A token saved before binding keeps
119
- // working only where its identity is on record: every sign-in saved its resource, so it matches, and the connection picks no
120
- // tenant. One saved without the tenant a connection now sends (Grafana Cloud's stack) can't be verified: Connect again.
103
+ // The saved token while bound to this resource and tenant. A pre-binding token works only where its identity is on record (resource matches, no tenant sent); one lacking a tenant the connection now sends can't be verified: Connect again.
121
104
  let unbound = false;
122
105
  const current = () => {
123
106
  const t = store.read();
124
- // No address (a cleared setting): nothing is connected, whatever is still on disk.
125
107
  if (!t || !URL.canParse(o.mcpUrl))
126
108
  return (unbound = false), undefined;
127
109
  const resource = resourceOf();
128
110
  unbound = Boolean((t.endpoint !== undefined && t.endpoint !== o.mcpUrl) || (resource && t.resource !== resource) || t.tenant !== tenantOf());
129
111
  return unbound ? undefined : t;
130
112
  };
131
- /** What a saved token is bound to: written by a sign-in, never by a vendor's answer. */
132
113
  const binding = () => { const resource = resourceOf(), tenant = tenantOf(); return { endpoint: o.mcpUrl, ...(resource ? { resource } : {}), ...(tenant ? { tenant } : {}) }; };
133
114
  const BOUND = ["endpoint", "resource", "tenant", "issuer", "token_endpoint", "client_id", "client_secret"];
134
115
  const strip = (x) => Object.fromEntries(Object.entries(x).filter(([k]) => !BOUND.includes(k)));
@@ -154,7 +135,6 @@ export function oauth(o) {
154
135
  const res = await fetchImpl(url, { ...init, redirect: "error", headers: { accept: "application/json", ...init?.headers }, signal: AbortSignal.timeout(15_000) });
155
136
  return { ok: res.ok, status: res.status, body: (await res.json().catch(() => ({}))) };
156
137
  };
157
- /** A token answer as StoredToken fields; a refusal throws its error. */
158
138
  function parse(raw, now = Date.now()) {
159
139
  const a = o.tokenAnswer ? o.tokenAnswer(raw) : raw;
160
140
  if (typeof a.error === "string" || a.ok === false)
@@ -182,8 +162,7 @@ export function oauth(o) {
182
162
  return false;
183
163
  }
184
164
  }
185
- // An expired mark is a claim about the token: while it stands, ask the vendor again, and a token that answers is signed in
186
- // (no container restart). A reconnect marks ok itself.
165
+ // An expired mark is a claim about the token: re-ask the vendor while it stands; a token that answers is signed in. A reconnect marks ok itself.
187
166
  let healer;
188
167
  function mark(state, detail) {
189
168
  if (state === "ok" && healer) {
@@ -207,7 +186,6 @@ export function oauth(o) {
207
186
  return t;
208
187
  }
209
188
  const save = (t) => store.write(t);
210
- /** The token saved now (a new sign-in may have replaced the one a refresh started from). */
211
189
  const token = () => current();
212
190
  async function doRefresh() {
213
191
  const t = load();
@@ -242,8 +220,7 @@ export function oauth(o) {
242
220
  next = parse(answer);
243
221
  }
244
222
  catch (err) {
245
- // A refusal (invalid_grant and the like) needs the owner; a 5xx is the vendor's problem and may pass.
246
- // A refused refresh on a token the vendor still answers (a rotated refresh token reused after a restart) is not an expiry.
223
+ // A refusal (invalid_grant) needs the owner; a 5xx is the vendor's and may pass. A refused refresh on a token the vendor still answers (rotated refresh token reused after a restart) is not an expiry.
247
224
  if (res.status < 500) {
248
225
  const gone = await refused();
249
226
  // A reconnect saved a newer grant while the probe was in flight: its verdict is on the old token.
@@ -260,7 +237,7 @@ export function oauth(o) {
260
237
  return token();
261
238
  }
262
239
  const refresh = () => (refreshing ??= doRefresh().finally(() => (refreshing = undefined)));
263
- /** The vendor's endpoints and the scopes it lists: the server's 401 names its resource metadata (the MCP way), else the well-known paths. */
240
+ /** The vendor's endpoints and scopes: the 401 names its resource metadata (the MCP way), else the well-known paths. */
264
241
  async function discover() {
265
242
  const listed = o.scopes?.supported;
266
243
  if (o.endpoints)
@@ -311,7 +288,6 @@ export function oauth(o) {
311
288
  token: r.body.token_endpoint,
312
289
  ...(typeof r.body.registration_endpoint === "string" ? { registration: r.body.registration_endpoint } : {}),
313
290
  issuer,
314
- // What the owner may pick: the resource's own list, else the server's (offline_access is added on its own).
315
291
  supported: (listed ?? (resourceScopes?.length ? resourceScopes : offered)).filter((s) => s !== "offline_access"),
316
292
  // Without offline_access there may be no refresh token, and the sign-in would end with the first access token.
317
293
  offline: offered.includes("offline_access") || Boolean(resourceScopes?.includes("offline_access")),
@@ -353,7 +329,6 @@ export function oauth(o) {
353
329
  const { supported } = await discover();
354
330
  return { supported, recommended: recommended(supported) };
355
331
  },
356
- /** The vendor's sign-in URL, asking for `scopes` (the owner's pick; default: the recommended ones). */
357
332
  async start(redirectUri, scopes) {
358
333
  if (!redirectAllowed(redirectUri, o.boardUrl))
359
334
  throw new SignInError("redirect must be a loopback address or the board's own https address");
@@ -448,7 +423,7 @@ export function oauth(o) {
448
423
  return end({ state: "expired", detail: "the code expired before it was entered" });
449
424
  const p = await json(tokenUrl, { method: "POST", body: new URLSearchParams({ grant_type: "urn:ietf:params:oauth:grant-type:device_code", device_code: deviceCode, client_id: d.client_id }) }).catch(() => undefined);
450
425
  if (!p || p.status >= 500)
451
- continue; // the vendor's hiccup: ask again
426
+ continue;
452
427
  const err = typeof p.body.error === "string" ? p.body.error : "";
453
428
  if (err === "authorization_pending")
454
429
  continue;
@@ -3,20 +3,12 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
3
  import { type CallToolResult, type Tool } from "@modelcontextprotocol/sdk/types.js";
4
4
  import type { Logger } from "pino";
5
5
  import { type Auth } from "./oauth.js";
6
- /** A connection's own logic, where it has any. */
7
6
  export interface Hooks {
8
- /**
9
- * After each connect (Jira: find the configured site); a throw fails the connect. It returns a commit function when its work
10
- * publishes state other calls read (Jira's cloudId): the proxy runs it only if this connect becomes the session, so a connect a
11
- * sign-in or reset superseded never writes its state over the winner's. Work that publishes nothing may return nothing.
12
- */
7
+ /** After each connect; a throw fails it. Returns a commit fn if it publishes state other calls read: run only if this connect becomes the session. */
13
8
  connected?(client: Client, tools: Tool[]): Promise<void | (() => void)>;
14
9
  /** The tools as agents see them (a pinned argument dropped from the schema, a lead line in a description). */
15
10
  tools?(tools: Tool[]): Tool[];
16
- /**
17
- * The arguments sent upstream for one call of a tool the upstream lists (`tool`: its schema); a throw refuses the call.
18
- * A pinned argument overrides whatever the caller sent.
19
- */
11
+ /** Arguments sent upstream for one call (`tool`: its schema); a pinned argument overrides the caller's; a throw refuses the call. */
20
12
  args?(name: string, args: Record<string, unknown>, tool: Tool): Record<string, unknown>;
21
13
  /** Tools never listed or called (a real security rule; most connections have none). */
22
14
  deny?: RegExp;
@@ -28,39 +20,29 @@ export interface Hooks {
28
20
  health?(): string | undefined;
29
21
  /** More of the sign-in's state for the board (GitHub: scopes, per-org problems, the rate limit), merged into /auth/status. */
30
22
  status?(): Record<string, unknown>;
31
- /**
32
- * Serves a call itself instead of this proxy's own session (Slack: one session per workspace, each its own proxy). Admission is
33
- * done by then (bearer, caller, deny); the hook applies the read rule (`readOnly`) and answers every failure as a result.
34
- */
23
+ /** Serves a call itself instead of this proxy's own session (Slack: one proxy per workspace); admission is done, the hook applies the read rule and answers failures as results. */
35
24
  call?(name: string, args: Record<string, unknown>, readOnly: boolean): Promise<CallToolResult>;
36
25
  }
37
26
  export interface ProxyOptions {
38
- /** The vendor's name in messages ("Glean"). */
39
27
  name: string;
40
28
  /** Unset: not configured yet (Connect on the board, or its setup flow, saves the value it needs). */
41
29
  upstream: URL | undefined;
42
30
  auth: Auth;
43
31
  log: Logger;
44
- /** The kernel's bearer for /mcp (the connection's service key). */
45
32
  serviceKey?: string;
46
33
  /** The read endpoint's bearer (jobs reach it only through the kernel); unset: no /mcp/read. */
47
34
  readKey?: string;
48
35
  /** The tools the module's manifest tags read: /mcp/read serves only these (and only those the upstream marks read-only). */
49
36
  reads?: string[];
50
- /** The board's bearer for /auth/*. */
51
37
  authKey?: string;
52
38
  /** Checks the kernel's caller assertion on a tools/call to /mcp; throws to refuse. */
53
39
  caller(req: IncomingMessage): Promise<unknown>;
54
- /** The MCP server's instructions to agents. */
55
40
  instructions: string;
56
41
  /** How long one tool call may take (ClickHouse's queries run up to two minutes); default: the MCP SDK's 60 seconds. */
57
42
  callTimeoutMs?: number;
58
43
  /** Remembers the tool list here (tools.json), for stand-ins while not connected. */
59
44
  stateDir?: string;
60
- /**
61
- * How long a call waits on a connect another call (or a reset) started before it opens a session of its own; default 20 s, the
62
- * board's budget for one handshake. Without the bound, one stalled handshake would hold up every call after it.
63
- */
45
+ /** How long a call waits on another's connect before opening its own session; default 20 s, the board's handshake budget. */
64
46
  resetWaitMs?: number;
65
47
  hooks?: Hooks;
66
48
  /** More routes on the same port (a write kind's executor); true when it answered. */
@@ -71,12 +53,8 @@ export type VendorProxy = HttpServer & {
71
53
  call(name: string, args: Record<string, unknown>, readOnly?: boolean): Promise<CallToolResult>;
72
54
  /** A new sign-in saved elsewhere (another proxy's Connect): the session opened with the old one is retired. */
73
55
  signedIn(): Promise<void>;
74
- /** The tools this proxy's current session advertises (the connection's view applied); undefined when it couldn't list them. */
75
56
  list(): Promise<Tool[] | undefined>;
76
- /**
77
- * Drops the session without opening another: the sign-out whose grant is already gone, or a check that failed, so the next call
78
- * (or Connect) opens a session from the sign-in that is there now. Nothing waits on an upstream handshake.
79
- */
57
+ /** Drops the session without opening another (sign-out whose grant is gone, or a failed check); nothing waits on an upstream handshake. */
80
58
  forget(): void;
81
59
  };
82
60
  export declare function createVendorProxy(o: ProxyOptions): VendorProxy;