-
Notifications
You must be signed in to change notification settings - Fork 0
test(mcp): Isolate MCP test config #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,18 @@ import ( | |
| "time" | ||
| ) | ||
|
|
||
| // isolateConfigHome points NewServerRegistry at a per-test directory on every | ||
| // platform. os.UserConfigDir only reads XDG_CONFIG_HOME on unix-like systems; | ||
| // on darwin it derives ~/Library/Application Support from HOME, so setting only | ||
| // XDG_CONFIG_HOME leaks registry, cache, and OAuth state into the real user | ||
| // config directory and makes later runs fail on stale state. | ||
| func isolateConfigHome(t *testing.T) { | ||
| t.Helper() | ||
| home := t.TempDir() | ||
| t.Setenv("HOME", home) | ||
| t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) | ||
| } | ||
|
Comment on lines
+13
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 5 \
'User(Config|Cache|Home)Dir|XDG_(CONFIG|CACHE)_HOME|AppData|LocalAppData|USERPROFILE|GOOS|windows' \
--glob '*.go' --glob 'go.mod' --glob '*.yml' --glob '*.yaml' --glob 'Dockerfile*' .Repository: flanksource/clicky Length of output: 16977 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- test helper and registry call sites ---'
cat -n mcp/client_registry_test.go | sed -n '1,220p'
printf '%s\n' '--- registry path implementation ---'
cat -n mcp/client_registry.go | sed -n '235,275p'
printf '%s\n' '--- related config/cache/home helpers ---'
rg -n -C 8 'GetConfigPathFor|GetPromptsPathFor|UserConfigDir|UserCacheDir|UserHomeDir|\\.cache|mcp-config|mcp-prompts|OAuth|oauth' mcp ai --glob '*.go'
printf '%s\n' '--- Go stdlib source locations and relevant implementations ---'
if command -v go >/dev/null 2>&1; then
goroot="$(go env GOROOT)"
printf 'GOROOT=%s\n' "$goroot"
rg -n -C 12 'func User(Config|Cache|Home)Dir|XDG_CONFIG_HOME|XDG_CACHE_HOME|LocalAppData|APPDATA|USERPROFILE|Library/Application Support' \
"$goroot/src/os" "$goroot/src/internal" 2>/dev/null || true
else
printf '%s\n' 'go command unavailable'
fiRepository: flanksource/clicky Length of output: 50375 🏁 Script executed: #!/bin/bash
set -euo pipefail
if ! command -v go >/dev/null 2>&1; then
echo "go command unavailable"
exit 0
fi
goroot="$(go env GOROOT)"
printf '%s\n' '--- UserConfigDir/UserCacheDir/UserHomeDir implementations ---'
rg -l 'func User(Config|Cache|Home)Dir' "$goroot/src/os" | while IFS= read -r f; do
echo "FILE: $f"
rg -n -A45 -B5 'func User(Config|Cache|Home)Dir' "$f"
done
printf '%s\n' '--- helper call sites ---'
rg -n -C 3 'isolateConfigHome\(' mcp --glob '*.go'
printf '%s\n' '--- all NewServerRegistry uses in tests ---'
rg -n -C 3 'NewServerRegistry\(' --glob '*_test.go' .Repository: flanksource/clicky Length of output: 11228 Redirect Windows user directories in On Windows, 🤖 Prompt for AI Agents |
||
|
|
||
| func TestServerConfigValidate(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: flanksource/clicky
Length of output: 14017
🏁 Script executed:
Repository: flanksource/clicky
Length of output: 50375
🏁 Script executed:
Repository: flanksource/clicky
Length of output: 19514
🌐 Web query:
github mark3labs mcp-go v0.56.0 transport.NewStdio environment os.Environ💡 Result:
In the mark3labs/mcp-go library, specifically as of version 0.56.0, the transport.NewStdio function (and related helpers) handles environment variables by merging provided custom environment variables with the host process's existing environment variables [1][2]. When spawning a subprocess, the transport implementation uses the following logic to set the environment [1]: cmd.Env = append(os.Environ, c.env...) This means: 1. It retrieves the host's current environment variables using os.Environ [1]. 2. It appends the slice of custom environment variables (provided via the env argument in NewStdio or NewStdioWithOptions) to the host environment [1]. 3. The resulting environment is then passed to the exec.Cmd instance used to launch the subprocess [1]. If you need finer control over the process creation—such as replacing the environment entirely rather than appending to it, or configuring other low-level system attributes—the library provides the NewStdioWithOptions function [1][3]. By using this with the WithCommandFunc option, you can provide a custom factory function to define exactly how the exec.Cmd is constructed and configured, including full control over its Env field [4][3].
Citations:
Stdioclient with options mark3labs/mcp-go#457🏁 Script executed:
Repository: flanksource/clicky
Length of output: 6996
🏁 Script executed:
Repository: flanksource/clicky
Length of output: 507
Preserve
GOPATHorGOMODCACHEWhen both variables are unset, changing
HOMEmakes the childgo runuse a temporary module cache. Preserve one variable or isolate application configuration without changingHOME.🤖 Prompt for AI Agents