{"record":{"id":"3e831a8d5de82db9","repo":"angular/angular-cli","slug":"dev-server-already-started","errorCode":null,"errorMessage":"Dev server already started.","messagePattern":"Dev server already started\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/commands/mcp/devserver.ts","lineNumber":111,"sourceCode":"    host,\n    port,\n    workspacePath,\n    project,\n  }: {\n    host: Host;\n    port: number;\n    workspacePath: string;\n    project: string;\n  }) {\n    this.host = host;\n    this.port = port;\n    this.workspacePath = workspacePath;\n    this.project = project;\n  }\n\n  start() {\n    if (this.devserverProcess) {\n      throw Error('Dev server already started.');\n    }\n\n    const args = ['serve'];\n    if (this.project) {\n      args.push(this.project);\n    }\n\n    args.push(`--port=${this.port}`);\n\n    this.devserverProcess = this.host.startNgProcess(args, {\n      stdio: 'pipe',\n      cwd: this.workspacePath,\n    });\n    processStreamLines(this.devserverProcess.stdout, (line) => this.addLog(line));\n    processStreamLines(this.devserverProcess.stderr, (line) => this.addLog(line));\n\n    this.devserverProcess.on('close', () => {\n      this.stop();","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/commands/mcp/devserver.ts#L93-L129","documentation":"The MCP devserver manager in @angular/cli throws this plain Error from start() when a Devserver instance already has a child process running. It guards against launching a second `ng serve` process from the same Devserver object, since each instance owns exactly one dev-server process.","triggerScenarios":"Calling Devserver.start() twice on the same instance without calling stop() in between — e.g. the MCP client invokes the devserver-start tool twice, or start() is retried after a first successful launch while this.devserverProcess is still set.","commonSituations":"An MCP agent re-issues a devserver-start tool call because it assumed the previous one failed; automation scripts starting the server on each request; forgetting that the server persists across tool calls within one MCP session.","solutions":["Call devserver.stop() (or the devserver-stop MCP tool) before starting again.","Check whether a server is already running (list current devservers / track the instance) and reuse it instead of calling start().","Wrap start() in a check or try-catch and treat this message as an idempotent 'already running' signal.","Create a fresh Devserver instance for a different workspace/project instead of reusing the existing one."],"exampleFix":"// before\nconst server = new Devserver({ workspacePath, project });\nserver.start();\nserver.start(); // throws 'Dev server already started.'\n// after\nconst server = new Devserver({ workspacePath, project });\nif (!server.isRunning()) server.start();","handlingStrategy":"try-catch","validationCode":"if (!server.isRunning?.()) {\n  server.start();\n}","typeGuard":"function isAlreadyStartedError(err: unknown): err is Error {\n  return err instanceof Error && err.message === 'Dev server already started.';\n}","tryCatchPattern":"try {\n  server.start();\n} catch (err) {\n  if (!isAlreadyStartedError(err)) throw err;\n  // already running: reuse the existing devserver\n}","preventionTips":["Track whether a Devserver instance was already started before invoking start().","Treat devserver-start as idempotent: on this error, reuse the running server.","Always pair start with stop in teardown logic.","Use the MCP devserver-stop tool before re-running devserver-start."],"tags":["dev-server","mcp","angular-cli","state-conflict"],"backgroundTag":"dev-server-already-running","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}