This commit implements several related improvements to the models command and configuration system: - Added MCP support for the models command: - Created new direct function implementation in models.js - Registered modelsDirect in task-master-core.js for proper export - Added models tool registration in tools/index.js - Ensured project name replacement when copying .taskmasterconfig in init.js - Improved .taskmasterconfig copying during project initialization: - Added copyTemplateFile() call in createProjectStructure() - Ensured project name is properly replaced in the config - Restructured tool registration in logical workflow groups: - Organized registration into 6 functional categories - Improved command ordering to follow typical workflow - Added clear group comments for maintainability - Enhanced documentation in cursor rules: - Updated dev_workflow.mdc with clearer config management instructions - Added comprehensive models command reference to taskmaster.mdc - Clarified CLI vs MCP usage patterns and options - Added warning against manual .taskmasterconfig editing
82 lines
2.3 KiB
JavaScript
82 lines
2.3 KiB
JavaScript
/**
|
|
* models.js
|
|
* MCP tool for managing AI model configurations
|
|
*/
|
|
|
|
import { z } from 'zod';
|
|
import {
|
|
getProjectRootFromSession,
|
|
handleApiResult,
|
|
createErrorResponse
|
|
} from './utils.js';
|
|
import { modelsDirect } from '../core/task-master-core.js';
|
|
|
|
/**
|
|
* Register the models tool with the MCP server
|
|
* @param {Object} server - FastMCP server instance
|
|
*/
|
|
export function registerModelsTool(server) {
|
|
server.addTool({
|
|
name: 'models',
|
|
description:
|
|
'Get information about available AI models or set model configurations. Run without arguments to get the current model configuration and API key status for the selected model providers.',
|
|
parameters: z.object({
|
|
setMain: z
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
'Set the primary model for task generation/updates. Model provider API key is required in the MCP config ENV.'
|
|
),
|
|
setResearch: z
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
'Set the model for research-backed operations. Model provider API key is required in the MCP config ENV.'
|
|
),
|
|
setFallback: z
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
'Set the model to use if the primary fails. Model provider API key is required in the MCP config ENV.'
|
|
),
|
|
listAvailableModels: z
|
|
.boolean()
|
|
.optional()
|
|
.describe('List all available models not currently in use.'),
|
|
projectRoot: z
|
|
.string()
|
|
.optional()
|
|
.describe('The directory of the project. Must be an absolute path.')
|
|
}),
|
|
execute: async (args, { log, session }) => {
|
|
try {
|
|
log.info(`Starting models tool with args: ${JSON.stringify(args)}`);
|
|
|
|
// Get project root from args or session
|
|
const rootFolder =
|
|
args.projectRoot || getProjectRootFromSession(session, log);
|
|
|
|
// Ensure project root was determined
|
|
if (!rootFolder) {
|
|
return createErrorResponse(
|
|
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
|
);
|
|
}
|
|
|
|
// Call the direct function
|
|
const result = await modelsDirect(
|
|
{ ...args, projectRoot: rootFolder },
|
|
log,
|
|
{ session }
|
|
);
|
|
|
|
// Handle and return the result
|
|
return handleApiResult(result, log);
|
|
} catch (error) {
|
|
log.error(`Error in models tool: ${error.message}`);
|
|
return createErrorResponse(error.message);
|
|
}
|
|
}
|
|
});
|
|
}
|