toolcraft 0.0.5 → 0.0.7

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 (149) hide show
  1. package/README.md +1 -0
  2. package/dist/cli.d.ts +1 -0
  3. package/dist/cli.js +77 -59
  4. package/node_modules/@poe-code/agent-defs/dist/agents/claude-code.d.ts +2 -0
  5. package/node_modules/@poe-code/agent-defs/dist/agents/claude-code.js +15 -0
  6. package/node_modules/@poe-code/agent-defs/dist/agents/claude-desktop.d.ts +2 -0
  7. package/node_modules/@poe-code/agent-defs/dist/agents/claude-desktop.js +13 -0
  8. package/node_modules/@poe-code/agent-defs/dist/agents/codex.d.ts +2 -0
  9. package/node_modules/@poe-code/agent-defs/dist/agents/codex.js +14 -0
  10. package/node_modules/@poe-code/agent-defs/dist/agents/goose.d.ts +2 -0
  11. package/node_modules/@poe-code/agent-defs/dist/agents/goose.js +14 -0
  12. package/node_modules/@poe-code/agent-defs/dist/agents/index.d.ts +7 -0
  13. package/node_modules/@poe-code/agent-defs/dist/agents/index.js +7 -0
  14. package/node_modules/@poe-code/agent-defs/dist/agents/kimi.d.ts +2 -0
  15. package/node_modules/@poe-code/agent-defs/dist/agents/kimi.js +15 -0
  16. package/node_modules/@poe-code/agent-defs/dist/agents/opencode.d.ts +2 -0
  17. package/node_modules/@poe-code/agent-defs/dist/agents/opencode.js +14 -0
  18. package/node_modules/@poe-code/agent-defs/dist/agents/poe-agent.d.ts +2 -0
  19. package/node_modules/@poe-code/agent-defs/dist/agents/poe-agent.js +13 -0
  20. package/node_modules/@poe-code/agent-defs/dist/index.d.ts +5 -0
  21. package/node_modules/@poe-code/agent-defs/dist/index.js +3 -0
  22. package/node_modules/@poe-code/agent-defs/dist/registry.d.ts +3 -0
  23. package/node_modules/@poe-code/agent-defs/dist/registry.js +26 -0
  24. package/node_modules/@poe-code/agent-defs/dist/specifier.d.ts +7 -0
  25. package/node_modules/@poe-code/agent-defs/dist/specifier.js +27 -0
  26. package/node_modules/@poe-code/agent-defs/dist/types.d.ts +16 -0
  27. package/node_modules/@poe-code/agent-defs/dist/types.js +1 -0
  28. package/node_modules/@poe-code/agent-defs/package.json +20 -0
  29. package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.d.ts +5 -0
  30. package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.js +552 -0
  31. package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.d.ts +17 -0
  32. package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.js +58 -0
  33. package/node_modules/@poe-code/config-mutations/dist/execution/run-mutations.d.ts +7 -0
  34. package/node_modules/@poe-code/config-mutations/dist/execution/run-mutations.js +46 -0
  35. package/node_modules/@poe-code/config-mutations/dist/formats/index.d.ts +13 -0
  36. package/node_modules/@poe-code/config-mutations/dist/formats/index.js +49 -0
  37. package/node_modules/@poe-code/config-mutations/dist/formats/json.d.ts +31 -0
  38. package/node_modules/@poe-code/config-mutations/dist/formats/json.js +140 -0
  39. package/node_modules/@poe-code/config-mutations/dist/formats/toml.d.ts +2 -0
  40. package/node_modules/@poe-code/config-mutations/dist/formats/toml.js +72 -0
  41. package/node_modules/@poe-code/config-mutations/dist/formats/yaml.d.ts +2 -0
  42. package/node_modules/@poe-code/config-mutations/dist/formats/yaml.js +73 -0
  43. package/node_modules/@poe-code/config-mutations/dist/fs-utils.d.ts +18 -0
  44. package/node_modules/@poe-code/config-mutations/dist/fs-utils.js +45 -0
  45. package/node_modules/@poe-code/config-mutations/dist/index.d.ts +8 -0
  46. package/node_modules/@poe-code/config-mutations/dist/index.js +8 -0
  47. package/node_modules/@poe-code/config-mutations/dist/mutations/config-mutation.d.ts +47 -0
  48. package/node_modules/@poe-code/config-mutations/dist/mutations/config-mutation.js +34 -0
  49. package/node_modules/@poe-code/config-mutations/dist/mutations/file-mutation.d.ts +52 -0
  50. package/node_modules/@poe-code/config-mutations/dist/mutations/file-mutation.js +46 -0
  51. package/node_modules/@poe-code/config-mutations/dist/mutations/template-mutation.d.ts +40 -0
  52. package/node_modules/@poe-code/config-mutations/dist/mutations/template-mutation.js +32 -0
  53. package/node_modules/@poe-code/config-mutations/dist/template/render.d.ts +7 -0
  54. package/node_modules/@poe-code/config-mutations/dist/template/render.js +28 -0
  55. package/node_modules/@poe-code/config-mutations/dist/testing/format-utils.d.ts +7 -0
  56. package/node_modules/@poe-code/config-mutations/dist/testing/format-utils.js +21 -0
  57. package/node_modules/@poe-code/config-mutations/dist/testing/index.d.ts +3 -0
  58. package/node_modules/@poe-code/config-mutations/dist/testing/index.js +2 -0
  59. package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.d.ts +25 -0
  60. package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.js +170 -0
  61. package/node_modules/@poe-code/config-mutations/dist/types.d.ts +156 -0
  62. package/node_modules/@poe-code/config-mutations/dist/types.js +6 -0
  63. package/node_modules/@poe-code/config-mutations/package.json +33 -0
  64. package/node_modules/@poe-code/file-lock/README.md +52 -0
  65. package/node_modules/@poe-code/file-lock/dist/index.d.ts +1 -0
  66. package/node_modules/@poe-code/file-lock/dist/index.js +1 -0
  67. package/node_modules/@poe-code/file-lock/dist/lock.d.ts +27 -0
  68. package/node_modules/@poe-code/file-lock/dist/lock.js +203 -0
  69. package/node_modules/@poe-code/file-lock/package.json +23 -0
  70. package/node_modules/auth-store/README.md +47 -0
  71. package/node_modules/auth-store/dist/create-secret-store.d.ts +2 -0
  72. package/node_modules/auth-store/dist/create-secret-store.js +35 -0
  73. package/node_modules/auth-store/dist/encrypted-file-store.d.ts +39 -0
  74. package/node_modules/auth-store/dist/encrypted-file-store.js +156 -0
  75. package/node_modules/auth-store/dist/index.d.ts +7 -0
  76. package/node_modules/auth-store/dist/index.js +4 -0
  77. package/node_modules/auth-store/dist/keychain-store.d.ts +22 -0
  78. package/node_modules/auth-store/dist/keychain-store.js +111 -0
  79. package/node_modules/auth-store/dist/provider-store.d.ts +10 -0
  80. package/node_modules/auth-store/dist/provider-store.js +28 -0
  81. package/node_modules/auth-store/dist/types.d.ts +20 -0
  82. package/node_modules/auth-store/dist/types.js +1 -0
  83. package/node_modules/auth-store/package.json +25 -0
  84. package/node_modules/mcp-oauth/README.md +31 -0
  85. package/node_modules/mcp-oauth/dist/client/auth-store-session-store.d.ts +14 -0
  86. package/node_modules/mcp-oauth/dist/client/auth-store-session-store.js +97 -0
  87. package/node_modules/mcp-oauth/dist/client/authorization-state.d.ts +8 -0
  88. package/node_modules/mcp-oauth/dist/client/authorization-state.js +34 -0
  89. package/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.d.ts +3 -0
  90. package/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +491 -0
  91. package/node_modules/mcp-oauth/dist/client/loopback-authorization.d.ts +20 -0
  92. package/node_modules/mcp-oauth/dist/client/loopback-authorization.js +169 -0
  93. package/node_modules/mcp-oauth/dist/client/pkce.d.ts +2 -0
  94. package/node_modules/mcp-oauth/dist/client/pkce.js +7 -0
  95. package/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +40 -0
  96. package/node_modules/mcp-oauth/dist/client/token-endpoint.js +143 -0
  97. package/node_modules/mcp-oauth/dist/client/types.d.ts +113 -0
  98. package/node_modules/mcp-oauth/dist/client/types.js +1 -0
  99. package/node_modules/mcp-oauth/dist/index.d.ts +10 -0
  100. package/node_modules/mcp-oauth/dist/index.js +7 -0
  101. package/node_modules/mcp-oauth/dist/resource-indicator.d.ts +1 -0
  102. package/node_modules/mcp-oauth/dist/resource-indicator.js +11 -0
  103. package/node_modules/mcp-oauth/dist/server/jwks-token-verifier.d.ts +27 -0
  104. package/node_modules/mcp-oauth/dist/server/jwks-token-verifier.js +259 -0
  105. package/node_modules/mcp-oauth/dist/types.compile-check.d.ts +1 -0
  106. package/node_modules/mcp-oauth/dist/types.compile-check.js +22 -0
  107. package/node_modules/mcp-oauth/package.json +31 -0
  108. package/node_modules/tiny-mcp-client/.turbo/turbo-build.log +4 -0
  109. package/node_modules/tiny-mcp-client/dist/index.d.ts +2 -0
  110. package/node_modules/tiny-mcp-client/dist/index.js +1 -0
  111. package/node_modules/tiny-mcp-client/dist/internal.d.ts +547 -0
  112. package/node_modules/tiny-mcp-client/dist/internal.js +2404 -0
  113. package/node_modules/tiny-mcp-client/dist/jsonrpc-types.compile-check.d.ts +1 -0
  114. package/node_modules/tiny-mcp-client/dist/jsonrpc-types.compile-check.js +37 -0
  115. package/node_modules/tiny-mcp-client/dist/mcp-lifecycle-types.compile-check.d.ts +1 -0
  116. package/node_modules/tiny-mcp-client/dist/mcp-lifecycle-types.compile-check.js +50 -0
  117. package/node_modules/tiny-mcp-client/dist/mcp-prompt-types.compile-check.d.ts +1 -0
  118. package/node_modules/tiny-mcp-client/dist/mcp-prompt-types.compile-check.js +50 -0
  119. package/node_modules/tiny-mcp-client/dist/mcp-resource-types.compile-check.d.ts +1 -0
  120. package/node_modules/tiny-mcp-client/dist/mcp-resource-types.compile-check.js +51 -0
  121. package/node_modules/tiny-mcp-client/dist/mcp-tool-types.compile-check.d.ts +1 -0
  122. package/node_modules/tiny-mcp-client/dist/mcp-tool-types.compile-check.js +89 -0
  123. package/node_modules/tiny-mcp-client/dist/mcp-transport-types.compile-check.d.ts +1 -0
  124. package/node_modules/tiny-mcp-client/dist/mcp-transport-types.compile-check.js +56 -0
  125. package/node_modules/tiny-mcp-client/dist/mcp-utility-types.compile-check.d.ts +1 -0
  126. package/node_modules/tiny-mcp-client/dist/mcp-utility-types.compile-check.js +145 -0
  127. package/node_modules/tiny-mcp-client/dist/oauth-discovery.d.ts +24 -0
  128. package/node_modules/tiny-mcp-client/dist/oauth-discovery.js +385 -0
  129. package/node_modules/tiny-mcp-client/package.json +22 -0
  130. package/node_modules/tiny-mcp-client/src/http-oauth.integration.test.ts +823 -0
  131. package/node_modules/tiny-mcp-client/src/http-oauth.test.ts +882 -0
  132. package/node_modules/tiny-mcp-client/src/index.ts +94 -0
  133. package/node_modules/tiny-mcp-client/src/internal.ts +3566 -0
  134. package/node_modules/tiny-mcp-client/src/jsonrpc-types.compile-check.ts +66 -0
  135. package/node_modules/tiny-mcp-client/src/mcp-client-http-transport.integration.test.ts +222 -0
  136. package/node_modules/tiny-mcp-client/src/mcp-client-sdk.test.ts +1294 -0
  137. package/node_modules/tiny-mcp-client/src/mcp-client-tiny-stdio-test-server-tools.test.ts +143 -0
  138. package/node_modules/tiny-mcp-client/src/mcp-lifecycle-types.compile-check.ts +65 -0
  139. package/node_modules/tiny-mcp-client/src/mcp-prompt-types.compile-check.ts +66 -0
  140. package/node_modules/tiny-mcp-client/src/mcp-resource-types.compile-check.ts +70 -0
  141. package/node_modules/tiny-mcp-client/src/mcp-tool-types.compile-check.ts +117 -0
  142. package/node_modules/tiny-mcp-client/src/mcp-transport-types.compile-check.ts +75 -0
  143. package/node_modules/tiny-mcp-client/src/mcp-utility-types.compile-check.ts +181 -0
  144. package/node_modules/tiny-mcp-client/src/mock-servers.test.ts +980 -0
  145. package/node_modules/tiny-mcp-client/src/oauth-discovery.ts +583 -0
  146. package/node_modules/tiny-mcp-client/src/transports.test.ts +8139 -0
  147. package/node_modules/tiny-mcp-client/src/utilities.test.ts +372 -0
  148. package/node_modules/tiny-mcp-client/tsconfig.json +11 -0
  149. package/package.json +24 -11
