@al76/tools-and-spec-workflow-mcp
Version:
MCP server for spec-driven development workflow with real-time web dashboard
125 lines (124 loc) • 5.31 kB
JavaScript
import { ApprovalStorage } from '../dashboard/approval-storage.js';
import { join } from 'path';
import { validateProjectPath } from '../core/path-utils.js';
export const getApprovalStatusTool = {
name: 'get-approval-status',
description: `检查审批请求的当前状态。
# 说明
在 request-approval 后调用以轮询用户决定。继续检查直到状态为 "approved" 或 "needs-revision"。如果需要修订,审查反馈,使用 create-spec-doc 更新文档,然后创建新的审批请求。仅在 "approved" 状态后进入下一阶段。`,
inputSchema: {
type: 'object',
properties: {
projectPath: {
type: 'string',
description: '项目根目录的绝对路径(可选 - 如果未提供将使用上下文)'
},
approvalId: {
type: 'string',
description: '要检查的审批请求ID'
}
},
required: ['approvalId']
}
};
export async function getApprovalStatusHandler(args, context) {
try {
// Use provided projectPath or fall back to context
const projectPath = args.projectPath || context.projectPath;
if (!projectPath) {
return {
success: false,
message: 'Project path is required. Please provide projectPath parameter.'
};
}
// Validate and resolve project path
const validatedProjectPath = await validateProjectPath(projectPath);
const approvalStorage = new ApprovalStorage(validatedProjectPath);
await approvalStorage.start();
const approval = await approvalStorage.getApproval(args.approvalId);
if (!approval) {
await approvalStorage.stop();
return {
success: false,
message: `Approval request not found: ${args.approvalId}`
};
}
await approvalStorage.stop();
const isCompleted = approval.status === 'approved' || approval.status === 'rejected';
const canProceed = approval.status === 'approved';
const mustWait = approval.status !== 'approved';
const nextSteps = [];
if (approval.status === 'pending') {
nextSteps.push('BLOCKED - Do not proceed');
nextSteps.push('VERBAL APPROVAL NOT ACCEPTED - Use dashboard or VS Code extension only');
nextSteps.push('Approval must be done via dashboard or VS Code extension');
nextSteps.push('Continue polling with get-approval-status');
}
else if (approval.status === 'approved') {
nextSteps.push('APPROVED - Can proceed');
nextSteps.push('Run delete-approval before continuing');
if (approval.response) {
nextSteps.push(`Response: ${approval.response}`);
}
}
else if (approval.status === 'rejected') {
nextSteps.push('BLOCKED - REJECTED');
nextSteps.push('Do not proceed');
nextSteps.push('Review feedback and revise');
if (approval.response) {
nextSteps.push(`Reason: ${approval.response}`);
}
if (approval.annotations) {
nextSteps.push(`Notes: ${approval.annotations}`);
}
}
else if (approval.status === 'needs-revision') {
nextSteps.push('BLOCKED - Do not proceed');
nextSteps.push('Update document with feedback');
nextSteps.push('Create NEW approval request');
if (approval.response) {
nextSteps.push(`Feedback: ${approval.response}`);
}
if (approval.annotations) {
nextSteps.push(`Notes: ${approval.annotations}`);
}
if (approval.comments && approval.comments.length > 0) {
nextSteps.push(`${approval.comments.length} comments for targeted fixes`);
}
}
return {
success: true,
message: approval.status === 'pending'
? `BLOCKED: Status is ${approval.status}. Verbal approval is NOT accepted. Use dashboard or VS Code extension only.`
: `Approval status: ${approval.status}`,
data: {
approvalId: args.approvalId,
title: approval.title,
type: approval.type,
status: approval.status,
createdAt: approval.createdAt,
respondedAt: approval.respondedAt,
response: approval.response,
annotations: approval.annotations,
isCompleted,
canProceed,
mustWait,
blockNext: !canProceed,
dashboardUrl: context.dashboardUrl
},
nextSteps,
projectContext: {
projectPath: validatedProjectPath,
workflowRoot: join(validatedProjectPath, '.spec-workflow'),
dashboardUrl: context.dashboardUrl
}
};
}
catch (error) {
return {
success: false,
message: `Failed to check approval status: ${error.message}`
};
}
}
//# sourceMappingURL=get-approval-status.js.map