@grebyn/toolflow-mcp-server
Version:
MCP server for managing other MCP servers - discover, install, organize into bundles, and automate with workflows. Uses StreamableHTTP transport with dual OAuth/API key authentication.
96 lines (94 loc) • 3.56 kB
JavaScript
/**
* List Workflows Tool
* Search and paginate through workflows with unified scope model
*/
import { ApiClient } from '../../utils/api-client.js';
import { formatEmptyResults, formatPaginationInfo, formatNextSteps, formatTags } from '../shared/formatters.js';
export const listWorkflowsTool = {
name: 'list_workflows',
description: 'Find workflows by searching name, description, and tags. Workflows are saved task recipes with instructions and required MCP servers. Returns your organization\'s workflows only. Supports pagination and full-text search.',
inputSchema: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'Optional search term to find workflows by name, description, or tags. Examples: "deployment", "vercel", "testing", "documentation"'
},
limit: {
type: 'number',
default: 20,
minimum: 1,
maximum: 100,
description: 'Maximum number of workflows to return (1-100, default: 20)'
},
offset: {
type: 'number',
default: 0,
minimum: 0,
description: 'Number of workflows to skip for pagination (default: 0)'
},
}
},
async execute(args, context) {
try {
// Validate user context
if (!context.userId) {
throw new Error('User authentication required');
}
// Set defaults
const query = args.query || '';
const limit = Math.min(args.limit || 20, 100);
const offset = args.offset || 0;
// Use API to search workflows (organization only)
const workflows = await ApiClient.searchWorkflows({
query,
limit,
offset
}, context);
// Handle empty results
if (!workflows || workflows.length === 0) {
return formatEmptyResults({ query }, 'workflows');
}
// Format results
return formatWorkflowsResponse(workflows, { query }, { limit, offset, totalResults: workflows.length });
}
catch (error) {
console.error('Error listing workflows:', error);
return {
content: [{
type: 'text',
text: `❌ Failed to list workflows: ${error instanceof Error ? error.message : 'Unknown error'}`
}]
};
}
}
};
function formatWorkflowsResponse(workflows, searchInfo, pagination) {
const { query } = searchInfo;
let output = '';
// Header
const searchText = query ? ` matching "${query}"` : '';
output = `🔍 Found ${workflows.length} organization workflow${workflows.length === 1 ? '' : 's'}${searchText}:
`;
// Show all workflows (organization only)
workflows.forEach(workflow => {
output += formatWorkflowItem(workflow);
});
// Add pagination info
output += formatPaginationInfo(pagination);
// Add next steps
output += formatNextSteps('workflows');
return {
content: [{
type: 'text',
text: output
}]
};
}
function formatWorkflowItem(workflow) {
const tags = formatTags(workflow.tags);
return `• **${workflow.name}** (ID: ${workflow.id})
${workflow.description}${tags}
`;
}
//# sourceMappingURL=listWorkflows.js.map