From 533f5cdc2529cb90875be726e0068ff7093624c5 Mon Sep 17 00:00:00 2001 From: Joe Danziger Date: Fri, 11 Apr 2025 12:07:58 -0400 Subject: [PATCH] Don't add task-master-mcp to mcp.json if it already exists (#169) --- .changeset/two-bats-smoke.md | 2 +- README-task-master.md | 2 +- README.md | 2 +- docs/tutorial.md | 4 ++-- scripts/init.js | 24 ++++++++++++++++++++++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.changeset/two-bats-smoke.md b/.changeset/two-bats-smoke.md index b242fbff..61930d0e 100644 --- a/.changeset/two-bats-smoke.md +++ b/.changeset/two-bats-smoke.md @@ -33,7 +33,7 @@ - Updated README, added tutorial/examples guide, supported client list documentation. - Adjusts the MCP server invokation in the mcp.json we ship with `task-master init`. Fully functional now. -- Rename the npx -y command. It's now `npx -y task-master-ai task-master-mcp` +- Rename the npx -y command. It's now `npx -y task-master-mcp` - Add additional binary alias: `task-master-mcp-server` pointing to the same MCP server script - **Significant improvements to model configuration:** diff --git a/README-task-master.md b/README-task-master.md index 61da5036..862e3744 100644 --- a/README-task-master.md +++ b/README-task-master.md @@ -146,7 +146,7 @@ To enable enhanced task management capabilities directly within Cursor using the 4. Configure with the following details: - Name: "Task Master" - Type: "Command" - - Command: "npx -y --package task-master-ai task-master-mcp" + - Command: "npx -y task-master-mcp" 5. Save the settings Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience. diff --git a/README.md b/README.md index ed867782..6610109c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M "mcpServers": { "taskmaster-ai": { "command": "npx", - "args": ["-y", "--package", "task-master-ai", "task-master-mcp"], + "args": ["-y", "task-master-mcp"], "env": { "ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE", "PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE", diff --git a/docs/tutorial.md b/docs/tutorial.md index 66c7b0a2..1dec41ba 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -17,7 +17,7 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M "mcpServers": { "taskmaster-ai": { "command": "npx", - "args": ["-y", "--package", "task-master-ai", "task-master-mcp"], + "args": ["-y", "task-master-mcp"], "env": { "ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE", "PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE", @@ -132,7 +132,7 @@ You can also set up the MCP server in Cursor settings: 4. Configure with the following details: - Name: "Task Master" - Type: "Command" - - Command: "npx -y --package task-master-ai task-master-mcp" + - Command: "npx -y task-master-mcp" 5. Save the settings Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience. diff --git a/scripts/init.js b/scripts/init.js index c609874b..4bbd65ee 100755 --- a/scripts/init.js +++ b/scripts/init.js @@ -909,7 +909,7 @@ function setupMCPConfiguration(targetDir, projectName) { const newMCPServer = { 'task-master-ai': { command: 'npx', - args: ['-y', '--package', 'task-master-ai', 'task-master-mcp'], + args: ['-y', 'task-master-mcp'], env: { ANTHROPIC_API_KEY: '%ANTHROPIC_API_KEY%', PERPLEXITY_API_KEY: '%PERPLEXITY_API_KEY%', @@ -925,7 +925,10 @@ function setupMCPConfiguration(targetDir, projectName) { // Check if mcp.json already exists if (fs.existsSync(mcpJsonPath)) { - log('info', 'MCP configuration file already exists, updating...'); + log( + 'info', + 'MCP configuration file already exists, checking for existing task-master-mcp...' + ); try { // Read existing config const mcpConfig = JSON.parse(fs.readFileSync(mcpJsonPath, 'utf8')); @@ -935,6 +938,23 @@ function setupMCPConfiguration(targetDir, projectName) { mcpConfig.mcpServers = {}; } + // Check if any existing server configuration already has task-master-mcp in its args + const hasMCPString = Object.values(mcpConfig.mcpServers).some( + (server) => + server.args && + server.args.some( + (arg) => typeof arg === 'string' && arg.includes('task-master-mcp') + ) + ); + + if (hasMCPString) { + log( + 'info', + 'Found existing task-master-mcp configuration in mcp.json, leaving untouched' + ); + return; // Exit early, don't modify the existing configuration + } + // Add the task-master-ai server if it doesn't exist if (!mcpConfig.mcpServers['task-master-ai']) { mcpConfig.mcpServers['task-master-ai'] = newMCPServer['task-master-ai'];