-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix(mcp): pass resolved tag through to handleApiResult in JS tools #1703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gw1108
wants to merge
3
commits into
eyaltoledano:main
Choose a base branch
from
gw1108:fix/issue-1683-mcp-tag-response
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "task-master-ai": patch | ||
| --- | ||
|
|
||
| Fix MCP tool responses returning the wrong active tag when a `tag` argument is passed explicitly. Tools like `next_task`, `add_task`, `update_task`, `update_subtask`, `expand_task`, `remove_task`, `move_task` and others now report the requested tag in their response payload instead of falling back to `currentTag` from `.taskmaster/state.json`. Resolves #1683 (and related symptom in #1638). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
apps/mcp/tests/integration/tools/next-task-tag.tool.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /** | ||
| * @fileoverview Regression test for upstream issue #1683 (and #1638) | ||
| * | ||
| * Verifies that JS-side MCP tools which take a `tag` parameter | ||
| * return that same tag back in their response payload, instead of | ||
| * silently falling back to the `currentTag` from `.taskmaster/state.json`. | ||
| * | ||
| * Before the fix, `next_task(tag="phase3")` would respond with | ||
| * `{ ..., "tag": "master" }` whenever state.json still pointed at master. | ||
| * | ||
| * @integration | ||
| */ | ||
|
|
||
| import { execFileSync } from 'node:child_process'; | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { createTask } from '@tm/core/testing'; | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| describe('MCP response tag honors explicit tag arg (issue #1683)', () => { | ||
| let testDir: string; | ||
| let tasksPath: string; | ||
| let statePath: string; | ||
| let cliPath: string; | ||
| let mcpServerPath: string; | ||
|
|
||
| beforeEach(() => { | ||
| testDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tm-mcp-1683-')); | ||
| process.chdir(testDir); | ||
|
|
||
| cliPath = path.resolve(__dirname, '../../../../../dist/task-master.js'); | ||
| mcpServerPath = path.resolve( | ||
| __dirname, | ||
| '../../../../../dist/mcp-server.js' | ||
| ); | ||
|
|
||
| execFileSync(process.execPath, [cliPath, 'init', '--yes'], { | ||
| stdio: 'pipe', | ||
| env: { ...process.env, TASKMASTER_SKIP_AUTO_UPDATE: '1' } | ||
| }); | ||
|
|
||
| tasksPath = path.join(testDir, '.taskmaster', 'tasks', 'tasks.json'); | ||
| statePath = path.join(testDir, '.taskmaster', 'state.json'); | ||
|
|
||
| // Multi-tag tasks file with master + phase3 | ||
| const data = { | ||
| master: { | ||
| tasks: [createTask({ id: 1, title: 'Master task', status: 'pending' })], | ||
| metadata: { | ||
| version: '1.0.0', | ||
| lastModified: new Date().toISOString(), | ||
| taskCount: 1, | ||
| completedCount: 0, | ||
| tags: ['master'] | ||
| } | ||
| }, | ||
| phase3: { | ||
| tasks: [ | ||
| createTask({ | ||
| id: 41, | ||
| title: 'Phase3 task', | ||
| status: 'pending', | ||
| priority: 'high' | ||
| }) | ||
| ], | ||
| metadata: { | ||
| version: '1.0.0', | ||
| lastModified: new Date().toISOString(), | ||
| taskCount: 1, | ||
| completedCount: 0, | ||
| tags: ['phase3'] | ||
| } | ||
| } | ||
| }; | ||
| fs.writeFileSync(tasksPath, JSON.stringify(data, null, 2)); | ||
|
|
||
| // Pin currentTag to master so we can detect a fallback bug | ||
| fs.writeFileSync( | ||
| statePath, | ||
| JSON.stringify({ currentTag: 'master' }, null, 2) | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| try { | ||
| process.chdir(path.resolve(__dirname, '../../../../..')); | ||
| } catch { | ||
| process.chdir(os.homedir()); | ||
| } | ||
| if (testDir && fs.existsSync(testDir)) { | ||
| fs.rmSync(testDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| const callMCPTool = (toolName: string, args: Record<string, string>): any => { | ||
| const toolArgs = Object.entries(args).flatMap(([key, value]) => [ | ||
| '--tool-arg', | ||
| `${key}=${value}` | ||
| ]); | ||
|
|
||
| const npxBin = process.platform === 'win32' ? 'npx.cmd' : 'npx'; | ||
| const output = execFileSync( | ||
| npxBin, | ||
| [ | ||
| '@modelcontextprotocol/inspector', | ||
| '--cli', | ||
| 'node', | ||
| mcpServerPath, | ||
| '--method', | ||
| 'tools/call', | ||
| '--tool-name', | ||
| toolName, | ||
| ...toolArgs | ||
| ], | ||
| { encoding: 'utf-8', stdio: 'pipe' } | ||
| ); | ||
| const mcpResponse = JSON.parse(output); | ||
| const resultText = mcpResponse.content[0].text; | ||
| return JSON.parse(resultText); | ||
| }; | ||
|
|
||
| it('next_task(tag="phase3") response carries tag="phase3" even when state.json points at master', () => { | ||
| const data = callMCPTool('next_task', { | ||
| projectRoot: testDir, | ||
| tag: 'phase3' | ||
| }); | ||
| expect(data.tag).toBe('phase3'); | ||
| }, 30000); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Replace direct JSON writes with the project JSON utility.
Line 76 and Line 79 use
fs.writeFileSyncfor JSON. This bypasses the shared JSON utility and its validation/error-handling conventions.As per coding guidelines, "Use readJSON and writeJSON utilities for all JSON file operations instead of raw fs.readFileSync or fs.writeFileSync" and "Include error handling for JSON file operations and validate JSON structure after reading."
🤖 Prompt for AI Agents