luma-mcp 1.0.2 → 1.1.0
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/.env.example +39 -0
- package/CHANGELOG.md +50 -0
- package/README.md +187 -32
- package/build/config.d.ts +2 -0
- package/build/config.d.ts.map +1 -1
- package/build/config.js +24 -8
- package/build/config.js.map +1 -1
- package/build/index.js +17 -6
- package/build/index.js.map +1 -1
- package/build/siliconflow-client.d.ts +23 -0
- package/build/siliconflow-client.d.ts.map +1 -0
- package/build/siliconflow-client.js +85 -0
- package/build/siliconflow-client.js.map +1 -0
- package/build/vision-client.d.ts +18 -0
- package/build/vision-client.d.ts.map +1 -0
- package/build/vision-client.js +5 -0
- package/build/vision-client.js.map +1 -0
- package/build/zhipu-client.d.ts +6 -1
- package/build/zhipu-client.d.ts.map +1 -1
- package/build/zhipu-client.js +10 -3
- package/build/zhipu-client.js.map +1 -1
- package/package.json +8 -3
- package/test/test-deepseek-raw.ts +94 -0
- package/test/test-local.ts +20 -7
- package/.claude/settings.local.json +0 -10
- package/mcp-server/README.md +0 -41
- package/mcp-server/README.zh-CN.md +0 -42
- package/mcp-server/build/core/api-common.js +0 -122
- package/mcp-server/build/core/chat-service.js +0 -80
- package/mcp-server/build/core/environment.js +0 -128
- package/mcp-server/build/core/error-handler.js +0 -376
- package/mcp-server/build/core/file-service.js +0 -126
- package/mcp-server/build/index.js +0 -160
- package/mcp-server/build/tools/image-analysis.js +0 -125
- package/mcp-server/build/tools/video-analysis.js +0 -125
- package/mcp-server/build/types/index.js +0 -35
- package/mcp-server/build/types/validation-types.js +0 -1
- package/mcp-server/build/utils/logger.js +0 -120
- package/mcp-server/build/utils/validation.js +0 -198
- package/mcp-server/package.json +0 -53
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { ValidationError } from '../types/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Runtime type validator
|
|
5
|
-
*/
|
|
6
|
-
export class RuntimeValidator {
|
|
7
|
-
/**
|
|
8
|
-
* Validate data against specified Zod schema
|
|
9
|
-
*/
|
|
10
|
-
static validate(data, schema, options = {}) {
|
|
11
|
-
const { throwOnError = true, customMessage, logErrors = true } = options;
|
|
12
|
-
try {
|
|
13
|
-
const result = schema.parse(data);
|
|
14
|
-
return {
|
|
15
|
-
success: true,
|
|
16
|
-
data: result
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
const validationErrors = this.parseZodError(error);
|
|
21
|
-
if (logErrors) {
|
|
22
|
-
console.warn('Validation failed', {
|
|
23
|
-
errors: validationErrors,
|
|
24
|
-
data: this.sanitizeData(data)
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if (throwOnError) {
|
|
28
|
-
const message = customMessage || `Validation failed: ${validationErrors.map(e => e.message).join(', ')}`;
|
|
29
|
-
throw new ValidationError(message, { errors: validationErrors });
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
success: false,
|
|
33
|
-
error: {
|
|
34
|
-
message: validationErrors.map(e => e.message).join(', '),
|
|
35
|
-
code: 'VALIDATION_ERROR'
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Safe validation, does not throw exceptions
|
|
42
|
-
*/
|
|
43
|
-
static safeValidate(data, schema) {
|
|
44
|
-
return this.validate(data, schema, { throwOnError: false });
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Parse Zod error to standard validation error format
|
|
48
|
-
*/
|
|
49
|
-
static parseZodError(error) {
|
|
50
|
-
return error.issues.map(issue => ({
|
|
51
|
-
message: issue.message,
|
|
52
|
-
field: issue.path.join('.'),
|
|
53
|
-
code: issue.code,
|
|
54
|
-
expected: this.getExpectedType(issue),
|
|
55
|
-
received: 'received' in issue ? String(issue.received) : 'unknown'
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Get expected type description
|
|
60
|
-
*/
|
|
61
|
-
static getExpectedType(issue) {
|
|
62
|
-
switch (issue.code) {
|
|
63
|
-
case 'invalid_type':
|
|
64
|
-
return issue.expected;
|
|
65
|
-
case 'too_small':
|
|
66
|
-
return `minimum ${issue.minimum}`;
|
|
67
|
-
case 'too_big':
|
|
68
|
-
return `maximum ${issue.maximum}`;
|
|
69
|
-
default:
|
|
70
|
-
return 'valid value';
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Sanitize sensitive data for logging
|
|
75
|
-
*/
|
|
76
|
-
static sanitizeData(data) {
|
|
77
|
-
if (typeof data !== 'object' || data === null) {
|
|
78
|
-
return data;
|
|
79
|
-
}
|
|
80
|
-
const sensitiveKeys = ['password', 'token', 'secret', 'key', 'auth'];
|
|
81
|
-
const sanitized = { ...data };
|
|
82
|
-
for (const key of Object.keys(sanitized)) {
|
|
83
|
-
if (sensitiveKeys.some(sensitive => key.toLowerCase().includes(sensitive))) {
|
|
84
|
-
sanitized[key] = '[REDACTED]';
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return sanitized;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Parameter validation decorator
|
|
92
|
-
*/
|
|
93
|
-
export function ValidateParams(schema, options = {}) {
|
|
94
|
-
return function (target, propertyKey, descriptor) {
|
|
95
|
-
const originalMethod = descriptor.value;
|
|
96
|
-
descriptor.value = async function (...args) {
|
|
97
|
-
// Assume the first parameter is the parameter object to validate
|
|
98
|
-
const params = args[0];
|
|
99
|
-
try {
|
|
100
|
-
const validationResult = RuntimeValidator.validate(params, schema, options);
|
|
101
|
-
if (!validationResult.success) {
|
|
102
|
-
throw new ValidationError('Parameter validation failed', { errors: validationResult.errors });
|
|
103
|
-
}
|
|
104
|
-
// Replace original parameters with validated data
|
|
105
|
-
args[0] = validationResult.data;
|
|
106
|
-
return await originalMethod.apply(this, args);
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
console.error(`Parameter validation failed for ${propertyKey}`, {
|
|
110
|
-
error: error instanceof Error ? error.message : String(error),
|
|
111
|
-
params: RuntimeValidator['sanitizeData'](params)
|
|
112
|
-
});
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
return descriptor;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Return value validation decorator
|
|
121
|
-
*/
|
|
122
|
-
export function ValidateReturn(schema, options = {}) {
|
|
123
|
-
return function (target, propertyKey, descriptor) {
|
|
124
|
-
const originalMethod = descriptor.value;
|
|
125
|
-
descriptor.value = async function (...args) {
|
|
126
|
-
const result = await originalMethod.apply(this, args);
|
|
127
|
-
try {
|
|
128
|
-
const validationResult = RuntimeValidator.validate(result, schema, options);
|
|
129
|
-
if (!validationResult.success) {
|
|
130
|
-
throw new ValidationError('Return value validation failed', { errors: validationResult.errors });
|
|
131
|
-
}
|
|
132
|
-
return validationResult.data;
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
console.error(`Return value validation failed for ${propertyKey}`, {
|
|
136
|
-
error: error instanceof Error ? error.message : String(error),
|
|
137
|
-
result: RuntimeValidator['sanitizeData'](result)
|
|
138
|
-
});
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
return descriptor;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Common validation schemas
|
|
147
|
-
*/
|
|
148
|
-
export const CommonSchemas = {
|
|
149
|
-
/** Non-empty string */
|
|
150
|
-
nonEmptyString: z.string().min(1, 'String cannot be empty'),
|
|
151
|
-
/** Positive integer */
|
|
152
|
-
positiveInteger: z.number().int().positive('Must be a positive integer'),
|
|
153
|
-
/** Non-negative integer */
|
|
154
|
-
nonNegativeInteger: z.number().int().min(0, 'Must be a non-negative integer'),
|
|
155
|
-
/** URL format */
|
|
156
|
-
url: z.string().url('Must be a valid URL'),
|
|
157
|
-
/** Email format */
|
|
158
|
-
email: z.string().email('Must be a valid email address'),
|
|
159
|
-
/** UUID format */
|
|
160
|
-
uuid: z.string().uuid('Must be a valid UUID'),
|
|
161
|
-
/** File path */
|
|
162
|
-
filePath: z.string().min(1).refine((path) => !path.includes('..'), 'File path cannot contain ".."'),
|
|
163
|
-
/** Tool name */
|
|
164
|
-
toolName: z.string().regex(/^[a-z][a-z0-9-]*[a-z0-9]$/, 'Tool name must be lowercase, start with letter, and contain only letters, numbers, and hyphens')
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* Tool parameter validation schema builder
|
|
168
|
-
*/
|
|
169
|
-
export class ToolSchemaBuilder {
|
|
170
|
-
schema = {};
|
|
171
|
-
/**
|
|
172
|
-
* Add required field
|
|
173
|
-
*/
|
|
174
|
-
required(name, schema) {
|
|
175
|
-
this.schema[name] = schema;
|
|
176
|
-
return this;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Add optional field
|
|
180
|
-
*/
|
|
181
|
-
optional(name, schema) {
|
|
182
|
-
this.schema[name] = schema.optional();
|
|
183
|
-
return this;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Add field with default value
|
|
187
|
-
*/
|
|
188
|
-
withDefault(name, schema, defaultValue) {
|
|
189
|
-
this.schema[name] = schema.default(() => defaultValue);
|
|
190
|
-
return this;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Build final validation schema
|
|
194
|
-
*/
|
|
195
|
-
build() {
|
|
196
|
-
return z.object(this.schema);
|
|
197
|
-
}
|
|
198
|
-
}
|
package/mcp-server/package.json
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@z_ai/mcp-server",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "MCP Server for Z.AI - A Model Context Protocol server that provides AI capabilities",
|
|
5
|
-
"main": "build/index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"bin": {
|
|
8
|
-
"zai-mcp-server": "./build/index.js"
|
|
9
|
-
},
|
|
10
|
-
"homepage": "https://docs.z.ai/",
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://docs.z.ai/"
|
|
13
|
-
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsc && chmod 755 build/index.js",
|
|
16
|
-
"start": "node build/index.js",
|
|
17
|
-
"prepare": "npm run build",
|
|
18
|
-
"prerelease": "npm version prerelease --preid=beta",
|
|
19
|
-
"publish-beta": "npm publish --tag beta",
|
|
20
|
-
"publish": "npm publish"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"zai",
|
|
24
|
-
"mcp",
|
|
25
|
-
"vision"
|
|
26
|
-
],
|
|
27
|
-
"author": "Z.AI",
|
|
28
|
-
"contributors": [
|
|
29
|
-
"Chao Gong (https://github.com/tomsun28)",
|
|
30
|
-
"Lei Yuan (https://github.com/Web-Life)"
|
|
31
|
-
],
|
|
32
|
-
"license": "Apache-2.0",
|
|
33
|
-
"files": [
|
|
34
|
-
"build",
|
|
35
|
-
"README.zh-CN.md",
|
|
36
|
-
"README.md"
|
|
37
|
-
],
|
|
38
|
-
"engines": {
|
|
39
|
-
"node": ">=18.0.0"
|
|
40
|
-
},
|
|
41
|
-
"publishConfig": {
|
|
42
|
-
"access": "public"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"zod": "^3.23.8",
|
|
46
|
-
"@modelcontextprotocol/sdk": "1.17.5"
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@types/node": "24.3.1",
|
|
50
|
-
"ts-node": "10.9.2",
|
|
51
|
-
"typescript": "5.9.2"
|
|
52
|
-
}
|
|
53
|
-
}
|