n8n-mcp 2.27.1 → 2.28.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.
Files changed (67) hide show
  1. package/README.md +6 -3
  2. package/dist/mcp/handlers-n8n-manager.d.ts +2 -1
  3. package/dist/mcp/handlers-n8n-manager.d.ts.map +1 -1
  4. package/dist/mcp/handlers-n8n-manager.js +212 -62
  5. package/dist/mcp/handlers-n8n-manager.js.map +1 -1
  6. package/dist/mcp/server.js +3 -3
  7. package/dist/mcp/server.js.map +1 -1
  8. package/dist/mcp/tool-docs/index.js +1 -1
  9. package/dist/mcp/tool-docs/index.js.map +1 -1
  10. package/dist/mcp/tool-docs/workflow_management/index.d.ts +1 -1
  11. package/dist/mcp/tool-docs/workflow_management/index.d.ts.map +1 -1
  12. package/dist/mcp/tool-docs/workflow_management/index.js +3 -3
  13. package/dist/mcp/tool-docs/workflow_management/index.js.map +1 -1
  14. package/dist/mcp/tool-docs/workflow_management/n8n-create-workflow.js +2 -2
  15. package/dist/mcp/tool-docs/workflow_management/n8n-create-workflow.js.map +1 -1
  16. package/dist/mcp/tool-docs/workflow_management/n8n-deploy-template.d.ts.map +1 -1
  17. package/dist/mcp/tool-docs/workflow_management/n8n-deploy-template.js +16 -14
  18. package/dist/mcp/tool-docs/workflow_management/n8n-deploy-template.js.map +1 -1
  19. package/dist/mcp/tool-docs/workflow_management/n8n-executions.js +1 -1
  20. package/dist/mcp/tool-docs/workflow_management/n8n-executions.js.map +1 -1
  21. package/dist/mcp/tool-docs/workflow_management/n8n-test-workflow.d.ts +3 -0
  22. package/dist/mcp/tool-docs/workflow_management/n8n-test-workflow.d.ts.map +1 -0
  23. package/dist/mcp/tool-docs/workflow_management/n8n-test-workflow.js +140 -0
  24. package/dist/mcp/tool-docs/workflow_management/n8n-test-workflow.js.map +1 -0
  25. package/dist/mcp/tools-documentation.js +1 -1
  26. package/dist/mcp/tools-n8n-manager.d.ts.map +1 -1
  27. package/dist/mcp/tools-n8n-manager.js +32 -11
  28. package/dist/mcp/tools-n8n-manager.js.map +1 -1
  29. package/dist/services/expression-validator.js +3 -5
  30. package/dist/services/expression-validator.js.map +1 -1
  31. package/dist/triggers/handlers/base-handler.d.ts +21 -0
  32. package/dist/triggers/handlers/base-handler.d.ts.map +1 -0
  33. package/dist/triggers/handlers/base-handler.js +60 -0
  34. package/dist/triggers/handlers/base-handler.js.map +1 -0
  35. package/dist/triggers/handlers/chat-handler.d.ts +38 -0
  36. package/dist/triggers/handlers/chat-handler.d.ts.map +1 -0
  37. package/dist/triggers/handlers/chat-handler.js +129 -0
  38. package/dist/triggers/handlers/chat-handler.js.map +1 -0
  39. package/dist/triggers/handlers/form-handler.d.ts +35 -0
  40. package/dist/triggers/handlers/form-handler.d.ts.map +1 -0
  41. package/dist/triggers/handlers/form-handler.js +113 -0
  42. package/dist/triggers/handlers/form-handler.js.map +1 -0
  43. package/dist/triggers/handlers/webhook-handler.d.ts +38 -0
  44. package/dist/triggers/handlers/webhook-handler.d.ts.map +1 -0
  45. package/dist/triggers/handlers/webhook-handler.js +115 -0
  46. package/dist/triggers/handlers/webhook-handler.js.map +1 -0
  47. package/dist/triggers/index.d.ts +5 -0
  48. package/dist/triggers/index.d.ts.map +1 -0
  49. package/dist/triggers/index.js +14 -0
  50. package/dist/triggers/index.js.map +1 -0
  51. package/dist/triggers/trigger-detector.d.ts +6 -0
  52. package/dist/triggers/trigger-detector.d.ts.map +1 -0
  53. package/dist/triggers/trigger-detector.js +191 -0
  54. package/dist/triggers/trigger-detector.js.map +1 -0
  55. package/dist/triggers/trigger-registry.d.ts +18 -0
  56. package/dist/triggers/trigger-registry.d.ts.map +1 -0
  57. package/dist/triggers/trigger-registry.js +87 -0
  58. package/dist/triggers/trigger-registry.js.map +1 -0
  59. package/dist/triggers/types.d.ts +76 -0
  60. package/dist/triggers/types.d.ts.map +1 -0
  61. package/dist/triggers/types.js +3 -0
  62. package/dist/triggers/types.js.map +1 -0
  63. package/package.json +1 -1
  64. package/dist/mcp/tool-docs/workflow_management/n8n-trigger-webhook-workflow.d.ts +0 -3
  65. package/dist/mcp/tool-docs/workflow_management/n8n-trigger-webhook-workflow.d.ts.map +0 -1
  66. package/dist/mcp/tool-docs/workflow_management/n8n-trigger-webhook-workflow.js +0 -120
  67. package/dist/mcp/tool-docs/workflow_management/n8n-trigger-webhook-workflow.js.map +0 -1
