@wowok/agent-mcp 2.2.11 → 2.2.14

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 (37) hide show
  1. package/dist/index.d.ts +12 -0
  2. package/dist/index.js +98 -47
  3. package/dist/schema-query/index.d.ts +29 -0
  4. package/dist/schema-query/index.js +149 -0
  5. package/dist/schemas/account_operation.schema.json +255 -0
  6. package/dist/schemas/guard2file.schema.json +71 -0
  7. package/dist/schemas/index.json +139 -0
  8. package/dist/schemas/local_info_operation.schema.json +142 -0
  9. package/dist/schemas/local_mark_operation.schema.json +119 -0
  10. package/dist/schemas/machineNode2file.schema.json +71 -0
  11. package/dist/schemas/messenger_operation.schema.json +1393 -0
  12. package/dist/schemas/onchain_events.schema.json +113 -0
  13. package/dist/schemas/onchain_operations.schema.json +376 -0
  14. package/dist/schemas/onchain_operations_allocation.schema.json +914 -0
  15. package/dist/schemas/onchain_operations_arbitration.schema.json +1166 -0
  16. package/dist/schemas/onchain_operations_contact.schema.json +853 -0
  17. package/dist/schemas/onchain_operations_demand.schema.json +984 -0
  18. package/dist/schemas/onchain_operations_gen_passport.schema.json +1141 -0
  19. package/dist/schemas/onchain_operations_guard.schema.json +713 -0
  20. package/dist/schemas/onchain_operations_machine.schema.json +1347 -0
  21. package/dist/schemas/onchain_operations_order.schema.json +830 -0
  22. package/dist/schemas/onchain_operations_payment.schema.json +717 -0
  23. package/dist/schemas/onchain_operations_permission.schema.json +1088 -0
  24. package/dist/schemas/onchain_operations_personal.schema.json +1282 -0
  25. package/dist/schemas/onchain_operations_progress.schema.json +751 -0
  26. package/dist/schemas/onchain_operations_repository.schema.json +1572 -0
  27. package/dist/schemas/onchain_operations_reward.schema.json +955 -0
  28. package/dist/schemas/onchain_operations_service.schema.json +1411 -0
  29. package/dist/schemas/onchain_operations_treasury.schema.json +1155 -0
  30. package/dist/schemas/onchain_table_data.schema.json +35 -0
  31. package/dist/schemas/operations/guard.json +163 -0
  32. package/dist/schemas/operations/permission.json +22 -0
  33. package/dist/schemas/query_toolkit.schema.json +32 -0
  34. package/dist/schemas/schema_query.schema.json +33 -0
  35. package/dist/schemas/wip_file.schema.json +27 -0
  36. package/dist/schemas/wowok_buildin_info.schema.json +487 -0
  37. package/package.json +8 -5
package/dist/index.d.ts CHANGED
@@ -15642,6 +15642,15 @@ declare const WatchQueryOperationsSchema: z.ZodEffects<z.ZodUnion<[z.ZodDiscrimi
15642
15642
  cursor?: string | null | undefined;
15643
15643
  limit?: number | null | undefined;
15644
15644
  } | undefined;
