修改后台权限

This commit is contained in:
yoyuzh
2026-03-24 14:30:59 +08:00
parent 00f902f475
commit b2d9db7be9
9310 changed files with 1246063 additions and 48 deletions

View File

@@ -0,0 +1,53 @@
/**
* AJV-based JSON Schema validator provider
*/
import Ajv from 'ajv';
import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from './types.js';
/**
* @example
* ```typescript
* // Use with default AJV instance (recommended)
* import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
* const validator = new AjvJsonSchemaValidator();
*
* // Use with custom AJV instance
* import { Ajv } from 'ajv';
* const ajv = new Ajv({ strict: true, allErrors: true });
* const validator = new AjvJsonSchemaValidator(ajv);
* ```
*/
export declare class AjvJsonSchemaValidator implements jsonSchemaValidator {
private _ajv;
/**
* Create an AJV validator
*
* @param ajv - Optional pre-configured AJV instance. If not provided, a default instance will be created.
*
* @example
* ```typescript
* // Use default configuration (recommended for most cases)
* import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
* const validator = new AjvJsonSchemaValidator();
*
* // Or provide custom AJV instance for advanced configuration
* import { Ajv } from 'ajv';
* import addFormats from 'ajv-formats';
*
* const ajv = new Ajv({ validateFormats: true });
* addFormats(ajv);
* const validator = new AjvJsonSchemaValidator(ajv);
* ```
*/
constructor(ajv?: Ajv);
/**
* Create a validator for the given JSON Schema
*
* The validator is compiled once and can be reused multiple times.
* If the schema has an $id, it will be cached by AJV automatically.
*
* @param schema - Standard JSON Schema object
* @returns A validator function that validates input data
*/
getValidator<T>(schema: JsonSchemaType): JsonSchemaValidator<T>;
}
//# sourceMappingURL=ajv-provider.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ajv-provider.d.ts","sourceRoot":"","sources":["../../../src/validation/ajv-provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAA6B,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAgBtH;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAuB,YAAW,mBAAmB;IAC9D,OAAO,CAAC,IAAI,CAAM;IAElB;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,GAAG,CAAC,EAAE,GAAG;IAIrB;;;;;;;;OAQG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC;CAyBlE"}

View File

@@ -0,0 +1,94 @@
"use strict";
/**
* AJV-based JSON Schema validator provider
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AjvJsonSchemaValidator = void 0;
const ajv_1 = __importDefault(require("ajv"));
const ajv_formats_1 = __importDefault(require("ajv-formats"));
function createDefaultAjvInstance() {
const ajv = new ajv_1.default({
strict: false,
validateFormats: true,
validateSchema: false,
allErrors: true
});
const addFormats = ajv_formats_1.default;
addFormats(ajv);
return ajv;
}
/**
* @example
* ```typescript
* // Use with default AJV instance (recommended)
* import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
* const validator = new AjvJsonSchemaValidator();
*
* // Use with custom AJV instance
* import { Ajv } from 'ajv';
* const ajv = new Ajv({ strict: true, allErrors: true });
* const validator = new AjvJsonSchemaValidator(ajv);
* ```
*/
class AjvJsonSchemaValidator {
/**
* Create an AJV validator
*
* @param ajv - Optional pre-configured AJV instance. If not provided, a default instance will be created.
*
* @example
* ```typescript
* // Use default configuration (recommended for most cases)
* import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
* const validator = new AjvJsonSchemaValidator();
*
* // Or provide custom AJV instance for advanced configuration
* import { Ajv } from 'ajv';
* import addFormats from 'ajv-formats';
*
* const ajv = new Ajv({ validateFormats: true });
* addFormats(ajv);
* const validator = new AjvJsonSchemaValidator(ajv);
* ```
*/
constructor(ajv) {
this._ajv = ajv ?? createDefaultAjvInstance();
}
/**
* Create a validator for the given JSON Schema
*
* The validator is compiled once and can be reused multiple times.
* If the schema has an $id, it will be cached by AJV automatically.
*
* @param schema - Standard JSON Schema object
* @returns A validator function that validates input data
*/
getValidator(schema) {
// Check if schema has $id and is already compiled/cached
const ajvValidator = '$id' in schema && typeof schema.$id === 'string'
? (this._ajv.getSchema(schema.$id) ?? this._ajv.compile(schema))
: this._ajv.compile(schema);
return (input) => {
const valid = ajvValidator(input);
if (valid) {
return {
valid: true,
data: input,
errorMessage: undefined
};
}
else {
return {
valid: false,
data: undefined,
errorMessage: this._ajv.errorsText(ajvValidator.errors)
};
}
};
}
}
exports.AjvJsonSchemaValidator = AjvJsonSchemaValidator;
//# sourceMappingURL=ajv-provider.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ajv-provider.js","sourceRoot":"","sources":["../../../src/validation/ajv-provider.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,8CAAsB;AACtB,8DAAsC;AAGtC,SAAS,wBAAwB;IAC7B,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC;QAChB,MAAM,EAAE,KAAK;QACb,eAAe,EAAE,IAAI;QACrB,cAAc,EAAE,KAAK;QACrB,SAAS,EAAE,IAAI;KAClB,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,qBAAoD,CAAC;IACxE,UAAU,CAAC,GAAG,CAAC,CAAC;IAEhB,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAa,sBAAsB;IAG/B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,YAAY,GAAS;QACjB,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,wBAAwB,EAAE,CAAC;IAClD,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,CAAI,MAAsB;QAClC,yDAAyD;QACzD,MAAM,YAAY,GACd,KAAK,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;YAC7C,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAChE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEpC,OAAO,CAAC,KAAc,EAAgC,EAAE;YACpD,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAElC,IAAI,KAAK,EAAE,CAAC;gBACR,OAAO;oBACH,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,KAAU;oBAChB,YAAY,EAAE,SAAS;iBAC1B,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO;oBACH,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,SAAS;oBACf,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC;iBAC1D,CAAC;YACN,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CACJ;AA7DD,wDA6DC"}

