@0xmaxma/claude-gateway 1.8.6 → 1.8.8

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 (109) hide show
  1. package/README.md +159 -4
  2. package/dist/agent/dreaming/config.d.ts +3 -1
  3. package/dist/agent/dreaming/config.d.ts.map +1 -1
  4. package/dist/agent/dreaming/config.js +14 -3
  5. package/dist/agent/dreaming/config.js.map +1 -1
  6. package/dist/agent/dreaming/index.d.ts +2 -0
  7. package/dist/agent/dreaming/index.d.ts.map +1 -1
  8. package/dist/agent/dreaming/index.js +1 -1
  9. package/dist/agent/dreaming/index.js.map +1 -1
  10. package/dist/agent/knowledge/config.d.ts +3 -1
  11. package/dist/agent/knowledge/config.d.ts.map +1 -1
  12. package/dist/agent/knowledge/config.js +13 -3
  13. package/dist/agent/knowledge/config.js.map +1 -1
  14. package/dist/agent/runner.d.ts +66 -1
  15. package/dist/agent/runner.d.ts.map +1 -1
  16. package/dist/agent/runner.js +165 -12
  17. package/dist/agent/runner.js.map +1 -1
  18. package/dist/agent/skill-learning/config.d.ts +3 -1
  19. package/dist/agent/skill-learning/config.d.ts.map +1 -1
  20. package/dist/agent/skill-learning/config.js +13 -3
  21. package/dist/agent/skill-learning/config.js.map +1 -1
  22. package/dist/agent/skill-learning/index.d.ts +2 -0
  23. package/dist/agent/skill-learning/index.d.ts.map +1 -1
  24. package/dist/agent/skill-learning/index.js +1 -1
  25. package/dist/agent/skill-learning/index.js.map +1 -1
  26. package/dist/api/connectors-router.d.ts +50 -0
  27. package/dist/api/connectors-router.d.ts.map +1 -0
  28. package/dist/api/connectors-router.js +650 -0
  29. package/dist/api/connectors-router.js.map +1 -0
  30. package/dist/api/gateway-router.d.ts +4 -0
  31. package/dist/api/gateway-router.d.ts.map +1 -1
  32. package/dist/api/gateway-router.js +26 -0
  33. package/dist/api/gateway-router.js.map +1 -1
  34. package/dist/api/oauth-connectors-router.d.ts +43 -0
  35. package/dist/api/oauth-connectors-router.d.ts.map +1 -0
  36. package/dist/api/oauth-connectors-router.js +384 -0
  37. package/dist/api/oauth-connectors-router.js.map +1 -0
  38. package/dist/api/router.d.ts.map +1 -1
  39. package/dist/api/router.js +101 -9
  40. package/dist/api/router.js.map +1 -1
  41. package/dist/apps/agent-manager.d.ts +6 -2
  42. package/dist/apps/agent-manager.d.ts.map +1 -1
  43. package/dist/apps/agent-manager.js +14 -17
  44. package/dist/apps/agent-manager.js.map +1 -1
  45. package/dist/apps/installer.d.ts +3 -1
  46. package/dist/apps/installer.d.ts.map +1 -1
  47. package/dist/apps/installer.js +8 -2
  48. package/dist/apps/installer.js.map +1 -1
  49. package/dist/cli/commands/service.d.ts +34 -4
  50. package/dist/cli/commands/service.d.ts.map +1 -1
  51. package/dist/cli/commands/service.js +552 -96
  52. package/dist/cli/commands/service.js.map +1 -1
  53. package/dist/config/bootstrap.d.ts.map +1 -1
  54. package/dist/config/bootstrap.js +4 -1
  55. package/dist/config/bootstrap.js.map +1 -1
  56. package/dist/config/config-write-lock.d.ts +45 -0
  57. package/dist/config/config-write-lock.d.ts.map +1 -0
  58. package/dist/config/config-write-lock.js +164 -0
  59. package/dist/config/config-write-lock.js.map +1 -0
  60. package/dist/config/loader.d.ts.map +1 -1
  61. package/dist/config/loader.js +36 -0
  62. package/dist/config/loader.js.map +1 -1
  63. package/dist/config/migrator.d.ts.map +1 -1
  64. package/dist/config/migrator.js +12 -1
  65. package/dist/config/migrator.js.map +1 -1
  66. package/dist/config/watcher.d.ts.map +1 -1
  67. package/dist/config/watcher.js +29 -0
  68. package/dist/config/watcher.js.map +1 -1
  69. package/dist/connectors/custom-connectors-store.d.ts +54 -0
  70. package/dist/connectors/custom-connectors-store.d.ts.map +1 -0
  71. package/dist/connectors/custom-connectors-store.js +204 -0
  72. package/dist/connectors/custom-connectors-store.js.map +1 -0
  73. package/dist/connectors/custom.d.ts +69 -0
  74. package/dist/connectors/custom.d.ts.map +1 -0
  75. package/dist/connectors/custom.js +158 -0
  76. package/dist/connectors/custom.js.map +1 -0
  77. package/dist/connectors/mcp-oauth.d.ts +152 -0
  78. package/dist/connectors/mcp-oauth.d.ts.map +1 -0
  79. package/dist/connectors/mcp-oauth.js +522 -0
  80. package/dist/connectors/mcp-oauth.js.map +1 -0
  81. package/dist/connectors/oauth-refresh-sweep.d.ts +71 -0
  82. package/dist/connectors/oauth-refresh-sweep.d.ts.map +1 -0
  83. package/dist/connectors/oauth-refresh-sweep.js +337 -0
  84. package/dist/connectors/oauth-refresh-sweep.js.map +1 -0
  85. package/dist/connectors/pending-oauth-store.d.ts +39 -0
  86. package/dist/connectors/pending-oauth-store.d.ts.map +1 -0
  87. package/dist/connectors/pending-oauth-store.js +50 -0
  88. package/dist/connectors/pending-oauth-store.js.map +1 -0
  89. package/dist/connectors/resolve.d.ts +52 -0
  90. package/dist/connectors/resolve.d.ts.map +1 -0
  91. package/dist/connectors/resolve.js +176 -0
  92. package/dist/connectors/resolve.js.map +1 -0
  93. package/dist/connectors/token-env.d.ts +93 -0
  94. package/dist/connectors/token-env.d.ts.map +1 -0
  95. package/dist/connectors/token-env.js +323 -0
  96. package/dist/connectors/token-env.js.map +1 -0
  97. package/dist/connectors/types.d.ts +126 -0
  98. package/dist/connectors/types.d.ts.map +1 -0
  99. package/dist/connectors/types.js +13 -0
  100. package/dist/connectors/types.js.map +1 -0
  101. package/dist/index.js +37 -4
  102. package/dist/index.js.map +1 -1
  103. package/dist/session/process.d.ts +23 -0
  104. package/dist/session/process.d.ts.map +1 -1
  105. package/dist/session/process.js +97 -4
  106. package/dist/session/process.js.map +1 -1
  107. package/dist/types.d.ts +46 -1
  108. package/dist/types.d.ts.map +1 -1
  109. package/package.json +1 -1
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Generic OAuth 2.1 + PKCE (+ optional Dynamic Client Registration) support for
3
+ * "custom" MCP connectors whose only auth option is a real OAuth sign-in (no
4
+ * static API key) — e.g. Firecrawl's `https://mcp.firecrawl.dev/v2/mcp-oauth`.
5
+ *
6
+ * This module never touches Express or the pending-flow store — pure discovery
7
+ * + token functions, unit-testable with plain HTTP mocks. See
8
+ * `pending-oauth-store.ts` for the in-flight-flow state and
9
+ * `api/oauth-connectors-router.ts` for the HTTP endpoints that glue this
10
+ * together with `connectors/custom.ts`'s existing secret storage.
11
+ *
12
+ * Empirically verified against production Firecrawl (2026-09, this repo's own
13
+ * throwaway PoC — see git history / PR description, not reproduced here):
14
+ * DCR genuinely works with an arbitrary redirect_uri (no pre-registration
15
+ * needed), and the RFC 8707 `resource` parameter is REQUIRED on both the
16
+ * authorize request and the token exchange — omitting it yields a token that
17
+ * exchanges fine but is rejected by the MCP endpoint itself
18
+ * ("OAUTH_CONNECTION_INVALID"). Always pass `resource` through this module's
19
+ * functions; never make it optional.
20
+ */
21
+ export interface OAuthMetadata {
22
+ /** The MCP server URL this metadata was discovered for — also the RFC 8707 `resource`. */
23
+ resource: string;
24
+ authorizationEndpoint: string;
25
+ tokenEndpoint: string;
26
+ /** Absent when the AS doesn't advertise RFC 7591 Dynamic Client Registration. */
27
+ registrationEndpoint?: string;
28
+ /**
29
+ * Scopes to request for this resource: the protected-resource metadata's list
30
+ * when it publishes one, else the authorization server's. Empty when neither
31
+ * does — see `resolveScope` for what gets sent then.
32
+ */
33
+ scopesSupported: string[];
34
+ }
35
+ export interface TokenResponse {
36
+ access_token: string;
37
+ token_type: string;
38
+ expires_in?: number;
39
+ refresh_token?: string;
40
+ scope?: string;
41
+ }
42
+ /**
43
+ * A token endpoint that answered, and answered with a refusal.
44
+ *
45
+ * The distinction this class exists to draw is between "the grant is dead" and
46
+ * "we couldn't reach the provider just now". The refresh sweep gives up on a
47
+ * connector after a few consecutive failures and deletes its stored credentials,
48
+ * which is right for the first case and destructive for the second — a fifteen
49
+ * minute provider outage is an ordinary event and must not cost the user their
50
+ * sign-in. Only an explicit OAuth error response can be classified, so only this
51
+ * error type carries `isPermanent`; anything else the sweep sees (a DNS failure,
52
+ * a socket timeout, a 502, a discovery step that returned the wrong shape) is
53
+ * treated as retryable by default.
54
+ */
55
+ export declare class OAuthTokenError extends Error {
56
+ readonly status: number;
57
+ /** RFC 6749 §5.2 `error` code from the response body, when it had one. */
58
+ readonly errorCode?: string | undefined;
59
+ constructor(message: string, status: number,
60
+ /** RFC 6749 §5.2 `error` code from the response body, when it had one. */
61
+ errorCode?: string | undefined);
62
+ /**
63
+ * True when the authorization server has told us this grant will never work
64
+ * again. Deliberately a small allowlist rather than "any 4xx": a 400 with no
65
+ * recognisable `error` code, or a 429, says more about this request than about
66
+ * the grant, and retrying costs nothing but a backoff.
67
+ */
68
+ get isPermanent(): boolean;
69
+ }
70
+ /**
71
+ * Discover OAuth metadata for an MCP server by probing it unauthenticated
72
+ * (expects a 401 advertising `resource_metadata`, per RFC 9728), then walking
73
+ * protected-resource metadata → authorization-server metadata (RFC 8414).
74
+ * Throws a descriptive error at whichever step fails — callers surface it
75
+ * to the admin as "can't set up OAuth for this URL", not a generic 500.
76
+ */
77
+ export declare function discoverOAuthMetadata(mcpUrl: string): Promise<OAuthMetadata>;
78
+ /**
79
+ * `discoverOAuthMetadata` with a process-local cache, for the background refresh
80
+ * sweep.
81
+ *
82
+ * Discovery costs three round trips — an MCP probe that is *expected* to 401, then
83
+ * protected-resource metadata, then authorization-server metadata — to obtain a
84
+ * document that changes about never. Paying that on every refresh is not just waste:
85
+ * each of those three requests is another way for a refresh to fail, and a failed
86
+ * refresh is what eventually makes the sweep give up and delete the connector's
87
+ * credentials. Fewer moving parts on the periodic path means fewer spurious failures.
88
+ *
89
+ * Only the sweep uses this. An admin-initiated `oauth/start` still calls
90
+ * `discoverOAuthMetadata` directly: that is the moment a human is waiting to find out
91
+ * whether this URL works at all, so it should see today's truth, not a cached answer
92
+ * from before they fixed their provider's configuration.
93
+ */
94
+ export declare function discoverOAuthMetadataCached(mcpUrl: string): Promise<OAuthMetadata>;
95
+ /** Drop every cached metadata document. For tests, and for a forced re-discovery. */
96
+ export declare function clearOAuthMetadataCache(): void;
97
+ /**
98
+ * Register a public (no client_secret) client via RFC 7591 DCR. Throws if the
99
+ * server rejects it — callers fall back to a per-connector static client_id
100
+ * (an env var an admin configured by hand) when this isn't available at all,
101
+ * see `resolveClientId` below.
102
+ */
103
+ export declare function registerClient(registrationEndpoint: string, redirectUri: string, clientName: string): Promise<string>;
104
+ /**
105
+ * Resolve a client_id for `metadata`: try DCR first, fall back to a static
106
+ * `MCP_OAUTH_CLIENT_ID__<connectorId>` env var (an admin-configured client_id
107
+ * for a provider that advertises no registration_endpoint at all).
108
+ */
109
+ export declare function resolveClientId(metadata: OAuthMetadata, connectorId: string, redirectUri: string): Promise<string>;
110
+ /**
111
+ * The `scope` to send with an authorization request for `metadata`.
112
+ *
113
+ * An admin-set `MCP_OAUTH_SCOPES__<connectorId>` (space-separated) wins, for the
114
+ * same reason `MCP_OAUTH_CLIENT_ID__<connectorId>` exists above: discovery is the
115
+ * provider's story about itself, and when that story is wrong the sign-in fails at
116
+ * the provider with an `invalid_scope` the operator cannot otherwise do anything
117
+ * about. Some servers publish a scope the client is not entitled to; some grant a
118
+ * refresh_token only when `offline_access` is asked for and never advertise it.
119
+ * Both are one env var away from working, instead of a code change away.
120
+ *
121
+ * `offline_access` is the fallback when nothing is discovered or configured: the
122
+ * refresh sweep needs a refresh_token, and an authorization request carrying no
123
+ * scope at all gets whatever the provider's default happens to be.
124
+ */
125
+ export declare function resolveScope(metadata: OAuthMetadata, connectorId: string): string;
126
+ export interface PkcePair {
127
+ codeVerifier: string;
128
+ codeChallenge: string;
129
+ }
130
+ export declare function generatePkce(): PkcePair;
131
+ export declare function generateState(): string;
132
+ export declare function buildAuthorizeUrl(opts: {
133
+ metadata: OAuthMetadata;
134
+ clientId: string;
135
+ redirectUri: string;
136
+ scope: string;
137
+ codeChallenge: string;
138
+ state: string;
139
+ }): string;
140
+ export declare function exchangeCode(opts: {
141
+ metadata: OAuthMetadata;
142
+ clientId: string;
143
+ redirectUri: string;
144
+ code: string;
145
+ codeVerifier: string;
146
+ }): Promise<TokenResponse>;
147
+ export declare function refreshAccessToken(opts: {
148
+ metadata: OAuthMetadata;
149
+ clientId: string;
150
+ refreshToken: string;
151
+ }): Promise<TokenResponse>;
152
+ //# sourceMappingURL=mcp-oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-oauth.d.ts","sourceRoot":"","sources":["../../src/connectors/mcp-oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAiIH,MAAM,WAAW,aAAa;IAC5B,0FAA0F;IAC1F,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IAGtC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM;gBAH3B,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM;IACvB,0EAA0E;IACjE,SAAS,CAAC,EAAE,MAAM,YAAA;IAM7B;;;;;OAKG;IACH,IAAI,WAAW,IAAI,OAAO,CASzB;CACF;AA6BD;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAyElF;AA6CD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAA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