package/README.md CHANGED
@@ -598,7 +598,7 @@ ALWAYS explicitly configure ALL parameters that control node behavior.
598
598
  - `n8n_create_workflow(workflow)` - Deploy
599
599
  - `n8n_validate_workflow({id})` - Post-deployment check
600
600
  - `n8n_update_partial_workflow({id, operations: [...]})` - Batch updates
601
- - `n8n_trigger_webhook_workflow()` - Test webhooks
601
+ - `n8n_test_workflow({workflowId})` - Test workflow execution
602
602
 
603
603
  ## Critical Warnings
604
604
 
@@ -974,10 +974,13 @@ These tools require `N8N_API_URL` and `N8N_API_KEY` in your configuration.
974
974
  - **`n8n_validate_workflow`** - Validate workflows in n8n by ID
975
975
  - **`n8n_autofix_workflow`** - Automatically fix common workflow errors
976
976
  - **`n8n_workflow_versions`** - Manage version history and rollback
977
- - **`n8n_deploy_template`** - Deploy templates from n8n.io directly to your instance (NEW!)
977
+ - **`n8n_deploy_template`** - Deploy templates from n8n.io directly to your instance with auto-fix
978
978
 
979
979
  #### Execution Management
980
- - **`n8n_trigger_webhook_workflow`** - Trigger workflows via webhook URL
980
+ - **`n8n_test_workflow`** - Test/trigger workflow execution:
981
+ - Auto-detects trigger type (webhook, form, chat) from workflow
982
+ - Supports custom data, headers, and HTTP methods for webhooks
983
+ - Chat triggers support message and sessionId for conversations
981
984
  - **`n8n_executions`** - Unified execution management (v2.26.0):
982
985
  - `action: 'list'` - List executions with status filtering
983
986
  - `action: 'get'` - Get execution details by ID