View File

@@ -0,0 +1,51 @@
/**
* Cloudflare Worker-compatible JSON Schema validator provider
*
* This provider uses @cfworker/json-schema for validation without code generation,
* making it compatible with edge runtimes like Cloudflare Workers that restrict
* eval and new Function.
*/
import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from './types.js';
/**
* JSON Schema draft version supported by @cfworker/json-schema
*/
export type CfWorkerSchemaDraft = '4' | '7' | '2019-09' | '2020-12';
/**
*
* @example
* ```typescript
* // Use with default configuration (2020-12, shortcircuit)
* const validator = new CfWorkerJsonSchemaValidator();
*
* // Use with custom configuration
* const validator = new CfWorkerJsonSchemaValidator({
* draft: '2020-12',
* shortcircuit: false // Report all errors
* });
* ```
*/
export declare class CfWorkerJsonSchemaValidator implements jsonSchemaValidator {
private shortcircuit;
private draft;
/**
* Create a validator
*
* @param options - Configuration options
* @param options.shortcircuit - If true, stop validation after first error (default: true)
* @param options.draft - JSON Schema draft version to use (default: '2020-12')
*/
constructor(options?: {
shortcircuit?: boolean;
draft?: CfWorkerSchemaDraft;
});
/**
* Create a validator for the given JSON Schema
*
* Unlike AJV, this validator is not cached internally
*
* @param schema - Standard JSON Schema object
* @returns A validator function that validates input data
*/
getValidator<T>(schema: JsonSchemaType): JsonSchemaValidator<T>;
}
//# sourceMappingURL=cfworker-provider.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cfworker-provider.d.ts","sourceRoot":"","sources":["../../../src/validation/cfworker-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAA6B,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtH;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IACnE,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAsB;IAEnC;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,mBAAmB,CAAA;KAAE;IAK7E;;;;;;;OAOG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC;CAsBlE"}

View File

@@ -0,0 +1,69 @@
"use strict";
/**
* Cloudflare Worker-compatible JSON Schema validator provider
*
* This provider uses @cfworker/json-schema for validation without code generation,
* making it compatible with edge runtimes like Cloudflare Workers that restrict
* eval and new Function.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CfWorkerJsonSchemaValidator = void 0;
const json_schema_1 = require("@cfworker/json-schema");
/**
*
* @example
* ```typescript
* // Use with default configuration (2020-12, shortcircuit)
* const validator = new CfWorkerJsonSchemaValidator();
*
* // Use with custom configuration
* const validator = new CfWorkerJsonSchemaValidator({
* draft: '2020-12',
* shortcircuit: false // Report all errors
* });
* ```
*/
class CfWorkerJsonSchemaValidator {
/**
* Create a validator
*
* @param options - Configuration options
* @param options.shortcircuit - If true, stop validation after first error (default: true)
* @param options.draft - JSON Schema draft version to use (default: '2020-12')
*/
constructor(options) {
this.shortcircuit = options?.shortcircuit ?? true;
this.draft = options?.draft ?? '2020-12';
}
/**
* Create a validator for the given JSON Schema
*
* Unlike AJV, this validator is not cached internally
*
* @param schema - Standard JSON Schema object
* @returns A validator function that validates input data
*/
getValidator(schema) {
// Cast to the cfworker Schema type - our JsonSchemaType is structurally compatible
const validator = new json_schema_1.Validator(schema, this.draft, this.shortcircuit);
return (input) => {
const result = validator.validate(input);
if (result.valid) {
return {
valid: true,
data: input,
errorMessage: undefined
};
}
else {
return {
valid: false,
data: undefined,
errorMessage: result.errors.map(err => `${err.instanceLocation}: ${err.error}`).join('; ')
};
}
};
}
}
exports.CfWorkerJsonSchemaValidator = CfWorkerJsonSchemaValidator;
//# sourceMappingURL=cfworker-provider.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cfworker-provider.js","sourceRoot":"","sources":["../../../src/validation/cfworker-provider.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,uDAAkD;AAQlD;;;;;;;;;;;;;GAaG;AACH,MAAa,2BAA2B;IAIpC;;;;;;OAMG;IACH,YAAY,OAAiE;QACzE,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,IAAI,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,SAAS,CAAC;IAC7C,CAAC;IAED;;;;;;;OAOG;IACH,YAAY,CAAI,MAAsB;QAClC,mFAAmF;QACnF,MAAM,SAAS,GAAG,IAAI,uBAAS,CAAC,MAAoD,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAErH,OAAO,CAAC,KAAc,EAAgC,EAAE;YACpD,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAEzC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO;oBACH,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,KAAU;oBAChB,YAAY,EAAE,SAAS;iBAC1B,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO;oBACH,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,SAAS;oBACf,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,gBAAgB,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC7F,CAAC;YACN,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CACJ;AA9CD,kEA8CC"}

