get_pattern_for_task
Retrieve the appropriate coding pattern for tasks like components, APIs, or services by specifying task type and context, ensuring structured and efficient development workflows.
Instructions
Get the correct pattern to use for a specific task
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | ||
| taskType | Yes | Type of task to get pattern for |
Implementation Reference
- src/tools/index.ts:82-100 (handler)MCP tool handler case for 'get_pattern_for_task': validates input parameters (taskType and optional requirements), calls getPatternForTask helper, and formats the returned pattern as MCP content response.case 'get_pattern_for_task': { const params = z.object({ taskType: z.enum(['component', 'hook', 'service', 'api', 'test', 'error-handling']), requirements: z.array(z.string()).optional(), }).parse(args); const pattern = await getPatternForTask( params.taskType, params.requirements ); return { content: [ { type: 'text', text: pattern, }, ], }; }
- src/tools/tool-definitions.ts:52-78 (schema)Tool definition object for 'get_pattern_for_task' including name, description, and inputSchema specifying taskType enum and optional context properties.{ name: 'get_pattern_for_task', description: 'Get the correct pattern to use for a specific task', inputSchema: { type: 'object', properties: { taskType: { type: 'string', enum: ['component', 'api', 'test', 'hook', 'service', 'utility'], description: 'Type of task to get pattern for', }, context: { type: 'object', properties: { hasState: { type: 'boolean' }, hasAsync: { type: 'boolean' }, needsAuth: { type: 'boolean' }, complexity: { type: 'string', enum: ['simple', 'medium', 'complex'], }, }, }, }, required: ['taskType'], }, },
- Core helper function getPatternForTask that retrieves base pattern for taskType, enhances with project context from CODEBASE-CONTEXT.md, and adjusts for specific requirements.export async function getPatternForTask( taskType: TaskType, requirements?: string[] ): Promise<string> { const projectPath = process.env.PROJECT_PATH || process.cwd(); const contextPath = join(projectPath, 'CODEBASE-CONTEXT.md'); const templatePath = join(projectPath, '..', 'PROJECT-TEMPLATE-v10.md'); let basePattern = getBasePattern(taskType); // Enhance with project-specific patterns if (existsSync(contextPath)) { const contextContent = readFileSync(contextPath, 'utf-8'); basePattern = enhanceWithProjectContext(basePattern, contextContent, taskType); } // Add requirements-specific adjustments if (requirements && requirements.length > 0) { basePattern = adjustForRequirements(basePattern, requirements, taskType); } return basePattern; }
- src/tools/index.ts:25-30 (registration)Tool registration via setupTools: sets ListToolsRequestHandler to return toolDefinitions array which includes the get_pattern_for_task tool.export function setupTools(server: Server) { // Handle tool listing server.setRequestHandler(ListToolsRequestSchema, async () => { console.error(`Handling tools/list request, returning ${toolDefinitions.length} tools`); return { tools: toolDefinitions }; });