import { z } from "zod";
/**
* Coordination Tools - "The Linking Glue"
* Helps orchestrate other tools and suggests workflows.
*/
// ============================================
// Suggest Tool Chain
// ============================================
export const suggestToolChainSchema = {
name: "suggest_tool_chain",
description: "Suggests a sequence of Code-MCP tools to achieve a specific complex goal",
inputSchema: z.object({
goal: z.string().describe("The user's high-level goal"),
context: z.string().optional().describe("Current project state")
})
};
type ToolStep = { tool: string; reason: string };
export function suggestToolChainHandler(args: { goal: string; context?: string }) {
const { goal } = args;
const lowerGoal = goal.toLowerCase();
// Logic to suggest chains based on keywords
let chain: ToolStep[] = [];
let name = "Custom Workflow";
if (lowerGoal.includes("refactor")) {
name = "Refactoring Workflow";
chain = [
{ tool: "derive_patterns", reason: "Analyze existing code for duplication and patterns" },
{ tool: "reflect_on_code", reason: "Get specific improvement suggestions" },
{ tool: "plan_task", reason: "Create a plan for the refactor" },
{ tool: "generate_tests", reason: "Ensure tests exist before changing code" },
{ tool: "generate_snippet", reason: "Generate new standardized components" },
{ tool: "lint_code", reason: "Verify quality of changes" }
];
} else if (lowerGoal.includes("feature") || lowerGoal.includes("create")) {
name = "Feature Implementation Workflow";
chain = [
{ tool: "act_as_architect", reason: "(Prompt) Design the system first" },
{ tool: "typescript_helper", reason: "Define types and interfaces" },
{ tool: "decision_matrix", reason: "Make tech/design choices if needed" },
{ tool: "generate_snippet", reason: "Scaffold boilerplate code" },
{ tool: "sql_helper", reason: "Generate database schema/migration" },
{ tool: "generate_api_client", reason: "Create client SDK" }
];
} else if (lowerGoal.includes("debug") || lowerGoal.includes("fix")) {
name = "Debugging Workflow";
chain = [
{ tool: "act_as_debugger", reason: "(Prompt) Enter debug mindset" },
{ tool: "debug_problem", reason: "Systematically analyze the bug" },
{ tool: "git_helper", reason: "Use bisect if needed to find regression" },
{ tool: "explain_code", reason: "Understand complex logic in buggy file" },
{ tool: "generate_tests", reason: "Create reproduction test case" }
];
} else if (lowerGoal.includes("deploy") || lowerGoal.includes("ci")) {
name = "DevOps Workflow";
chain = [
{ tool: "track_project", reason: "Understand project structure" },
{ tool: "check_dependencies", reason: "Ensure security before deploy" },
{ tool: "generate_dockerfile", reason: "Containerize application" },
{ tool: "generate_github_actions", reason: "Setup CI/CD pipeline" },
{ tool: "generate_env_template", reason: "Document environment variables" }
];
} else {
// Generic agentic flow
name = "Autonomous Agent Flow";
chain = [
{ tool: "sequential_thinking", reason: "Break down the problem" },
{ tool: "research_synthesis", reason: "Gather context" },
{ tool: "plan_task", reason: "Create execution plan" },
{ tool: "decision_matrix", reason: "Choose best path" }
];
}
return {
content: [{
type: "text",
text: `# Recommended Tool Chain: ${name}\n\nTo achieve "${goal}", try using these tools in order:\n\n${chain.map((s, i) => `${i + 1}. **\`${s.tool}\`**\n - π‘ ${s.reason}`).join('\n\n')}\n\nThis chain ensures you follow best practices.`
}]
};
}
// ============================================
// Project Profiler
// ============================================
export const projectProfilerSchema = {
name: "project_profiler",
description: "Analyzes the project state and suggests immediate 'Quick Wins' using Code-MCP tools",
inputSchema: z.object({
files: z.array(z.string()).describe("List of file paths in project"),
hasTests: z.boolean().describe("Does project have tests?"),
hasDocs: z.boolean().describe("Does project have README/CONTRIBUTING?"),
hasCI: z.boolean().describe("Does project have CI config?")
})
};
export function projectProfilerHandler(args: { files: string[]; hasTests: boolean; hasDocs: boolean; hasCI: boolean }) {
const { files, hasTests, hasDocs, hasCI } = args;
const suggestions: string[] = [];
const missing: string[] = [];
// Check docs
if (!hasDocs) {
missing.push("Documentation");
suggestions.push("- Run `generate_readme` to create a professional README.");
suggestions.push("- Run `generate_license` to add a LICENSE file.");
suggestions.push("- Run `developer_rules` to generate a CONTRIBUTING guide.");
}
// Check tests
if (!hasTests) {
missing.push("Tests");
suggestions.push("- Run `generate_snippet(test-suite)` to add test scaffolding.");
suggestions.push("- Run `generate_tests` on core features.");
}
// Check CI
if (!hasCI) {
missing.push("CI/CD");
suggestions.push("- Run `generate_github_actions` to setup automated builds.");
}
// Check structure
const hasDocker = files.some(f => f.includes("Dockerfile"));
if (!hasDocker) {
suggestions.push("- Run `generate_dockerfile` to containerize the app.");
}
const hasEnv = files.some(f => f.includes(".env"));
if (!hasEnv) {
suggestions.push("- Run `generate_env_template` to create a safe .env.example.");
}
return {
content: [{
type: "text",
text: `# Project Profiler Report\n\n**Missing Critical Areas**: ${missing.length ? missing.join(", ") : "None! π"}\n\n## π Quick Wins (Recommended Actions)\n\n${suggestions.length ? suggestions.join('\n') : "Project looks great! Analyzed " + files.length + " files."}`
}]
};
}
// Export all
export const coordinationTools = {
suggestToolChainSchema, suggestToolChainHandler,
projectProfilerSchema, projectProfilerHandler
};