toolcraft 0.0.313 → 0.0.315
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/composition.json +3 -3
- package/dist/composition.json +3 -3
- package/node_modules/tiny-http-mcp-server/dist/composition.json +1 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/README.md +25 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/auth-store-session-store.d.ts +1 -6
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/auth-store-session-store.js +7 -18
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/client-registration.d.ts +4 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/client-registration.js +103 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +76 -50
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/scope.d.ts +2 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/scope.js +9 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-auth-method.d.ts +2 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-auth-method.js +7 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +3 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +23 -10
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/types.d.ts +27 -4
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +2 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +1 -0
- package/node_modules/tiny-http-mcp-server/package.json +1 -1
- package/node_modules/tiny-mcp-client/dist/index.d.ts +27 -4
- package/node_modules/tiny-mcp-client/dist/index.js +226 -73
- package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
- package/node_modules/toolcraft-schema/package.json +1 -1
- package/package.json +2 -2
package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { normalizeOAuthTokenEndpointAuthMethod } from "./token-auth-method.js";
|
|
1
2
|
import { canonicalizeResourceIndicator } from "../resource-indicator.js";
|
|
2
3
|
import { readBoundedResponseText } from "../http-response.js";
|
|
3
4
|
import { fetchMcpResponse } from "../http-fetch.js";
|
|
5
|
+
import { normalizeOAuthScope } from "./scope.js";
|
|
4
6
|
const MAX_JS_DATE_MS = 8_640_000_000_000_000;
|
|
5
7
|
export class OAuthError extends Error {
|
|
6
8
|
error;
|
|
@@ -39,6 +41,7 @@ export async function exchangeAuthorizationCode(input) {
|
|
|
39
41
|
tokenEndpoint: input.tokenEndpoint,
|
|
40
42
|
clientId: input.clientId,
|
|
41
43
|
clientSecret: input.clientSecret,
|
|
44
|
+
tokenEndpointAuthMethod: input.tokenEndpointAuthMethod,
|
|
42
45
|
params: {
|
|
43
46
|
grant_type: "authorization_code",
|
|
44
47
|
code: input.code,
|
|
@@ -57,6 +60,7 @@ export async function refreshAccessToken(input) {
|
|
|
57
60
|
tokenEndpoint: input.tokenEndpoint,
|
|
58
61
|
clientId: input.clientId,
|
|
59
62
|
clientSecret: input.clientSecret,
|
|
63
|
+
tokenEndpointAuthMethod: input.tokenEndpointAuthMethod,
|
|
60
64
|
params: {
|
|
61
65
|
grant_type: "refresh_token",
|
|
62
66
|
refresh_token: input.refreshToken,
|
|
@@ -68,21 +72,28 @@ export async function refreshAccessToken(input) {
|
|
|
68
72
|
});
|
|
69
73
|
}
|
|
70
74
|
async function requestTokens(input) {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const method = normalizeOAuthTokenEndpointAuthMethod(input.tokenEndpointAuthMethod) ??
|
|
76
|
+
(input.clientSecret === undefined ? "none" : "client_secret_post");
|
|
77
|
+
if (method !== "none" && (input.clientSecret === undefined || input.clientSecret.trim() === ""))
|
|
78
|
+
throw new Error("OAuth token endpoint authentication requires a client secret");
|
|
79
|
+
const body = new URLSearchParams(input.params);
|
|
80
|
+
const headers = new Headers({ "Content-Type": "application/x-www-form-urlencoded" });
|
|
81
|
+
if (method === "client_secret_basic") {
|
|
82
|
+
const encoded = new URLSearchParams({ credential: input.clientId }).toString().slice("credential=".length);
|
|
83
|
+
const encodedSecret = new URLSearchParams({ credential: input.clientSecret }).toString().slice("credential=".length);
|
|
84
|
+
headers.set("Authorization", `Basic ${Buffer.from(`${encoded}:${encodedSecret}`).toString("base64")}`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
body.set("client_id", input.clientId);
|
|
88
|
+
if (method === "client_secret_post")
|
|
89
|
+
body.set("client_secret", input.clientSecret);
|
|
77
90
|
}
|
|
78
91
|
input.signal?.throwIfAborted();
|
|
79
92
|
const deadline = AbortSignal.timeout(30_000);
|
|
80
93
|
const signal = input.signal === undefined ? deadline : AbortSignal.any([input.signal, deadline]);
|
|
81
94
|
const response = await fetchMcpResponse(input.fetch, input.tokenEndpoint, {
|
|
82
95
|
method: "POST",
|
|
83
|
-
headers
|
|
84
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
85
|
-
},
|
|
96
|
+
headers,
|
|
86
97
|
body: body.toString(),
|
|
87
98
|
signal
|
|
88
99
|
});
|
|
@@ -117,7 +128,9 @@ async function requestTokens(input) {
|
|
|
117
128
|
const normalizedRefreshToken = typeof refreshToken === "string" && refreshToken.trim().length > 0
|
|
118
129
|
? refreshToken.trim()
|
|
119
130
|
: undefined;
|
|
120
|
-
const normalizedScope =
|
|
131
|
+
const normalizedScope = normalizeOAuthScope(scope);
|
|
132
|
+
if (scope !== undefined && normalizedScope === undefined)
|
|
133
|
+
throw new Error("Invalid OAuth scope syntax in token response");
|
|
121
134
|
return {
|
|
122
135
|
accessToken: normalizedAccessToken,
|
|
123
136
|
refreshToken: normalizedRefreshToken === undefined ? undefined : normalizedRefreshToken,
|
|
@@ -70,16 +70,34 @@ export interface StoredOAuthTokens {
|
|
|
70
70
|
expiresAt: number | null;
|
|
71
71
|
scope?: string;
|
|
72
72
|
}
|
|
73
|
+
/** Full RFC 7591 response, including JSON provider extensions. */
|
|
74
|
+
export interface OAuthClientRegistration extends Record<string, unknown> {
|
|
75
|
+
client_id: string;
|
|
76
|
+
client_secret?: string | null;
|
|
77
|
+
redirect_uris?: string[] | null;
|
|
78
|
+
grant_types?: string[] | null;
|
|
79
|
+
response_types?: string[] | null;
|
|
80
|
+
contacts?: string[] | null;
|
|
81
|
+
client_id_issued_at?: number | null;
|
|
82
|
+
client_secret_expires_at?: number | null;
|
|
83
|
+
token_endpoint_auth_method?: string | null;
|
|
84
|
+
}
|
|
85
|
+
export interface StoredOAuthClient {
|
|
86
|
+
clientId: string;
|
|
87
|
+
clientSecret?: string;
|
|
88
|
+
registration?: OAuthClientRegistration;
|
|
89
|
+
tokenEndpointAuthMethod?: OAuthTokenEndpointAuthMethod;
|
|
90
|
+
}
|
|
91
|
+
export type OAuthTokenEndpointAuthMethod = "none" | "client_secret_post" | "client_secret_basic";
|
|
73
92
|
export interface StoredOAuthSession {
|
|
74
93
|
resource: string;
|
|
75
94
|
authorizationServer: string;
|
|
76
|
-
client:
|
|
77
|
-
clientId: string;
|
|
78
|
-
clientSecret?: string;
|
|
79
|
-
};
|
|
95
|
+
client: StoredOAuthClient;
|
|
80
96
|
tokens?: StoredOAuthTokens;
|
|
81
97
|
/** A refresh was begun; its winning response may not have been persisted. */
|
|
82
98
|
refreshState?: "pending";
|
|
99
|
+
/** Canonical explicitly requested scope set when the server omits token scope. */
|
|
100
|
+
requestedScope?: string;
|
|
83
101
|
discovery: {
|
|
84
102
|
resourceMetadataUrl: string;
|
|
85
103
|
resourceMetadata: Record<string, unknown>;
|
|
@@ -102,11 +120,16 @@ export interface DefaultOAuthClientProviderOptions {
|
|
|
102
120
|
clientId?: string;
|
|
103
121
|
clientSecret?: string;
|
|
104
122
|
metadata?: OAuthClientMetadata;
|
|
123
|
+
/** Import a complete registration owned by the caller. */
|
|
124
|
+
registration?: OAuthClientRegistration;
|
|
125
|
+
tokenEndpointAuthMethod?: OAuthTokenEndpointAuthMethod;
|
|
105
126
|
} | {
|
|
106
127
|
mode: "static";
|
|
107
128
|
clientId: string;
|
|
108
129
|
clientSecret?: string;
|
|
109
130
|
metadata?: OAuthClientMetadata;
|
|
131
|
+
registration?: OAuthClientRegistration;
|
|
132
|
+
tokenEndpointAuthMethod?: OAuthTokenEndpointAuthMethod;
|
|
110
133
|
};
|
|
111
134
|
/** Disable interactive authorization while allowing cached tokens and silent refresh. */
|
|
112
135
|
allowInteractive?: boolean;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export { createAuthStoreSessionStore, } from "./client/auth-store-session-store.js";
|
|
2
|
+
export { parseOAuthClientRegistration } from "./client/client-registration.js";
|
|
2
3
|
export { createDefaultOAuthClientProvider, createOAuthClientProvider, } from "./client/default-oauth-client-provider.js";
|
|
3
4
|
export { buildSuccessPage, createLoopbackAuthorizationSession, extractCodeFromInput, } from "./client/loopback-authorization.js";
|
|
4
5
|
export { generateCodeChallenge, generateCodeVerifier, } from "./client/pkce.js";
|
|
5
6
|
export { OAuthError, } from "./client/token-endpoint.js";
|
|
6
7
|
export { canonicalizeResourceIndicator, } from "./resource-indicator.js";
|
|
7
8
|
export { createJwksTokenVerifier, } from "./server/jwks-token-verifier.js";
|
|
8
|
-
export type { DefaultOAuthClientProviderOptions, OAuthAuthorizationServerMetadata, OAuthClientMetadata, OAuthClientProvider, OAuthClientProviderOptions, OAuthDiscoveryResult, OAuthMetadataFetch, OAuthProtectedResourceMetadata, OAuthSessionStore, OAuthUnauthorizedChallenge, StoredOAuthSession, StoredOAuthTokens, } from "./client/types.js";
|
|
9
|
+
export type { DefaultOAuthClientProviderOptions, OAuthAuthorizationServerMetadata, OAuthClientMetadata, OAuthClientRegistration, OAuthClientProvider, OAuthClientProviderOptions, OAuthDiscoveryResult, OAuthMetadataFetch, OAuthProtectedResourceMetadata, OAuthSessionStore, OAuthUnauthorizedChallenge, OAuthTokenEndpointAuthMethod, StoredOAuthSession, StoredOAuthClient, StoredOAuthTokens, } from "./client/types.js";
|
|
9
10
|
export type { JwksTokenVerifier, JwksTokenVerifierOptions, JwksVerifiedAccessToken, } from "./server/jwks-token-verifier.js";
|
|
10
11
|
export type { LoopbackAuthorizationOptions, LoopbackAuthorizationSession, OAuthLandingPage, } from "./client/loopback-authorization.js";
|
|
11
12
|
export { readBoundedResponseText } from "./http-response.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createAuthStoreSessionStore, } from "./client/auth-store-session-store.js";
|
|
2
|
+
export { parseOAuthClientRegistration } from "./client/client-registration.js";
|
|
2
3
|
export { createDefaultOAuthClientProvider, createOAuthClientProvider, } from "./client/default-oauth-client-provider.js";
|
|
3
4
|
export { buildSuccessPage, createLoopbackAuthorizationSession, extractCodeFromInput, } from "./client/loopback-authorization.js";
|
|
4
5
|
export { generateCodeChallenge, generateCodeVerifier, } from "./client/pkce.js";
|
|
@@ -173,16 +173,34 @@ interface StoredOAuthTokens {
|
|
|
173
173
|
expiresAt: number | null;
|
|
174
174
|
scope?: string;
|
|
175
175
|
}
|
|
176
|
+
/** Full RFC 7591 response, including JSON provider extensions. */
|
|
177
|
+
interface OAuthClientRegistration extends Record<string, unknown> {
|
|
178
|
+
client_id: string;
|
|
179
|
+
client_secret?: string | null;
|
|
180
|
+
redirect_uris?: string[] | null;
|
|
181
|
+
grant_types?: string[] | null;
|
|
182
|
+
response_types?: string[] | null;
|
|
183
|
+
contacts?: string[] | null;
|
|
184
|
+
client_id_issued_at?: number | null;
|
|
185
|
+
client_secret_expires_at?: number | null;
|
|
186
|
+
token_endpoint_auth_method?: string | null;
|
|
187
|
+
}
|
|
188
|
+
interface StoredOAuthClient {
|
|
189
|
+
clientId: string;
|
|
190
|
+
clientSecret?: string;
|
|
191
|
+
registration?: OAuthClientRegistration;
|
|
192
|
+
tokenEndpointAuthMethod?: OAuthTokenEndpointAuthMethod;
|
|
193
|
+
}
|
|
194
|
+
type OAuthTokenEndpointAuthMethod = "none" | "client_secret_post" | "client_secret_basic";
|
|
176
195
|
interface StoredOAuthSession {
|
|
177
196
|
resource: string;
|
|
178
197
|
authorizationServer: string;
|
|
179
|
-
client:
|
|
180
|
-
clientId: string;
|
|
181
|
-
clientSecret?: string;
|
|
182
|
-
};
|
|
198
|
+
client: StoredOAuthClient;
|
|
183
199
|
tokens?: StoredOAuthTokens;
|
|
184
200
|
/** A refresh was begun; its winning response may not have been persisted. */
|
|
185
201
|
refreshState?: "pending";
|
|
202
|
+
/** Canonical explicitly requested scope set when the server omits token scope. */
|
|
203
|
+
requestedScope?: string;
|
|
186
204
|
discovery: {
|
|
187
205
|
resourceMetadataUrl: string;
|
|
188
206
|
resourceMetadata: Record<string, unknown>;
|
|
@@ -205,11 +223,16 @@ interface DefaultOAuthClientProviderOptions {
|
|
|
205
223
|
clientId?: string;
|
|
206
224
|
clientSecret?: string;
|
|
207
225
|
metadata?: OAuthClientMetadata;
|
|
226
|
+
/** Import a complete registration owned by the caller. */
|
|
227
|
+
registration?: OAuthClientRegistration;
|
|
228
|
+
tokenEndpointAuthMethod?: OAuthTokenEndpointAuthMethod;
|
|
208
229
|
} | {
|
|
209
230
|
mode: "static";
|
|
210
231
|
clientId: string;
|
|
211
232
|
clientSecret?: string;
|
|
212
233
|
metadata?: OAuthClientMetadata;
|
|
234
|
+
registration?: OAuthClientRegistration;
|
|
235
|
+
tokenEndpointAuthMethod?: OAuthTokenEndpointAuthMethod;
|
|
213
236
|
};
|
|
214
237
|
/** Disable interactive authorization while allowing cached tokens and silent refresh. */
|
|
215
238
|
allowInteractive?: boolean;
|