lokalise-mcp
Version:
The Lokalise MCP Server brings Lokalise's localization power to Claude and AI assistants—manage projects, keys, and translations by chat.
91 lines (90 loc) • 4.28 kB
JavaScript
import { formatErrorForMcpTool } from "../../shared/utils/error.util.js";
import { Logger } from "../../shared/utils/logger.util.js";
import queuedprocessesController from "./queuedprocesses.controller.js";
import { GetQueuedprocessesToolArgs, ListQueuedprocessesToolArgs, } from "./queuedprocesses.types.js";
/**
* @function handleListQueuedprocesses
* @description MCP Tool handler to retrieve a list of queuedprocesses from a Lokalise project.
* It calls the queuedprocessesController to fetch the data and formats the response for the MCP.
*
* @param {ListQueuedprocessessToolArgsType} args - Arguments provided to the tool.
* @returns {Promise<{ content: Array<{ type: 'text', text: string }> }>} Formatted response for the MCP.
* @throws {McpError} Formatted error if the controller or service layer encounters an issue.
*/
async function handleListQueuedprocesses(args) {
const methodLogger = Logger.forContext("queuedprocesses.tool.ts", "handleListQueuedprocesses");
methodLogger.debug(`Getting Lokalise queuedprocesses list (limit: ${args.limit || "default"}, page: ${args.page || "1"})...`, args);
try {
const result = await queuedprocessesController.listQueuedprocesses(args);
methodLogger.debug("Got the response from the controller", result);
return {
content: [
{
type: "text",
text: result.content,
},
],
};
}
catch (error) {
methodLogger.error("Tool failed", {
error: error.message,
args,
});
return formatErrorForMcpTool(error);
}
}
/**
* MCP Tool handler to retrieve details of a specific queued process.
* Returns status, type, and details about the async operation.
*/
async function handleGetQueuedprocesses(args) {
const methodLogger = Logger.forContext("queuedprocesses.tool.ts", "handleGetQueuedprocesses");
methodLogger.debug("Getting queuedprocesses details...", args);
try {
const result = await queuedprocessesController.getQueuedprocesses(args);
methodLogger.debug("Got the response from the controller", result);
return {
content: [
{
type: "text",
text: result.content,
},
],
};
}
catch (error) {
methodLogger.error("Tool failed", {
error: error.message,
args,
});
return formatErrorForMcpTool(error);
}
}
/**
* @function registerTools
* @description Registers all queuedprocesses-related tools with the MCP server.
* This function binds the tool names to their handler functions and schemas.
*
* @param {McpServer} server - The MCP server instance where tools will be registered.
*/
function registerTools(server) {
const methodLogger = Logger.forContext("queuedprocesses.tool.ts", "registerTools");
methodLogger.info("Registering queuedprocesses MCP tools");
server.tool("lokalise_list_queued_processes", "Lists all background/async processes in a Lokalise project with status tracking. Required: projectId. Optional: limit (100), page. Use to monitor file uploads, downloads, bulk operations, or troubleshoot process issues. Returns: Processes with status, progress, and completion estimates.", ListQueuedprocessesToolArgs.shape, handleListQueuedprocesses);
server.tool("lokalise_get_queued_process", "Gets detailed status and information about a specific async process (upload, download, etc.). Required: projectId, processId. Use to check process completion, diagnose failures, or get detailed progress information. Returns: Complete process details with logs and status history.", GetQueuedprocessesToolArgs.shape, handleGetQueuedprocesses);
methodLogger.info("Queuedprocesses MCP tools registered successfully");
}
// Export the domain tool implementation
const queuedprocessesTool = {
registerTools,
getMeta() {
return {
name: "queuedprocesses",
description: "Monitor background/async operations in Lokalise projects",
version: "1.0.0",
toolsCount: 2,
};
},
};
export default queuedprocessesTool;