@@ -0,0 +1,385 @@
1
+ import { canonicalizeResourceIndicator } from "mcp-oauth";
2
+ function defaultOAuthMetadataFetch(input, init) {
3
+ return fetch(input, init);
4
+ }
5
+ function isObjectRecord(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
8
+ function isStringArray(value) {
9
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
10
+ }
11
+ function normalizeHostname(hostname) {
12
+ return hostname.endsWith(".") ? hostname.slice(0, -1).toLowerCase() : hostname.toLowerCase();
13
+ }
14
+ function isLoopbackHostname(hostname) {
15
+ const normalizedHostname = normalizeHostname(hostname);
16
+ return normalizedHostname === "localhost"
17
+ || normalizedHostname === "::1"
18
+ || normalizedHostname.startsWith("127.");
19
+ }
20
+ function assertSecureUrl(url, label) {
21
+ if (url.protocol === "https:") {
22
+ return;
23
+ }
24
+ if (url.protocol === "http:" && isLoopbackHostname(url.hostname)) {
25
+ return;
26
+ }
27
+ throw new Error(`${label} must use https unless it targets a loopback host`);
28
+ }
29
+ function validateProtectedResourceMetadata(value, resourceUrl) {
30
+ if (!isObjectRecord(value)) {
31
+ throw new Error("Protected resource metadata must be a JSON object");
32
+ }
33
+ if (typeof value.resource !== "string" || value.resource.length === 0) {
34
+ throw new Error("Protected resource metadata must include a resource string");
35
+ }
36
+ const normalizedResource = canonicalizeResourceIndicator(value.resource);
37
+ if (normalizedResource !== resourceUrl) {
38
+ throw new Error(`Protected resource metadata resource mismatch: expected ${resourceUrl}, received ${value.resource}`);
39
+ }
40
+ if (!isStringArray(value.authorization_servers) || value.authorization_servers.length === 0) {
41
+ throw new Error("Protected resource metadata must include a non-empty authorization_servers array");
42
+ }
43
+ return {
44
+ ...value,
45
+ resource: normalizedResource,
46
+ };
47
+ }
48
+ function validateAuthorizationServerMetadata(value, issuer) {
49
+ if (!isObjectRecord(value)) {
50
+ throw new Error("Authorization server metadata must be a JSON object");
51
+ }
52
+ if (typeof value.issuer !== "string" || value.issuer.length === 0) {
53
+ throw new Error("Authorization server metadata must include issuer");
54
+ }
55
+ if (value.issuer !== issuer) {
56
+ throw new Error(`Authorization server metadata issuer mismatch: expected ${issuer}, received ${value.issuer}`);
57
+ }
58
+ if (typeof value.authorization_endpoint !== "string" ||
59
+ value.authorization_endpoint.length === 0) {
60
+ throw new Error("Authorization server metadata must include authorization_endpoint");
61
+ }
62
+ if (typeof value.token_endpoint !== "string" || value.token_endpoint.length === 0) {
63
+ throw new Error("Authorization server metadata must include token_endpoint");
64
+ }
65
+ if (!isStringArray(value.response_types_supported) ||
66
+ !value.response_types_supported.includes("code")) {
67
+ throw new Error("Authorization server metadata must include response_types_supported containing code");
68
+ }
69
+ if (!isStringArray(value.code_challenge_methods_supported) ||
70
+ !value.code_challenge_methods_supported.includes("S256")) {
71
+ throw new Error("Authorization server metadata must include code_challenge_methods_supported containing S256");
72
+ }
73
+ return value;
74
+ }
75
+ async function readJsonResponse(response, label) {
76
+ if (!response.ok) {
77
+ const statusDescriptor = `${response.status} ${response.statusText}`.trim();
78
+ throw new Error(`${label} request failed (${statusDescriptor})`);
79
+ }
80
+ try {
81
+ return await response.json();
82
+ }
83
+ catch {
84
+ throw new Error(`${label} response must be valid JSON`);
85
+ }
86
+ }
87
+ function resolveWellKnownMetadataUrl(inputUrl, suffix) {
88
+ const url = new URL(typeof inputUrl === "string" ? inputUrl : inputUrl.toString());
89
+ const resourcePath = url.pathname === "/" ? "" : url.pathname;
90
+ url.pathname = `/.well-known/${suffix}${resourcePath}`;
91
+ return url.toString();
92
+ }
93
+ export function resolveProtectedResourceMetadataUrl(resourceUrl, resourceMetadataUrl) {
94
+ const resource = new URL(canonicalizeResourceIndicator(resourceUrl));
95
+ assertSecureUrl(resource, "Protected resource URL");
96
+ if (resourceMetadataUrl !== undefined) {
97
+ const resolvedResourceMetadataUrl = new URL(typeof resourceMetadataUrl === "string" ? resourceMetadataUrl : resourceMetadataUrl.toString(), resource);
98
+ assertSecureUrl(resolvedResourceMetadataUrl, "Protected resource metadata URL");
99
+ return resolvedResourceMetadataUrl.toString();
100
+ }
101
+ const resolvedResourceMetadataUrl = new URL(resolveWellKnownMetadataUrl(resource, "oauth-protected-resource"));
102
+ assertSecureUrl(resolvedResourceMetadataUrl, "Protected resource metadata URL");
103
+ return resolvedResourceMetadataUrl.toString();
104
+ }
105
+ function normalizeAuthorizationServerIssuer(issuer) {
106
+ const input = typeof issuer === "string" ? issuer : issuer.toString();
107
+ const url = new URL(input);
108
+ if (url.search.length > 0 || url.hash.length > 0) {
109
+ throw new Error("Authorization server issuer must not include query or fragment");
110
+ }
111
+ assertSecureUrl(url, "Authorization server issuer");
112
+ if (url.pathname.length > 1 && url.pathname.endsWith("/")) {
113
+ url.pathname = url.pathname.slice(0, -1);
114
+ }
115
+ return url.pathname === "/" ? url.origin : url.toString();
116
+ }
117
+ export function resolveAuthorizationServerMetadataUrl(issuer) {
118
+ return resolveWellKnownMetadataUrl(normalizeAuthorizationServerIssuer(issuer), "oauth-authorization-server");
119
+ }
120
+ export class OAuthMetadataDiscovery {
121
+ fetchImpl;
122
+ cache;
123
+ memoryCache = new Map();
124
+ constructor({ fetch = defaultOAuthMetadataFetch, cache } = {}) {
125
+ this.fetchImpl = fetch;
126
+ this.cache = cache;
127
+ }
128
+ async discover(resourceUrl, { resourceMetadataUrl } = {}) {
129
+ const cacheKey = canonicalizeResourceIndicator(resourceUrl);
130
+ const resourceMetadataLocation = resolveProtectedResourceMetadataUrl(cacheKey, resourceMetadataUrl);
131
+ const memoryCachedResult = this.memoryCache.get(cacheKey);
132
+ if (memoryCachedResult !== undefined &&
133
+ (resourceMetadataUrl === undefined
134
+ || memoryCachedResult.resourceMetadataUrl === resourceMetadataLocation)) {
135
+ return memoryCachedResult;
136
+ }
137
+ const sharedCachedResult = await this.cache?.get(cacheKey);
138
+ if (sharedCachedResult !== null &&
139
+ sharedCachedResult !== undefined &&
140
+ (resourceMetadataUrl === undefined
141
+ || sharedCachedResult.resourceMetadataUrl === resourceMetadataLocation)) {
142
+ this.memoryCache.set(cacheKey, sharedCachedResult);
143
+ return sharedCachedResult;
144
+ }
145
+ const resourceMetadataResponse = await this.fetchImpl(resourceMetadataLocation, {
146
+ method: "GET",
147
+ headers: {
148
+ Accept: "application/json",
149
+ },
150
+ });
151
+ const resourceMetadata = validateProtectedResourceMetadata(await readJsonResponse(resourceMetadataResponse, "Protected resource metadata"), cacheKey);
152
+ const authorizationServerErrors = [];
153
+ for (const authorizationServer of resourceMetadata.authorization_servers) {
154
+ const normalizedAuthorizationServer = normalizeAuthorizationServerIssuer(authorizationServer);
155
+ const authorizationServerMetadataUrl = resolveAuthorizationServerMetadataUrl(normalizedAuthorizationServer);
156
+ try {
157
+ const authorizationServerResponse = await this.fetchImpl(authorizationServerMetadataUrl, {
158
+ method: "GET",
159
+ headers: {
160
+ Accept: "application/json",
161
+ },
162
+ });
163
+ const authorizationServerMetadata = validateAuthorizationServerMetadata(await readJsonResponse(authorizationServerResponse, "Authorization server metadata"), normalizedAuthorizationServer);
164
+ const result = {
165
+ resource: resourceMetadata.resource,
166
+ resourceMetadataUrl: resourceMetadataLocation,
167
+ resourceMetadata,
168
+ authorizationServer: normalizedAuthorizationServer,
169
+ authorizationServerMetadataUrl,
170
+ authorizationServerMetadata,
171
+ };
172
+ this.memoryCache.set(cacheKey, result);
173
+ await this.cache?.set(cacheKey, result);
174
+ return result;
175
+ }
176
+ catch (error) {
177
+ authorizationServerErrors.push(`${authorizationServerMetadataUrl}: ${error instanceof Error ? error.message : String(error)}`);
178
+ }
179
+ }
180
+ throw new Error(`Unable to load authorization server metadata for ${cacheKey}: ${authorizationServerErrors.join("; ")}`);
181
+ }
182
+ }
183
+ export async function discoverOAuthMetadata(resourceUrl, options = {}) {
184
+ const discovery = new OAuthMetadataDiscovery(options);
185
+ return discovery.discover(resourceUrl, options);
186
+ }
187
+ function skipOptionalWhitespace(value, start) {
188
+ let index = start;
189
+ while (index < value.length && (value[index] === " " || value[index] === "\t")) {
190
+ index += 1;
191
+ }
192
+ return index;
193
+ }
194
+ function readToken(value, start) {
195
+ let index = start;
196
+ while (index < value.length) {
197
+ const character = value[index];
198
+ if (character === " "
199
+ || character === "\t"
200
+ || character === ","
201
+ || character === "="
202
+ || character === "\"") {
203
+ break;
204
+ }
205
+ index += 1;
206
+ }
207
+ if (index === start) {
208
+ return null;
209
+ }
210
+ return {
211
+ token: value.slice(start, index),
212
+ nextIndex: index,
213
+ };
214
+ }
215
+ function looksLikeAuthParam(value, start) {
216
+ const token = readToken(value, start);
217
+ if (token === null) {
218
+ return false;
219
+ }
220
+ return value[skipOptionalWhitespace(value, token.nextIndex)] === "=";
221
+ }
222
+ function isToken68Character(character) {
223
+ return ((character >= "a" && character <= "z")
224
+ || (character >= "A" && character <= "Z")
225
+ || (character >= "0" && character <= "9")
226
+ || character === "-"
227
+ || character === "."
228
+ || character === "_"
229
+ || character === "~"
230
+ || character === "+"
231
+ || character === "/");
232
+ }
233
+ function readToken68(value, start) {
234
+ let nextIndex = start;
235
+ while (nextIndex < value.length) {
236
+ const character = value[nextIndex];
237
+ if (character === "," || character === " " || character === "\t") {
238
+ break;
239
+ }
240
+ nextIndex += 1;
241
+ }
242
+ const token68 = value.slice(start, nextIndex);
243
+ if (token68.length === 0) {
244
+ return null;
245
+ }
246
+ let index = 0;
247
+ while (index < token68.length && isToken68Character(token68[index])) {
248
+ index += 1;
249
+ }
250
+ if (index === 0) {
251
+ return null;
252
+ }
253
+ while (index < token68.length && token68[index] === "=") {
254
+ index += 1;
255
+ }
256
+ if (index !== token68.length) {
257
+ return null;
258
+ }
259
+ return { token68, nextIndex };
260
+ }
261
+ function readQuotedString(value, start) {
262
+ if (value[start] !== "\"") {
263
+ return null;
264
+ }
265
+ let parsedValue = "";
266
+ let index = start + 1;
267
+ let escaping = false;
268
+ while (index < value.length) {
269
+ const character = value[index];
270
+ if (escaping) {
271
+ parsedValue += character;
272
+ escaping = false;
273
+ index += 1;
274
+ continue;
275
+ }
276
+ if (character === "\\") {
277
+ escaping = true;
278
+ index += 1;
279
+ continue;
280
+ }
281
+ if (character === "\"") {
282
+ return {
283
+ parsedValue,
284
+ nextIndex: index + 1,
285
+ };
286
+ }
287
+ parsedValue += character;
288
+ index += 1;
289
+ }
290
+ return null;
291
+ }
292
+ function parseAuthParam(value, start) {
293
+ const token = readToken(value, start);
294
+ if (token === null) {
295
+ return null;
296
+ }
297
+ let index = skipOptionalWhitespace(value, token.nextIndex);
298
+ if (value[index] !== "=") {
299
+ return null;
300
+ }
301
+ index = skipOptionalWhitespace(value, index + 1);
302
+ if (index >= value.length) {
303
+ return null;
304
+ }
305
+ const quotedValue = readQuotedString(value, index);
306
+ if (quotedValue !== null) {
307
+ return {
308
+ name: token.token,
309
+ value: quotedValue.parsedValue,
310
+ nextIndex: quotedValue.nextIndex,
311
+ };
312
+ }
313
+ let nextIndex = index;
314
+ while (nextIndex < value.length) {
315
+ const character = value[nextIndex];
316
+ if (character === "," || character === " " || character === "\t") {
317
+ break;
318
+ }
319
+ nextIndex += 1;
320
+ }
321
+ return {
322
+ name: token.token,
323
+ value: value.slice(index, nextIndex),
324
+ nextIndex,
325
+ };
326
+ }
327
+ export function parseBearerWwwAuthenticateHeader(headerValue) {
328
+ if (headerValue === null) {
329
+ return null;
330
+ }
331
+ let index = 0;
332
+ let firstBearerChallenge = null;
333
+ while (index < headerValue.length) {
334
+ index = skipOptionalWhitespace(headerValue, index);
335
+ while (headerValue[index] === ",") {
336
+ index = skipOptionalWhitespace(headerValue, index + 1);
337
+ }
338
+ const scheme = readToken(headerValue, index);
339
+ if (scheme === null) {
340
+ break;
341
+ }
342
+ index = skipOptionalWhitespace(headerValue, scheme.nextIndex);
343
+ const params = {};
344
+ if (index < headerValue.length && headerValue[index] !== ",") {
345
+ const token68 = readToken68(headerValue, index);
346
+ if (token68 !== null) {
347
+ index = token68.nextIndex;
348
+ }
349
+ else if (looksLikeAuthParam(headerValue, index)) {
350
+ while (index < headerValue.length) {
351
+ const parsedParam = parseAuthParam(headerValue, index);
352
+ if (parsedParam === null) {
353
+ break;
354
+ }
355
+ params[parsedParam.name] = parsedParam.value;
356
+ index = skipOptionalWhitespace(headerValue, parsedParam.nextIndex);
357
+ if (headerValue[index] !== ",") {
358
+ break;
359
+ }
360
+ const nextIndex = skipOptionalWhitespace(headerValue, index + 1);
361
+ if (!looksLikeAuthParam(headerValue, nextIndex)) {
362
+ index = nextIndex;
363
+ break;
364
+ }
365
+ index = nextIndex;
366
+ }
367
+ }
368
+ }
369
+ if (scheme.token.toLowerCase() === "bearer") {
370
+ const challenge = {
371
+ scheme: "Bearer",
372
+ params,
373
+ raw: headerValue,
374
+ };
375
+ if (Object.keys(params).length > 0) {
376
+ return challenge;
377
+ }
378
+ firstBearerChallenge ??= challenge;
379
+ }
380
+ if (headerValue[index] === ",") {
381
+ index += 1;
382
+ }
383
+ }
384
+ return firstBearerChallenge;
385
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "tiny-mcp-client",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/poe-platform/poe-code.git",
13
+ "directory": "packages/tiny-mcp-client"
14
+ },
15
+ "dependencies": {
16
+ "mcp-oauth": "*"
17
+ },
18
+ "devDependencies": {
19
+ "@modelcontextprotocol/sdk": "^1.26.0",
20
+ "tiny-stdio-mcp-server": "*"
21
+ }
22
+ }