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:
@@ -8,6 +8,11 @@
|
|||||||
- Rename `list-tasks` to `get-tasks` for more intuitive client requests like "get my tasks"
|
- Rename `list-tasks` to `get-tasks` for more intuitive client requests like "get my tasks"
|
||||||
- Rename `show-task` to `get-task` for consistency with GET-based API naming conventions
|
- Rename `show-task` to `get-task` for consistency with GET-based API naming conventions
|
||||||
|
|
||||||
|
- **Optimize MCP response payloads:**
|
||||||
|
- Add custom `processTaskResponse` function to `get-task` MCP tool to filter out unnecessary `allTasks` array data
|
||||||
|
- Significantly reduce response size by returning only the specific requested task instead of all tasks
|
||||||
|
- Preserve dependency status relationships for the UI/CLI while keeping MCP responses lean and efficient
|
||||||
|
|
||||||
- **Refactor project root handling for MCP Server:**
|
- **Refactor project root handling for MCP Server:**
|
||||||
- **Prioritize Session Roots**: MCP tools now extract the project root path directly from `session.roots[0].uri` provided by the client (e.g., Cursor).
|
- **Prioritize Session Roots**: MCP tools now extract the project root path directly from `session.roots[0].uri` provided by the client (e.g., Cursor).
|
||||||
- **New Utility `getProjectRootFromSession`**: Added to `mcp-server/src/tools/utils.js` to encapsulate session root extraction and decoding. **Further refined for more reliable detection, especially in integrated environments, including deriving root from script path and avoiding fallback to '/'.**
|
- **New Utility `getProjectRootFromSession`**: Added to `mcp-server/src/tools/utils.js` to encapsulate session root extraction and decoding. **Further refined for more reliable detection, especially in integrated environments, including deriving root from script path and avoiding fallback to '/'.**
|
||||||
|
|||||||
@@ -11,6 +11,24 @@ import {
|
|||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
import { showTaskDirect } from "../core/task-master-core.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
|
* Register the get-task tool with the MCP server
|
||||||
* @param {Object} server - FastMCP server instance
|
* @param {Object} server - FastMCP server instance
|
||||||
@@ -63,7 +81,8 @@ export function registerShowTaskTool(server) {
|
|||||||
log.error(`Failed to get task: ${result.error.message}`);
|
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) {
|
} catch (error) {
|
||||||
log.error(`Error in get-task tool: ${error.message}\n${error.stack}`); // Add stack trace
|
log.error(`Error in get-task tool: ${error.message}\n${error.stack}`); // Add stack trace
|
||||||
return createErrorResponse(`Failed to get task: ${error.message}`);
|
return createErrorResponse(`Failed to get task: ${error.message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user