mcp-product-manager
Version:
MCP Orchestrator for task and project management with web interface
62 lines • 2.12 kB
JavaScript
// next-action.js - POST /api/orchestrator/next-action
import { Router } from 'express';
import { orchestratorApi } from '../../utils/bashApi.js';
import { success, error, asyncHandler } from '../../utils/response.js';
const router = Router();
// Get next recommended action for an agent
router.post('/api/orchestrator/next-action', asyncHandler(async (req, res) => {
const { project, agent } = req.body;
if (!project || !agent) {
const errorResponse = error('Missing required fields: project, agent', 400);
return res.status(errorResponse.status).json(errorResponse.body);
}
try {
// Call bash API to get next action
const result = await orchestratorApi.getNextAction(project, agent);
// Ensure result is properly parsed
let parsedResult = result;
if (typeof result === 'string') {
try {
parsedResult = JSON.parse(result);
}
catch (e) {
console.error('Failed to parse next action result:', result);
parsedResult = { error: 'Invalid response format', raw: result };
}
}
res.json(success({
project,
agent,
recommendation: parsedResult
}));
}
catch (err) {
console.error('Failed to get next action:', err);
const errorResponse = error('Failed to get next action', 500, {
error: err.message
});
res.status(errorResponse.status).json(errorResponse.body);
}
}));
// MCP tool definition
export const tool = {
name: 'get_next_action',
description: 'Get recommended next action for an agent on a project',
inputSchema: {
type: 'object',
properties: {
project: {
type: 'string',
description: 'Project name'
},
agent: {
type: 'string',
description: 'Agent name/ID'
}
},
required: ['project', 'agent']
}
};
export { router };
export default router;
//# sourceMappingURL=next-action.js.map