@vitemcp/server 1.9.7 → 1.9.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.
- package/README.md +15 -3
- package/dist/{OAuthProvider-BaPwgWny.d.cts → OAuthProvider-Dt3F-oDh.d.cts} +54 -0
- package/dist/{OAuthProvider-BaPwgWny.d.ts → OAuthProvider-Dt3F-oDh.d.ts} +54 -0
- package/dist/ViteMCP.cjs +4 -4
- package/dist/ViteMCP.d.cts +3 -3
- package/dist/ViteMCP.d.ts +3 -3
- package/dist/ViteMCP.js +3 -3
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +10 -2
- package/dist/auth/index.d.ts +10 -2
- package/dist/auth/index.js +1 -1
- package/dist/bin/vitemcp.cjs +7 -1
- package/dist/bin/vitemcp.cjs.map +1 -1
- package/dist/bin/vitemcp.js +7 -1
- package/dist/bin/vitemcp.js.map +1 -1
- package/dist/{chunk-R7AFGJBR.cjs → chunk-2FAJF3V6.cjs} +146 -48
- package/dist/chunk-2FAJF3V6.cjs.map +1 -0
- package/dist/{chunk-ZVA6Y7EO.cjs → chunk-DURXYPPR.cjs} +4 -2
- package/dist/chunk-DURXYPPR.cjs.map +1 -0
- package/dist/{chunk-NSHLX6PZ.cjs → chunk-PNWCRGJY.cjs} +215 -48
- package/dist/chunk-PNWCRGJY.cjs.map +1 -0
- package/dist/{chunk-XQI4HYU6.js → chunk-TYR2KJIV.js} +4 -2
- package/dist/{chunk-XQI4HYU6.js.map → chunk-TYR2KJIV.js.map} +1 -1
- package/dist/{chunk-FAONEXUK.js → chunk-UVKIOOZA.js} +118 -20
- package/dist/chunk-UVKIOOZA.js.map +1 -0
- package/dist/{chunk-WXZQZWBE.js → chunk-ZVK5GKEO.js} +215 -48
- package/dist/chunk-ZVK5GKEO.js.map +1 -0
- package/dist/edge/index.cjs +5 -5
- package/dist/edge/index.js +1 -1
- package/dist/openapi/index.cjs +13 -13
- package/dist/openapi/index.d.cts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-FAONEXUK.js.map +0 -1
- package/dist/chunk-NSHLX6PZ.cjs.map +0 -1
- package/dist/chunk-R7AFGJBR.cjs.map +0 -1
- package/dist/chunk-WXZQZWBE.js.map +0 -1
- package/dist/chunk-ZVA6Y7EO.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/formatBytes.ts","../src/ownKeysOnly.ts","../src/toSdkSchema.ts"],"sourcesContent":["/** Renders a byte cap the way the error message should read (e.g. \"1 MiB\"). */\nexport const formatBytes = (bytes: number): string => {\n if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {\n return `${bytes / (1024 * 1024)} MiB`;\n }\n\n if (bytes >= 1024 && bytes % 1024 === 0) {\n return `${bytes / 1024} KiB`;\n }\n\n return `${bytes} bytes`;\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Has `schema` validate by own keys only — see `withOwnKeysOnly` — by\n * replacing its `~standard` in place. The schema keeps its `shape`, which the\n * SDK reads to complete an argument, and its JSON Schema, which `prompts/list`\n * is built from.\n *\n * For the argument schemas `ViteMCP` and `EdgeViteMCP` build for their\n * prompts. A tool's schemas belong to whoever wrote the tool, so\n * `toSdkSchema` wraps them instead.\n *\n * An argument map the request left out validates as an empty one, as the SDK\n * already arranges for a tool's. `prompts/get` may omit `arguments`, and the\n * SDK validates the map as it was sent, so a prompt whose arguments are all\n * optional refused the request as \"expected object, received undefined\".\n */\nexport const ownKeysOnly = <S extends StandardSchemaV1>(schema: S): S => {\n const standard = withOwnKeysOnly(schema[\"~standard\"]);\n\n return Object.defineProperty(schema, \"~standard\", {\n value: {\n ...standard,\n validate: (value: unknown) => standard.validate(value ?? {}),\n },\n });\n};\n\n/**\n * `standard`, with a `validate` that sees only the keys an object has of its\n * own.\n *\n * Zod and Valibot look each key up with `in` and read it with `[]`, and both\n * walk the prototype chain, so a key that was left out reads as present when\n * `Object.prototype` has a member by that name. An optional argument called\n * `toString`, `constructor` or `valueOf`, at any depth, failed every request\n * that left it out, as \"expected string, received function\", and a required\n * one was reported as the wrong type instead of as missing. Validating a copy\n * whose objects have no prototype leaves the library nothing to inherit.\n *\n * A library that hands its input back, as ArkType and `jsonSchemaAdapter` do,\n * hands back the copy, so the copied objects get their prototype back before\n * the value goes on: `execute` still receives ordinary objects.\n */\nexport const withOwnKeysOnly = <P extends StandardSchemaV1.Props>(\n standard: P,\n): P => ({\n ...standard,\n validate: async (value: unknown) => {\n const copies = new Map<object, object>();\n const result = await standard.validate(withoutPrototypes(value, copies));\n\n if (!result.issues && copies.size > 0) {\n restorePrototypes(result.value, new Set(copies.values()), new Set());\n }\n\n return result;\n },\n});\n\n/**\n * `value`, with each plain object in it, at any depth, copied onto one without\n * a prototype, and each array copied to reach them. `copies` maps every\n * original to its copy, so one that occurs twice, or inside itself, is copied\n * once.\n */\nconst withoutPrototypes = (\n value: unknown,\n copies: Map<object, object>,\n): unknown => {\n if (!isPlain(value)) {\n return value;\n }\n\n const existing = copies.get(value);\n\n if (existing) {\n return existing;\n }\n\n const copy: Record<string, unknown> = Array.isArray(value)\n ? []\n : Object.create(null);\n\n copies.set(value, copy);\n\n for (const [key, item] of Object.entries(value)) {\n copy[key] = withoutPrototypes(item, copies);\n }\n\n return copy;\n};\n\n/**\n * Gives each object copy in `copies` that `value` holds, at any depth,\n * `Object.prototype` back.\n */\nconst restorePrototypes = (\n value: unknown,\n copies: Set<object>,\n seen: Set<object>,\n): void => {\n if (!isPlain(value) || seen.has(value)) {\n return;\n }\n\n seen.add(value);\n\n if (copies.has(value) && !Array.isArray(value)) {\n Object.setPrototypeOf(value, Object.prototype);\n }\n\n for (const item of Object.values(value)) {\n restorePrototypes(item, copies, seen);\n }\n};\n\n/**\n * An array, or an object made by a literal or without a prototype: what JSON\n * parses to, and the only kinds of object that are copied.\n */\nconst isPlain = (value: unknown): value is Record<string, unknown> => {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const prototype: unknown = Object.getPrototypeOf(value);\n\n return (\n Array.isArray(value) || prototype === Object.prototype || prototype === null\n );\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema } from \"xsschema\";\n\nimport { withOwnKeysOnly } from \"./ownKeysOnly.js\";\n\n/**\n * Turns a Standard Schema that carries no JSON Schema into one. Which\n * libraries that can be done for depends on the runtime, so each entry point\n * supplies its own.\n */\nexport type JsonSchemaConverter = (\n schema: StandardSchemaV1,\n io: \"input\" | \"output\",\n) => Promise<JsonSchema>;\n\n/**\n * A tool's schema as the SDK registers it: one that validates by own keys only\n * (see `withOwnKeysOnly`) and carries a JSON Schema. The schema itself is left\n * as it was, since whoever wrote it may use it elsewhere.\n *\n * Zod v4 and ArkType emit JSON Schema natively, and theirs is kept; anything\n * else (Valibot, say) is converted, and the conversion is only what\n * `tools/list` advertises. Validation stays with the library the schema was\n * written in: the conversion drops what JSON Schema cannot say — a transform,\n * a `check()` — so validating against it instead would pass `execute`\n * arguments the schema never produced.\n *\n * Advertised inputs are closed with `strictInputSchema`. Outputs are left as\n * converted, since closing them would misdescribe results the schema allows.\n *\n * Shared by `ViteMCP` and `EdgeViteMCP`, so what a tool advertises does not\n * depend on which of them serves it. Rejects when `convert` does.\n */\nexport const toSdkSchema = async (\n schema: unknown,\n io: \"input\" | \"output\",\n convert: JsonSchemaConverter,\n): Promise<unknown> => {\n if (!schema) {\n return undefined;\n }\n\n const standard = withOwnKeysOnly(\n (\n schema as {\n \"~standard\": { jsonSchema?: unknown } & StandardSchemaV1.Props;\n }\n )[\"~standard\"],\n );\n\n if (standard.jsonSchema) {\n return { \"~standard\": standard };\n }\n\n const json = await convert(schema as StandardSchemaV1, io);\n const advertised = io === \"input\" ? strictInputSchema(json) : json;\n\n return {\n \"~standard\": {\n ...standard,\n jsonSchema: { input: () => advertised, output: () => advertised },\n },\n };\n};\n\n/**\n * JSON Schema for a Valibot schema, for advertising.\n *\n * Valibot's converter is called directly so it can be told to skip what JSON\n * Schema cannot express — a transform, a `check()` — rather than refuse the\n * whole schema. Valibot still validates, so the copy only has to describe what\n * a caller sends (`typeMode: \"input\"`, which stops at the first transform) or\n * receives (`\"output\"`).\n *\n * The `import()` has to stay inside the `try`. An edge bundle is built with\n * every import resolved ahead of time, and a bundler fails the build over one\n * it cannot resolve — unless it can see the failure is handled, in which case\n * a server that never touches Valibot builds without the converter installed.\n */\nexport const valibotToJsonSchema: JsonSchemaConverter = async (schema, io) => {\n let converter;\n\n try {\n converter = await import(\"@valibot/to-json-schema\");\n } catch {\n throw new Error(\n 'The \"@valibot/to-json-schema\" package is required to describe Valibot ' +\n \"schemas. Install it with: npm install @valibot/to-json-schema\",\n );\n }\n\n return converter.toJsonSchema(schema as never, {\n errorMode: \"ignore\",\n typeMode: io,\n }) as JsonSchema;\n};\n\n/**\n * Closes an advertised input schema's objects to undeclared keys, except where\n * the schema describes those keys itself. A record's value schema, or an\n * object's rest schema, arrives as `additionalProperties`; replacing it with\n * `false` would tell clients the tool takes none of those keys, so a\n * `v.record()` argument could only ever be sent as `{}`.\n */\nconst strictInputSchema = (schema: JsonSchema): JsonSchema => ({\n ...schema,\n additionalProperties:\n typeof schema.additionalProperties === \"object\"\n ? schema.additionalProperties\n : false,\n ...(schema.properties && {\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => [\n key,\n typeof value === \"object\" && value.type === \"object\"\n ? strictInputSchema(value)\n : value,\n ]),\n ),\n }),\n});\n"],"mappings":";AACO,IAAM,cAAc,CAAC,UAA0B;AACpD,MAAI,SAAS,OAAO,QAAQ,SAAS,OAAO,UAAU,GAAG;AACvD,WAAO,GAAG,SAAS,OAAO,KAAK;AAAA,EACjC;AAEA,MAAI,SAAS,QAAQ,QAAQ,SAAS,GAAG;AACvC,WAAO,GAAG,QAAQ,IAAI;AAAA,EACxB;AAEA,SAAO,GAAG,KAAK;AACjB;;;ACMO,IAAM,cAA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,CAAC,KAAK,KAAK,MAAM;AAAA,QACtD;AAAA,QACA,OAAO,UAAU,YAAY,MAAM,SAAS,WACxC,kBAAkB,KAAK,IACvB;AAAA,MACN,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/formatBytes.ts","../src/ownKeysOnly.ts","../src/toSdkSchema.ts"],"sourcesContent":["/** Renders a byte cap the way the error message should read (e.g. \"1 MiB\"). */\nexport const formatBytes = (bytes: number): string => {\n if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {\n return `${bytes / (1024 * 1024)} MiB`;\n }\n\n if (bytes >= 1024 && bytes % 1024 === 0) {\n return `${bytes / 1024} KiB`;\n }\n\n return `${bytes} bytes`;\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Has `schema` validate by own keys only — see `withOwnKeysOnly` — by\n * replacing its `~standard` in place. The schema keeps its `shape`, which the\n * SDK reads to complete an argument, and its JSON Schema, which `prompts/list`\n * is built from.\n *\n * For the argument schemas `ViteMCP` and `EdgeViteMCP` build for their\n * prompts. A tool's schemas belong to whoever wrote the tool, so\n * `toSdkSchema` wraps them instead.\n *\n * An argument map the request left out validates as an empty one, as the SDK\n * already arranges for a tool's. `prompts/get` may omit `arguments`, and the\n * SDK validates the map as it was sent, so a prompt whose arguments are all\n * optional refused the request as \"expected object, received undefined\".\n */\nexport const ownKeysOnly = <S extends StandardSchemaV1>(schema: S): S => {\n const standard = withOwnKeysOnly(schema[\"~standard\"]);\n\n return Object.defineProperty(schema, \"~standard\", {\n value: {\n ...standard,\n validate: (value: unknown) => standard.validate(value ?? {}),\n },\n });\n};\n\n/**\n * `standard`, with a `validate` that sees only the keys an object has of its\n * own.\n *\n * Zod and Valibot look each key up with `in` and read it with `[]`, and both\n * walk the prototype chain, so a key that was left out reads as present when\n * `Object.prototype` has a member by that name. An optional argument called\n * `toString`, `constructor` or `valueOf`, at any depth, failed every request\n * that left it out, as \"expected string, received function\", and a required\n * one was reported as the wrong type instead of as missing. Validating a copy\n * whose objects have no prototype leaves the library nothing to inherit.\n *\n * A library that hands its input back, as ArkType and `jsonSchemaAdapter` do,\n * hands back the copy, so the copied objects get their prototype back before\n * the value goes on: `execute` still receives ordinary objects.\n */\nexport const withOwnKeysOnly = <P extends StandardSchemaV1.Props>(\n standard: P,\n): P => ({\n ...standard,\n validate: async (value: unknown) => {\n const copies = new Map<object, object>();\n const result = await standard.validate(withoutPrototypes(value, copies));\n\n if (!result.issues && copies.size > 0) {\n restorePrototypes(result.value, new Set(copies.values()), new Set());\n }\n\n return result;\n },\n});\n\n/**\n * `value`, with each plain object in it, at any depth, copied onto one without\n * a prototype, and each array copied to reach them. `copies` maps every\n * original to its copy, so one that occurs twice, or inside itself, is copied\n * once.\n */\nconst withoutPrototypes = (\n value: unknown,\n copies: Map<object, object>,\n): unknown => {\n if (!isPlain(value)) {\n return value;\n }\n\n const existing = copies.get(value);\n\n if (existing) {\n return existing;\n }\n\n const copy: Record<string, unknown> = Array.isArray(value)\n ? []\n : Object.create(null);\n\n copies.set(value, copy);\n\n for (const [key, item] of Object.entries(value)) {\n copy[key] = withoutPrototypes(item, copies);\n }\n\n return copy;\n};\n\n/**\n * Gives each object copy in `copies` that `value` holds, at any depth,\n * `Object.prototype` back.\n */\nconst restorePrototypes = (\n value: unknown,\n copies: Set<object>,\n seen: Set<object>,\n): void => {\n if (!isPlain(value) || seen.has(value)) {\n return;\n }\n\n seen.add(value);\n\n if (copies.has(value) && !Array.isArray(value)) {\n Object.setPrototypeOf(value, Object.prototype);\n }\n\n for (const item of Object.values(value)) {\n restorePrototypes(item, copies, seen);\n }\n};\n\n/**\n * An array, or an object made by a literal or without a prototype: what JSON\n * parses to, and the only kinds of object that are copied.\n */\nconst isPlain = (value: unknown): value is Record<string, unknown> => {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const prototype: unknown = Object.getPrototypeOf(value);\n\n return (\n Array.isArray(value) || prototype === Object.prototype || prototype === null\n );\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema } from \"xsschema\";\n\nimport { withOwnKeysOnly } from \"./ownKeysOnly.js\";\n\n/**\n * Turns a Standard Schema that carries no JSON Schema into one. Which\n * libraries that can be done for depends on the runtime, so each entry point\n * supplies its own.\n */\nexport type JsonSchemaConverter = (\n schema: StandardSchemaV1,\n io: \"input\" | \"output\",\n) => Promise<JsonSchema>;\n\n/**\n * A tool's schema as the SDK registers it: one that validates by own keys only\n * (see `withOwnKeysOnly`) and carries a JSON Schema. The schema itself is left\n * as it was, since whoever wrote it may use it elsewhere.\n *\n * Zod v4 and ArkType emit JSON Schema natively, and theirs is kept; anything\n * else (Valibot, say) is converted, and the conversion is only what\n * `tools/list` advertises. Validation stays with the library the schema was\n * written in: the conversion drops what JSON Schema cannot say — a transform,\n * a `check()` — so validating against it instead would pass `execute`\n * arguments the schema never produced.\n *\n * Advertised inputs are closed with `strictInputSchema`. Outputs are left as\n * converted, since closing them would misdescribe results the schema allows.\n *\n * Shared by `ViteMCP` and `EdgeViteMCP`, so what a tool advertises does not\n * depend on which of them serves it. Rejects when `convert` does.\n */\nexport const toSdkSchema = async (\n schema: unknown,\n io: \"input\" | \"output\",\n convert: JsonSchemaConverter,\n): Promise<unknown> => {\n if (!schema) {\n return undefined;\n }\n\n const standard = withOwnKeysOnly(\n (\n schema as {\n \"~standard\": { jsonSchema?: unknown } & StandardSchemaV1.Props;\n }\n )[\"~standard\"],\n );\n\n if (standard.jsonSchema) {\n return { \"~standard\": standard };\n }\n\n const json = await convert(schema as StandardSchemaV1, io);\n const advertised = io === \"input\" ? strictInputSchema(json) : json;\n\n return {\n \"~standard\": {\n ...standard,\n jsonSchema: { input: () => advertised, output: () => advertised },\n },\n };\n};\n\n/**\n * JSON Schema for a Valibot schema, for advertising.\n *\n * Valibot's converter is called directly so it can be told to skip what JSON\n * Schema cannot express — a transform, a `check()` — rather than refuse the\n * whole schema. Valibot still validates, so the copy only has to describe what\n * a caller sends (`typeMode: \"input\"`, which stops at the first transform) or\n * receives (`\"output\"`).\n *\n * The `import()` has to stay inside the `try`. An edge bundle is built with\n * every import resolved ahead of time, and a bundler fails the build over one\n * it cannot resolve — unless it can see the failure is handled, in which case\n * a server that never touches Valibot builds without the converter installed.\n */\nexport const valibotToJsonSchema: JsonSchemaConverter = async (schema, io) => {\n let converter;\n\n try {\n converter = await import(\"@valibot/to-json-schema\");\n } catch {\n throw new Error(\n 'The \"@valibot/to-json-schema\" package is required to describe Valibot ' +\n \"schemas. Install it with: npm install @valibot/to-json-schema\",\n );\n }\n\n return converter.toJsonSchema(schema as never, {\n errorMode: \"ignore\",\n typeMode: io,\n }) as JsonSchema;\n};\n\n/**\n * Closes an advertised input schema's objects to undeclared keys, except where\n * the schema describes those keys itself. A record's value schema, or an\n * object's rest schema, arrives as `additionalProperties`; replacing it with\n * `false` would tell clients the tool takes none of those keys, so a\n * `v.record()` argument could only ever be sent as `{}`.\n *\n * Nor is an object closed whose keys are declared elsewhere: in its `allOf`,\n * `anyOf` or `oneOf` branches — a `v.intersect()`, `v.union()` or\n * `v.variant()` — or behind a `$ref`, which is how a `v.lazy()` arrives.\n * `additionalProperties` sees only the `properties` beside it, so closing one\n * refused every key declared elsewhere, and every argument with them.\n */\nconst strictInputSchema = (schema: JsonSchema): JsonSchema => ({\n ...schema,\n ...(!(schema.allOf ?? schema.anyOf ?? schema.oneOf ?? schema.$ref) && {\n additionalProperties:\n typeof schema.additionalProperties === \"object\"\n ? schema.additionalProperties\n : false,\n }),\n ...(schema.properties && {\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => [\n key,\n typeof value === \"object\" && value.type === \"object\"\n ? strictInputSchema(value)\n : value,\n ]),\n ),\n }),\n});\n"],"mappings":";AACO,IAAM,cAAc,CAAC,UAA0B;AACpD,MAAI,SAAS,OAAO,QAAQ,SAAS,OAAO,UAAU,GAAG;AACvD,WAAO,GAAG,SAAS,OAAO,KAAK;AAAA,EACj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OAAO,SAAS,OAAO,SAAS,OAAO,SAAS,OAAO,SAAS;AAAA,IACpE,sBACE,OAAO,OAAO,yBAAyB,WACnC,OAAO,uBACP;AAAA,EACR;AAAA,EACA,GAAI,OAAO,cAAc;AAAA,IACvB,YAAY,OAAO;AAAA,MACjB,OAAO,QAAQ,OAAO,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,QACtD;AAAA,QACA,OAAO,UAAU,YAAY,MAAM,SAAS,WACxC,kBAAkB,KAAK,IACvB;AAAA,MACN,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
withoutTrailingSlash
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZVK5GKEO.js";
|
|
4
4
|
import {
|
|
5
5
|
formatBytes,
|
|
6
6
|
ownKeysOnly,
|
|
7
7
|
toSdkSchema,
|
|
8
8
|
valibotToJsonSchema
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TYR2KJIV.js";
|
|
10
10
|
|
|
11
11
|
// src/ViteMCP.ts
|
|
12
12
|
import {
|
|
@@ -106,6 +106,27 @@ var noStore = {
|
|
|
106
106
|
"Cache-Control": "no-store",
|
|
107
107
|
Pragma: "no-cache"
|
|
108
108
|
};
|
|
109
|
+
var invalidClientHeaders = {
|
|
110
|
+
...noStore,
|
|
111
|
+
"WWW-Authenticate": 'Basic realm="oauth", charset="UTF-8"'
|
|
112
|
+
};
|
|
113
|
+
var parseBasicCredentials = (authorization) => {
|
|
114
|
+
const decoded = Buffer.from(authorization.slice(6).trim(), "base64").toString(
|
|
115
|
+
"utf8"
|
|
116
|
+
);
|
|
117
|
+
const separator = decoded.indexOf(":");
|
|
118
|
+
if (separator <= 0) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
return {
|
|
123
|
+
clientId: decodeURIComponent(decoded.slice(0, separator)),
|
|
124
|
+
clientSecret: decodeURIComponent(decoded.slice(separator + 1))
|
|
125
|
+
};
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
109
130
|
var toSnakeCase = (value) => {
|
|
110
131
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
111
132
|
return value;
|
|
@@ -173,21 +194,47 @@ var createOAuthRouter = (options) => {
|
|
|
173
194
|
const params = Object.fromEntries(new URLSearchParams(text).entries());
|
|
174
195
|
const authHeader = raw.headers.get("authorization");
|
|
175
196
|
if (authHeader?.toLowerCase().startsWith("basic ")) {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
197
|
+
const credentials = parseBasicCredentials(authHeader);
|
|
198
|
+
if (!credentials) {
|
|
199
|
+
return c.json(
|
|
200
|
+
{
|
|
201
|
+
error: "invalid_client",
|
|
202
|
+
error_description: "Malformed Basic Authorization header"
|
|
203
|
+
},
|
|
204
|
+
401,
|
|
205
|
+
invalidClientHeaders
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
if (params.client_secret !== void 0) {
|
|
209
|
+
return c.json(
|
|
210
|
+
{
|
|
211
|
+
error: "invalid_request",
|
|
212
|
+
error_description: "Send client credentials in the Authorization header or the request body, not both"
|
|
213
|
+
},
|
|
214
|
+
400,
|
|
215
|
+
noStore
|
|
184
216
|
);
|
|
185
217
|
}
|
|
218
|
+
if (params.client_id !== void 0 && params.client_id !== credentials.clientId) {
|
|
219
|
+
return c.json(
|
|
220
|
+
{
|
|
221
|
+
error: "invalid_request",
|
|
222
|
+
error_description: "client_id in the request body does not match the Authorization header"
|
|
223
|
+
},
|
|
224
|
+
400,
|
|
225
|
+
noStore
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
params.client_id = credentials.clientId;
|
|
229
|
+
params.client_secret = credentials.clientSecret;
|
|
186
230
|
}
|
|
187
231
|
const result = params.grant_type === "refresh_token" ? await proxy.exchangeRefreshToken(params) : await proxy.exchangeAuthorizationCode(params);
|
|
188
232
|
return c.json(result, 200, noStore);
|
|
189
233
|
} catch (error) {
|
|
190
234
|
const { body, status } = errorResponse(error);
|
|
235
|
+
if (body.error === "invalid_client") {
|
|
236
|
+
return c.json(body, 401, invalidClientHeaders);
|
|
237
|
+
}
|
|
191
238
|
return c.json(body, status, noStore);
|
|
192
239
|
}
|
|
193
240
|
});
|
|
@@ -358,10 +405,29 @@ function jsonSchemaAdapter(schema) {
|
|
|
358
405
|
}
|
|
359
406
|
};
|
|
360
407
|
}
|
|
408
|
+
var dialectOf = ($schema) => {
|
|
409
|
+
if (typeof $schema !== "string") {
|
|
410
|
+
return "2020-12";
|
|
411
|
+
}
|
|
412
|
+
switch ($schema.replace(/^https?:\/\//, "").replace(/#$/, "")) {
|
|
413
|
+
case "json-schema.org/draft-06/schema":
|
|
414
|
+
case "json-schema.org/draft-07/schema":
|
|
415
|
+
return "draft-07";
|
|
416
|
+
case "json-schema.org/draft/2019-09/schema":
|
|
417
|
+
return "2019-09";
|
|
418
|
+
case "json-schema.org/draft/2020-12/schema":
|
|
419
|
+
return "2020-12";
|
|
420
|
+
}
|
|
421
|
+
throw new Error(
|
|
422
|
+
`JSON Schema declares an unsupported dialect ("$schema": "${$schema}"). jsonSchemaAdapter validates 2020-12, 2019-09, draft-07 and draft-06.`
|
|
423
|
+
);
|
|
424
|
+
};
|
|
361
425
|
async function compileSchema(schema) {
|
|
426
|
+
const { $schema, ...body } = schema;
|
|
427
|
+
const dialect = dialectOf($schema);
|
|
362
428
|
let ajvModule;
|
|
363
429
|
try {
|
|
364
|
-
ajvModule = await import("ajv");
|
|
430
|
+
ajvModule = dialect === "2020-12" ? await import("ajv/dist/2020.js") : dialect === "2019-09" ? await import("ajv/dist/2019.js") : await import("ajv");
|
|
365
431
|
} catch {
|
|
366
432
|
throw new Error(
|
|
367
433
|
'The "ajv" package is required to validate JSON Schema tool parameters. Install it with: npm install ajv'
|
|
@@ -377,7 +443,7 @@ async function compileSchema(schema) {
|
|
|
377
443
|
addFormats(ajv);
|
|
378
444
|
} catch {
|
|
379
445
|
}
|
|
380
|
-
return ajv.compile(
|
|
446
|
+
return ajv.compile(body);
|
|
381
447
|
}
|
|
382
448
|
function toIssue(error) {
|
|
383
449
|
const path = error.instancePath.split("/").slice(1).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")).map((segment) => {
|
|
@@ -644,6 +710,8 @@ var ViteMCP = class {
|
|
|
644
710
|
for (const tool of tools) {
|
|
645
711
|
assertStandardSchema(tool.parameters, tool.name, "parameters");
|
|
646
712
|
assertStandardSchema(tool.outputSchema, tool.name, "outputSchema");
|
|
713
|
+
}
|
|
714
|
+
for (const tool of tools) {
|
|
647
715
|
this.#tools = this.#tools.filter((t) => t.name !== tool.name);
|
|
648
716
|
this.#tools.push(tool);
|
|
649
717
|
}
|
|
@@ -755,6 +823,11 @@ var ViteMCP = class {
|
|
|
755
823
|
this.#notifyListChanged("tools");
|
|
756
824
|
}
|
|
757
825
|
async start(options) {
|
|
826
|
+
if (options.transportType === "stdio" ? this.#stdioHandle : this.#httpServer) {
|
|
827
|
+
throw new UnexpectedStateError(
|
|
828
|
+
`ViteMCP is already running on ${options.transportType === "stdio" ? "stdio" : "HTTP"}; call stop() before starting it again`
|
|
829
|
+
);
|
|
830
|
+
}
|
|
758
831
|
this.#serverState = "starting" /* Starting */;
|
|
759
832
|
try {
|
|
760
833
|
if (options.transportType === "stdio") {
|
|
@@ -876,10 +949,11 @@ var ViteMCP = class {
|
|
|
876
949
|
return normalizeToolResult(result, tool.outputSchema !== void 0);
|
|
877
950
|
} catch (error) {
|
|
878
951
|
if (error instanceof UserError) {
|
|
952
|
+
const structuredContent = error.extras && await matchesOutputSchema(schemas.outputSchema, error.extras) ? error.extras : void 0;
|
|
879
953
|
return {
|
|
880
954
|
content: [{ text: error.message, type: "text" }],
|
|
881
955
|
isError: true,
|
|
882
|
-
...
|
|
956
|
+
...structuredContent ? { structuredContent } : {}
|
|
883
957
|
};
|
|
884
958
|
}
|
|
885
959
|
throw error;
|
|
@@ -1064,23 +1138,31 @@ var ViteMCP = class {
|
|
|
1064
1138
|
*
|
|
1065
1139
|
* `timeoutSignal` is folded into `context.signal` for a tool that declares
|
|
1066
1140
|
* `timeoutMs`; everything else mirrors the SDK's request signal alone. Call
|
|
1067
|
-
* `release()` once the handler has settled — see {@link requestScope}.
|
|
1141
|
+
* `release()` once the handler has settled — see {@link requestScope}. It
|
|
1142
|
+
* also ends the context's notifications, as an abort does.
|
|
1068
1143
|
*/
|
|
1069
1144
|
#makeContext(auth, rawCtx, timeoutSignal) {
|
|
1070
1145
|
const ctx = rawCtx;
|
|
1071
1146
|
const mcpReq = ctx?.mcpReq;
|
|
1147
|
+
const scope = requestScope(mcpReq?.signal, timeoutSignal);
|
|
1148
|
+
let settled = false;
|
|
1149
|
+
const notify = async (notification) => {
|
|
1150
|
+
if (settled || scope.signal.aborted) {
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
await mcpReq?.notify?.(notification);
|
|
1154
|
+
};
|
|
1072
1155
|
const requestedLevel = mcpReq?.envelope?.[LOG_LEVEL_META_KEY];
|
|
1073
1156
|
const emit = (level, message, data) => {
|
|
1074
1157
|
if (!requestedLevel || LOG_LEVELS.indexOf(level) < LOG_LEVELS.indexOf(requestedLevel)) {
|
|
1075
1158
|
return;
|
|
1076
1159
|
}
|
|
1077
|
-
void
|
|
1160
|
+
void notify({
|
|
1078
1161
|
method: "notifications/message",
|
|
1079
1162
|
params: { data: { context: data, message }, level }
|
|
1080
|
-
})
|
|
1163
|
+
}).catch(() => {
|
|
1081
1164
|
});
|
|
1082
1165
|
};
|
|
1083
|
-
const scope = requestScope(mcpReq?.signal, timeoutSignal);
|
|
1084
1166
|
return {
|
|
1085
1167
|
context: {
|
|
1086
1168
|
auth,
|
|
@@ -1106,7 +1188,7 @@ var ViteMCP = class {
|
|
|
1106
1188
|
if (progressToken === void 0) {
|
|
1107
1189
|
return;
|
|
1108
1190
|
}
|
|
1109
|
-
await
|
|
1191
|
+
await notify({
|
|
1110
1192
|
method: "notifications/progress",
|
|
1111
1193
|
params: {
|
|
1112
1194
|
message: progress.message,
|
|
@@ -1122,7 +1204,10 @@ var ViteMCP = class {
|
|
|
1122
1204
|
requestState: mcpReq?.requestState?.(),
|
|
1123
1205
|
signal: scope.signal
|
|
1124
1206
|
},
|
|
1125
|
-
release:
|
|
1207
|
+
release: () => {
|
|
1208
|
+
settled = true;
|
|
1209
|
+
scope.release();
|
|
1210
|
+
}
|
|
1126
1211
|
};
|
|
1127
1212
|
}
|
|
1128
1213
|
/**
|
|
@@ -1483,6 +1568,19 @@ var assertStandardSchema = (schema, toolName, field) => {
|
|
|
1483
1568
|
);
|
|
1484
1569
|
}
|
|
1485
1570
|
};
|
|
1571
|
+
var matchesOutputSchema = async (schema, value) => {
|
|
1572
|
+
if (!schema) {
|
|
1573
|
+
return true;
|
|
1574
|
+
}
|
|
1575
|
+
try {
|
|
1576
|
+
const result = await schema["~standard"].validate(
|
|
1577
|
+
value
|
|
1578
|
+
);
|
|
1579
|
+
return !result.issues;
|
|
1580
|
+
} catch {
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1486
1584
|
var promptArgsSchema = (prompt) => {
|
|
1487
1585
|
const args = prompt.arguments;
|
|
1488
1586
|
if (!args?.length) {
|
|
@@ -1576,4 +1674,4 @@ export {
|
|
|
1576
1674
|
ServerState,
|
|
1577
1675
|
ViteMCP
|
|
1578
1676
|
};
|
|
1579
|
-
//# sourceMappingURL=chunk-
|
|
1677
|
+
//# sourceMappingURL=chunk-UVKIOOZA.js.map
|