fix(mcp): optimize get_task response payload by removing allTasks data
- Add custom processTaskResponse function to get-task.js to filter response data - Significantly reduce MCP response size by returning only the requested task - Preserve allTasks in CLI/UI for dependency status formatting - Update changeset with documentation of optimization This change maintains backward compatibility while making MCP responses more efficient, addressing potential context overflow issues in AI clients.
This commit is contained in:
@@ -11,6 +11,24 @@ import {
|
||||
} from "./utils.js";
|
||||
import { showTaskDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Custom processor function that removes allTasks from the response
|
||||
* @param {Object} data - The data returned from showTaskDirect
|
||||
* @returns {Object} - The processed data with allTasks removed
|
||||
*/
|
||||
function processTaskResponse(data) {
|
||||
if (!data) return data;
|
||||
|
||||
// If we have the expected structure with task and allTasks
|
||||
if (data.task) {
|
||||
// Return only the task object, removing the allTasks array
|
||||
return data.task;
|
||||
}
|
||||
|
||||
// If structure is unexpected, return as is
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the get-task tool with the MCP server
|
||||
* @param {Object} server - FastMCP server instance
|
||||
@@ -63,7 +81,8 @@ export function registerShowTaskTool(server) {
|
||||
log.error(`Failed to get task: ${result.error.message}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error retrieving task details');
|
||||
// Use our custom processor function to remove allTasks from the response
|
||||
return handleApiResult(result, log, 'Error retrieving task details', processTaskResponse);
|
||||
} catch (error) {
|
||||
log.error(`Error in get-task tool: ${error.message}\n${error.stack}`); // Add stack trace
|
||||
return createErrorResponse(`Failed to get task: ${error.message}`);
|
||||
|
||||
Reference in New Issue
Block a user