atlas-mcp-server
Version:
ATLAS (Adaptive Task & Logic Automation System): An MCP server enabling LLM agents to manage projects, tasks, and knowledge via a Neo4j-backed, three-tier architecture. Facilitates complex workflow automation and project management through LLM Agents.
119 lines (118 loc) • 5.61 kB
JavaScript
import { ProjectService } from "../../../services/neo4j/projectService.js";
import { BaseErrorCode, McpError, ProjectErrorCode, } from "../../../types/errors.js";
import { ResponseFormat, createToolResponse } from "../../../types/mcp.js";
import { logger, requestContextService } from "../../../utils/index.js"; // Import requestContextService
import { AtlasProjectUpdateSchema } from "./types.js";
import { formatProjectUpdateResponse } from "./responseFormat.js";
export const atlasUpdateProject = async (input, context) => {
let validatedInput;
const reqContext = context.requestContext ??
requestContextService.createRequestContext({
toolName: "atlasUpdateProject",
});
try {
// Parse and validate the input against schema
validatedInput = AtlasProjectUpdateSchema.parse(input);
// Process according to operation mode (single or bulk)
if (validatedInput.mode === "bulk") {
// Execute bulk update operation
logger.info("Applying updates to multiple projects", {
...reqContext,
count: validatedInput.projects.length,
});
const results = {
success: true,
message: `Successfully updated ${validatedInput.projects.length} projects`,
updated: [],
errors: [],
};
// Process each project update sequentially to maintain data consistency
for (let i = 0; i < validatedInput.projects.length; i++) {
const projectUpdate = validatedInput.projects[i];
try {
// First check if project exists
const projectExists = await ProjectService.getProjectById(projectUpdate.id);
if (!projectExists) {
throw new McpError(ProjectErrorCode.PROJECT_NOT_FOUND, `Project with ID ${projectUpdate.id} not found`);
}
// Update the project
const updatedProject = await ProjectService.updateProject(projectUpdate.id, projectUpdate.updates);
results.updated.push(updatedProject);
}
catch (error) {
results.success = false;
results.errors.push({
index: i,
project: projectUpdate,
error: {
code: error instanceof McpError
? error.code
: BaseErrorCode.INTERNAL_ERROR,
message: error instanceof Error ? error.message : "Unknown error",
details: error instanceof McpError ? error.details : undefined,
},
});
}
}
if (results.errors.length > 0) {
results.message = `Updated ${results.updated.length} of ${validatedInput.projects.length} projects with ${results.errors.length} errors`;
}
logger.info("Bulk project modification completed", {
...reqContext,
successCount: results.updated.length,
errorCount: results.errors.length,
projectIds: results.updated.map((p) => p.id),
});
// Conditionally format response
if (validatedInput.responseFormat === ResponseFormat.JSON) {
return createToolResponse(JSON.stringify(results, null, 2));
}
else {
return formatProjectUpdateResponse(results);
}
}
else {
// Process single project modification
const { mode, id, updates } = validatedInput;
logger.info("Modifying project attributes", {
...reqContext,
id,
fields: Object.keys(updates),
});
// First check if project exists
const projectExists = await ProjectService.getProjectById(id);
if (!projectExists) {
throw new McpError(ProjectErrorCode.PROJECT_NOT_FOUND, `Project with ID ${id} not found`);
}
// Update the project
const updatedProject = await ProjectService.updateProject(id, updates);
logger.info("Project modifications applied successfully", {
...reqContext,
projectId: id,
});
// Conditionally format response
if (validatedInput.responseFormat === ResponseFormat.JSON) {
return createToolResponse(JSON.stringify(updatedProject, null, 2));
}
else {
return formatProjectUpdateResponse(updatedProject);
}
}
}
catch (error) {
// Handle specific error cases
if (error instanceof McpError) {
throw error;
}
logger.error("Failed to modify project(s)", error, {
...reqContext,
inputReceived: validatedInput ?? input,
});
// Handle not found error specifically
if (error instanceof Error && error.message.includes("not found")) {
throw new McpError(ProjectErrorCode.PROJECT_NOT_FOUND, `Project not found: ${error.message}`);
}
// Convert generic errors to properly formatted McpError
throw new McpError(BaseErrorCode.INTERNAL_ERROR, `Failed to modify project(s): ${error instanceof Error ? error.message : "Unknown error"}`);
}
};