15645
+ }>, z.ZodObject<{
15646
+ query_type: z.ZodLiteral<"local_names">;
15647
+ addresses: z.ZodArray<z.ZodString, "many">;
15648
+ }, "strip", z.ZodTypeAny, {
15649
+ query_type: "local_names";
15650
+ addresses: string[];
15651
+ }, {
15652
+ query_type: "local_names";
15653
+ addresses: string[];
15645
15654
  }>]>, z.ZodDiscriminatedUnion<"query_type", [z.ZodObject<{
15646
15655
  query_type: z.ZodLiteral<"onchain_personal_profile">;
15647
15656
  account: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
@@ -15775,6 +15784,9 @@ declare const WatchQueryOperationsSchema: z.ZodEffects<z.ZodUnion<[z.ZodDiscrimi
15775
15784
  cursor?: string | null | undefined;
15776
15785
  limit?: number | null | undefined;
15777
15786
  } | undefined;
15787
+ } | {
15788
+ query_type: "local_names";
15789
+ addresses: string[];
15778
15790
  } | {
15779
15791
  query_type: "onchain_personal_profile";
15780
15792
  no_cache?: boolean | undefined;
package/dist/index.js CHANGED
@@ -6,7 +6,8 @@ import { readFileSync } from "fs";
6
6
  import { resolve } from "path";
7
7
  const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
8
8
  import { CallService_DataSchema, CallMachine_DataSchema, MachineNode2File_InputSchema, MachineNode2File_OutputWrappedSchema, CallProgress_DataSchema, CallPermission_DataSchema, CallGuard_DataSchema, Guard2File_InputSchema, Guard2File_OutputWrappedSchema, CallArbitration_DataSchema, CallRepository_DataSchema, CallContact_DataSchema, CallTreasury_DataSchema, CallReward_DataSchema, CallAllocation_DataSchema, CallPersonal_DataSchema, CallPayment_DataSchema, CallDemand_DataSchema, CallOrder_DataSchema, CallEnvSchema, SubmissionCallSchema, strictParse, CallOutputSchema, handleCallResult, createServerConfig, createCapabilitiesConfig, createToolMeta, transformSubmission, getEnvConfig, WipGenerationOptionsSchema, WipToHtmlOptionsSchema, TokenDataFilterSchema, LocalInfoFilterSchema, LocalMarkFilterSchema, AccountFilterSchema, TokenTypeSchema, OnchainEventsInputSchema, OnchainEventsResultSchema, ProtocolInfoQuerySchema, ProtocolInfoResultSchema, TableAnswerSchema, TableItem_RepositoryDataSchema, TableItem_PermissionPermSchema, TableItem_EntityRegistrarSchema, TableItem_EntityLinkerSchema, TableItem_RewardRecordSchema, TableItem_DemandPresenterSchema, TableItem_TreasuryHistorySchema, TableItem_MachineNodeSchema, TableItem_ProgressHistorySchema, TableItem_AddressMarkSchema, NameOrAddressSchema, ObjectBaseSchema, AccountOrMark_AddressSchema, AccountOrMark_AddressAISchema, EntrypointSchema, AccountOperationOutputWrappedSchema, LocalMarkOperationOutputWrappedSchema, LocalInfoOperationOutputWrappedSchema, WipOperationOutputSchema, MessengerOperationOutputSchema, AccountOperationSchema, LocalMarkOperationSchema, LocalInfoOperationSchema, parseMachineNodesFromText, formatNodeErrors as formatMachineNodeErrors, MessengerOperationInputSchema, } from "./schema/index.js";
9
- import { CallService, CallMachine, CallProgress, CallPermission, CallGuard, CallArbitration, CallRepository, CallContact, CallTreasury, CallReward, CallAllocation, CallPersonal, CallPayment, CallDemand, CallOrder, gen_passport, guard2file, parseGuardFile, formatGuardParseErrors, machineNode2file, generateNodeComments, generate_wip, verify_wip, sign_wip, wip2html, account_operation, local_mark_operation, local_info_operation, watch_conversations, send_message, send_file, watch_messages, extract_zip_messages, generate_wts, verify_wts, sign_wts, wts2html, proof_message, mark_messages_as_viewed, mark_conversation_as_viewed, query_local_mark_list, query_account_list, query_local_info_list, query_local_token_list, query_account, query_personal, query_objects, query_table, query_tableItem, queryProtocolInfo, query_received, queryTableItem_RepositoryData, queryTableItem_PermissionPerm, queryTableItem_RewardRecord, queryTableItem_DemandPresenter, queryTableItem_TreasuryHistory, queryTableItem_MachineNode, queryTableItem_ProgressHistory, queryTableItem_AddressMark, queryTableItem_EntityRegistrar, queryTableItem_EntityLinker, query_events, blacklist, friendslist, guardlist, settings, AmountType, } from "@wowok/wowok";
9
+ import { CallService, CallMachine, CallProgress, CallPermission, CallGuard, CallArbitration, CallRepository, CallContact, CallTreasury, CallReward, CallAllocation, CallPersonal, CallPayment, CallDemand, CallOrder, gen_passport, guard2file, parseGuardFile, formatGuardParseErrors, machineNode2file, generateNodeComments, generate_wip, verify_wip, sign_wip, wip2html, account_operation, local_mark_operation, local_info_operation, watch_conversations, send_message, send_file, watch_messages, extract_zip_messages, generate_wts, verify_wts, sign_wts, wts2html, proof_message, mark_messages_as_viewed, mark_conversation_as_viewed, query_local_mark_list, query_account_list, query_local_info_list, query_local_token_list, query_account, GetLocalNamesByAddresses, query_personal, query_objects, query_table, query_tableItem, queryProtocolInfo, query_received, queryTableItem_RepositoryData, queryTableItem_PermissionPerm, queryTableItem_RewardRecord, queryTableItem_DemandPresenter, queryTableItem_TreasuryHistory, queryTableItem_MachineNode, queryTableItem_ProgressHistory, queryTableItem_AddressMark, queryTableItem_EntityRegistrar, queryTableItem_EntityLinker, query_events, blacklist, friendslist, guardlist, settings, AmountType, } from "@wowok/wowok";
10
+ import { areSchemasAvailable, getSchemaIndex, processSchemaQuery, } from "./schema-query/index.js";
10
11
  const SERVER_DESCRIPTION = `WoWok MCP Server - Making It Easy for AI Agents to Communicate, Collaborate, Trade, and Trust.
11
12
 
12
13
  ## Token System Overview
@@ -576,6 +577,10 @@ const WatchQueryOperationsSchema = z.preprocess((input) => {
576
577
  token_type: TokenTypeSchema.optional().describe("Token type to query; defaults to 0x2::wow::WOW (platform token)"),
577
578
  network: EntrypointSchema.optional(),
578
579
  }).describe("Query an account's coin balance OR paginated coin objects. Use balance=true for total amount, or coin={cursor,limit} to list individual coin objects. Returns: { address, balance? | coin? }"),
580
+ z.object({
581
+ query_type: z.literal("local_names"),
582
+ addresses: z.array(z.string()).describe("Array of addresses to look up local names for"),
583
+ }).describe("Query local names (account name and local mark name) for a list of addresses. Returns array of: { account?: string, local_mark?: string, address: string }"),
579
584
  ]),
580
585
  z.discriminatedUnion("query_type", [
581
586
  z.object({
@@ -1000,6 +1005,11 @@ async function handleWatchQueryOperations(args) {
1000
1005
  result = { query_type: "account_balance", result: queryResult };
1001
1006
  break;
1002
1007
  }
1008
+ case "local_names": {
1009
+ const queryResult = await GetLocalNamesByAddresses(validated.addresses);
1010
+ result = { query_type: "local_names", result: queryResult };
1011
+ break;
1012
+ }
1003
1013
  case "onchain_personal_profile": {
1004
1014
  const queryResult = await query_personal({ account: validated.account, no_cache: validated.no_cache, network: validated.network });
1005
1015
  result = { query_type: "onchain_personal_profile", result: queryResult };
@@ -1040,7 +1050,7 @@ async function handleWatchQueryOperations(args) {
1040
1050
  break;
1041
1051
  }
1042
1052
  default:
1043
- throw new Error(`Unknown query type. Valid query_types are: "local_mark_list", "account_list", "local_info_list", "token_list", "account_balance", "onchain_personal_profile", "onchain_objects", "onchain_received". For table queries, use the "onchain_table_data" tool.`);
1053
+ throw new Error(`Unknown query type. Valid query_types are: "local_mark_list", "account_list", "local_info_list", "token_list", "account_balance", "local_names", "onchain_personal_profile", "onchain_objects", "onchain_received". For table queries, use the "onchain_table_data" tool.`);
1044
1054
  }
1045
1055
  return {
1046
1056
  content: [{ type: "text", text: JSON.stringify({ result }) }],
@@ -1296,6 +1306,15 @@ async function handleMachineNode2File(args) {
1296
1306
  }
1297
1307
  export { OnchainOperationsSchema, WipOperationsSchema, WatchQueryOperationsSchema, AccountOperationSchema, LocalMarkOperationSchema, LocalInfoOperationSchema, ProtocolInfoQuerySchema, CallOutputSchema, MessengerOperationInputSchema, MessengerOperationOutputSchema };
1298
1308
  async function main() {
1309
+ if (areSchemasAvailable()) {
1310
+ const index = getSchemaIndex();
1311
+ if (index) {
1312
+ console.error(`Schema system ready: ${index.tools?.length || 0} tools, ${index.operations?.length || 0} operations`);
1313
+ }
1314
+ }
1315
+ else {
1316
+ console.error("Schema files not available. Run 'npm run generate:schemas' to generate them.");
1317
+ }
1299
1318
  server.registerTool("onchain_operations", {
1300
1319
  title: "⛓️ On-chain Operations",
1301
1320
  description: "On-chain operations for WoWok object: service (marketplace listings), machine (workflow templates), progress (order tracking), repository (on-chain database), arbitration (dispute resolution), contact (IM management), treasury (team funds), reward (incentive pools), allocation (auto-distribution), permission (access control), guard (programmable trust rules), personal (public profile), payment (direct coin transfers), demand (service requests), order (order management), gen_passport (verified credentials).",
@@ -1364,17 +1383,18 @@ async function main() {
1364
1383
  }, handleMachineNode2File);
1365
1384
  server.registerTool("query_toolkit", {
1366
1385
  title: "🔍 Data Query Toolkit",
1367
- description: "WOWOK data query toolkit — 8 query types covering local device data and on-chain blockchain data:\n\n"
1386
+ description: "WOWOK data query toolkit — 9 query types covering local device data and on-chain blockchain data:\n\n"
1368
1387
  + "LOCAL (device-only, never on-chain):\n"
1369
1388
  + "1. local_mark_list — Query your LOCAL address book: maps human-readable names to blockchain addresses with optional tags. Use to resolve names→addresses or find addresses by tag.\n"
1370
1389
  + "2. account_list — Query your LOCAL accounts: view all accounts stored on this device (addresses, public keys, messenger status, suspension state). Use to discover available accounts before operations.\n"
1371
1390
  + "3. local_info_list — Query your LOCAL private info: sensitive data like delivery addresses, phone numbers, contacts stored ONLY on this device.\n"
1372
1391
  + "4. token_list — Query cached token metadata: symbol, decimals, icon URL, description for tokens previously fetched from chain. Use to look up token precision/decimals before performing token operations. Returns: TokenTypeInfo[] (type, alias, name, symbol, decimals, iconUrl).\n"
1373
- + "5. account_balance — Query an account's coin balance OR paginated coin objects. Use balance=true for total amount, or coin={cursor,limit} to list individual coin objects. Supports multi-token via token_type parameter.\n\n"
1392
+ + "5. account_balance — Query an account's coin balance OR paginated coin objects. Use balance=true for total amount, or coin={cursor,limit} to list individual coin objects. Supports multi-token via token_type parameter.\n"
1393
+ + "6. local_names — Query local names by a list of addresses. For each address, returns the resolved account name (if exists) and local mark name (if exists). Returns: { account?, local_mark?, address }[].\n\n"
1374
1394
  + "ONCHAIN (blockchain):\n"
1375
- + "6. onchain_personal_profile — Query any user's PUBLIC on-chain profile: social links, reputation (likes/dislikes), personal info records, voting history, referrer.\n"
1376
- + "7. onchain_objects — Batch query on-chain WOWOK objects by ID or name: supports Service, Machine, Order, Treasury, Reward, Arb, Personal, Contact, and more.\n"
1377
- + "8. onchain_received — Query objects (Payments, Tokens, NFTs) received by a specific object. Supports pagination and all_type filter.\n\n"
1395
+ + "7. onchain_personal_profile — Query any user's PUBLIC on-chain profile: social links, reputation (likes/dislikes), personal info records, voting history, referrer.\n"
1396
+ + "8. onchain_objects — Batch query on-chain WOWOK objects by ID or name: supports Service, Machine, Order, Treasury, Reward, Arb, Personal, Contact, and more.\n"
1397
+ + "9. onchain_received — Query objects (Payments, Tokens, NFTs) received by a specific object. Supports pagination and all_type filter.\n\n"
1378
1398
  + "For dynamic table data queries (pagination, table items), use the 'onchain_table_data' tool.",
1379
1399
  inputSchema: WatchQueryOperationsSchema,
1380
1400
  outputSchema: z.object({
@@ -1419,54 +1439,85 @@ async function main() {
1419
1439
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
1420
1440
  _meta: createToolMeta("WoWok info", ["build-in", "constants", "permissions", "guard", "network", "value-types"]),
1421
1441
  }, handleWowokInfo);
1422
- server.registerTool("documents_and_learn", {
1423
- title: "📚 Documents and Learn",
1424
- description: "Access WoWok documentation and learning resources. Provides official documentation URL for users and AI to get more information about WoWok protocol, components, and usage.",
1442
+ server.registerTool("schema_query", {
1443
+ title: "📋 Schema Query",
1444
+ description: "Query JSON schemas for all WoWok MCP tools and operations. Use this tool to understand the exact structure required for calling other tools. Returns complete JSON Schema definitions with all properties, types, and descriptions. This is the authoritative source for tool schemas.",
1425
1445
  inputSchema: z.object({
1426
- topic: z.string().optional().describe("Optional topic to search for in documentation (e.g., 'guard', 'service', 'messenger', 'stage-01-introduction')"),
1446
+ action: z.enum(["list", "get", "search", "list_operations"])
1447
+ .describe("Action to perform: 'list' to see all available schemas, 'get' to retrieve a specific schema, 'search' to find schemas by keyword, 'list_operations' to list all on-chain operations"),
1448
+ name: z.string().optional().describe("Schema name for 'get' action (e.g., 'onchain_operations', 'account_operation', 'onchain_operations_permission')"),
1449
+ query: z.string().optional().describe("Search query for 'search' action"),
1427
1450
  }),
1428
1451
  outputSchema: z.object({
1429
- documentation_url: z.string().describe("Official WoWok documentation URL on GitHub"),
1430
- topic: z.string().optional().describe("Requested topic if specified"),
1431
- original_topic: z.string().optional().describe("Original topic input by user (before normalization)"),
1432
- message: z.string().describe("Welcome message with documentation information. Always included in response."),
1452
+ success: z.boolean().describe("Whether the request was successful"),
1453
+ action: z.string().describe("The action that was performed"),
1454
+ data: z.any().describe("Response data - JSON Schema object for 'get', array of schema info for 'list'/'search'/'list_operations'"),
1455
+ message: z.string().describe("Human-readable message describing the result"),
1456
+ suggestions: z.array(z.string()).optional().describe("Suggested next steps or alternatives"),
1433
1457
  }),
1434
- annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
1435
- _meta: createToolMeta("documentation", ["docs", "learn", "tutorial", "guide", "help", "reference"]),
1458
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
1459
+ _meta: createToolMeta("schema", ["schema", "json-schema", "types", "structure", "validation", "reference"]),
1436
1460
  }, async (args) => {
1437
- const GITHUB_BASE_URL = "https://github.com/wowok-ai/docs/blob/main/docs";
1438
- if (!args.topic) {
1439
- const url = GITHUB_BASE_URL;
1440
- const message = `Welcome to WoWok Documentation! Access comprehensive guides, tutorials, and API references at: ${url}`;
1441
- return {
1442
- content: [
1443
- {
1444
- type: "text",
1445
- text: message,
1446
- },
1447
- ],
1448
- structuredContent: {
1449
- documentation_url: url,
1450
- message: message,
1451
- },
1452
- };
1461
+ const request = {
1462
+ action: args.action,
1463
+ name: args.name,
1464
+ query: args.query,
1465
+ };
1466
+ const response = processSchemaQuery(request);
1467
+ let textContent = response.message;
1468
+ const data = response.data;
1469
+ if (response.success && data) {
1470
+ switch (args.action) {
1471
+ case "list":
1472
+ case "list_operations":
1473
+ if (Array.isArray(data) && data.length > 0) {
1474
+ textContent += "\n\nAvailable schemas:\n";
1475
+ for (const item of data) {
1476
+ textContent += `\n • ${item.name}`;
1477
+ if (item.title) {
1478
+ textContent += ` - ${item.title}`;
1479
+ }
1480
+ if (item.description) {
1481
+ textContent += `\n ${item.description.slice(0, 100)}...`;
1482
+ }
1483
+ textContent += "\n";
1484
+ }
1485
+ }
1486
+ break;
1487
+ case "get":
1488
+ if (data) {
1489
+ textContent += "\n\n## JSON Schema\n\n";
1490
+ textContent += "```json\n";
1491
+ textContent += JSON.stringify(data, null, 2);
1492
+ textContent += "\n```\n";
1493
+ }
1494
+ break;
1495
+ case "search":
1496
+ if (Array.isArray(data) && data.length > 0) {
1497
+ textContent += `\n\nFound ${data.length} schemas matching '${args.query}':\n`;
1498
+ for (const item of data) {
1499
+ textContent += `\n • ${item.name}`;
1500
+ if (item.title) {
1501
+ textContent += ` - ${item.title}`;
1502
+ }
1503
+ textContent += "\n";
1504
+ }
1505
+ }
1506
+ break;
1507
+ }
1508
+ }
1509
+ if (response.suggestions && response.suggestions.length > 0) {
1510
+ textContent += "\n\n💡 Suggestions:\n";
1511
+ for (const suggestion of response.suggestions) {
1512
+ textContent += ` • ${suggestion}\n`;
1513
+ }
1453
1514
  }
