@vvedantb/server 0.18.0 → 0.20.1
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/CHANGELOG.md +18 -0
- package/dist/ai/errors.d.ts +0 -2
- package/dist/ai/errors.js +0 -16
- package/dist/ai/serviceTier.d.ts +0 -4
- package/dist/ai/serviceTier.js +0 -4
- package/dist/artifacts/document.d.ts +0 -2
- package/dist/artifacts/document.js +0 -1
- package/dist/artifacts/protocol.d.ts +0 -5
- package/dist/artifacts/schemas.d.ts +0 -6
- package/dist/artifacts/storageShim.js +0 -2
- package/dist/convex/authFunctions.d.ts +0 -57
- package/dist/convex/clerkBilling.d.ts +2 -18
- package/dist/convex/clerkBilling.js +0 -9
- package/dist/convex/clerkBillingFunctions.d.ts +0 -35
- package/dist/convex/clerkBillingFunctions.js +0 -8
- package/dist/convex/clerkBillingNodeFunctions.d.ts +0 -29
- package/dist/convex/clerkBillingNodeFunctions.js +0 -1
- package/dist/convex/clerkUserAuth.d.ts +0 -18
- package/dist/convex/clerkUserAuth.js +0 -14
- package/dist/convex/clerkWebhook.d.ts +0 -2
- package/dist/convex/convexAdminClient.d.ts +0 -30
- package/dist/convex/convexAdminClient.js +0 -34
- package/dist/convex/convexQueryLimits.d.ts +0 -8
- package/dist/convex/convexQueryLimits.js +0 -8
- package/dist/convex/createMcpAuthActions.d.ts +0 -31
- package/dist/convex/expoPush.d.ts +0 -24
- package/dist/convex/expoPush.js +0 -4
- package/dist/convex/homepageRoutes.d.ts +42 -0
- package/dist/convex/homepageRoutes.js +46 -0
- package/dist/convex/index.d.ts +2 -0
- package/dist/convex/index.js +2 -0
- package/dist/convex/mcpServerInfo.d.ts +0 -2
- package/dist/convex/mcpTokenCache.d.ts +0 -17
- package/dist/convex/mcpTokenCache.js +0 -2
- package/dist/convex/memoryStore.js +0 -6
- package/dist/convex/originAllowlistCors.d.ts +0 -8
- package/dist/convex/productEmails.d.ts +22 -0
- package/dist/convex/productEmails.js +37 -0
- package/dist/convex/tempId.js +0 -2
- package/dist/convex/vPlan.d.ts +0 -4
- package/dist/convex/vProModule.d.ts +0 -27
- package/dist/convex/vProModule.js +0 -11
- package/dist/convex/verifyClerkAccessToken.d.ts +3 -13
- package/dist/convex/verifyClerkOAuthJwt.d.ts +0 -18
- package/dist/convex/verifyClerkOAuthJwt.js +0 -6
- package/dist/crypto/aesGcm.d.ts +0 -2
- package/dist/crypto/aesGcm.js +0 -2
- package/dist/crypto/encoding.d.ts +0 -8
- package/dist/crypto/encoding.js +0 -3
- package/dist/generative-ui/catalog.d.ts +0 -17
- package/dist/generative-ui/catalog.js +0 -18
- package/dist/generative-ui/spec.d.ts +0 -8
- package/dist/generative-ui/spec.js +0 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/dispatcher.d.ts +0 -7
- package/dist/mcp/dispatcher.js +0 -1
- package/dist/mcp/explorer.d.ts +0 -21
- package/dist/mcp/http.d.ts +3 -30
- package/dist/mcp/http.js +14 -0
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +2 -1
- package/dist/mcp/json.d.ts +0 -1
- package/dist/mcp/jsonRpc.d.ts +0 -2
- package/dist/mcp/metadata.d.ts +0 -15
- package/dist/mcp/routes.d.ts +2 -12
- package/dist/mcp/routes.js +6 -2
- package/dist/mcp/sdk.d.ts +0 -12
- package/dist/mcp/tools.d.ts +0 -18
- package/dist/mcp/tools.js +0 -1
- package/dist/mcp/zodJsonSchema.d.ts +14 -0
- package/dist/mcp/zodJsonSchema.js +98 -0
- package/dist/mcp-oauth-client/loopback.d.ts +0 -5
- package/dist/mcp-oauth-client/loopback.js +0 -6
- package/dist/mcp-oauth-client/oauth.d.ts +0 -14
- package/dist/mcp-oauth-client/oauth.js +0 -16
- package/dist/mcp-oauth-client/state.d.ts +0 -3
- package/dist/sandbox/runtime.d.ts +0 -15
- package/dist/sandbox/runtime.js +0 -25
- package/dist/skills/githubSkills.d.ts +51 -0
- package/dist/skills/githubSkills.js +172 -0
- package/dist/skills/index.d.ts +2 -0
- package/dist/skills/index.js +2 -0
- package/dist/skills/skillRef.d.ts +18 -0
- package/dist/skills/skillRef.js +168 -0
- package/package.json +1 -1
package/dist/mcp/tools.d.ts
CHANGED
|
@@ -59,7 +59,6 @@ export type ZodLikeSchema<Out> = {
|
|
|
59
59
|
issues: ReadonlyArray<Issue>;
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
|
-
/** Present on zod 4 schemas. Used for `tools/list` when no converter is given. */
|
|
63
62
|
toJSONSchema?(params: {
|
|
64
63
|
target: "draft-7";
|
|
65
64
|
io: "input";
|
|
@@ -86,21 +85,17 @@ export type ToolContext<Principal, Ctx, Scope extends string = string> = {
|
|
|
86
85
|
type ToolMeta<Scope extends string> = {
|
|
87
86
|
name: string;
|
|
88
87
|
title?: string;
|
|
89
|
-
/** A string, or a function of the scope (app-a: personal vs team wording). */
|
|
90
88
|
description: string | ((scope: Scope | undefined) => string);
|
|
91
89
|
annotations?: ToolAnnotations;
|
|
92
|
-
/** Scopes the tool is listed and callable on. Omit for all (app-a `scopes`). */
|
|
93
90
|
scopes?: readonly Scope[];
|
|
94
91
|
};
|
|
95
92
|
export type ZodToolDefinition<Args extends object, Principal, Ctx, Scope extends string> = ToolMeta<Scope> & {
|
|
96
93
|
inputSchema: ZodLikeSchema<Args>;
|
|
97
|
-
/** JSON Schema for `tools/list`. Overrides any converter. */
|
|
98
94
|
jsonSchema?: object;
|
|
99
95
|
handler: (args: Args, context: ToolContext<Principal, Ctx, Scope>) => Promise<ToolResult>;
|
|
100
96
|
};
|
|
101
97
|
export type JsonSchemaToolDefinition<Args extends object, Principal, Ctx, Scope extends string> = ToolMeta<Scope> & {
|
|
102
98
|
inputSchema: JsonSchemaObject;
|
|
103
|
-
/** Validate and normalise raw arguments. Throw to reject; the message becomes the validation error. */
|
|
104
99
|
parseArgs: (args: JsonObject) => Args;
|
|
105
100
|
handler: (args: Args, context: ToolContext<Principal, Ctx, Scope>) => Promise<ToolResult>;
|
|
106
101
|
};
|
|
@@ -110,16 +105,8 @@ export type McpTool<Principal, Ctx, Scope extends string = string> = {
|
|
|
110
105
|
readonly title?: string;
|
|
111
106
|
readonly description: string | ((scope: Scope | undefined) => string);
|
|
112
107
|
readonly annotations?: ToolAnnotations;
|
|
113
|
-
/** Scopes the tool is on (typed as `Scope[]` in `defineTool`; plain strings here so unscoped tools fit any registry). */
|
|
114
108
|
readonly scopes?: readonly string[];
|
|
115
|
-
/** JSON Schema for `tools/list`. */
|
|
116
109
|
inputJsonSchema(convert?: JsonSchemaConverter): object;
|
|
117
|
-
/**
|
|
118
|
-
* Validate `args`, run the handler, and shape errors like the MCP SDK:
|
|
119
|
-
* invalid args become an `isError` result starting
|
|
120
|
-
* "MCP error -32602: Input validation error: Invalid arguments for tool <name>: ",
|
|
121
|
-
* a thrown error becomes an `isError` result with its message.
|
|
122
|
-
*/
|
|
123
110
|
call(args: JsonObject, context: ToolContext<Principal, Ctx, Scope>): Promise<ToolResult>;
|
|
124
111
|
};
|
|
125
112
|
/** Format zod issues like MCP SDK 1.30+: "<message> at <path>", one per line. */
|
|
@@ -154,20 +141,15 @@ export declare function assertUniqueToolNames(tools: ReadonlyArray<{
|
|
|
154
141
|
name: string;
|
|
155
142
|
}>): void;
|
|
156
143
|
export type ToolsToListOptions<Scope extends string> = {
|
|
157
|
-
/** Keep only tools available on this scope. Tools without `scopes` are always kept. */
|
|
158
144
|
scope?: Scope;
|
|
159
|
-
/** zod to JSON Schema converter for schemas without `toJSONSchema()` (zod 3). */
|
|
160
145
|
toJsonSchema?: JsonSchemaConverter;
|
|
161
146
|
};
|
|
162
147
|
/** Build the `tools/list` result array, in definition order. */
|
|
163
148
|
export declare function toolsToList<Principal, Ctx, Scope extends string>(tools: ReadonlyArray<McpTool<Principal, Ctx, Scope>>, options?: ToolsToListOptions<Scope>): ToolListEntry[];
|
|
164
149
|
export type ToolRegistry<Principal, Ctx, Scope extends string> = {
|
|
165
150
|
readonly tools: ReadonlyArray<McpTool<Principal, Ctx, Scope>>;
|
|
166
|
-
/** Tools on a scope (all tools without `scopes`, plus those listing it). */
|
|
167
151
|
forScope(scope: Scope | undefined): ReadonlyArray<McpTool<Principal, Ctx, Scope>>;
|
|
168
|
-
/** Names on a scope, for `assertMcpTools` from server/convex. */
|
|
169
152
|
names(scope?: Scope): string[];
|
|
170
|
-
/** The tool with this name on this scope, or `undefined`. */
|
|
171
153
|
find(name: string, scope: Scope | undefined): McpTool<Principal, Ctx, Scope> | undefined;
|
|
172
154
|
list(options?: ToolsToListOptions<Scope>): ToolListEntry[];
|
|
173
155
|
};
|
package/dist/mcp/tools.js
CHANGED
|
@@ -21,7 +21,6 @@ export async function runTool(fn, options = {}) {
|
|
|
21
21
|
const label = (message) => options.errorLabel ? `${options.errorLabel}: ${message}` : message;
|
|
22
22
|
try {
|
|
23
23
|
const text = JSON.stringify(await fn(), null, 2);
|
|
24
|
-
// JSON.stringify returns undefined for undefined, functions and symbols.
|
|
25
24
|
if (typeof text !== "string")
|
|
26
25
|
return toolErrorResult(label("Result is not JSON"));
|
|
27
26
|
return toolTextResult(text);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { JsonSchemaConverter } from "./tools.js";
|
|
3
|
+
export type ZodJsonSchemaOptions = {
|
|
4
|
+
stripSafeIntegerBounds?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A `JsonSchemaConverter` for zod 4 schemas that reproduces the zod 3
|
|
8
|
+
* (zod-to-json-schema) output: draft-07, input types, its key order, and
|
|
9
|
+
* `additionalProperties: false` on every object with properties.
|
|
10
|
+
*
|
|
11
|
+
* Pass `z.toJSONSchema` from the app's own zod, so the package root does not
|
|
12
|
+
* load zod.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createZodJsonSchemaConverter(toJSONSchema: typeof z.toJSONSchema, options?: ZodJsonSchemaOptions): JsonSchemaConverter;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const EMPTY_INPUT_SCHEMA = {
|
|
2
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
type: "object",
|
|
4
|
+
properties: {},
|
|
5
|
+
};
|
|
6
|
+
function isZodType(schema) {
|
|
7
|
+
return "_zod" in schema;
|
|
8
|
+
}
|
|
9
|
+
function isEmptyObject(schema) {
|
|
10
|
+
return "shape" in schema && typeof schema.shape === "object" && schema.shape !== null && Object.keys(schema.shape).length === 0;
|
|
11
|
+
}
|
|
12
|
+
function isJsonObject(value) {
|
|
13
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
const KEY_ORDER = [
|
|
16
|
+
"type",
|
|
17
|
+
"enum",
|
|
18
|
+
"const",
|
|
19
|
+
"items",
|
|
20
|
+
"properties",
|
|
21
|
+
"required",
|
|
22
|
+
"additionalProperties",
|
|
23
|
+
"anyOf",
|
|
24
|
+
"allOf",
|
|
25
|
+
"oneOf",
|
|
26
|
+
"not",
|
|
27
|
+
"format",
|
|
28
|
+
"minimum",
|
|
29
|
+
"maximum",
|
|
30
|
+
"exclusiveMinimum",
|
|
31
|
+
"exclusiveMaximum",
|
|
32
|
+
"multipleOf",
|
|
33
|
+
"minItems",
|
|
34
|
+
"maxItems",
|
|
35
|
+
"minLength",
|
|
36
|
+
"maxLength",
|
|
37
|
+
"pattern",
|
|
38
|
+
"propertyNames",
|
|
39
|
+
"default",
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* A `JsonSchemaConverter` for zod 4 schemas that reproduces the zod 3
|
|
43
|
+
* (zod-to-json-schema) output: draft-07, input types, its key order, and
|
|
44
|
+
* `additionalProperties: false` on every object with properties.
|
|
45
|
+
*
|
|
46
|
+
* Pass `z.toJSONSchema` from the app's own zod, so the package root does not
|
|
47
|
+
* load zod.
|
|
48
|
+
*/
|
|
49
|
+
export function createZodJsonSchemaConverter(toJSONSchema, options = {}) {
|
|
50
|
+
const stripBounds = options.stripSafeIntegerBounds ?? false;
|
|
51
|
+
function normaliseProperties(node) {
|
|
52
|
+
if (node === null || typeof node !== "object" || Array.isArray(node))
|
|
53
|
+
return normalise(node);
|
|
54
|
+
const out = {};
|
|
55
|
+
for (const [key, value] of Object.entries(node))
|
|
56
|
+
out[key] = normalise(value);
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
function normalise(node) {
|
|
60
|
+
if (Array.isArray(node))
|
|
61
|
+
return node.map(normalise);
|
|
62
|
+
if (node === null || typeof node !== "object")
|
|
63
|
+
return node;
|
|
64
|
+
const source = { ...node };
|
|
65
|
+
if (stripBounds) {
|
|
66
|
+
if (source.maximum === Number.MAX_SAFE_INTEGER)
|
|
67
|
+
delete source.maximum;
|
|
68
|
+
if (source.minimum === -Number.MAX_SAFE_INTEGER)
|
|
69
|
+
delete source.minimum;
|
|
70
|
+
}
|
|
71
|
+
if (source.type === "object" && "properties" in source && !("additionalProperties" in source)) {
|
|
72
|
+
source.additionalProperties = false;
|
|
73
|
+
}
|
|
74
|
+
const out = {};
|
|
75
|
+
for (const key of KEY_ORDER) {
|
|
76
|
+
if (key in source)
|
|
77
|
+
out[key] = key === "properties" ? normaliseProperties(source[key]) : normalise(source[key]);
|
|
78
|
+
}
|
|
79
|
+
for (const [key, value] of Object.entries(source)) {
|
|
80
|
+
if (!KEY_ORDER.includes(key) && key !== "description" && key !== "$schema")
|
|
81
|
+
out[key] = normalise(value);
|
|
82
|
+
}
|
|
83
|
+
if ("description" in source)
|
|
84
|
+
out.description = normalise(source.description);
|
|
85
|
+
if ("$schema" in source)
|
|
86
|
+
out.$schema = normalise(source.$schema);
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
return (schema) => {
|
|
90
|
+
if (!isZodType(schema))
|
|
91
|
+
return {};
|
|
92
|
+
if (isEmptyObject(schema))
|
|
93
|
+
return EMPTY_INPUT_SCHEMA;
|
|
94
|
+
const raw = JSON.parse(JSON.stringify(toJSONSchema(schema, { target: "draft-7", io: "input" })));
|
|
95
|
+
const out = normalise(raw);
|
|
96
|
+
return isJsonObject(out) ? out : {};
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -2,22 +2,17 @@ export declare const LOOPBACK_PATH = "/callback";
|
|
|
2
2
|
export declare const LOOPBACK_TIMEOUT_MS: number;
|
|
3
3
|
/** The text of the pages the browser shows. Inserted as HTML, unescaped. */
|
|
4
4
|
export type LoopbackMessages = {
|
|
5
|
-
/** 400: the request does not carry the expected `state`. */
|
|
6
5
|
invalid: string;
|
|
7
|
-
/** 200: the redirect carried `error`, or no `code`. */
|
|
8
6
|
incomplete: string;
|
|
9
|
-
/** 200: the code was received. */
|
|
10
7
|
success: string;
|
|
11
8
|
};
|
|
12
9
|
export type LoopbackOptions = {
|
|
13
|
-
/** The page `<title>`. Default `"Sign in"`. */
|
|
14
10
|
title?: string;
|
|
15
11
|
messages?: Partial<LoopbackMessages>;
|
|
16
12
|
};
|
|
17
13
|
export type Loopback = {
|
|
18
14
|
/** The exact redirect_uri to register and send, for example http://127.0.0.1:51234/callback. */
|
|
19
15
|
redirectUrl: string;
|
|
20
|
-
/** Resolves with the authorisation code. `expectedState` is read when the request arrives, so it may be set later. */
|
|
21
16
|
waitForCode: (expectedState: () => string | undefined, timeoutMs?: number) => Promise<string>;
|
|
22
17
|
close: () => void;
|
|
23
18
|
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// The redirect target for sign-in: a one-shot HTTP server on 127.0.0.1 with a random port.
|
|
2
|
-
// Node only. `node:http` is imported when the server starts, never at module
|
|
3
|
-
// load, so the package root stays loadable in Convex's V8 runtime.
|
|
4
1
|
export const LOOPBACK_PATH = "/callback";
|
|
5
2
|
export const LOOPBACK_TIMEOUT_MS = 5 * 60_000;
|
|
6
3
|
const DEFAULT_TITLE = "Sign in";
|
|
@@ -28,7 +25,6 @@ export async function startLoopback(options = {}) {
|
|
|
28
25
|
const state = expected();
|
|
29
26
|
const error = url.searchParams.get("error");
|
|
30
27
|
const code = url.searchParams.get("code");
|
|
31
|
-
// A request without the state we sent is not our redirect: ignore it and keep waiting.
|
|
32
28
|
if (!state || url.searchParams.get("state") !== state) {
|
|
33
29
|
res.writeHead(400, html).end(page(messages.invalid));
|
|
34
30
|
return;
|
|
@@ -71,8 +67,6 @@ export async function startLoopback(options = {}) {
|
|
|
71
67
|
},
|
|
72
68
|
};
|
|
73
69
|
}
|
|
74
|
-
// The import sits directly in a try block: esbuild (Convex's bundler) and Metro
|
|
75
|
-
// then treat `node:http` as optional instead of failing a non-Node build.
|
|
76
70
|
async function loadNodeHttp() {
|
|
77
71
|
try {
|
|
78
72
|
return await import("node:http");
|
|
@@ -3,33 +3,20 @@ import type { FetchLike } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
|
3
3
|
import type { McpOAuthState } from "./state.js";
|
|
4
4
|
export type McpOAuthStorage = {
|
|
5
5
|
load: () => McpOAuthState | undefined;
|
|
6
|
-
/** undefined clears everything for the server. */
|
|
7
6
|
save: (state: McpOAuthState | undefined) => void;
|
|
8
7
|
};
|
|
9
8
|
export type McpOAuthProviderOptions = {
|
|
10
9
|
storage: McpOAuthStorage;
|
|
11
|
-
/** `client_name` sent with dynamic client registration. */
|
|
12
10
|
clientName: string;
|
|
13
|
-
/** `scope` sent with registration and, by `authorizeMcpServer` without `connectAs`, with the authorization request. Default: none. */
|
|
14
11
|
scope?: string;
|
|
15
|
-
/** Where the browser comes back to. Set only for the interactive sign-in: without it the provider never starts one. */
|
|
16
12
|
redirectUrl?: string;
|
|
17
|
-
/** Opens the authorization URL. Required with redirectUrl. */
|
|
18
13
|
redirectToAuthorization?: (url: URL) => void | Promise<void>;
|
|
19
|
-
/** Message of the UnauthorizedError thrown when a non-interactive provider would need a browser. */
|
|
20
14
|
signInRequiredMessage?: string;
|
|
21
|
-
/**
|
|
22
|
-
* When the provider can save a registered client.
|
|
23
|
-
* - `"interactive"` (default): only with redirectUrl and redirectToAuthorization, so a non-interactive 401 stops before any registration request.
|
|
24
|
-
* - `"always"`: also when not interactive, so the SDK never throws for want of somewhere to keep the result.
|
|
25
|
-
*/
|
|
26
15
|
clientRegistration?: "interactive" | "always";
|
|
27
|
-
/** Stamp `obtained_at` (from `now`) on saved tokens, for `isAccessTokenExpiring`. Default true. */
|
|
28
16
|
stampObtainedAt?: boolean;
|
|
29
17
|
now?: () => number;
|
|
30
18
|
};
|
|
31
19
|
export type McpOAuthProvider = OAuthClientProvider & {
|
|
32
|
-
/** The `state` sent with the latest authorization request, for the redirect handler to check. */
|
|
33
20
|
readonly pendingState: string | undefined;
|
|
34
21
|
};
|
|
35
22
|
/** True when tokens are stored, so the server counts as signed in. */
|
|
@@ -56,7 +43,6 @@ export type McpClientInfo = {
|
|
|
56
43
|
export declare function authorizeMcpServer(args: {
|
|
57
44
|
url: string;
|
|
58
45
|
provider: McpOAuthProvider;
|
|
59
|
-
/** The authorization code from the redirect. Created before the browser opens; it may reject (cancelled, timed out). */
|
|
60
46
|
code: Promise<string>;
|
|
61
47
|
fetch?: FetchLike;
|
|
62
48
|
connectAs?: McpClientInfo;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { randomToken } from "../crypto/random.js";
|
|
2
|
-
// MCP authorization (OAuth 2.1 with PKCE and dynamic client registration) for desktop apps. No Electron imports:
|
|
3
|
-
// the app supplies the storage, the redirect and the browser.
|
|
4
|
-
// The SDK is an optional peer, imported on first use and never at module load, so the package root stays loadable
|
|
5
|
-
// in Convex's V8 runtime without it. Each import() is awaited directly in a try block (not inside Promise.all):
|
|
6
|
-
// esbuild (Convex, Electron main) and Metro then treat a missing SDK as optional, and still bundle it when it is
|
|
7
|
-
// installed. tests-node/bundle.mjs checks this with Convex's esbuild.
|
|
8
2
|
const SDK_MISSING = "The MCP client OAuth helpers need the @modelcontextprotocol/sdk package";
|
|
9
3
|
async function loadSdkAuth() {
|
|
10
4
|
try {
|
|
@@ -24,7 +18,6 @@ async function loadSdkClient() {
|
|
|
24
18
|
throw new Error(SDK_MISSING, { cause: error });
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
|
-
// The SDK reads "no redirect URL" as a client-credentials flow, so a provider that only refreshes still needs one. It is never sent anywhere.
|
|
28
21
|
const REFRESH_ONLY_REDIRECT = "http://127.0.0.1/callback";
|
|
29
22
|
const DEFAULT_SIGN_IN_REQUIRED = "Sign-in required";
|
|
30
23
|
/** True when tokens are stored, so the server counts as signed in. */
|
|
@@ -78,7 +71,6 @@ export function createMcpOAuthProvider(options) {
|
|
|
78
71
|
},
|
|
79
72
|
clientInformation() {
|
|
80
73
|
const saved = storage.load()?.clientInformation;
|
|
81
|
-
// The loopback port changes on every sign-in, so a client registered for another redirect cannot be reused.
|
|
82
74
|
if (interactive && redirectUrl && saved?.redirect_uris && !saved.redirect_uris.includes(redirectUrl))
|
|
83
75
|
return undefined;
|
|
84
76
|
return saved;
|
|
@@ -98,8 +90,6 @@ export function createMcpOAuthProvider(options) {
|
|
|
98
90
|
return verifier;
|
|
99
91
|
},
|
|
100
92
|
redirectToAuthorization(url) {
|
|
101
|
-
// Rejects rather than throws: the SDK's UnauthorizedError class is only reachable once the SDK is loaded.
|
|
102
|
-
// The SDK awaits this call, so its flows see the same error either way.
|
|
103
93
|
if (!interactive || !redirectToAuthorization) {
|
|
104
94
|
return loadSdkAuth().then(({ UnauthorizedError }) => {
|
|
105
95
|
throw new UnauthorizedError(signInRequiredMessage);
|
|
@@ -118,7 +108,6 @@ export function createMcpOAuthProvider(options) {
|
|
|
118
108
|
verifier = undefined;
|
|
119
109
|
},
|
|
120
110
|
};
|
|
121
|
-
// Without this the SDK cannot register a client, so a 401 stops before any registration request.
|
|
122
111
|
if (interactive || options.clientRegistration === "always") {
|
|
123
112
|
provider.saveClientInformation = (info) => {
|
|
124
113
|
const registered = "redirect_uris" in info ? info.redirect_uris : undefined;
|
|
@@ -135,7 +124,6 @@ export function createMcpOAuthProvider(options) {
|
|
|
135
124
|
* same discovery (resource metadata from WWW-Authenticate or the well-known URL), then `code` is exchanged by `finishAuth`.
|
|
136
125
|
*/
|
|
137
126
|
export async function authorizeMcpServer(args) {
|
|
138
|
-
// A rejection that arrives before we await it must not surface as unhandled.
|
|
139
127
|
args.code.catch(() => undefined);
|
|
140
128
|
if (args.connectAs)
|
|
141
129
|
return connectThenAuthorize({ ...args, connectAs: args.connectAs });
|
|
@@ -180,7 +168,6 @@ export async function refreshMcpOAuth(args) {
|
|
|
180
168
|
return false;
|
|
181
169
|
}
|
|
182
170
|
}
|
|
183
|
-
// Sign out waits for this at most: a slow authorization server must not hold it up.
|
|
184
171
|
const REVOKE_TIMEOUT_MS = 3000;
|
|
185
172
|
/**
|
|
186
173
|
* Best-effort token revocation (RFC 7009) before the local tokens are cleared. Only when the authorization server advertises a
|
|
@@ -195,12 +182,10 @@ export async function revokeMcpOAuth(args) {
|
|
|
195
182
|
const fetchFn = (input, init) => (args.fetch ?? fetch)(input, { ...init, signal });
|
|
196
183
|
try {
|
|
197
184
|
const { discoverAuthorizationServerMetadata, discoverOAuthServerInfo } = await loadSdkAuth();
|
|
198
|
-
// The stored issuer is the server the tokens came from; without one, discover it from the MCP server.
|
|
199
185
|
const issuer = tokens.issuer ?? clientInformation?.issuer;
|
|
200
186
|
const metadata = issuer
|
|
201
187
|
? await discoverAuthorizationServerMetadata(issuer, { fetchFn })
|
|
202
188
|
: (await discoverOAuthServerInfo(args.url, { fetchFn })).authorizationServerMetadata;
|
|
203
|
-
// The OpenID metadata type has no field for it, though a server may send one.
|
|
204
189
|
const endpoint = metadata && "revocation_endpoint" in metadata && typeof metadata.revocation_endpoint === "string"
|
|
205
190
|
? metadata.revocation_endpoint
|
|
206
191
|
: undefined;
|
|
@@ -219,7 +204,6 @@ export async function revokeMcpOAuth(args) {
|
|
|
219
204
|
});
|
|
220
205
|
return response.ok;
|
|
221
206
|
};
|
|
222
|
-
// The refresh token first: revoking it may also end the access token, and it is the longer-lived one.
|
|
223
207
|
const outcomes = await Promise.all([...(tokens.refresh_token ? [revoke(tokens.refresh_token, "refresh_token")] : []), revoke(tokens.access_token, "access_token")].map((work) => work.catch(() => false)));
|
|
224
208
|
return outcomes.some(Boolean);
|
|
225
209
|
}
|
|
@@ -6,9 +6,7 @@ export type McpOAuthTokens = {
|
|
|
6
6
|
expires_in?: number;
|
|
7
7
|
scope?: string;
|
|
8
8
|
id_token?: string;
|
|
9
|
-
/** Stamped by the SDK: the authorization server these tokens came from. */
|
|
10
9
|
issuer?: string;
|
|
11
|
-
/** Stamped by the provider when the tokens are saved (`stampObtainedAt`), because `expires_in` is relative. */
|
|
12
10
|
obtained_at?: number;
|
|
13
11
|
[key: string]: unknown;
|
|
14
12
|
};
|
|
@@ -16,7 +14,6 @@ export type McpOAuthClientInformation = {
|
|
|
16
14
|
client_id: string;
|
|
17
15
|
client_secret?: string;
|
|
18
16
|
redirect_uris?: string[];
|
|
19
|
-
/** Stamped by the SDK: the authorization server this client was registered with. */
|
|
20
17
|
issuer?: string;
|
|
21
18
|
[key: string]: unknown;
|
|
22
19
|
};
|
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
import { type JsonInput, type JsonValue } from "../mcp/json.js";
|
|
2
2
|
export type SandboxTool = {
|
|
3
3
|
readonly name: string;
|
|
4
|
-
/** true for tools that change state; counted against `maxMutatingCalls`. */
|
|
5
4
|
readonly mutating: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Receives the JSON text of the single argument object and resolves to the
|
|
8
|
-
* JSON text of the result. A rejection's message is what the script sees.
|
|
9
|
-
*/
|
|
10
5
|
readonly invoke: (argsJson: string) => Promise<string>;
|
|
11
6
|
};
|
|
12
7
|
export type ExecuteLimits = {
|
|
13
|
-
/** Wall clock for the whole execution, including time spent in tools. */
|
|
14
8
|
readonly deadlineMs: number;
|
|
15
|
-
/** QuickJS heap cap. */
|
|
16
9
|
readonly memoryBytes: number;
|
|
17
|
-
/** QuickJS stack cap. */
|
|
18
10
|
readonly stackBytes: number;
|
|
19
|
-
/** Total tool calls per execution. */
|
|
20
11
|
readonly maxCalls: number;
|
|
21
|
-
/** Subset cap for tools that change state. */
|
|
22
12
|
readonly maxMutatingCalls: number;
|
|
23
|
-
/** `console` lines kept; the rest are counted in one closing line. */
|
|
24
13
|
readonly maxLogLines: number;
|
|
25
|
-
/** Characters kept per `console` line. */
|
|
26
14
|
readonly maxLogLineChars: number;
|
|
27
15
|
};
|
|
28
16
|
export declare const DEFAULT_EXECUTE_LIMITS: ExecuteLimits;
|
|
@@ -30,7 +18,6 @@ export type SandboxCallRecord = {
|
|
|
30
18
|
readonly name: string;
|
|
31
19
|
readonly ms: number;
|
|
32
20
|
readonly ok: boolean;
|
|
33
|
-
/** Set when `onCall` returned a stub, so the tool never ran. */
|
|
34
21
|
readonly skipped?: true;
|
|
35
22
|
};
|
|
36
23
|
type ExecuteTelemetry = {
|
|
@@ -66,9 +53,7 @@ export type SandboxCallDecision = {
|
|
|
66
53
|
readonly stub: JsonInput;
|
|
67
54
|
};
|
|
68
55
|
export type SandboxOptions = {
|
|
69
|
-
/** JSON-serialisable values set as VM globals before the script runs, for example `{ args }`. */
|
|
70
56
|
readonly globals?: Readonly<Record<string, JsonInput>>;
|
|
71
|
-
/** Called before each tool call. A throw or rejection refuses the call with its message. */
|
|
72
57
|
readonly onCall?: (call: SandboxCall) => SandboxCallDecision | Promise<SandboxCallDecision>;
|
|
73
58
|
};
|
|
74
59
|
/**
|
package/dist/sandbox/runtime.js
CHANGED
|
@@ -10,11 +10,6 @@ export const DEFAULT_EXECUTE_LIMITS = {
|
|
|
10
10
|
};
|
|
11
11
|
const QUICKJS_MISSING = "The code sandbox needs the quickjs-emscripten-core and @jitl/quickjs-singlefile-cjs-release-sync packages, in a Node runtime";
|
|
12
12
|
let modulePromise;
|
|
13
|
-
// QuickJS is an optional peer, imported on first use and never at module load, so the package root stays loadable
|
|
14
|
-
// without it and V8 bundles of the root carry no WASM. Each import() is awaited directly in a try block, as in
|
|
15
|
-
// mcp-oauth-client/oauth.ts. The "browser" field in package.json maps both packages to empty modules for browser-platform
|
|
16
|
-
// bundles (Convex V8), whose bundler would otherwise follow the import into the variant's Node built-ins.
|
|
17
|
-
// tests-node/bundle.mjs checks both.
|
|
18
13
|
async function importQuickJs() {
|
|
19
14
|
try {
|
|
20
15
|
const core = await import("quickjs-emscripten-core");
|
|
@@ -29,10 +24,8 @@ async function importQuickJs() {
|
|
|
29
24
|
}
|
|
30
25
|
async function importModule() {
|
|
31
26
|
const { core, variant } = await importQuickJs();
|
|
32
|
-
// The variant is CommonJS: Node and bundlers nest its default export differently, which the core unwraps.
|
|
33
27
|
return core.newQuickJSWASMModuleFromVariant(Promise.resolve(variant));
|
|
34
28
|
}
|
|
35
|
-
/** Loads the WASM module once per process; a failed load is retried next call. */
|
|
36
29
|
function loadModule() {
|
|
37
30
|
if (modulePromise === undefined) {
|
|
38
31
|
modulePromise = importModule().catch((err) => {
|
|
@@ -42,13 +35,6 @@ function loadModule() {
|
|
|
42
35
|
}
|
|
43
36
|
return modulePromise;
|
|
44
37
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Globals the script sees. `tools` is a lazy proxy so any name routes to the
|
|
47
|
-
* host without the catalog living inside the VM; `search` is an ordinary tool
|
|
48
|
-
* the host supplies. `console` hands lines to the host instead of printing.
|
|
49
|
-
* Host `globals` arrive as JSON text and may not replace anything already
|
|
50
|
-
* global.
|
|
51
|
-
*/
|
|
52
38
|
const PRELUDE = `
|
|
53
39
|
for (const [name, value] of Object.entries(JSON.parse(globalThis.__globals))) {
|
|
54
40
|
if (name in globalThis || name === "tools" || name === "console" || name.startsWith("__")) {
|
|
@@ -102,7 +88,6 @@ ${code}
|
|
|
102
88
|
return json;
|
|
103
89
|
});`;
|
|
104
90
|
}
|
|
105
|
-
/** Turns a value dumped out of the VM (usually a thrown Error) into one line. */
|
|
106
91
|
function describeThrown(dumped) {
|
|
107
92
|
if (isJsonObject(dumped) && typeof dumped.message === "string") {
|
|
108
93
|
return typeof dumped.name === "string" && dumped.name !== "" ? `${dumped.name}: ${dumped.message}` : dumped.message;
|
|
@@ -126,7 +111,6 @@ export async function runSandboxedScript(code, tools, limitOverrides = {}, optio
|
|
|
126
111
|
const startedAt = Date.now();
|
|
127
112
|
const deadline = startedAt + limits.deadlineMs;
|
|
128
113
|
const calls = [];
|
|
129
|
-
// Collected on the host as they are written, so a failed run still returns them.
|
|
130
114
|
const logs = [];
|
|
131
115
|
let droppedLogs = 0;
|
|
132
116
|
const finish = (result) => {
|
|
@@ -151,10 +135,7 @@ export async function runSandboxedScript(code, tools, limitOverrides = {}, optio
|
|
|
151
135
|
const pending = new Set();
|
|
152
136
|
let totalCalls = 0;
|
|
153
137
|
let mutatingCalls = 0;
|
|
154
|
-
// Host handlers can settle after this function has returned (a deadline hit
|
|
155
|
-
// while a slow tool is still running). Touching the vm then aborts the process.
|
|
156
138
|
let alive = true;
|
|
157
|
-
/** Asks `onCall`, then runs the tool unless it refused or stubbed the call. */
|
|
158
139
|
const callTool = async (tool, argsJson) => {
|
|
159
140
|
if (options.onCall !== undefined) {
|
|
160
141
|
const args = JSON.parse(argsJson);
|
|
@@ -197,7 +178,6 @@ export async function runSandboxedScript(code, tools, limitOverrides = {}, optio
|
|
|
197
178
|
rejectWith(`Mutating tool call limit (${limits.maxMutatingCalls}) reached`);
|
|
198
179
|
return deferred.handle;
|
|
199
180
|
}
|
|
200
|
-
// Counted before onCall, so refused and stubbed calls use up the caps like real ones.
|
|
201
181
|
totalCalls += 1;
|
|
202
182
|
if (tool.mutating)
|
|
203
183
|
mutatingCalls += 1;
|
|
@@ -226,10 +206,6 @@ export async function runSandboxedScript(code, tools, limitOverrides = {}, optio
|
|
|
226
206
|
}
|
|
227
207
|
const promise = evaluated.value;
|
|
228
208
|
try {
|
|
229
|
-
// Drive the VM: run microtasks, then either finish, wait for the next
|
|
230
|
-
// host tool to settle, or give up at the deadline. Jobs are pumped before
|
|
231
|
-
// the deadline check so an interrupt or OOM thrown inside the script
|
|
232
|
-
// surfaces as its own message rather than the generic deadline one.
|
|
233
209
|
for (;;) {
|
|
234
210
|
const jobs = runtime.executePendingJobs();
|
|
235
211
|
if (jobs.error) {
|
|
@@ -249,7 +225,6 @@ export async function runSandboxedScript(code, tools, limitOverrides = {}, optio
|
|
|
249
225
|
state.error.dispose();
|
|
250
226
|
return fail(message);
|
|
251
227
|
}
|
|
252
|
-
// Pending: `state.error` is a plain host Error here, not a handle.
|
|
253
228
|
if (Date.now() > deadline) {
|
|
254
229
|
return fail(`Execution exceeded ${limits.deadlineMs}ms`);
|
|
255
230
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type SkillRef } from "./skillRef.js";
|
|
2
|
+
export type GithubFetch = (url: string) => Promise<Response>;
|
|
3
|
+
export declare const SKILL_MAX_FILES = 100;
|
|
4
|
+
export declare const SKILL_MAX_TEXT_BYTES: number;
|
|
5
|
+
export declare const SKILL_MAX_BINARY_BYTES: number;
|
|
6
|
+
export declare const SKILL_MAX_TOTAL_BYTES: number;
|
|
7
|
+
export declare const SKILL_CHOOSER_MAX = 25;
|
|
8
|
+
export interface GithubTreeFile {
|
|
9
|
+
path: string;
|
|
10
|
+
sha: string;
|
|
11
|
+
size: number;
|
|
12
|
+
}
|
|
13
|
+
export interface GithubSkillRepo {
|
|
14
|
+
owner: string;
|
|
15
|
+
repo: string;
|
|
16
|
+
ref: string;
|
|
17
|
+
explicitRef: boolean;
|
|
18
|
+
commitSha: string;
|
|
19
|
+
files: GithubTreeFile[];
|
|
20
|
+
}
|
|
21
|
+
export interface SkillCandidate {
|
|
22
|
+
name: string;
|
|
23
|
+
path: string;
|
|
24
|
+
description: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SkillBundleFile {
|
|
27
|
+
path: string;
|
|
28
|
+
kind: "text" | "binary";
|
|
29
|
+
text?: string;
|
|
30
|
+
base64?: string;
|
|
31
|
+
size: number;
|
|
32
|
+
}
|
|
33
|
+
export interface SkillBundle {
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
path: string;
|
|
37
|
+
instructions: string;
|
|
38
|
+
contentHash: string;
|
|
39
|
+
files: SkillBundleFile[];
|
|
40
|
+
skipped: string[];
|
|
41
|
+
}
|
|
42
|
+
export declare class GithubSkillError extends Error {
|
|
43
|
+
}
|
|
44
|
+
export declare function resolveGithubSkillRepo(gh: GithubFetch, skillRef: SkillRef): Promise<GithubSkillRepo>;
|
|
45
|
+
export declare function findSkillFolders(repo: GithubSkillRepo, skillRef: SkillRef): string[];
|
|
46
|
+
export declare function readSkillCandidate(gh: GithubFetch, repo: GithubSkillRepo, folder: string): Promise<SkillCandidate & {
|
|
47
|
+
text: string;
|
|
48
|
+
}>;
|
|
49
|
+
export declare function listSkillCandidates(gh: GithubFetch, repo: GithubSkillRepo, folders: string[]): Promise<SkillCandidate[]>;
|
|
50
|
+
export declare function readSkillBundle(gh: GithubFetch, repo: GithubSkillRepo, folder: string): Promise<SkillBundle>;
|
|
51
|
+
export declare function fetchSkillContentHash(gh: GithubFetch, repo: GithubSkillRepo, folder: string): Promise<string | null>;
|