response-language
Set or retrieve the response language for your project using specific parameters, ensuring compatibility with AI-driven development workflows in Cursor AI and code editors via Task Master.
Instructions
Get or set the response language for the project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | Yes | The new response language to set. like "中文" "English" or "español". | |
| projectRoot | Yes | The root directory for the project. ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY. IF NOT SET, THE TOOL WILL NOT WORK. |
Implementation Reference
- Main execution handler for the response-language tool. Normalizes project root, executes the direct function, handles API results and errors.execute: withNormalizedProjectRoot(async (args, { log, session }) => { try { log.info( `Executing response-language tool with args: ${JSON.stringify(args)}` ); const result = await responseLanguageDirect( { ...args, projectRoot: args.projectRoot }, log, { session } ); return handleApiResult({ result, log, errorPrefix: 'Error setting response language', projectRoot: args.projectRoot }); } catch (error) { log.error(`Error in response-language tool: ${error.message}`); return createErrorResponse(error.message); } })
- Zod schema defining input parameters: projectRoot (string, required) and language (string).parameters: z.object({ projectRoot: z .string() .describe( 'The root directory for the project. ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY. IF NOT SET, THE TOOL WILL NOT WORK.' ), language: z .string() .describe( 'The new response language to set. like "中文" "English" or "español".' ) }),
- mcp-server/src/tools/response-language.js:9-51 (registration)Registration function that adds the 'response-language' tool to the MCP server with name, description, schema, and handler.export function registerResponseLanguageTool(server) { server.addTool({ name: 'response-language', description: 'Get or set the response language for the project', parameters: z.object({ projectRoot: z .string() .describe( 'The root directory for the project. ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY. IF NOT SET, THE TOOL WILL NOT WORK.' ), language: z .string() .describe( 'The new response language to set. like "中文" "English" or "español".' ) }), execute: withNormalizedProjectRoot(async (args, { log, session }) => { try { log.info( `Executing response-language tool with args: ${JSON.stringify(args)}` ); const result = await responseLanguageDirect( { ...args, projectRoot: args.projectRoot }, log, { session } ); return handleApiResult({ result, log, errorPrefix: 'Error setting response language', projectRoot: args.projectRoot }); } catch (error) { log.error(`Error in response-language tool: ${error.message}`); return createErrorResponse(error.message); } }) }); }
- Direct function called by the tool handler. Manages silent mode, calls setResponseLanguage, handles errors.export async function responseLanguageDirect(args, log, context = {}) { const { projectRoot, language } = args; const mcpLog = createLogWrapper(log); log.info( `Executing response-language_direct with args: ${JSON.stringify(args)}` ); log.info(`Using project root: ${projectRoot}`); try { enableSilentMode(); return setResponseLanguage(language, { mcpLog, projectRoot }); } catch (error) { return { success: false, error: { code: 'DIRECT_FUNCTION_ERROR', message: error.message, details: error.stack } }; } finally { disableSilentMode(); } }
- Core helper function that sets the response language in the project configuration file by updating global.responseLanguage and writing the config.function setResponseLanguage(lang, options = {}) { const { mcpLog, projectRoot } = options; const report = (level, ...args) => { if (mcpLog && typeof mcpLog[level] === 'function') { mcpLog[level](...args); } }; // Use centralized config path finding instead of hardcoded path const configPath = findConfigPath(null, { projectRoot }); const configExists = isConfigFilePresent(projectRoot); log( 'debug', `Checking for config file using findConfigPath, found: ${configPath}` ); log( 'debug', `Checking config file using isConfigFilePresent(), exists: ${configExists}` ); if (!configExists) { return { success: false, error: { code: 'CONFIG_MISSING', message: 'The configuration file is missing. Run "task-master init" to create it.' } }; } // Validate response language if (typeof lang !== 'string' || lang.trim() === '') { return { success: false, error: { code: 'INVALID_RESPONSE_LANGUAGE', message: `Invalid response language: ${lang}. Must be a non-empty string.` } }; } try { const currentConfig = getConfig(projectRoot); currentConfig.global.responseLanguage = lang; const writeResult = writeConfig(currentConfig, projectRoot); if (!writeResult) { return { success: false, error: { code: 'WRITE_ERROR', message: 'Error writing updated configuration to configuration file' } }; } return { success: true, data: { responseLanguage: lang, message: successMessage } }; } catch (error) { report('error', `Error setting response language: ${error.message}`); return { success: false, error: { code: 'SET_RESPONSE_LANGUAGE_ERROR', message: error.message } }; } } export default setResponseLanguage;