@salesforce/magen-mcp-workflow 0.0.1

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 (134) hide show
  1. package/README.md +168 -0
  2. package/dist/checkpointing/index.d.ts +3 -0
  3. package/dist/checkpointing/index.js +10 -0
  4. package/dist/checkpointing/index.js.map +1 -0
  5. package/dist/checkpointing/jsonCheckpointer.d.ts +19 -0
  6. package/dist/checkpointing/jsonCheckpointer.js +164 -0
  7. package/dist/checkpointing/jsonCheckpointer.js.map +1 -0
  8. package/dist/checkpointing/statePersistence.d.ts +26 -0
  9. package/dist/checkpointing/statePersistence.js +117 -0
  10. package/dist/checkpointing/statePersistence.js.map +1 -0
  11. package/dist/checkpointing/workflowStateManager.d.ts +99 -0
  12. package/dist/checkpointing/workflowStateManager.js +206 -0
  13. package/dist/checkpointing/workflowStateManager.js.map +1 -0
  14. package/dist/common/fileSystem.d.ts +113 -0
  15. package/dist/common/fileSystem.js +62 -0
  16. package/dist/common/fileSystem.js.map +1 -0
  17. package/dist/common/metadata.d.ts +93 -0
  18. package/dist/common/metadata.js +40 -0
  19. package/dist/common/metadata.js.map +1 -0
  20. package/dist/common/propertyMetadata.d.ts +58 -0
  21. package/dist/common/propertyMetadata.js +8 -0
  22. package/dist/common/propertyMetadata.js.map +1 -0
  23. package/dist/common/types.d.ts +16 -0
  24. package/dist/common/types.js +8 -0
  25. package/dist/common/types.js.map +1 -0
  26. package/dist/index.d.ts +15 -0
  27. package/dist/index.js +37 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/logging/logger.d.ts +56 -0
  30. package/dist/logging/logger.js +113 -0
  31. package/dist/logging/logger.js.map +1 -0
  32. package/dist/nodes/abstractBaseNode.d.ts +27 -0
  33. package/dist/nodes/abstractBaseNode.js +34 -0
  34. package/dist/nodes/abstractBaseNode.js.map +1 -0
  35. package/dist/nodes/abstractToolNode.d.ts +32 -0
  36. package/dist/nodes/abstractToolNode.js +44 -0
  37. package/dist/nodes/abstractToolNode.js.map +1 -0
  38. package/dist/nodes/getUserInput/factory.d.ts +42 -0
  39. package/dist/nodes/getUserInput/factory.js +64 -0
  40. package/dist/nodes/getUserInput/factory.js.map +1 -0
  41. package/dist/nodes/getUserInput/index.d.ts +2 -0
  42. package/dist/nodes/getUserInput/index.js +3 -0
  43. package/dist/nodes/getUserInput/index.js.map +1 -0
  44. package/dist/nodes/getUserInput/node.d.ts +68 -0
  45. package/dist/nodes/getUserInput/node.js +41 -0
  46. package/dist/nodes/getUserInput/node.js.map +1 -0
  47. package/dist/nodes/index.d.ts +5 -0
  48. package/dist/nodes/index.js +12 -0
  49. package/dist/nodes/index.js.map +1 -0
  50. package/dist/nodes/toolExecutor.d.ts +22 -0
  51. package/dist/nodes/toolExecutor.js +19 -0
  52. package/dist/nodes/toolExecutor.js.map +1 -0
  53. package/dist/nodes/userInputExtraction/factory.d.ts +42 -0
  54. package/dist/nodes/userInputExtraction/factory.js +55 -0
  55. package/dist/nodes/userInputExtraction/factory.js.map +1 -0
  56. package/dist/nodes/userInputExtraction/index.d.ts +2 -0
  57. package/dist/nodes/userInputExtraction/index.js +3 -0
  58. package/dist/nodes/userInputExtraction/index.js.map +1 -0
  59. package/dist/nodes/userInputExtraction/node.d.ts +60 -0
  60. package/dist/nodes/userInputExtraction/node.js +24 -0
  61. package/dist/nodes/userInputExtraction/node.js.map +1 -0
  62. package/dist/routers/checkPropertiesFulfilledRouter.d.ts +74 -0
  63. package/dist/routers/checkPropertiesFulfilledRouter.js +106 -0
  64. package/dist/routers/checkPropertiesFulfilledRouter.js.map +1 -0
  65. package/dist/routers/index.d.ts +1 -0
  66. package/dist/routers/index.js +8 -0
  67. package/dist/routers/index.js.map +1 -0
  68. package/dist/services/abstractService.d.ts +71 -0
  69. package/dist/services/abstractService.js +83 -0
  70. package/dist/services/abstractService.js.map +1 -0
  71. package/dist/services/getInputService.d.ts +43 -0
  72. package/dist/services/getInputService.js +48 -0
  73. package/dist/services/getInputService.js.map +1 -0
  74. package/dist/services/index.d.ts +3 -0
  75. package/dist/services/index.js +10 -0
  76. package/dist/services/index.js.map +1 -0
  77. package/dist/services/inputExtractionService.d.ts +46 -0
  78. package/dist/services/inputExtractionService.js +133 -0
  79. package/dist/services/inputExtractionService.js.map +1 -0
  80. package/dist/storage/wellKnownDirectory.d.ts +79 -0
  81. package/dist/storage/wellKnownDirectory.js +121 -0
  82. package/dist/storage/wellKnownDirectory.js.map +1 -0
  83. package/dist/tools/base/abstractTool.d.ts +61 -0
  84. package/dist/tools/base/abstractTool.js +87 -0
  85. package/dist/tools/base/abstractTool.js.map +1 -0
  86. package/dist/tools/base/abstractWorkflowTool.d.ts +34 -0
  87. package/dist/tools/base/abstractWorkflowTool.js +94 -0
  88. package/dist/tools/base/abstractWorkflowTool.js.map +1 -0
  89. package/dist/tools/base/index.d.ts +2 -0
  90. package/dist/tools/base/index.js +9 -0
  91. package/dist/tools/base/index.js.map +1 -0
  92. package/dist/tools/orchestrator/config.d.ts +55 -0
  93. package/dist/tools/orchestrator/config.js +8 -0
  94. package/dist/tools/orchestrator/config.js.map +1 -0
  95. package/dist/tools/orchestrator/index.d.ts +3 -0
  96. package/dist/tools/orchestrator/index.js +9 -0
  97. package/dist/tools/orchestrator/index.js.map +1 -0
  98. package/dist/tools/orchestrator/metadata.d.ts +55 -0
  99. package/dist/tools/orchestrator/metadata.js +49 -0
  100. package/dist/tools/orchestrator/metadata.js.map +1 -0
  101. package/dist/tools/orchestrator/orchestratorTool.d.ts +39 -0
  102. package/dist/tools/orchestrator/orchestratorTool.js +186 -0
  103. package/dist/tools/orchestrator/orchestratorTool.js.map +1 -0
  104. package/dist/tools/utilities/getInput/factory.d.ts +43 -0
  105. package/dist/tools/utilities/getInput/factory.js +32 -0
  106. package/dist/tools/utilities/getInput/factory.js.map +1 -0
  107. package/dist/tools/utilities/getInput/index.d.ts +3 -0
  108. package/dist/tools/utilities/getInput/index.js +10 -0
  109. package/dist/tools/utilities/getInput/index.js.map +1 -0
  110. package/dist/tools/utilities/getInput/metadata.d.ts +78 -0
  111. package/dist/tools/utilities/getInput/metadata.js +43 -0
  112. package/dist/tools/utilities/getInput/metadata.js.map +1 -0
  113. package/dist/tools/utilities/getInput/tool.d.ts +89 -0
  114. package/dist/tools/utilities/getInput/tool.js +69 -0
  115. package/dist/tools/utilities/getInput/tool.js.map +1 -0
  116. package/dist/tools/utilities/index.d.ts +2 -0
  117. package/dist/tools/utilities/index.js +9 -0
  118. package/dist/tools/utilities/index.js.map +1 -0
  119. package/dist/tools/utilities/inputExtraction/factory.d.ts +43 -0
  120. package/dist/tools/utilities/inputExtraction/factory.js +32 -0
  121. package/dist/tools/utilities/inputExtraction/factory.js.map +1 -0
  122. package/dist/tools/utilities/inputExtraction/index.d.ts +3 -0
  123. package/dist/tools/utilities/inputExtraction/index.js +10 -0
  124. package/dist/tools/utilities/inputExtraction/index.js.map +1 -0
  125. package/dist/tools/utilities/inputExtraction/metadata.d.ts +66 -0
  126. package/dist/tools/utilities/inputExtraction/metadata.js +52 -0
  127. package/dist/tools/utilities/inputExtraction/metadata.js.map +1 -0
  128. package/dist/tools/utilities/inputExtraction/tool.d.ts +82 -0
  129. package/dist/tools/utilities/inputExtraction/tool.js +71 -0
  130. package/dist/tools/utilities/inputExtraction/tool.js.map +1 -0
  131. package/dist/utils/toolExecutionUtils.d.ts +55 -0
  132. package/dist/utils/toolExecutionUtils.js +70 -0
  133. package/dist/utils/toolExecutionUtils.js.map +1 -0
  134. package/package.json +42 -0
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright (c) 2025, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ import { createInputExtractionMetadata, } from './metadata.js';
8
+ import { AbstractWorkflowTool } from '../../base/abstractWorkflowTool.js';
9
+ export class InputExtractionTool extends AbstractWorkflowTool {
10
+ constructor(server, toolId, orchestratorToolId, logger) {
11
+ super(server, createInputExtractionMetadata(toolId), orchestratorToolId, 'InputExtractionTool', logger);
12
+ }
13
+ handleRequest = async (input) => {
14
+ try {
15
+ const guidance = this.generateInputExtractionGuidance(input);
16
+ return this.finalizeWorkflowToolOutput(guidance, input.workflowStateData, input.resultSchema);
17
+ }
18
+ catch (error) {
19
+ const toolError = error instanceof Error ? error : new Error('Unknown error occurred');
20
+ return {
21
+ isError: true,
22
+ content: [
23
+ {
24
+ type: 'text',
25
+ text: `Error: ${toolError.message}`,
26
+ },
27
+ ],
28
+ };
29
+ }
30
+ };
31
+ generateInputExtractionGuidance(input) {
32
+ return `
33
+ # ROLE
34
+ You are a highly accurate and precise data extraction tool.
35
+
36
+ # TASK
37
+
38
+ Your task is to analyze a user utterance and extract values for a given list of properties.
39
+ For each property you are asked to find, you must provide its extracted value or \`null\`
40
+ if no value is found.
41
+
42
+ ---
43
+ # CONTEXT
44
+
45
+ ## USER UTTERANCE TO ANALYZE
46
+ ${JSON.stringify(input.userUtterance)}
47
+
48
+ ## PROPERTIES TO EXTRACT
49
+ Here is the list of properties you need to find values for. Use each property's description
50
+ to understand what to look for.
51
+
52
+ \`\`\`json
53
+ ${JSON.stringify(input.propertiesToExtract)}
54
+ \`\`\`
55
+
56
+ ---
57
+ # INSTRUCTIONS
58
+ 1. Carefully read the "USER UTTERANCE TO ANALYZE".
59
+ 2. For each property listed in "PROPERTIES TO EXTRACT", search the text for a
60
+ corresponding value.
61
+ 3. If a clear value is found for a property, place it in your output.
62
+ 4. If a property's value is not ABSOLUTELY INFERABLE from USER UTTERANCE TO ANALYZE, you
63
+ MUST use \`null\` as the value for that property. You MAY NOT infer your own property
64
+ values, in the absence of their clear specification in the USER UTTERANCE TO ANALYZE.
65
+ 5. Ensure the keys in your output JSON object exactly match the \`propertyName\` values
66
+ from the input list.
67
+ 6. The exact format of your output object will be given in the section below.
68
+ `;
69
+ }
70
+ }
71
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version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}
@@ -0,0 +1,55 @@
1
+ import z from 'zod';
2
+ import { MCPToolInvocationData } from '../common/metadata.js';
3
+ import { Logger } from '../logging/logger.js';
4
+ import { ToolExecutor } from '../nodes/toolExecutor.js';
5
+ /**
6
+ * Executes a tool with logging and validation.
7
+ *
8
+ * This utility provides a standardized pattern for tool execution that includes:
9
+ * - Pre-execution logging of tool invocation data
10
+ * - Tool execution via the provided executor
11
+ * - Post-execution logging of results
12
+ * - Result validation using Zod schemas
13
+ * - Optional custom validation logic
14
+ *
15
+ * This function is used by both workflow nodes (via AbstractToolNode) and
16
+ * services (via AbstractService) to ensure consistent tool execution patterns
17
+ * across the codebase.
18
+ *
19
+ * @param toolExecutor - The executor to use for running the tool
20
+ * @param logger - Logger instance for recording execution details
21
+ * @param toolInvocationData - The tool invocation data including metadata and input
22
+ * @param resultSchema - Zod schema to validate the result against
23
+ * @param validator - Optional custom validator function for additional validation logic
24
+ * @returns The validated result from the tool execution
25
+ *
26
+ * @throws {z.ZodError} If the result does not match the schema (when using default validation)
27
+ * @throws {Error} If tool execution fails or custom validator throws
28
+ *
29
+ * @example
30
+ * // Basic usage with schema validation
31
+ * const result = executeToolWithLogging(
32
+ * toolExecutor,
33
+ * logger,
34
+ * toolInvocationData,
35
+ * MyToolResultSchema
36
+ * );
37
+ *
38
+ * @example
39
+ * // With custom validator
40
+ * const result = executeToolWithLogging(
41
+ * toolExecutor,
42
+ * logger,
43
+ * toolInvocationData,
44
+ * MyToolResultSchema,
45
+ * (result, schema) => {
46
+ * const validated = schema.parse(result);
47
+ * // Additional custom validation or transformation
48
+ * if (validated.someField < 0) {
49
+ * throw new Error('Value must be positive');
50
+ * }
51
+ * return validated;
52
+ * }
53
+ * );
54
+ */
55
+ export declare function executeToolWithLogging<TResultSchema extends z.ZodObject<z.ZodRawShape>>(toolExecutor: ToolExecutor, logger: Logger, toolInvocationData: MCPToolInvocationData<z.ZodObject<z.ZodRawShape>>, resultSchema: TResultSchema, validator?: (result: unknown, schema: TResultSchema) => z.infer<TResultSchema>): z.infer<TResultSchema>;
@@ -0,0 +1,70 @@
1
+ /*
2
+ * Copyright (c) 2025, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ /**
8
+ * Executes a tool with logging and validation.
9
+ *
10
+ * This utility provides a standardized pattern for tool execution that includes:
11
+ * - Pre-execution logging of tool invocation data
12
+ * - Tool execution via the provided executor
13
+ * - Post-execution logging of results
14
+ * - Result validation using Zod schemas
15
+ * - Optional custom validation logic
16
+ *
17
+ * This function is used by both workflow nodes (via AbstractToolNode) and
18
+ * services (via AbstractService) to ensure consistent tool execution patterns
19
+ * across the codebase.
20
+ *
21
+ * @param toolExecutor - The executor to use for running the tool
22
+ * @param logger - Logger instance for recording execution details
23
+ * @param toolInvocationData - The tool invocation data including metadata and input
24
+ * @param resultSchema - Zod schema to validate the result against
25
+ * @param validator - Optional custom validator function for additional validation logic
26
+ * @returns The validated result from the tool execution
27
+ *
28
+ * @throws {z.ZodError} If the result does not match the schema (when using default validation)
29
+ * @throws {Error} If tool execution fails or custom validator throws
30
+ *
31
+ * @example
32
+ * // Basic usage with schema validation
33
+ * const result = executeToolWithLogging(
34
+ * toolExecutor,
35
+ * logger,
36
+ * toolInvocationData,
37
+ * MyToolResultSchema
38
+ * );
39
+ *
40
+ * @example
41
+ * // With custom validator
42
+ * const result = executeToolWithLogging(
43
+ * toolExecutor,
44
+ * logger,
45
+ * toolInvocationData,
46
+ * MyToolResultSchema,
47
+ * (result, schema) => {
48
+ * const validated = schema.parse(result);
49
+ * // Additional custom validation or transformation
50
+ * if (validated.someField < 0) {
51
+ * throw new Error('Value must be positive');
52
+ * }
53
+ * return validated;
54
+ * }
55
+ * );
56
+ */
57
+ export function executeToolWithLogging(toolExecutor, logger, toolInvocationData, resultSchema, validator) {
58
+ logger.debug('Tool invocation data (pre-execution)', { toolInvocationData });
59
+ const result = toolExecutor.execute(toolInvocationData);
60
+ logger.debug('Tool execution result (post-execution)', { result });
61
+ if (validator) {
62
+ return validator(result, resultSchema);
63
+ }
64
+ else {
65
+ const validatedResult = resultSchema.parse(result);
66
+ logger.debug('Validated tool result', { validatedResult });
67
+ return validatedResult;
68
+ }
69
+ }
70
+ //# sourceMappingURL=toolExecutionUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolExecutionUtils.js","sourceRoot":"","sources":["../../src/utils/toolExecutionUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAA0B,EAC1B,MAAc,EACd,kBAAqE,EACrE,YAA2B,EAC3B,SAA8E;IAE9E,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAE7E,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAExD,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAEnE,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACzC,CAAC;SAAM,CAAC;QACN,MAAM,eAAe,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;QAC3D,OAAO,eAAe,CAAC;IACzB,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@salesforce/magen-mcp-workflow",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "files": [
6
+ "dist",
7
+ "README.md"
8
+ ],
9
+ "description": "MCP Workflow Engine - A framework for building deterministic workflows with LangGraph and Model Context Protocol",
10
+ "license": "MIT",
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "tsc --build",
21
+ "test": "vitest run",
22
+ "test:coverage": "vitest run --coverage",
23
+ "test:watch": "vitest",
24
+ "lint": "eslint --max-warnings 0 --config ../../eslint.config.mjs \"{src,tests}/**/*.ts\"",
25
+ "format": "prettier --write \"{src,tests}/**/*.ts\""
26
+ },
27
+ "dependencies": {
28
+ "@langchain/langgraph": "^0.4.9",
29
+ "@langchain/langgraph-checkpoint": "^0.0.11",
30
+ "@langchain/core": "^0.3.28",
31
+ "@modelcontextprotocol/sdk": "^1.21.1",
32
+ "pino": "^9.9.5",
33
+ "zod": "^3.25.67",
34
+ "zod-to-json-schema": "^3.24.6"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^24.8.1",
38
+ "@vitest/coverage-v8": "^3.2.4",
39
+ "typescript": "^5.9.3",
40
+ "vitest": "^3.2.3"
41
+ }
42
+ }