The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Read the project a Claude Code local-scope server runs in
Claude9958888c6aa9
diff --git a/cli/beacon/internal/endpoint/inventory/inventory.go b/cli/beacon/internal/endpoint/inventory/inventory.goindex 9320fb6a..cb6f450b 100644--- a/cli/beacon/internal/endpoint/inventory/inventory.go+++ b/cli/beacon/internal/endpoint/inventory/inventory.go@@ -8,6 +8,7 @@ import ("os""path/filepath""runtime"+ "slices""sort""strings""time"@@ -138,6 +139,11 @@ type MCPServer struct {ParserStatus string `json:"parser_status"`Redaction string `json:"redaction"`Definition map[string]interface{} `json:"definition,omitempty"`+ // ProjectDirs are the directories of the projects whose entry in a runtime's own config+ // declares the server (Claude Code's ~/.claude.json projects.<path>.mcpServers), which the+ // runtime starts it in. In memory only, for readers such as Beacon Intel that must read the+ // config a launcher finds there; never serialized, so the inventory record is unchanged.+ ProjectDirs []string `json:"-"`}type candidate struct {@@ -860,6 +866,12 @@ func serversFromNestedMCPBlocks(item candidate, value interface{}, redaction strswitch typed := value.(type) {case map[string]interface{}:for key, nested := range typed {+ if key == "projects" {+ if projects, ok := nested.(map[string]interface{}); ok {+ servers = append(servers, serversFromProjects(item, projects, redaction, co)...)+ continue+ }+ }if isMCPServerBlockKey(key) {servers = append(servers, serversFromBlock(item, nested, redaction, co)...)}@@ -873,6 +885,24 @@ func serversFromNestedMCPBlocks(item candidate, value interface{}, redaction strreturn servers}+// serversFromProjects reads a projects block keyed by project directory (Claude Code's+// ~/.claude.json), and records each server's project so a reader knows where it is started.+func serversFromProjects(item candidate, projects map[string]interface{}, redaction string, co contentOptions) []MCPServer {+ var servers []MCPServer+ for dir, nested := range projects {+ found := serversFromNestedMCPBlocks(item, nested, redaction, co)+ if filepath.IsAbs(dir) {+ for i := range found {+ if len(found[i].ProjectDirs) == 0 {+ found[i].ProjectDirs = []string{dir}+ }+ }+ }+ servers = append(servers, found...)+ }+ return servers+}+func isMCPServerBlockKey(key string) bool {switch key {case "mcpServers", "mcp_servers", "mcp":@@ -978,15 +1008,27 @@ func inferTransport(def map[string]interface{}, url, command string) string {}}+func mergeDirs(dirs, more []string) []string {+ for _, d := range more {+ if !slices.Contains(dirs, d) {+ dirs = append(dirs, d)+ }+ }+ sort.Strings(dirs)+ return dirs+}+func dedupeServers(servers []MCPServer) []MCPServer {- seen := map[string]bool{}+ seen := map[string]int{}out := make([]MCPServer, 0, len(servers))for _, server := range servers {key := server.Runtime + "\x00" + server.SourcePathHash + "\x00" + server.ServerNameHash + "\x00" + server.DefinitionHash- if seen[key] {+ if i, ok := seen[key]; ok {+ // The same definition in several projects is one entry, started in each of them.+ out[i].ProjectDirs = mergeDirs(out[i].ProjectDirs, server.ProjectDirs)continue}- seen[key] = true+ seen[key] = len(out)out = append(out, server)}sort.Slice(out, func(i, j int) bool {diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.goindex c8fbe6e4..c9484b28 100644--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go@@ -1441,3 +1441,41 @@ func TestScanFollowsPiAgentDirForTheUserExtension(t *testing.T) {t.Fatalf("pi user candidates = %v, want [%s]", got, want)}}++// Claude Code starts a local-scope server (~/.claude.json projects.<path>.mcpServers) in its+// project, so the scan keeps that directory for in-memory readers, and keeps it out of the record.+func TestClaudeProjectServersCarryTheirProjectInMemoryOnly(t *testing.T) {+ home := t.TempDir()+ a, b, c := filepath.Join(home, "work", "proj-alpha"), filepath.Join(home, "work", "proj-beta"), filepath.Join(home, "work", "proj-gamma")+ config, err := json.Marshal(map[string]interface{}{+ "mcpServers": map[string]interface{}{"global": map[string]interface{}{"command": "npx", "args": []string{"-y", "g"}}},+ "projects": map[string]interface{}{+ a: map[string]interface{}{"mcpServers": map[string]interface{}{"tool": map[string]interface{}{"command": "npx", "args": []string{"-y", "@acme/tool"}}}},+ b: map[string]interface{}{"mcpServers": map[string]interface{}{"tool": map[string]interface{}{"command": "npx", "args": []string{"-y", "@acme/tool"}}}},+ c: map[string]interface{}{"mcpServers": map[string]interface{}{"other": map[string]interface{}{"command": "uvx", "args": []string{"x"}}}},+ "relative": map[string]interface{}{"mcpServers": map[string]interface{}{"rel": map[string]interface{}{"command": "uvx", "args": []string{"y"}}}},+ },+ })+ if err != nil {+ t.Fatal(err)+ }+ writeFile(t, filepath.Join(home, ".claude.json"), string(config))+ result := Scan(Options{HomeDir: home, SkipProjectScope: true, Runtimes: []string{"claude_code"}, Now: fixedNow, IncludeContents: true})+ got := map[string][]string{}+ for _, s := range result.MCPServers {+ got[s.ServerName] = s.ProjectDirs+ encoded, err := json.Marshal(s)+ if err != nil {+ t.Fatal(err)+ }+ if strings.Contains(string(encoded), "proj-") || strings.Contains(strings.ToLower(string(encoded)), "projectdirs") {+ t.Errorf("project directory serialized: %s", encoded)+ }+ }+ want := map[string][]string{"global": nil, "tool": {a, b}, "other": {c}, "rel": nil}+ for name, dirs := range want {+ if !slices.Equal(got[name], dirs) {+ t.Errorf("%s ProjectDirs = %v, want %v", name, got[name], dirs)+ }+ }+}diff --git a/cli/beacon/internal/intel/installed.go b/cli/beacon/internal/intel/installed.goindex 64685ff5..bf750917 100644--- a/cli/beacon/internal/intel/installed.go+++ b/cli/beacon/internal/intel/installed.go@@ -123,7 +123,7 @@ func FromInventory(res inventory.Result, opts FromInventoryOptions) ([]Installed}if q, basis, ok := PackageFromCommand(command, args); ok {program, programArgs := launcher(command, args)- if registryFromEnv(s.Definition) || opts.Registries.forServer(program, programArgs, s.Definition).private(q) {+ if registryFromEnv(s.Definition) || opts.Registries.forServer(program, programArgs, s.Definition, s.ProjectDirs).private(q) {basis = privateBasis(basis)}if (basis == BasisPrivateNPM || basis == BasisPrivatePyPI) && !opts.IncludePrivateNames {diff --git a/cli/beacon/internal/intel/registries.go b/cli/beacon/internal/intel/registries.goindex 54aacd1a..96f38887 100644--- a/cli/beacon/internal/intel/registries.go+++ b/cli/beacon/internal/intel/registries.go@@ -229,8 +229,11 @@ func (r *Registries) readProject(dir string) {// uv is told to use one (--directory, --project). A directory Beacon cannot resolve (a// relative path, ${workspaceFolder}) leaves it unable to tell, so both ecosystems are held// back for that server.-func (r Registries) forServer(command string, args []string, def map[string]interface{}) Registries {- var nodeDirs, projects []string+func (r Registries) forServer(command string, args []string, def map[string]interface{}, projectDirs []string) Registries {+ // The runtime starts a server declared in a project's entry (Claude Code's local scope) in+ // that project, so the launcher reads the project's config whatever the server's own cwd.+ projects := append([]string(nil), projectDirs...)+ var nodeDirs []stringunresolved := falseif command = strings.TrimSpace(command); command != "" && strings.ContainsAny(command, `/\`) {nodeDirs = append(nodeDirs, filepath.Dir(command))diff --git a/cli/beacon/internal/intel/registries_test.go b/cli/beacon/internal/intel/registries_test.goindex c7da3393..089ac794 100644--- a/cli/beacon/internal/intel/registries_test.go+++ b/cli/beacon/internal/intel/registries_test.go@@ -1,6 +1,7 @@package intelimport (+ "encoding/json""os""path/filepath""strings"@@ -183,8 +184,8 @@ func TestRegistriesForAServerOnItsOwnNode(t *testing.T) {if base.private("npm:@acme/x") {t.Fatal("the nvm node is not on Beacon's PATH in this test")}- byCommand := base.forServer(filepath.Join(nvm, "bin", "npx"), nil, map[string]interface{}{})- byPath := base.forServer("npx", nil, map[string]interface{}{"env": map[string]interface{}{"PATH": filepath.Join(nvm, "bin") + string(filepath.ListSeparator) + "/usr/bin"}})+ byCommand := base.forServer(filepath.Join(nvm, "bin", "npx"), nil, map[string]interface{}{}, nil)+ byPath := base.forServer("npx", nil, map[string]interface{}{"env": map[string]interface{}{"PATH": filepath.Join(nvm, "bin") + string(filepath.ListSeparator) + "/usr/bin"}}, nil)for name, reg := range map[string]Registries{"absolute command": byCommand, "env PATH": byPath} {if !reg.private("npm:@acme/x") || reg.private("npm:@playwright/mcp") {t.Errorf("%s: %+v", name, reg)@@ -328,3 +329,35 @@ func TestFromInventoryHoldsBackLauncherConfigAndEnvFiles(t *testing.T) {t.Fatalf("with consent = %+v", items)}}++// Claude Code starts a local-scope server in its project, so npx there reads the project's+// npmrc whatever directory the agent asking runs in.+func TestFromInventoryReadsTheProjectAClaudeLocalServerRunsIn(t *testing.T) {+ home := t.TempDir()+ project := filepath.Join(home, "work", "acme")+ writeConfig(t, filepath.Join(project, ".npmrc"), "@acme:registry=https://npm.acme.internal/\n")+ config, err := json.Marshal(map[string]interface{}{"projects": map[string]interface{}{+ project: map[string]interface{}{"mcpServers": map[string]interface{}{+ "tool": map[string]interface{}{"command": "npx", "args": []string{"-y", "@acme/secret-tool"}},+ "public": map[string]interface{}{"command": "npx", "args": []string{"-y", "@playwright/mcp"}},+ }},+ }})+ if err != nil {+ t.Fatal(err)+ }+ writeConfig(t, filepath.Join(home, ".claude.json"), string(config))+ inv := inventory.Scan(inventory.Options{HomeDir: home, SkipProjectScope: true, Runtimes: []string{"claude_code"}, IncludeContents: true})+ // The agent asks from somewhere else entirely.+ reg := LocalRegistries(RegistryEnv{Home: home, WorkingDir: t.TempDir()})+ items, skipped := FromInventory(inv, FromInventoryOptions{Registries: reg})+ var sent []string+ for _, item := range items {+ sent = append(sent, item.Q)+ }+ if strings.Join(sent, ",") != "npm:@playwright/mcp" {+ t.Fatalf("sent = %v, skipped = %+v", sent, skipped)+ }+ if len(skipped) != 1 || skipped[0].Name != "tool" || skipped[0].Reason != ReasonPrivatePackage {+ t.Fatalf("skipped = %+v", skipped)+ }+}diff --git a/docs/cli/intel.mdx b/docs/cli/intel.mdxindex 0496fbc1..b3845f56 100644--- a/docs/cli/intel.mdx+++ b/docs/cli/intel.mdx@@ -140,7 +140,9 @@ Names that may be private are held back and listed as skipped unless the agent pfile and the like), the server's `env` or `envFile`, the environment it inherits(`npm_config_registry`, `npm_config_@scope:registry`, `UV_INDEX_URL`, `PIP_INDEX_URL` and thelike), and the npm, yarn, bun, pip and uv configuration files in your home directory, the system- locations, and the working directory and those above it, whether or not `include_project` is set+ locations, and the working directory and those above it, whether or not `include_project` is set,+ as well as the project directory a server runs in (its `cwd`, uv's `--directory`, or the project a+ Claude Code local-scope server is declared for in `~/.claude.json`) and those above it(`.npmrc`, including the global and builtin ones under npm's prefix, pnpm's global `rc`,`.yarnrc.yml`, `bunfig.toml`, `pip.conf`, `uv.toml`, `pyproject.toml`). A private npm scope holds back only that scope's packages.Settings that name the public registry don't count. A registry configured anywhere else (a