This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 5c39b3fe5 fix(rmqctl): keep the environment-selected config in the MCP
snippet (#6943)
5c39b3fe5 is described below
commit 5c39b3fe535cfe78e256f7c397afa71dd8595e3e
Author: bai mengxuan <[email protected]>
AuthorDate: Fri Nov 27 12:22:18 2026 +0800
fix(rmqctl): keep the environment-selected config in the MCP snippet (#6943)
---
rmqctl/cmd/mcp.go | 11 +++++++++--
rmqctl/cmd/mcp_config_path_test.go | 32 ++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/rmqctl/cmd/mcp.go b/rmqctl/cmd/mcp.go
index e994e83ff..f1133f522 100644
--- a/rmqctl/cmd/mcp.go
+++ b/rmqctl/cmd/mcp.go
@@ -66,9 +66,16 @@ func (a *App) newMCPConfigCommand(runtime commandRuntime)
*cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
out := cmd.OutOrStdout()
stdioArgs := []string{"mcp", "stdio"}
- if runtime.options.configPath != "" {
+ selectedPath := runtime.options.configPath
+ if selectedPath == "" {
+ // The snippet has to reproduce the file this
invocation selected. RMQCTL_CONFIG is
+ // inherited by a shell, but an MCP client
launched from a GUI does not inherit it,
+ // so the child would resolve the default
context instead of the selected one.
+ selectedPath = a.Store.Getenv("RMQCTL_CONFIG")
+ }
+ if selectedPath != "" {
// The MCP client may launch from a different
working directory.
- configPath, err :=
filepath.Abs(runtime.options.configPath)
+ configPath, err := filepath.Abs(selectedPath)
if err != nil {
return err
}
diff --git a/rmqctl/cmd/mcp_config_path_test.go
b/rmqctl/cmd/mcp_config_path_test.go
index e4b66ebc5..680a857bd 100644
--- a/rmqctl/cmd/mcp_config_path_test.go
+++ b/rmqctl/cmd/mcp_config_path_test.go
@@ -60,6 +60,38 @@ func TestMCPConfigResolvesSelectedPathBeforeClientLaunch(t
*testing.T) {
}
}
+func TestMCPConfigCarriesTheEnvironmentSelectedPath(t *testing.T) {
+ t.Chdir(t.TempDir())
+ stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
+ app := NewApp(stdout, stderr)
+ app.Store.Getenv = func(key string) string {
+ if key == "RMQCTL_CONFIG" {
+ return filepath.Join("env", "selected.yaml")
+ }
+ return ""
+ }
+ if code := app.Execute([]string{"mcp", "config"}); code != 0 {
+ t.Fatalf("exit = %d: %s", code, stderr)
+ }
+ var snippet struct {
+ Servers map[string]struct {
+ Args []string `json:"args"`
+ } `json:"mcpServers"`
+ }
+ if err := json.Unmarshal(stdout.Bytes(), &snippet); err != nil {
+ t.Fatal(err)
+ }
+ args := snippet.Servers["rocketmq-studio"].Args
+ expected, err := filepath.Abs(filepath.Join("env", "selected.yaml"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ // A client that launches without the shell's environment must still
open the file this run used.
+ if want := []string{"mcp", "stdio", "--config", expected};
!reflect.DeepEqual(args, want) {
+ t.Fatalf("args = %q; want the selected config %q", args, want)
+ }
+}
+
func TestMCPConfigLeavesUnspecifiedPathUnbound(t *testing.T) {
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
app := NewApp(stdout, stderr)