{"record":{"id":"536a0db082ae3423","repo":"flipped-aurora/gin-vue-admin","slug":"mcp","errorCode":null,"errorMessage":"当前 MCP 服务不是由页面启动的，无法自动停用","messagePattern":"当前 MCP 服务不是由页面启动的，无法自动停用","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/mcp/standalone_manager.go","lineNumber":205,"sourceCode":"\t\tLogPath:    logPath,\n\t\tConfigPath: configPath,\n\t\tWorkDir:    workDir,\n\t\tCommand:    commandPath,\n\t\tArgs:       append([]string{}, commandArgs...),\n\t}\n\tif err := writeManagedProcessMeta(meta); err != nil {\n\t\treturn GetManagedStandaloneStatus(context.Background()), err\n\t}\n\n\treturn waitForManagedProcess(ctx, meta)\n}\n\nfunc StopManagedStandalone(ctx context.Context) (ManagedStandaloneStatus, error) {\n\tmeta, err := readManagedProcessMeta()\n\tif err != nil {\n\t\tstatus := GetManagedStandaloneStatus(ctx)\n\t\tif status.Reachable {\n\t\t\treturn status, errors.New(\"当前 MCP 服务不是由页面启动的，无法自动停用\")\n\t\t}\n\t\treturn status, nil\n\t}\n\n\tif meta.PID > 0 && processExists(meta.PID) {\n\t\tif err := terminateProcess(meta.PID); err != nil {\n\t\t\treturn GetManagedStandaloneStatus(context.Background()), fmt.Errorf(\"停用 MCP 独立服务失败: %w\", err)\n\t\t}\n\t}\n\n\tdeadline := time.NewTimer(mcpStopWaitTimeout)\n\tticker := time.NewTicker(200 * time.Millisecond)\n\tdefer deadline.Stop()\n\tdefer ticker.Stop()\n\n\tfor {\n\t\tselect {\n\t\tcase <-ctx.Done():","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/standalone_manager.go#L187-L223","documentation":"StopManagedStandalone stops the MCP standalone service only if the backend itself started it (verified via the managed-process meta file). When meta cannot be read (service not page-managed) but the endpoint IS reachable, it returns this error to tell the caller the running instance belongs to something else (e.g. manually launched `go run`) and cannot be auto-terminated. If the service is unreachable and unmanaged, it returns the status with no error.","triggerScenarios":"Clicking stop/deactivate for the MCP standalone service in the page while the service was started manually from a terminal, by another tool, or the managed-process meta file was deleted/corrupted while the process still runs.","commonSituations":"Developer started the MCP server via `go run ./cmd/mcp` or a compiled binary by hand, then tries to manage it from the admin UI; stale or wiped runtime meta directory after reinstall/clean while an orphan process keeps listening.","solutions":["Stop the process manually: find the PID listening on the MCP port and kill it (e.g. lsof -i :PORT then kill PID)","Restart the service from the admin page so it becomes page-managed, then stop it from the page","Check the MCP runtime meta file (mcp runtime dir) is intact; if it was deleted, the running process is orphaned and must be killed manually","Verify GetManagedStandaloneStatus in the UI to confirm who owns the running process before stopping"],"exampleFix":"// manually stop an orphaned MCP process\nlsof -i :8888    # find PID bound to the MCP port\nkill <PID>       # then manage lifecycle from the page","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"status, err := mcp.StopManagedStandalone(ctx)\nif err != nil {\n    log.Printf(\"service is externally managed: %v; stop it manually\", err)\n    // fall back: locate PID by port and terminate by hand\n}","preventionTips":["Always start/stop the MCP service from the page so the meta file tracks ownership","Never delete the mcp runtime directory while the service is running","After manual `go run` starts, expect page-side stop to fail and kill the process manually"],"tags":["mcp","process-lifecycle","golang"],"backgroundTag":"process-not-managed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}