@zuens2020/back-agent-mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ZUENS2020
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # Back-Agent MCP Server
2
+
3
+ An MCP (Model Context Protocol) server that executes development tasks using Claude Code CLI.
4
+
5
+ ## Features
6
+
7
+ - Execute tasks through Claude Code CLI via MCP protocol
8
+ - **Non-interactive mode by default** (`-p` flag auto-applied)
9
+ - Specify custom working directories
10
+ - Configurable timeout settings
11
+ - Comprehensive error handling and logging
12
+
13
+ ## Prerequisites
14
+
15
+ - Node.js >= 18
16
+ - Claude Code CLI installed and available in PATH
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ # Clone the repository
22
+ git clone <repository-url>
23
+ cd back-agent-mcp
24
+
25
+ # Install dependencies
26
+ npm install
27
+
28
+ # Build the project
29
+ npm run build
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### Running the Server
35
+
36
+ ```bash
37
+ # Development mode (with tsx)
38
+ npm run dev
39
+
40
+ # Production mode (built)
41
+ npm start
42
+ ```
43
+
44
+ ### Installation
45
+
46
+ ```bash
47
+ npm install @zuens2020/back-agent-mcp
48
+ ```
49
+
50
+ ### Configuration with Claude Desktop
51
+
52
+ Add the following to your Claude Desktop configuration file:
53
+
54
+ **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
55
+ **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
56
+ **Linux:** `~/.config/Claude/claude_desktop_config.json`
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "back-agent": {
62
+ "command": "node",
63
+ "args": ["--experimental-modules", "C:\\Users\\YourUsername\\AppData\\Roaming\\npm\\node_modules\\@zuens2020\\back-agent-mcp\\dist\\index.js"]
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ Or using npx:
70
+
71
+ ```json
72
+ {
73
+ "mcpServers": {
74
+ "back-agent": {
75
+ "command": "npx",
76
+ "args": ["-y", "@zuens2020/back-agent-mcp"]
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ ### Available Tools
83
+
84
+ #### execute-task
85
+
86
+ Executes a development task using Claude Code CLI.
87
+
88
+ **Parameters:**
89
+
90
+ | Name | Type | Required | Description |
91
+ |------|------|----------|-------------|
92
+ | `task` | string | Yes | The task description to execute |
93
+ | `workingDirectory` | string | No | Working directory for execution |
94
+ | `timeout` | number | No | Timeout in seconds (max 3600, default 300) |
95
+ | `additionalArgs` | string[] | No | Additional CLI arguments (excluding `-p` which is auto-added) |
96
+
97
+ **Example:**
98
+
99
+ ```json
100
+ {
101
+ "task": "Create a function that calculates fibonacci numbers",
102
+ "workingDirectory": "C:\\Projects\\my-app",
103
+ "timeout": 600
104
+ }
105
+ ```
106
+
107
+ ## Development
108
+
109
+ ```bash
110
+ # Type checking
111
+ npm run typecheck
112
+
113
+ # Build
114
+ npm run build
115
+
116
+ # Development mode
117
+ npm run dev
118
+ ```
119
+
120
+ ## Project Structure
121
+
122
+ ```
123
+ src/
124
+ ├── index.ts # Main entry point
125
+ ├── server/
126
+ │ └── tools/
127
+ │ └── execute-task.ts # Task execution tool
128
+ ├── claude/
129
+ │ └── executor.ts # Claude Code CLI executor
130
+ └── utils/
131
+ ├── logger.ts # Logging utilities
132
+ └── error-handler.ts # Error handling
133
+ ```
134
+
135
+ ## Environment Variables
136
+
137
+ | Variable | Description | Values |
138
+ |----------|-------------|--------|
139
+ | `LOG_LEVEL` | Set logging verbosity | `DEBUG`, `INFO`, `WARN`, `ERROR` |
140
+
141
+ ## License
142
+
143
+ MIT
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Claude Code CLI Executor
3
+ *
4
+ * Executes tasks by spawning Claude Code as a child process.
5
+ */
6
+ export interface ExecutionOptions {
7
+ /** Task description to execute */
8
+ task: string;
9
+ /** Working directory for Claude Code */
10
+ workingDirectory?: string;
11
+ /** Timeout in milliseconds (default: 300000 = 5 minutes) */
12
+ timeout?: number;
13
+ /** Additional CLI arguments for Claude Code */
14
+ additionalArgs?: string[];
15
+ }
16
+ export interface ExecutionResult {
17
+ success: boolean;
18
+ stdout: string;
19
+ stderr: string;
20
+ exitCode: number | null;
21
+ error?: string;
22
+ }
23
+ /**
24
+ * Execute a task using Claude Code CLI
25
+ */
26
+ export declare function executeClaudeTask(options: ExecutionOptions): Promise<ExecutionResult>;
27
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/claude/executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAkH3F"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Claude Code CLI Executor
3
+ *
4
+ * Executes tasks by spawning Claude Code as a child process.
5
+ */
6
+ import { spawn } from 'node:child_process';
7
+ import { existsSync } from 'node:fs';
8
+ import { resolve } from 'node:path';
9
+ import { logger } from '../utils/logger.js';
10
+ import { ErrorCode, McpServerError } from '../utils/error-handler.js';
11
+ /**
12
+ * Execute a task using Claude Code CLI
13
+ */
14
+ export async function executeClaudeTask(options) {
15
+ const { task, workingDirectory, timeout = 300000, additionalArgs = [], } = options;
16
+ logger.info(`Executing task: "${task.substring(0, 100)}${task.length > 100 ? '...' : ''}"`);
17
+ // Validate working directory if provided
18
+ let cwd;
19
+ if (workingDirectory) {
20
+ cwd = resolve(workingDirectory);
21
+ if (!existsSync(cwd)) {
22
+ throw new McpServerError(ErrorCode.INVALID_WORKING_DIRECTORY, `Working directory does not exist: ${workingDirectory}`, { path: cwd });
23
+ }
24
+ logger.info(`Using working directory: ${cwd}`);
25
+ }
26
+ // Build CLI arguments
27
+ const args = buildCliArgs(task, cwd, additionalArgs);
28
+ logger.debug(`Claude CLI args: ${JSON.stringify(args)}`);
29
+ // Spawn the process
30
+ const claude = spawn('claude', args, {
31
+ env: process.env,
32
+ stdio: ['ignore', 'pipe', 'pipe'],
33
+ shell: true, // Use shell to find 'claude' in PATH
34
+ });
35
+ let stdout = '';
36
+ let stderr = '';
37
+ let timedOut = false;
38
+ // Set timeout
39
+ const timeoutHandle = setTimeout(() => {
40
+ logger.warn(`Task timeout after ${timeout}ms, terminating process...`);
41
+ timedOut = true;
42
+ claude.kill('SIGTERM');
43
+ }, timeout);
44
+ // Collect stdout
45
+ claude.stdout?.on('data', (data) => {
46
+ const chunk = data.toString();
47
+ stdout += chunk;
48
+ logger.debug(`stdout: ${chunk.substring(0, 200)}`);
49
+ });
50
+ // Collect stderr
51
+ claude.stderr?.on('data', (data) => {
52
+ const chunk = data.toString();
53
+ stderr += chunk;
54
+ logger.debug(`stderr: ${chunk.substring(0, 200)}`);
55
+ });
56
+ // Wait for process to exit
57
+ return new Promise((resolve) => {
58
+ claude.on('close', (code) => {
59
+ clearTimeout(timeoutHandle);
60
+ if (timedOut) {
61
+ logger.error('Task execution timed out');
62
+ resolve({
63
+ success: false,
64
+ stdout,
65
+ stderr,
66
+ exitCode: code,
67
+ error: `Execution timed out after ${timeout}ms`,
68
+ });
69
+ return;
70
+ }
71
+ const success = code === 0;
72
+ logger.info(`Task completed with exit code: ${code}`);
73
+ resolve({
74
+ success,
75
+ stdout,
76
+ stderr,
77
+ exitCode: code,
78
+ });
79
+ });
80
+ claude.on('error', (error) => {
81
+ clearTimeout(timeoutHandle);
82
+ // Check if Claude Code is not found
83
+ if (error.message.includes('ENOENT') || error.message.includes('not found')) {
84
+ logger.error('Claude Code CLI not found');
85
+ resolve({
86
+ success: false,
87
+ stdout: '',
88
+ stderr: '',
89
+ exitCode: null,
90
+ error: 'Claude Code CLI not found. Please ensure Claude Code is installed and in your PATH.',
91
+ });
92
+ return;
93
+ }
94
+ logger.error(`Process error: ${error.message}`);
95
+ resolve({
96
+ success: false,
97
+ stdout,
98
+ stderr,
99
+ exitCode: null,
100
+ error: error.message,
101
+ });
102
+ });
103
+ });
104
+ }
105
+ /**
106
+ * Build CLI arguments for Claude Code
107
+ */
108
+ function buildCliArgs(task, workingDirectory, additionalArgs = []) {
109
+ const args = [];
110
+ // Add working directory if specified
111
+ if (workingDirectory) {
112
+ args.push('--directory', workingDirectory);
113
+ }
114
+ // Add additional arguments (exclude -p if user provided it, we add it by default)
115
+ const filteredArgs = additionalArgs.filter(arg => arg !== '-p' && arg !== '--print');
116
+ args.push(...filteredArgs);
117
+ // Add -p flag for one-time execution (non-interactive mode)
118
+ // This must come immediately before the task
119
+ args.push('-p', task);
120
+ return args;
121
+ }
122
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/claude/executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAqBtE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAyB;IAC/D,MAAM,EACJ,IAAI,EACJ,gBAAgB,EAChB,OAAO,GAAG,MAAM,EAChB,cAAc,GAAG,EAAE,GACpB,GAAG,OAAO,CAAC;IAEZ,MAAM,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE5F,yCAAyC;IACzC,IAAI,GAAuB,CAAC;IAC5B,IAAI,gBAAgB,EAAE,CAAC;QACrB,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAChC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,E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for the server.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Back-Agent MCP Server
3
+ *
4
+ * An MCP server that executes tasks using Claude Code CLI.
5
+ *
6
+ * Main entry point for the server.
7
+ */
8
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
10
+ import { registerExecuteTaskTool } from './server/tools/execute-task.js';
11
+ import { logger, setLogLevel, LogLevel } from './utils/logger.js';
12
+ const SERVER_INFO = {
13
+ name: 'back-agent-mcp',
14
+ version: '1.0.0',
15
+ };
16
+ /**
17
+ * Start the MCP server
18
+ */
19
+ async function main() {
20
+ // Set log level from environment variable if provided
21
+ const logLevel = process.env.LOG_LEVEL?.toUpperCase();
22
+ if (logLevel === 'DEBUG') {
23
+ setLogLevel(LogLevel.DEBUG);
24
+ }
25
+ else if (logLevel === 'WARN') {
26
+ setLogLevel(LogLevel.WARN);
27
+ }
28
+ else if (logLevel === 'ERROR') {
29
+ setLogLevel(LogLevel.ERROR);
30
+ }
31
+ logger.info(`Starting ${SERVER_INFO.name} v${SERVER_INFO.version}`);
32
+ // Create MCP server instance
33
+ const server = new McpServer(SERVER_INFO);
34
+ // Register tools
35
+ registerExecuteTaskTool(server);
36
+ logger.info('Registered tool: execute-task');
37
+ // Create stdio transport for communication
38
+ const transport = new StdioServerTransport();
39
+ // Connect the server to the transport
40
+ await server.connect(transport);
41
+ // IMPORTANT: Log to stderr, not stdout (stdio is used for MCP communication)
42
+ logger.info('Back-Agent MCP Server is running');
43
+ logger.info('Waiting for tool calls...');
44
+ }
45
+ // Start the server
46
+ main().catch((error) => {
47
+ logger.error(`Fatal error starting server: ${error}`);
48
+ process.exit(1);
49
+ });
50
+ // Handle graceful shutdown
51
+ process.on('SIGINT', () => {
52
+ logger.info('Received SIGINT, shutting down...');
53
+ process.exit(0);
54
+ });
55
+ process.on('SIGTERM', () => {
56
+ logger.info('Received SIGTERM, shutting down...');
57
+ process.exit(0);
58
+ });
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElE,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,OAAO;CACjB,CAAC;AAEF;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,sDAAsD;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC;IACtD,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;SAAM,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QAC/B,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;SAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,YAAY,WAAW,CAAC,IAAI,KAAK,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;IAEpE,6BAA6B;IAC7B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,iBAAiB;IACjB,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;IAE7C,2CAA2C;IAC3C,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE7C,sCAAsC;IACtC,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,6EAA6E;IAC7E,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IAChD,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;AAC3C,CAAC;AAED,mBAAmB;AACnB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,MAAM,CAAC,KAAK,CAAC,gCAAgC,KAAK,EAAE,CAAC,CAAC;IACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,2BAA2B;AAC3B,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACxB,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Execute Task Tool for MCP Server
3
+ *
4
+ * This tool allows clients to execute development tasks using Claude Code CLI.
5
+ */
6
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
+ import { z } from 'zod';
8
+ /**
9
+ * Input schema for the execute-task tool
10
+ */
11
+ export declare const executeTaskInputSchema: z.ZodObject<{
12
+ task: z.ZodString;
13
+ workingDirectory: z.ZodOptional<z.ZodString>;
14
+ timeout: z.ZodOptional<z.ZodNumber>;
15
+ additionalArgs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
16
+ }, "strip", z.ZodTypeAny, {
17
+ task: string;
18
+ workingDirectory?: string | undefined;
19
+ timeout?: number | undefined;
20
+ additionalArgs?: string[] | undefined;
21
+ }, {
22
+ task: string;
23
+ workingDirectory?: string | undefined;
24
+ timeout?: number | undefined;
25
+ additionalArgs?: string[] | undefined;
26
+ }>;
27
+ export type ExecuteTaskInput = z.infer<typeof executeTaskInputSchema>;
28
+ /**
29
+ * Register the execute-task tool with the MCP server
30
+ */
31
+ export declare function registerExecuteTaskTool(server: McpServer): void;
32
+ //# sourceMappingURL=execute-task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-task.d.ts","sourceRoot":"","sources":["../../../src/server/tools/execute-task.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;EAKjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAqE/D"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Execute Task Tool for MCP Server
3
+ *
4
+ * This tool allows clients to execute development tasks using Claude Code CLI.
5
+ */
6
+ import { z } from 'zod';
7
+ import { executeClaudeTask } from '../../claude/executor.js';
8
+ import { logger } from '../../utils/logger.js';
9
+ import { createErrorResponse } from '../../utils/error-handler.js';
10
+ /**
11
+ * Input schema for the execute-task tool
12
+ */
13
+ export const executeTaskInputSchema = z.object({
14
+ task: z.string().describe('The task description to execute with Claude Code'),
15
+ workingDirectory: z.string().optional().describe('The working directory for Claude Code execution'),
16
+ timeout: z.number().min(1).max(3600).optional().describe('Timeout in seconds (max 3600)'),
17
+ additionalArgs: z.array(z.string()).optional().describe('Additional CLI arguments for Claude Code'),
18
+ });
19
+ /**
20
+ * Register the execute-task tool with the MCP server
21
+ */
22
+ export function registerExecuteTaskTool(server) {
23
+ server.registerTool('execute-task', {
24
+ description: 'Execute a development task using Claude Code CLI. ' +
25
+ 'This tool spawns Claude Code as a child process and returns the output. ' +
26
+ 'Useful for automated code generation, refactoring, debugging, and other development tasks.',
27
+ inputSchema: executeTaskInputSchema,
28
+ }, async (input) => {
29
+ // Validate input
30
+ const validationResult = executeTaskInputSchema.safeParse(input);
31
+ if (!validationResult.success) {
32
+ const errorMessages = validationResult.error.errors
33
+ .map((e) => `${e.path.join('.')}: ${e.message}`)
34
+ .join(', ');
35
+ logger.error(`Invalid input: ${errorMessages}`);
36
+ return createErrorResponse(new Error(`Invalid input: ${errorMessages}`));
37
+ }
38
+ const { task, workingDirectory, timeout = 300, additionalArgs = [] } = validationResult.data;
39
+ logger.info(`Executing task via MCP: "${task.substring(0, 50)}..."`);
40
+ try {
41
+ // Execute the task
42
+ const result = await executeClaudeTask({
43
+ task,
44
+ workingDirectory,
45
+ timeout: timeout * 1000, // Convert to milliseconds
46
+ additionalArgs,
47
+ });
48
+ // Format and return the result
49
+ if (result.success) {
50
+ const output = result.stdout.trim()
51
+ ? result.stdout
52
+ : 'Task completed successfully with no output.';
53
+ logger.info('Task completed successfully');
54
+ return {
55
+ content: [
56
+ {
57
+ type: 'text',
58
+ text: formatSuccessOutput(output, result.exitCode),
59
+ },
60
+ ],
61
+ };
62
+ }
63
+ else {
64
+ logger.error('Task execution failed');
65
+ return {
66
+ content: [
67
+ {
68
+ type: 'text',
69
+ text: formatErrorOutput(result, task),
70
+ },
71
+ ],
72
+ isError: true,
73
+ };
74
+ }
75
+ }
76
+ catch (error) {
77
+ logger.error(`Unexpected error: ${error}`);
78
+ return createErrorResponse(error);
79
+ }
80
+ });
81
+ }
82
+ /**
83
+ * Format successful execution output
84
+ */
85
+ function formatSuccessOutput(stdout, exitCode) {
86
+ const lines = [];
87
+ lines.push('## Task Completed Successfully');
88
+ lines.push('');
89
+ if (stdout) {
90
+ lines.push('### Output:');
91
+ lines.push('```\n' + stdout.trim() + '\n```');
92
+ }
93
+ if (exitCode !== null) {
94
+ lines.push('');
95
+ lines.push(`Exit Code: ${exitCode}`);
96
+ }
97
+ return lines.join('\n');
98
+ }
99
+ /**
100
+ * Format failed execution output
101
+ */
102
+ function formatErrorOutput(result, task) {
103
+ const lines = [];
104
+ lines.push('## Task Execution Failed');
105
+ lines.push('');
106
+ lines.push(`**Task:** ${task.substring(0, 100)}${task.length > 100 ? '...' : ''}`);
107
+ lines.push('');
108
+ if (result.error) {
109
+ lines.push(`**Error:** ${result.error}`);
110
+ lines.push('');
111
+ }
112
+ if (result.stderr) {
113
+ lines.push('### Error Output:');
114
+ lines.push('```\n' + result.stderr.trim() + '\n```');
115
+ lines.push('');
116
+ }
117
+ if (result.stdout) {
118
+ lines.push('### Standard Output:');
119
+ lines.push('```\n' + result.stdout.trim() + '\n```');
120
+ lines.push('');
121
+ }
122
+ if (result.exitCode !== null) {
123
+ lines.push(`Exit Code: ${result.exitCode}`);
124
+ }
125
+ return lines.join('\n');
126
+ }
127
+ //# sourceMappingURL=execute-task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-task.js","sourceRoot":"","sources":["../../../src/server/tools/execute-task.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,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,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,CAAC;QACrD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,CAAC;QACrD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,cAAc,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Error types and error handling utilities for Back-Agent MCP Server
3
+ */
4
+ export declare enum ErrorCode {
5
+ CLAUDE_NOT_FOUND = "CLAUDE_NOT_FOUND",
6
+ INVALID_WORKING_DIRECTORY = "INVALID_WORKING_DIRECTORY",
7
+ EXECUTION_TIMEOUT = "EXECUTION_TIMEOUT",
8
+ EXECUTION_FAILED = "EXECUTION_FAILED",
9
+ INVALID_INPUT = "INVALID_INPUT",
10
+ INTERNAL_ERROR = "INTERNAL_ERROR"
11
+ }
12
+ export declare class McpServerError extends Error {
13
+ code: ErrorCode;
14
+ details?: unknown | undefined;
15
+ constructor(code: ErrorCode, message: string, details?: unknown | undefined);
16
+ }
17
+ export declare function isMcpServerError(error: unknown): error is McpServerError;
18
+ export declare function formatErrorMessage(error: unknown): string;
19
+ /**
20
+ * Create a standardized error response for MCP tool calls
21
+ */
22
+ export declare function createErrorResponse(error: unknown): {
23
+ content: Array<{
24
+ type: 'text';
25
+ text: string;
26
+ }>;
27
+ isError: true;
28
+ };
29
+ //# sourceMappingURL=error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,SAAS;IACnB,gBAAgB,qBAAqB;IACrC,yBAAyB,8BAA8B;IACvD,iBAAiB,sBAAsB;IACvC,gBAAgB,qBAAqB;IACrC,aAAa,kBAAkB;IAC/B,cAAc,mBAAmB;CAClC;AAED,qBAAa,cAAe,SAAQ,KAAK;IAE9B,IAAI,EAAE,SAAS;IAEf,OAAO,CAAC,EAAE,OAAO;gBAFjB,IAAI,EAAE,SAAS,EACtB,OAAO,EAAE,MAAM,EACR,OAAO,CAAC,EAAE,OAAO,YAAA;CAK3B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAczD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG;IACnD,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,EAAE,IAAI,CAAC;CACf,CAMA"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Error types and error handling utilities for Back-Agent MCP Server
3
+ */
4
+ export var ErrorCode;
5
+ (function (ErrorCode) {
6
+ ErrorCode["CLAUDE_NOT_FOUND"] = "CLAUDE_NOT_FOUND";
7
+ ErrorCode["INVALID_WORKING_DIRECTORY"] = "INVALID_WORKING_DIRECTORY";
8
+ ErrorCode["EXECUTION_TIMEOUT"] = "EXECUTION_TIMEOUT";
9
+ ErrorCode["EXECUTION_FAILED"] = "EXECUTION_FAILED";
10
+ ErrorCode["INVALID_INPUT"] = "INVALID_INPUT";
11
+ ErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
12
+ })(ErrorCode || (ErrorCode = {}));
13
+ export class McpServerError extends Error {
14
+ code;
15
+ details;
16
+ constructor(code, message, details) {
17
+ super(message);
18
+ this.code = code;
19
+ this.details = details;
20
+ this.name = 'McpServerError';
21
+ }
22
+ }
23
+ export function isMcpServerError(error) {
24
+ return error instanceof McpServerError;
25
+ }
26
+ export function formatErrorMessage(error) {
27
+ if (isMcpServerError(error)) {
28
+ let message = `[${error.code}] ${error.message}`;
29
+ if (error.details) {
30
+ message += `\nDetails: ${JSON.stringify(error.details)}`;
31
+ }
32
+ return message;
33
+ }
34
+ if (error instanceof Error) {
35
+ return error.message;
36
+ }
37
+ return String(error);
38
+ }
39
+ /**
40
+ * Create a standardized error response for MCP tool calls
41
+ */
42
+ export function createErrorResponse(error) {
43
+ const message = formatErrorMessage(error);
44
+ return {
45
+ content: [{ type: 'text', text: message }],
46
+ isError: true,
47
+ };
48
+ }
49
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAN,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,kDAAqC,CAAA;IACrC,oEAAuD,CAAA;IACvD,oDAAuC,CAAA;IACvC,kDAAqC,CAAA;IACrC,4CAA+B,CAAA;IAC/B,8CAAiC,CAAA;AACnC,CAAC,EAPW,SAAS,KAAT,SAAS,QAOpB;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IAE9B;IAEA;IAHT,YACS,IAAe,EACtB,OAAe,EACR,OAAiB;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJR,SAAI,GAAJ,IAAI,CAAW;QAEf,YAAO,GAAP,OAAO,CAAU;QAGxB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,cAAc,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,IAAI,OAAO,GAAG,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;QACjD,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,IAAI,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3D,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAIhD,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QACnD,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Logger utility for Back-Agent MCP Server
3
+ *
4
+ * IMPORTANT: All logs must go to stderr to avoid interfering with
5
+ * the MCP stdio communication (which uses stdout for JSON-RPC messages).
6
+ */
7
+ export declare enum LogLevel {
8
+ DEBUG = 0,
9
+ INFO = 1,
10
+ WARN = 2,
11
+ ERROR = 3
12
+ }
13
+ /**
14
+ * Set the current log level
15
+ */
16
+ export declare function setLogLevel(level: LogLevel): void;
17
+ export declare const logger: {
18
+ debug: (message: string, ...args: unknown[]) => void;
19
+ info: (message: string, ...args: unknown[]) => void;
20
+ warn: (message: string, ...args: unknown[]) => void;
21
+ error: (message: string, ...args: unknown[]) => void;
22
+ };
23
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACV;AAID;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAEjD;AA6BD,eAAO,MAAM,MAAM;qBACA,MAAM,WAAW,OAAO,EAAE;oBAC3B,MAAM,WAAW,OAAO,EAAE;oBAC1B,MAAM,WAAW,OAAO,EAAE;qBACzB,MAAM,WAAW,OAAO,EAAE;CAC5C,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Logger utility for Back-Agent MCP Server
3
+ *
4
+ * IMPORTANT: All logs must go to stderr to avoid interfering with
5
+ * the MCP stdio communication (which uses stdout for JSON-RPC messages).
6
+ */
7
+ export var LogLevel;
8
+ (function (LogLevel) {
9
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
10
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
11
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
12
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
13
+ })(LogLevel || (LogLevel = {}));
14
+ let currentLogLevel = LogLevel.INFO;
15
+ /**
16
+ * Set the current log level
17
+ */
18
+ export function setLogLevel(level) {
19
+ currentLogLevel = level;
20
+ }
21
+ /**
22
+ * Format timestamp for log messages
23
+ */
24
+ function getTimestamp() {
25
+ return new Date().toISOString();
26
+ }
27
+ /**
28
+ * Write log message to stderr
29
+ */
30
+ function log(level, message, ...args) {
31
+ if (level < currentLogLevel) {
32
+ return;
33
+ }
34
+ const levelName = LogLevel[level];
35
+ const timestamp = getTimestamp();
36
+ const prefix = `[${timestamp}] [${levelName}]`;
37
+ const output = args.length > 0
38
+ ? `${prefix} ${message} ${args.map(String).join(' ')}`
39
+ : `${prefix} ${message}`;
40
+ // Always write to stderr to avoid interfering with MCP stdio communication
41
+ console.error(output);
42
+ }
43
+ export const logger = {
44
+ debug: (message, ...args) => log(LogLevel.DEBUG, message, ...args),
45
+ info: (message, ...args) => log(LogLevel.INFO, message, ...args),
46
+ warn: (message, ...args) => log(LogLevel.WARN, message, ...args),
47
+ error: (message, ...args) => log(LogLevel.ERROR, message, ...args),
48
+ };
49
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAN,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,yCAAS,CAAA;IACT,uCAAQ,CAAA;IACR,uCAAQ,CAAA;IACR,yCAAS,CAAA;AACX,CAAC,EALW,QAAQ,KAAR,QAAQ,QAKnB;AAED,IAAI,eAAe,GAAa,QAAQ,CAAC,IAAI,CAAC;AAE9C;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAe;IACzC,eAAe,GAAG,KAAK,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,SAAS,YAAY;IACnB,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,SAAS,GAAG,CAAC,KAAe,EAAE,OAAe,EAAE,GAAG,IAAe;IAC/D,IAAI,KAAK,GAAG,eAAe,EAAE,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,SAAS,MAAM,SAAS,GAAG,CAAC;IAE/C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC;QAC5B,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACtD,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;IAE3B,2EAA2E;IAC3E,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACrF,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACnF,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACnF,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACtF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@zuens2020/back-agent-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for executing tasks via Claude Code CLI",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "back-agent-mcp": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsx src/index.ts",
18
+ "start": "node dist/index.js",
19
+ "typecheck": "tsc --noEmit",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "keywords": [
23
+ "mcp",
24
+ "model-context-protocol",
25
+ "claude-code",
26
+ "automation",
27
+ "claude",
28
+ "ai"
29
+ ],
30
+ "author": "ZUENS2020 <shengyuanzhang-zuens2020@outlook.com>",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/ZUENS2020/back-agent-mcp.git"
35
+ },
36
+ "homepage": "https://github.com/ZUENS2020/back-agent-mcp#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/ZUENS2020/back-agent-mcp/issues"
39
+ },
40
+ "engines": {
41
+ "node": ">=18"
42
+ },
43
+ "dependencies": {
44
+ "@modelcontextprotocol/sdk": "^1.0.4",
45
+ "zod": "^3.23.8"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^22.10.5",
49
+ "tsx": "^4.19.2",
50
+ "typescript": "^5.7.3"
51
+ }
52
+ }