1454
- const normalizedTopic = args.topic.toLowerCase().trim();
1455
- const url = `${GITHUB_BASE_URL}/${normalizedTopic}.md`;
1456
- const message = `Documentation for "${normalizedTopic}"\nGitHub URL: ${url}`;
1457
1515
  return {
1458
- content: [
1459
- {
1516
+ content: [{
1460
1517
  type: "text",
1461
- text: message,
1462
- },
1463
- ],
1464
- structuredContent: {
1465
- documentation_url: url,
1466
- topic: normalizedTopic,
1467
- original_topic: args.topic,
1468
- message: message,
1469
- },
1518
+ text: textContent,
1519
+ }],
1520
+ structuredContent: response,
1470
1521
  };
1471
1522
  });
1472
1523
  const transport = new StdioServerTransport();
@@ -0,0 +1,29 @@
1
+ export interface SchemaInfo {
2
+ name: string;
3
+ title: string;
4
+ description?: string;
5
+ path: string;
6
+ }
7
+ export interface SchemaQueryRequest {
8
+ action: "list" | "get" | "search" | "list_operations";
9
+ name?: string;
10
+ query?: string;
11
+ }
12
+ export interface SchemaQueryResponse {
13
+ [key: string]: unknown;
14
+ success: boolean;
15
+ action: string;
16
+ data: any;
17
+ message: string;
18
+ suggestions?: string[];
19
+ }
20
+ export declare function areSchemasAvailable(): boolean;
21
+ export declare function getSchemaIndex(): {
22
+ tools: SchemaInfo[];
23
+ operations: SchemaInfo[];
24
+ } | null;
25
+ export declare function listSchemas(): SchemaInfo[];
26
+ export declare function getSchema(name: string): any | null;
27
+ export declare function searchSchemas(query: string): SchemaInfo[];
28
+ export declare function listOperations(): SchemaInfo[];
29
+ export declare function processSchemaQuery(request: SchemaQueryRequest): SchemaQueryResponse;
@@ -0,0 +1,149 @@
1
+ import { readFileSync, existsSync } from "fs";
2
+ import { resolve, join } from "path";
3
+ import { fileURLToPath } from "url";
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = fileURLToPath(new URL(".", import.meta.url));
6
+ const SCHEMAS_DIR = resolve(__dirname, "../../dist/schemas");
7
+ export function areSchemasAvailable() {
8
+ return existsSync(SCHEMAS_DIR) && existsSync(join(SCHEMAS_DIR, "index.json"));
9
+ }
10
+ export function getSchemaIndex() {
11
+ try {
12
+ const indexPath = join(SCHEMAS_DIR, "index.json");
13
+ if (!existsSync(indexPath))
14
+ return null;
15
+ const content = readFileSync(indexPath, "utf-8");
16
+ return JSON.parse(content);
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ export function listSchemas() {
23
+ const index = getSchemaIndex();
24
+ if (!index)
25
+ return [];
26
+ return [
27
+ ...(index.tools || []),
28
+ ...(index.operations || []),
29
+ ];
30
+ }
31
+ export function getSchema(name) {
32
+ try {
33
+ let schemaPath = join(SCHEMAS_DIR, `${name}.schema.json`);
34
+ if (!existsSync(schemaPath)) {
35
+ schemaPath = join(SCHEMAS_DIR, `${name}.json`);
36
+ }
37
+ if (!existsSync(schemaPath)) {
38
+ return null;
39
+ }
40
+ const content = readFileSync(schemaPath, "utf-8");
41
+ return JSON.parse(content);
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ }
47
+ export function searchSchemas(query) {
48
+ const allSchemas = listSchemas();
49
+ const lowerQuery = query.toLowerCase();
50
+ return allSchemas.filter(schema => {
51
+ const nameMatch = schema.name.toLowerCase().includes(lowerQuery);
52
+ const titleMatch = schema.title?.toLowerCase().includes(lowerQuery);
53
+ const descMatch = schema.description?.toLowerCase().includes(lowerQuery);
54
+ return nameMatch || titleMatch || descMatch;
55
+ });
56
+ }
57
+ export function listOperations() {
58
+ const index = getSchemaIndex();
59
+ if (!index)
60
+ return [];
61
+ return (index.operations || []).filter(op => op.name.startsWith("onchain_operations_"));
62
+ }
63
+ export function processSchemaQuery(request) {
64
+ const { action, name, query } = request;
65
+ if (!areSchemasAvailable()) {
66
+ return {
67
+ success: false,
68
+ action,
69
+ data: null,
70
+ message: "Schema files are not available. Please run 'npm run generate:schemas' first.",
71
+ suggestions: ["Run 'npm run generate:schemas' to generate schema files", "Ensure the dist/schemas directory exists"],
72
+ };
73
+ }
74
+ switch (action) {
75
+ case "list": {
76
+ const schemas = listSchemas();
77
+ return {
78
+ success: true,
79
+ action,
80
+ data: schemas,
81
+ message: `Found ${schemas.length} available schemas`,
82
+ };
83
+ }
84
+ case "get": {
85
+ if (!name) {
86
+ return {
87
+ success: false,
88
+ action,
89
+ data: null,
90
+ message: "Schema name is required for 'get' action",
91
+ suggestions: ["Provide a schema name", "Use 'list' action to see available schemas"],
92
+ };
93
+ }
94
+ const schema = getSchema(name);
95
+ if (!schema) {
96
+ const suggestions = searchSchemas(name).slice(0, 5);
97
+ return {
98
+ success: false,
99
+ action,
100
+ data: null,
101
+ message: `Schema '${name}' not found`,
102
+ suggestions: suggestions.length > 0
103
+ ? suggestions.map(s => `Did you mean: ${s.name}?`)
104
+ : ["Use 'list' action to see available schemas"],
105
+ };
106
+ }
107
+ return {
108
+ success: true,
109
+ action,
110
+ data: schema,
111
+ message: `Retrieved schema: ${name}`,
112
+ };
113
+ }
114
+ case "search": {
115
+ if (!query) {
116
+ return {
117
+ success: false,
118
+ action,
119
+ data: null,
120
+ message: "Search query is required for 'search' action",
121
+ };
122
+ }
123
+ const results = searchSchemas(query);
124
+ return {
125
+ success: true,
126
+ action,
127
+ data: results,
128
+ message: `Found ${results.length} schemas matching '${query}'`,
129
+ };
130
+ }
131
+ case "list_operations": {
132
+ const operations = listOperations();
133
+ return {
134
+ success: true,
135
+ action,
136
+ data: operations,
137
+ message: `Found ${operations.length} on-chain operations`,
138
+ };
139
+ }
140
+ default:
141
+ return {
142
+ success: false,
143
+ action,
144
+ data: null,
145
+ message: `Unknown action: ${action}`,
146
+ suggestions: ["Use 'list', 'get', 'search', or 'list_operations'"],
147
+ };
148
+ }
149
+ }