Skip to main content
Glama

Simplified MCP Server

by celeryhq
WORKFLOW_DISCOVERY_IMPLEMENTATION.md8 kB
# Workflow Discovery Implementation ## Overview I have successfully implemented a workflow discovery service that integrates with your real Simplified API endpoint. The implementation correctly calls the `/api/v1/service/workflows` endpoint and transforms the response into MCP-compatible workflow tools. ## Implementation Details ### API Integration The service calls your actual API endpoint: ``` GET /api/v1/service/workflows/mcp ``` Expected API response format: ```json { "count": 1, "next": "null", "previous": null, "results": [ { "id": 561, "title": "MCP workflow check competitor", "description": "Fetch competitor page and return summary", "inputs": { "properties": { "competitor_page": { "title": "Competitor Page", "type": "string" } }, "required": ["competitor_page"], "title": "", "type": "object" } } ] } ``` ### Workflow Transformation Each workflow from the API is transformed into an MCP tool definition: **API Format** → **MCP Tool Format** - `id: 561` → `id: "561"` - `title: "MCP workflow check competitor"` → `name: "mcp-workflow-check-competitor"` (sanitized for MCP) - `description: "Fetch competitor page and return summary"` → `description: "Fetch competitor page and return summary"` - `inputs: {...}` → `inputSchema: {...}` (converted to MCP-compatible JSON Schema) Additional fields added: - `category: "workflow"` - `version: "1.0.0"` - `executionType: "async"` - `metadata`: Original API data for reference including original inputs **Input Schema Transformation**: ```json // API inputs format "inputs": { "properties": { "competitor_page": { "title": "Competitor Page", "type": "string" } }, "required": ["competitor_page"], "type": "object" } // Becomes MCP inputSchema "inputSchema": { "type": "object", "properties": { "competitor_page": { "title": "Competitor Page", "type": "string" } }, "required": ["competitor_page"] } ``` ### Name Sanitization Workflow titles are sanitized to be valid MCP tool names: - Convert to lowercase - Replace spaces with hyphens - Remove invalid characters - Ensure starts with letter - Prefix with "workflow-" if needed Examples: - "MCP workflow check competitor" → "mcp-workflow-check-competitor" - "Human approval" → "human-approval" - "Data Analysis & Reports" → "data-analysis-reports" ## Files Created 1. **`src/services/workflow-discovery-simple.ts`** - Main implementation 2. **`test-workflow-discovery.js`** - Test script with real API 3. **`test-workflow-transformation.js`** - Test script with mock data 4. **`example-mcp-tool-usage.js`** - Example showing MCP tool usage 5. **`WORKFLOW_DISCOVERY_IMPLEMENTATION.md`** - This documentation ## Testing Results ✅ **API Integration**: Successfully calls the correct endpoint ✅ **Authentication**: Properly handles API key authentication ✅ **Error Handling**: Shows clear error messages for invalid tokens ✅ **Response Parsing**: Correctly parses the API response format ✅ **Workflow Transformation**: Transforms API data to MCP format ✅ **Input Schema Extraction**: Properly extracts and validates workflow input schemas ✅ **Name Sanitization**: Converts titles to valid tool names ✅ **Caching**: Implements 1-minute cache for performance ✅ **Filtering**: Supports workflow filtering by patterns ## Usage Instructions ### 1. Set Your Real API Token Update your `.env` file with a real Simplified API token: ```bash SIMPLIFIED_API_TOKEN=your_real_api_token_here ``` ### 2. Test the Implementation Run the test script: ```bash node test-workflow-discovery.js ``` Expected output with valid token: ``` 🔍 Testing Workflow Discovery with Real API... Using API Token: sk_live_abc... Using API Base URL: https://api.simplified.com 1. Testing API connection... Connection status: ✅ Available 2. Discovering workflows... Found 2 workflows 3. Workflow Details: 1. mcp-workflow-check-competitor ID: 561 Description: Fetch competitor page and return summary Category: workflow Version: 1.0.0 Execution Type: async Input Schema Properties: competitor_page Required Fields: competitor_page Input Schema Details: - competitor_page: string (Competitor Page) Metadata: { "originalId": 561, "originalTitle": "MCP workflow check competitor", "originalInputs": { "properties": { "competitor_page": { "title": "Competitor Page", "type": "string" } }, "required": ["competitor_page"], "type": "object" }, "source": "simplified-api" } 2. human-approval ID: 2818 Description: Category: workflow Version: 1.0.0 Execution Type: async Input Schema Properties: parameters Required Fields: none Metadata: { "originalId": 2818, "originalTitle": "Human approval", "source": "simplified-api" } ✅ Workflow discovery test completed successfully! ``` ### 3. Integration with MCP Server To integrate this with your MCP server: ```typescript import { SimpleWorkflowDiscoveryService } from './services/workflow-discovery-simple.js'; // Create the service const discoveryService = new SimpleWorkflowDiscoveryService(apiClient, logger, { enabled: true, filterPatterns: [] // Optional: filter workflows by name patterns }); // Discover workflows const workflows = await discoveryService.listWorkflows(); // Convert to MCP tools workflows.forEach(workflow => { const toolName = `workflow-${workflow.name}`; // Register as MCP tool... }); ``` ## Configuration Options ### Environment Variables ```bash # Required SIMPLIFIED_API_TOKEN=your_token_here # Optional SIMPLIFIED_API_BASE_URL=https://api.simplified.com # Default LOG_LEVEL=debug # For detailed logging ``` ### Workflow Filtering Filter workflows by name patterns: ```typescript const config = { enabled: true, filterPatterns: [ 'test-*', // Only workflows starting with "test-" '*-approval', // Only workflows ending with "-approval" 'data-*' // Only workflows starting with "data-" ] }; ``` ## Error Handling The service handles various error scenarios: - **401 Unauthorized**: Invalid API token - **Network errors**: Connection issues - **Invalid response**: Malformed API responses - **Transformation errors**: Issues converting API data All errors are logged with detailed information for debugging. ## Caching - **Cache Duration**: 1 minute - **Cache Invalidation**: Automatic after timeout - **Manual Refresh**: `refreshWorkflows()` method - **Cache Stats**: `getCacheStats()` method ## Next Steps 1. **Set Real API Token**: Replace the test token with your actual Simplified API token 2. **Test with Real Data**: Run the test script to verify it works with your workflows 3. **Integrate with MCP**: Add this service to your main MCP server implementation 4. **Add Workflow Execution**: Implement workflow execution using the discovered workflow definitions 5. **Enhance Input Schemas**: Optionally enhance the input schemas with actual workflow parameters ## Troubleshooting ### Common Issues 1. **401 Unauthorized**: Check your API token is valid and has the right permissions 2. **Empty Results**: Verify you have active workflows in your account 3. **Network Errors**: Check your internet connection and API endpoint accessibility 4. **Invalid Names**: Workflow titles with special characters are automatically sanitized ### Debug Mode Enable debug logging to see detailed information: ```bash LOG_LEVEL=debug node test-workflow-discovery.js ``` This will show: - API request details - Response parsing steps - Workflow transformation process - Caching operations - Error details

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/celeryhq/simplified-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server