openclaw - 💡(How to fix) Fix Feature request: per-agent MCP server scoping [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#72591Fetched 2026-04-28 06:34:09
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Author
Timeline (top)
commented ×1

Code Example

{
  "mcp": {
    "servers": {
      "my-erp": {
        "command": "python3",
        "args": ["/path/to/server.py"],
        "agents": ["admin-agent", "work-group-*"]
      },
      "lightweight-tool": {
        "command": "node",
        "args": ["server.js"]
        // no agents field = available to all (current default behaviour)
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Problem

When multiple agents are configured on a single gateway, every MCP server defined in mcp.servers is spawned once per agent — regardless of whether that agent needs those tools.

For example, with 12 agents and 10 MCP servers, the gateway spawns 120 processes even though only 4-5 agents actually use those MCP tools. The remaining agents (e.g. simple chat/social agents) get processes they'll never call.

On a 32GB instance with 10 server types and 12 agents, the unnecessary MCP processes consume ~3GB of RAM.

Proposed solution

Add an optional agents field to mcp.servers.* config that accepts an array of agent IDs (or glob patterns):

{
  "mcp": {
    "servers": {
      "my-erp": {
        "command": "python3",
        "args": ["/path/to/server.py"],
        "agents": ["admin-agent", "work-group-*"]
      },
      "lightweight-tool": {
        "command": "node",
        "args": ["server.js"]
        // no agents field = available to all (current default behaviour)
      }
    }
  }
}

When agents is set, the gateway would only spawn that MCP server for matching agents. When omitted, current behaviour is preserved (spawn for all).

Alternatives considered

  • tools.deny on agents: hides MCP tools from the prompt but processes still spawn and consume RAM
  • Separate gateway instances: works but adds operational complexity for what should be a config-level concern

Impact

This would significantly reduce memory usage for multi-agent deployments where not all agents need the same MCP tools.

extent analysis

TL;DR

To reduce memory usage, add an optional agents field to mcp.servers.* config to limit MCP server spawning to specific agents.

Guidance

  • Review the proposed solution and consider adding the agents field to mcp.servers.* config to restrict MCP server spawning.
  • Evaluate the current mcp.servers configuration and identify which agents actually use each MCP tool to determine the optimal agents field values.
  • Test the updated configuration to verify that MCP servers are only spawned for the specified agents and that memory usage is reduced.
  • Consider the alternatives mentioned, such as tools.deny on agents or separate gateway instances, but note their limitations and added complexity.

Example

{
  "mcp": {
    "servers": {
      "my-erp": {
        "command": "python3",
        "args": ["/path/to/server.py"],
        "agents": ["admin-agent", "work-group-*"]
      }
    }
  }
}

Notes

The proposed solution assumes that the agents field can be properly parsed and matched against agent IDs or glob patterns. Additional implementation details, such as error handling and config validation, may be necessary.

Recommendation

Apply the proposed workaround by adding the agents field to mcp.servers.* config, as it provides a config-level solution to reduce memory usage without adding operational complexity.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Feature request: per-agent MCP server scoping [1 comments, 2 participants]