@svadmin/mcp 0.3.7 → 0.4.7

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.ts +29 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/mcp",
3
- "version": "0.3.7",
3
+ "version": "0.4.7",
4
4
  "description": "MCP (Model Context Protocol) server — expose svadmin DataProvider as tools for AI agents",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -20,7 +20,7 @@
20
20
  }
21
21
  },
22
22
  "peerDependencies": {
23
- "@svadmin/core": "^0.50.0"
23
+ "@svadmin/core": "^0.53.0"
24
24
  },
25
25
  "license": "MIT",
26
26
  "publishConfig": {
@@ -30,7 +30,7 @@
30
30
  "author": "zuohuadong",
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "https://github.com/vibeunion/svadmin.git",
33
+ "url": "git+https://github.com/vibeunion/svadmin.git",
34
34
  "directory": "packages/mcp"
35
35
  },
36
36
  "homepage": "https://github.com/vibeunion/svadmin#readme",
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { definedOptions } from '@svadmin/core/options';
1
2
  /**
2
3
  * @svadmin/mcp — Model Context Protocol server for svadmin DataProvider
3
4
  *
@@ -51,11 +52,11 @@ export interface MCPTool {
51
52
  properties: Record<string, MCPPropertySchema>;
52
53
  required?: string[];
53
54
  };
54
- /** 显式声明是否为只读操作(只读操作可并发执行,无持久化副作用) */
55
+ /** Declares whether the operation is read-only and safe for concurrent execution without persistent side effects. */
55
56
  readOnly?: boolean;
56
- /** 显式声明是否支持并发调用 */
57
+ /** Declares whether concurrent calls are supported. */
57
58
  concurrent?: boolean;
58
- /** 显式声明是否具有高风险/破坏性 */
59
+ /** Declares whether the operation is high risk or destructive. */
59
60
  destructive?: boolean;
60
61
  }
61
62
 
@@ -226,7 +227,7 @@ async function handleToolCall(
226
227
  args: Record<string, unknown>,
227
228
  options: MCPServerOptions,
228
229
  ): Promise<unknown> {
229
- const resource = args.resource as string;
230
+ const resource = args['resource'] as string;
230
231
  if (resource && !options.resources.includes(resource)) {
231
232
  throw new Error(`Unauthorized resource access: ${resource} is not exposed.`);
232
233
  }
@@ -234,64 +235,64 @@ async function handleToolCall(
234
235
 
235
236
  switch (toolName) {
236
237
  case 'svadmin_getList': {
237
- const resource = args.resource as string;
238
- const page = (args.page as number) ?? 1;
239
- const pageSize = (args.pageSize as number) ?? 10;
240
- const sorters = args.sortField
241
- ? [{ field: args.sortField as string, order: (args.sortOrder as 'asc' | 'desc') ?? 'asc' }]
238
+ const resource = args['resource'] as string;
239
+ const page = (args['page'] as number) ?? 1;
240
+ const pageSize = (args['pageSize'] as number) ?? 10;
241
+ const sorters = args['sortField']
242
+ ? [{ field: args['sortField'] as string, order: (args['sortOrder'] as 'asc' | 'desc') ?? 'asc' }]
242
243
  : undefined;
243
- const filters = args.filters
244
- ? JSON.parse(args.filters as string)
244
+ const filters = args['filters']
245
+ ? JSON.parse(args['filters'] as string)
245
246
  : undefined;
246
247
 
247
- return dp.getList({
248
+ return dp.getList(definedOptions({
248
249
  resource,
249
250
  pagination: { current: page, pageSize },
250
251
  sorters,
251
252
  filters,
252
- });
253
+ }));
253
254
  }
254
255
 
255
256
  case 'svadmin_getOne': {
256
257
  return dp.getOne({
257
- resource: args.resource as string,
258
- id: args.id as string,
258
+ resource: args['resource'] as string,
259
+ id: args['id'] as string,
259
260
  });
260
261
  }
261
262
 
262
263
  case 'svadmin_getMany': {
263
- const ids = (args.ids as string).split(',').map(id => id.trim());
264
+ const ids = (args['ids'] as string).split(',').map(id => id.trim());
264
265
  if (dp.getMany) {
265
- return dp.getMany({ resource: args.resource as string, ids });
266
+ return dp.getMany({ resource: args['resource'] as string, ids });
266
267
  }
267
268
  // Fallback: fetch one by one
268
269
  const results = await Promise.all(
269
- ids.map(id => dp.getOne({ resource: args.resource as string, id }))
270
+ ids.map(id => dp.getOne({ resource: args['resource'] as string, id }))
270
271
  );
271
272
  return { data: results.map(r => r.data) };
272
273
  }
273
274
 
274
275
  case 'svadmin_create': {
275
- const data = JSON.parse(args.data as string);
276
+ const data = JSON.parse(args['data'] as string);
276
277
  return dp.create({
277
- resource: args.resource as string,
278
+ resource: args['resource'] as string,
278
279
  variables: data,
279
280
  });
280
281
  }
281
282
 
282
283
  case 'svadmin_update': {
283
- const data = JSON.parse(args.data as string);
284
+ const data = JSON.parse(args['data'] as string);
284
285
  return dp.update({
285
- resource: args.resource as string,
286
- id: args.id as string,
286
+ resource: args['resource'] as string,
287
+ id: args['id'] as string,
287
288
  variables: data,
288
289
  });
289
290
  }
290
291
 
291
292
  case 'svadmin_delete': {
292
293
  return dp.deleteOne({
293
- resource: args.resource as string,
294
- id: args.id as string,
294
+ resource: args['resource'] as string,
295
+ id: args['id'] as string,
295
296
  });
296
297
  }
297
298
 
@@ -323,7 +324,7 @@ async function handleToolCall(
323
324
  * ```
324
325
  */
325
326
  /**
326
- * 投影 MCP 工具为标准白名单 Schema,确保元数据与安全标记正确保留。
327
+ * Projects an MCP tool into the standard allowlisted schema while preserving metadata and safety flags.
327
328
  */
328
329
  export function projectMCPToolSchema(tool: MCPTool): MCPTool {
329
330
  return {
@@ -369,8 +370,8 @@ export function createMCPServer(options: MCPServerOptions): MCPServer {
369
370
  };
370
371
 
371
372
  case 'tools/call': {
372
- const toolName = (params as Record<string, unknown>)?.name as string;
373
- const toolArgs = ((params as Record<string, unknown>)?.arguments ?? {}) as Record<string, unknown>;
373
+ const toolName = (params as Record<string, unknown>)?.['name'] as string;
374
+ const toolArgs = ((params as Record<string, unknown>)?.['arguments'] ?? {}) as Record<string, unknown>;
374
375
 
375
376
  if (!toolName) {
376
377
  return {