@@ -17,7 +17,7 @@ export declare function handleDeleteWorkflow(args: unknown, context?: InstanceCo
17
17
  export declare function handleListWorkflows(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
18
18
  export declare function handleValidateWorkflow(args: unknown, repository: NodeRepository, context?: InstanceContext): Promise<McpToolResponse>;
19
19
  export declare function handleAutofixWorkflow(args: unknown, repository: NodeRepository, context?: InstanceContext): Promise<McpToolResponse>;
20
- export declare function handleTriggerWebhookWorkflow(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
20
+ export declare function handleTestWorkflow(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
21
21
  export declare function handleGetExecution(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
22
22
  export declare function handleListExecutions(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
23
23
  export declare function handleDeleteExecution(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
@@ -25,4 +25,5 @@ export declare function handleHealthCheck(context?: InstanceContext): Promise<Mc
25
25
  export declare function handleDiagnostic(request: any, context?: InstanceContext): Promise<McpToolResponse>;
26
26
  export declare function handleWorkflowVersions(args: unknown, repository: NodeRepository, context?: InstanceContext): Promise<McpToolResponse>;
27
27
  export declare function handleDeployTemplate(args: unknown, templateService: TemplateService, repository: NodeRepository, context?: InstanceContext): Promise<McpToolResponse>;
28
+ export declare function handleTriggerWebhookWorkflow(args: unknown, context?: InstanceContext): Promise<McpToolResponse>;
28
29
  //# sourceMappingURL=handlers-n8n-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handlers-n8n-manager.d.ts","sourceRoot":"","sources":["../../src/mcp/handlers-n8n-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAML,eAAe,EAGhB,MAAM,kBAAkB,CAAC;AAiB1B,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAA2B,MAAM,2BAA2B,CAAC;AAOrF,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AA4LhE,wBAAgB,0BAA0B,IAAI,MAAM,CAEnD;AAMD,wBAAgB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AAoB,CACxC,IAAI,EAAE,OAAO,EACb,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,cAAc,EAC1B,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,eAAe,CAAC,CAoM1B;AAQD,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAyErH"}
@@ -47,7 +47,7 @@ exports.handleDeleteWorkflow = handleDeleteWorkflow;
47
47
  exports.handleListWorkflows = handleListWorkflows;
48
48
  exports.handleValidateWorkflow = handleValidateWorkflow;
49
49
  exports.handleAutofixWorkflow = handleAutofixWorkflow;
50
- exports.handleTriggerWebhookWorkflow = handleTriggerWebhookWorkflow;
50
+ exports.handleTestWorkflow = handleTestWorkflow;
51
51
  exports.handleGetExecution = handleGetExecution;
52
52
  exports.handleListExecutions = handleListExecutions;
53
53
  exports.handleDeleteExecution = handleDeleteExecution;
@@ -55,6 +55,7 @@ exports.handleHealthCheck = handleHealthCheck;
55
55
  exports.handleDiagnostic = handleDiagnostic;
56
56
  exports.handleWorkflowVersions = handleWorkflowVersions;
57
57
  exports.handleDeployTemplate = handleDeployTemplate;
58
+ exports.handleTriggerWebhookWorkflow = handleTriggerWebhookWorkflow;
58
59
  const n8n_api_client_1 = require("../services/n8n-api-client");
59
60
  const n8n_api_1 = require("../config/n8n-api");
60
61
  const n8n_api_2 = require("../types/n8n-api");
@@ -209,16 +210,23 @@ const autofixWorkflowSchema = zod_1.z.object({
209
210
  'typeversion-correction',
210
211
  'error-output-config',
211
212
  'node-type-correction',
212
- 'webhook-missing-path'
213
+ 'webhook-missing-path',
214
+ 'typeversion-upgrade',
215
+ 'version-migration'
213
216
  ])).optional(),
214
217
  confidenceThreshold: zod_1.z.enum(['high', 'medium', 'low']).optional().default('medium'),
215
218
  maxFixes: zod_1.z.number().optional().default(50)
216
219
  });
217
- const triggerWebhookSchema = zod_1.z.object({
218
- webhookUrl: zod_1.z.string().url(),
220
+ const testWorkflowSchema = zod_1.z.object({
221
+ workflowId: zod_1.z.string(),
222
+ triggerType: zod_1.z.enum(['webhook', 'form', 'chat']).optional(),
219
223
  httpMethod: zod_1.z.enum(['GET', 'POST', 'PUT', 'DELETE']).optional(),
224
+ webhookPath: zod_1.z.string().optional(),
225
+ message: zod_1.z.string().optional(),
226
+ sessionId: zod_1.z.string().optional(),
220
227
  data: zod_1.z.record(zod_1.z.unknown()).optional(),
221
228
  headers: zod_1.z.record(zod_1.z.string()).optional(),
229
+ timeout: zod_1.z.number().optional(),
222
230
  waitForResponse: zod_1.z.boolean().optional(),
223
231
  });
224
232
  const listExecutionsSchema = zod_1.z.object({
@@ -870,22 +878,109 @@ async function handleAutofixWorkflow(args, repository, context) {
870
878
  };
871
879
  }
872
880
  }
873
- async function handleTriggerWebhookWorkflow(args, context) {
881
+ async function handleTestWorkflow(args, context) {
874
882
  try {
875
883
  const client = ensureApiConfigured(context);
876
- const input = triggerWebhookSchema.parse(args);
877
- const webhookRequest = {
878
- webhookUrl: input.webhookUrl,
879
- httpMethod: input.httpMethod || 'POST',
884
+ const input = testWorkflowSchema.parse(args);
885
+ const { detectTriggerFromWorkflow, ensureRegistryInitialized, TriggerRegistry, } = await Promise.resolve().then(() => __importStar(require('../triggers')));
886
+ await ensureRegistryInitialized();
887
+ const workflow = await client.getWorkflow(input.workflowId);
888
+ let triggerType = input.triggerType;
889
+ let triggerInfo;
890
+ const detection = detectTriggerFromWorkflow(workflow);
891
+ if (!triggerType) {
892
+ if (detection.detected && detection.trigger) {
893
+ triggerType = detection.trigger.type;
894
+ triggerInfo = detection.trigger;
895
+ }
896
+ else {
897
+ return {
898
+ success: false,
899
+ error: 'Workflow cannot be triggered externally',
900
+ details: {
901
+ workflowId: input.workflowId,
902
+ reason: detection.reason,
903
+ hint: 'Only workflows with webhook, form, or chat triggers can be executed via the API. Add one of these trigger nodes to your workflow.',
904
+ },
905
+ };
906
+ }
907
+ }
908
+ else {
909
+ if (detection.detected && detection.trigger?.type === triggerType) {
910
+ triggerInfo = detection.trigger;
911
+ }
912
+ else if (!detection.detected || detection.trigger?.type !== triggerType) {
913
+ return {
914
+ success: false,
915
+ error: `Workflow does not have a ${triggerType} trigger`,
916
+ details: {
917
+ workflowId: input.workflowId,
918
+ requestedTrigger: triggerType,
919
+ detectedTrigger: detection.trigger?.type || 'none',
920
+ hint: detection.detected
921
+ ? `Workflow has a ${detection.trigger?.type} trigger. Either use that type or omit triggerType for auto-detection.`
922
+ : 'Workflow has no externally-triggerable triggers (webhook, form, or chat).',
923
+ },
924
+ };
925
+ }
926
+ }
927
+ const handler = TriggerRegistry.getHandler(triggerType, client, context);
928
+ if (!handler) {
929
+ return {
930
+ success: false,
931
+ error: `No handler registered for trigger type: ${triggerType}`,
932
+ details: {
933
+ supportedTypes: TriggerRegistry.getRegisteredTypes(),
934
+ },
935
+ };
936
+ }
937
+ if (handler.capabilities.requiresActiveWorkflow && !workflow.active) {
938
+ return {
939
+ success: false,
940
+ error: 'Workflow must be active to trigger via this method',
941
+ details: {
942
+ workflowId: input.workflowId,
943
+ triggerType,
944
+ hint: 'Activate the workflow in n8n using n8n_update_partial_workflow with [{type: "activateWorkflow"}]',
945
+ },
946
+ };
947
+ }
948
+ if (triggerType === 'chat' && !input.message) {
949
+ return {
950
+ success: false,
951
+ error: 'Chat trigger requires a message parameter',
952
+ details: {
953
+ hint: 'Provide message="your message" for chat triggers',
954
+ },
955
+ };
956
+ }
957
+ const triggerInput = {
958
+ workflowId: input.workflowId,
959
+ triggerType,
960
+ httpMethod: input.httpMethod,
961
+ webhookPath: input.webhookPath,
962
+ message: input.message || '',
963
+ sessionId: input.sessionId,
880
964
  data: input.data,
965
+ formData: input.data,
881
966
  headers: input.headers,
882
- waitForResponse: input.waitForResponse ?? true
967
+ timeout: input.timeout,
968
+ waitForResponse: input.waitForResponse,
883
969
  };
884
- const response = await client.triggerWebhook(webhookRequest);
970
+ const response = await handler.execute(triggerInput, workflow, triggerInfo);
885
971
  return {
886
- success: true,
887
- data: response,
888
- message: 'Webhook triggered successfully'
972
+ success: response.success,
973
+ data: response.data,
974
+ message: response.success
975
+ ? `Workflow triggered successfully via ${triggerType}`
976
+ : response.error,
977
+ executionId: response.executionId,
978
+ workflowId: input.workflowId,
979
+ details: {
980
+ triggerType,
981
+ metadata: response.metadata,
982
+ ...(response.details || {}),
983
+ },
889
984
  };
890
985
  }
891
986
  catch (error) {
@@ -893,39 +988,20 @@ async function handleTriggerWebhookWorkflow(args, context) {
893
988
  return {
894
989
  success: false,
895
990
  error: 'Invalid input',
896
- details: { errors: error.errors }
991
+ details: { errors: error.errors },
897
992
  };
898
993
  }
899
994
  if (error instanceof n8n_errors_1.N8nApiError) {
900
- const errorData = error.details;
901
- const executionId = errorData?.executionId || errorData?.id || errorData?.execution?.id;
902
- const workflowId = errorData?.workflowId || errorData?.workflow?.id;
903
- if (executionId) {
904
- return {
905
- success: false,
906
- error: (0, n8n_errors_1.formatExecutionError)(executionId, workflowId),
907
- code: error.code,
908
- executionId,
909
- workflowId: workflowId || undefined
910
- };
911
- }
912
- if (error.code === 'SERVER_ERROR' || error.statusCode && error.statusCode >= 500) {
913
- return {
914
- success: false,
915
- error: (0, n8n_errors_1.formatNoExecutionError)(),
916
- code: error.code
917
- };
918
- }
919
995
  return {
920
996
  success: false,
921
997
  error: (0, n8n_errors_1.getUserFriendlyErrorMessage)(error),
922
998
  code: error.code,
923
- details: error.details
999
+ details: error.details,
924
1000
  };
925
1001
  }
926
1002
  return {
927
1003
  success: false,
928
- error: error instanceof Error ? error.message : 'Unknown error occurred'
1004
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
929
1005
  };
930
1006
  }
931
1007
  }
@@ -1695,7 +1771,7 @@ const deployTemplateSchema = zod_1.z.object({
1695
1771
  templateId: zod_1.z.number().positive().int(),
1696
1772
  name: zod_1.z.string().optional(),
1697
1773
  autoUpgradeVersions: zod_1.z.boolean().default(true),
1698
- validate: zod_1.z.boolean().default(true),
1774
+ autoFix: zod_1.z.boolean().default(true),
1699
1775
  stripCredentials: zod_1.z.boolean().default(true)
1700
1776
  });
1701
1777
  async function handleDeployTemplate(args, templateService, repository, context) {
@@ -1765,29 +1841,6 @@ async function handleDeployTemplate(args, templateService, repository, context)
1765
1841
  }
1766
1842
  }
1767
1843
  }
1768
- if (input.validate) {
1769
- const validator = new workflow_validator_1.WorkflowValidator(repository, enhanced_config_validator_1.EnhancedConfigValidator);
1770
- const validationResult = await validator.validateWorkflow(workflow, {
1771
- validateNodes: true,
1772
- validateConnections: true,
1773
- validateExpressions: true,
1774
- profile: 'runtime'
1775
- });
1776
- if (validationResult.errors.length > 0) {
1777
- return {
1778
- success: false,
1779
- error: 'Workflow validation failed',
1780
- details: {
1781
- errors: validationResult.errors.map(e => ({
1782
- node: e.nodeName,
1783
- message: e.message
1784
- })),
1785
- warnings: validationResult.warnings.length,
1786
- hint: 'Use validate=false to skip validation, or fix the template issues'
1787
- }
1788
- };
1789
- }
1790
- }
1791
1844
  const triggerNode = workflow.nodes.find((n) => n.type?.includes('Trigger') ||
1792
1845
  n.type?.includes('webhook') ||
1793
1846
  n.type === 'n8n-nodes-base.webhook');
@@ -1800,6 +1853,35 @@ async function handleDeployTemplate(args, templateService, repository, context)
1800
1853
  });
1801
1854
  const apiConfig = context ? (0, n8n_api_1.getN8nApiConfigFromContext)(context) : (0, n8n_api_1.getN8nApiConfig)();
1802
1855
  const baseUrl = apiConfig?.baseUrl?.replace('/api/v1', '') || '';
1856
+ let fixesApplied = [];
1857
+ let fixSummary = '';
1858
+ let autoFixStatus = 'skipped';
1859
+ if (input.autoFix) {
1860
+ try {
1861
+ const autofixResult = await handleAutofixWorkflow({
1862
+ id: createdWorkflow.id,
1863
+ applyFixes: true,
1864
+ fixTypes: ['expression-format', 'typeversion-upgrade'],
1865
+ confidenceThreshold: 'medium'
1866
+ }, repository, context);
1867
+ if (autofixResult.success && autofixResult.data) {
1868
+ const fixData = autofixResult.data;
1869
+ autoFixStatus = 'success';
1870
+ if (fixData.fixesApplied && fixData.fixesApplied > 0) {
1871
+ fixesApplied = fixData.fixes || [];
1872
+ fixSummary = ` Auto-fixed ${fixData.fixesApplied} issue(s).`;
1873
+ }
1874
+ }
1875
+ }
1876
+ catch (fixError) {
1877
+ autoFixStatus = 'failed';
1878
+ logger_1.logger.warn('Auto-fix failed after template deployment', {
1879
+ workflowId: createdWorkflow.id,
1880
+ error: fixError instanceof Error ? fixError.message : 'Unknown error'
1881
+ });
1882
+ fixSummary = ' Auto-fix failed (workflow deployed successfully).';
1883
+ }
1884
+ }
1803
1885
  return {
1804
1886
  success: true,
1805
1887
  data: {
@@ -1811,9 +1893,11 @@ async function handleDeployTemplate(args, templateService, repository, context)
1811
1893
  requiredCredentials: requiredCredentials.length > 0 ? requiredCredentials : undefined,
1812
1894
  url: baseUrl ? `${baseUrl}/workflow/${createdWorkflow.id}` : undefined,
1813
1895
  templateId: input.templateId,
1814
- templateUrl: template.url || `https://n8n.io/workflows/${input.templateId}`
1896
+ templateUrl: template.url || `https://n8n.io/workflows/${input.templateId}`,
1897
+ autoFixStatus,
1898
+ fixesApplied: fixesApplied.length > 0 ? fixesApplied : undefined
1815
1899
  },
1816
- message: `Workflow "${createdWorkflow.name}" deployed successfully from template ${input.templateId}. ${requiredCredentials.length > 0
1900
+ message: `Workflow "${createdWorkflow.name}" deployed successfully from template ${input.templateId}.${fixSummary} ${requiredCredentials.length > 0
1817
1901
  ? `Configure ${requiredCredentials.length} credential(s) in n8n to activate.`
1818
1902
  : ''}`
1819
1903
  };
@@ -1840,4 +1924,70 @@ async function handleDeployTemplate(args, templateService, repository, context)
1840
1924
  };
1841
1925
  }
1842
1926
  }
1927
+ async function handleTriggerWebhookWorkflow(args, context) {
1928
+ const triggerWebhookSchema = zod_1.z.object({
1929
+ webhookUrl: zod_1.z.string().url(),
1930
+ httpMethod: zod_1.z.enum(['GET', 'POST', 'PUT', 'DELETE']).optional(),
1931
+ data: zod_1.z.record(zod_1.z.unknown()).optional(),
1932
+ headers: zod_1.z.record(zod_1.z.string()).optional(),
1933
+ waitForResponse: zod_1.z.boolean().optional(),
1934
+ });
1935
+ try {
1936
+ const client = ensureApiConfigured(context);
1937
+ const input = triggerWebhookSchema.parse(args);
1938
+ const webhookRequest = {
1939
+ webhookUrl: input.webhookUrl,
1940
+ httpMethod: input.httpMethod || 'POST',
1941
+ data: input.data,
1942
+ headers: input.headers,
1943
+ waitForResponse: input.waitForResponse ?? true
1944
+ };
1945
+ const response = await client.triggerWebhook(webhookRequest);
1946
+ return {
1947
+ success: true,
1948
+ data: response,
1949
+ message: 'Webhook triggered successfully'
1950
+ };
1951
+ }
1952
+ catch (error) {
1953
+ if (error instanceof zod_1.z.ZodError) {
1954
+ return {
1955
+ success: false,
1956
+ error: 'Invalid input',
1957
+ details: { errors: error.errors }
1958
+ };
1959
+ }
1960
+ if (error instanceof n8n_errors_1.N8nApiError) {
1961
+ const errorData = error.details;
1962
+ const executionId = errorData?.executionId || errorData?.id || errorData?.execution?.id;
1963
+ const workflowId = errorData?.workflowId || errorData?.workflow?.id;
1964
+ if (executionId) {
1965
+ return {
1966
+ success: false,
1967
+ error: (0, n8n_errors_1.formatExecutionError)(executionId, workflowId),
1968
+ code: error.code,
1969
+ executionId,
1970
+ workflowId: workflowId || undefined
1971
+ };
1972
+ }
1973
+ if (error.code === 'SERVER_ERROR' || error.statusCode && error.statusCode >= 500) {
1974
+ return {
1975
+ success: false,
1976
+ error: (0, n8n_errors_1.formatNoExecutionError)(),
1977
+ code: error.code
1978
+ };
1979
+ }
1980
+ return {
1981
+ success: false,
1982
+ error: (0, n8n_errors_1.getUserFriendlyErrorMessage)(error),
1983
+ code: error.code,
1984
+ details: error.details
1985
+ };
1986
+ }
1987
+ return {
1988
+ success: false,
1989
+ error: error instanceof Error ? error.message : 'Unknown error occurred'
1990
+ };
1991
+ }
1992
+ }
1843
1993
  //# sourceMappingURL=handlers-n8n-manager.js.map