version mise à jour par claude , à tester
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* Workflow Tools
|
||||
* MCP tools for searching and retrieving workflow information via API
|
||||
*/
|
||||
|
||||
const workflowService = require('../services/workflow-service');
|
||||
|
||||
/**
|
||||
* List available workflow tools
|
||||
*/
|
||||
function listTools() {
|
||||
return [
|
||||
{
|
||||
name: 'search_workflows',
|
||||
description: 'Search workflows by name, description, or code. Returns matching workflows with metadata. Workflows are lazy-loaded from API on first request and cached for 1 hour.',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
query: {
|
||||
type: 'string',
|
||||
description: 'Search query (searches in name, description, code)',
|
||||
},
|
||||
category: {
|
||||
type: 'string',
|
||||
description: 'Filter by workflow category/application',
|
||||
},
|
||||
limit: {
|
||||
type: 'number',
|
||||
description: 'Maximum results to return (default: 50)',
|
||||
default: 50,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'get_workflow_details',
|
||||
description: 'Get full details of a specific workflow by ID or code',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
workflow_id: {
|
||||
type: 'string',
|
||||
description: 'Workflow ID or code',
|
||||
},
|
||||
},
|
||||
required: ['workflow_id'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'list_workflow_categories',
|
||||
description: 'List all available workflow categories',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute workflow tool
|
||||
*/
|
||||
async function executeTool(name, args) {
|
||||
try {
|
||||
switch (name) {
|
||||
case 'search_workflows':
|
||||
return await searchWorkflows(args);
|
||||
|
||||
case 'get_workflow_details':
|
||||
return await getWorkflowDetails(args);
|
||||
|
||||
case 'list_workflow_categories':
|
||||
return await listWorkflowCategories(args);
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown workflow tool: ${name}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[WorkflowTools] Error executing ${name}:`, error.message);
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error: error.message,
|
||||
tool: name
|
||||
}, null, 2)
|
||||
}],
|
||||
isError: true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool: search_workflows
|
||||
*/
|
||||
async function searchWorkflows(args) {
|
||||
const { query, category, limit = 50 } = args;
|
||||
|
||||
console.error(`[WorkflowTools] Searching workflows: query="${query}", category="${category}", limit=${limit}`);
|
||||
|
||||
const results = await workflowService.searchWorkflows(query, category, limit);
|
||||
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
count: results.length,
|
||||
workflows: results.map(w => ({
|
||||
id: w.Id,
|
||||
code: w.Code,
|
||||
name: w.Name,
|
||||
category: w.Category,
|
||||
description: w.Description,
|
||||
version: w.Version,
|
||||
created: w.Created,
|
||||
modified: w.Modified
|
||||
}))
|
||||
}, null, 2)
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool: get_workflow_details
|
||||
*/
|
||||
async function getWorkflowDetails(args) {
|
||||
const { workflow_id } = args;
|
||||
|
||||
console.error(`[WorkflowTools] Getting workflow details: ${workflow_id}`);
|
||||
|
||||
const workflow = await workflowService.getWorkflowDetails(workflow_id);
|
||||
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
workflow
|
||||
}, null, 2)
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool: list_workflow_categories
|
||||
*/
|
||||
async function listWorkflowCategories(args) {
|
||||
console.error('[WorkflowTools] Listing workflow categories');
|
||||
|
||||
const categories = await workflowService.listWorkflowCategories();
|
||||
const stats = await workflowService.getWorkflowStats();
|
||||
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
totalCategories: categories.length,
|
||||
categories,
|
||||
stats: {
|
||||
totalWorkflows: stats.total,
|
||||
categoryCounts: stats.categoryCounts,
|
||||
cacheAge: stats.cacheAge
|
||||
}
|
||||
}, null, 2)
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
listTools,
|
||||
executeTool,
|
||||
};
|
||||
Reference in New Issue
Block a user