View File

@@ -0,0 +1,29 @@
/**
* JSON Schema validation
*
* This module provides configurable JSON Schema validation for the MCP SDK.
* Choose a validator based on your runtime environment:
*
* - AjvJsonSchemaValidator: Best for Node.js (default, fastest)
* Import from: @modelcontextprotocol/sdk/validation/ajv
* Requires peer dependencies: ajv, ajv-formats
*
* - CfWorkerJsonSchemaValidator: Best for edge runtimes
* Import from: @modelcontextprotocol/sdk/validation/cfworker
* Requires peer dependency: @cfworker/json-schema
*
* @example
* ```typescript
* // For Node.js with AJV
* import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
* const validator = new AjvJsonSchemaValidator();
*
* // For Cloudflare Workers
* import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/cfworker';
* const validator = new CfWorkerJsonSchemaValidator();
* ```
*
* @module validation
*/
export type { JsonSchemaType, JsonSchemaValidator, JsonSchemaValidatorResult, jsonSchemaValidator } from './types.js';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}

View File

@@ -0,0 +1,30 @@
"use strict";
/**
* JSON Schema validation
*
* This module provides configurable JSON Schema validation for the MCP SDK.
* Choose a validator based on your runtime environment:
*
* - AjvJsonSchemaValidator: Best for Node.js (default, fastest)
* Import from: @modelcontextprotocol/sdk/validation/ajv
* Requires peer dependencies: ajv, ajv-formats
*
* - CfWorkerJsonSchemaValidator: Best for edge runtimes
* Import from: @modelcontextprotocol/sdk/validation/cfworker
* Requires peer dependency: @cfworker/json-schema
*
* @example
* ```typescript
* // For Node.js with AJV
* import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
* const validator = new AjvJsonSchemaValidator();
*
* // For Cloudflare Workers
* import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/cfworker';
* const validator = new CfWorkerJsonSchemaValidator();
* ```
*
* @module validation
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG"}

View File

@@ -0,0 +1,65 @@
import type { JSONSchema } from 'json-schema-typed';
/**
* JSON Schema type definition (JSON Schema Draft 2020-12)
*
* This uses the object form of JSON Schema (excluding boolean schemas).
* While `true` and `false` are valid JSON Schemas, this SDK uses the
* object form for practical type safety.
*
* Re-exported from json-schema-typed for convenience.
* @see https://json-schema.org/draft/2020-12/json-schema-core.html
*/
export type JsonSchemaType = JSONSchema.Interface;
/**
* Result of a JSON Schema validation operation
*/
export type JsonSchemaValidatorResult<T> = {
valid: true;
data: T;
errorMessage: undefined;
} | {
valid: false;
data: undefined;
errorMessage: string;
};
/**
* A validator function that validates data against a JSON Schema
*/
export type JsonSchemaValidator<T> = (input: unknown) => JsonSchemaValidatorResult<T>;
/**
* Provider interface for creating validators from JSON Schemas
*
* This is the main extension point for custom validator implementations.
* Implementations should:
* - Support JSON Schema Draft 2020-12 (or be compatible with it)
* - Return validator functions that can be called multiple times
* - Handle schema compilation/caching internally
* - Provide clear error messages on validation failure
*
* @example
* ```typescript
* class MyValidatorProvider implements jsonSchemaValidator {
* getValidator<T>(schema: JsonSchemaType<T>): JsonSchemaValidator<T> {
* // Compile/cache validator from schema
* return (input: unknown) => {
* // Validate input against schema
* if (valid) {
* return { valid: true, data: input as T, errorMessage: undefined };
* } else {
* return { valid: false, data: undefined, errorMessage: 'Error details' };
* }
* };
* }
* }
* ```
*/
export interface jsonSchemaValidator {
/**
* Create a validator for the given JSON Schema
*
* @param schema - Standard JSON Schema object
* @returns A validator function that can be called multiple times
*/
getValidator<T>(schema: JsonSchemaType): JsonSchemaValidator<T>;
}
//# sourceMappingURL=types.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/validation/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IACjC;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC;IAAC,YAAY,EAAE,SAAS,CAAA;CAAE,GACjD;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,yBAAyB,CAAC,CAAC,CAAC,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,mBAAmB;IAChC;;;;;OAKG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;CACnE"}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/validation/types.ts"],"names":[],"mappings":""}