Skip to content

Feature request: per-agent MCP server configuration #593

@dhaley

Description

@dhaley

Problem

agent-shell-make-agent-config has no :mcp-servers slot. The only way to configure MCP servers is the global agent-shell-mcp-servers variable, which means every agent session gets the same full set of MCP servers regardless of which agent config is selected.

This matters for:

  • Token costs: Each MCP server adds tool definitions to the context window. An agent that only needs one MCP (e.g., Entra ID management) still gets all 9 servers' tool schemas loaded, burning tokens on irrelevant tool descriptions every turn.
  • Least privilege: Agents should only have access to the MCPs they need.

Current behavior

The :client-maker lambda pattern appears to support per-agent MCP isolation via let-binding:

:client-maker (lambda (buffer)
                (let ((agent-shell-mcp-servers my-restricted-servers))
                  (agent-shell--make-acp-client ...)))

But this doesn't work. agent-shell--make-acp-client only creates the ACP client connection, it doesn't send MCP server configs. The MCP servers are sent later during session creation in agent-shell--initiate-new-session and agent-shell--initiate-session-resume-by-id, which call (agent-shell--mcp-servers). By that point the let binding is long gone and the global value is used.

Proposed solution

Add a :mcp-servers key to agent-shell-make-agent-config:

(agent-shell-make-agent-config
 :identifier 'entra-agent
 :mcp-servers '(((name . "entra")
                 (type . "http")
                 (url . "http://localhost:8000/mcp")
                 (headers . ())))
 :client-maker ...)

And have agent-shell--mcp-servers check for a per-agent override:

(defun agent-shell--mcp-servers ()
  (when-let* ((servers (or (map-elt (agent-shell--state) :mcp-servers)
                           agent-shell-mcp-servers)))
    ;; ... existing normalization logic ...
    ))

With agent-shell--start storing the config's :mcp-servers into the buffer-local state.

Alternative (less invasive)

Make agent-shell-mcp-servers buffer-local in agent buffers. agent-shell--start could setq-local it from the config's :mcp-servers key before session init. This requires no changes to agent-shell--mcp-servers itself.

Use case

I run 8+ specialized agents (Jenkins, Jira, Entra, cost-explorer, etc.) each with a single MCP server and isolated AWS SSO profiles. Without per-agent MCP isolation, every agent loads all tool schemas (~9 MCPs), wasting context tokens and defeating the purpose of specialized agents.

Checklist

  • I agree to communicate with the author myself (not AI-generated).
  • I've read the README's Filing issues section.
  • I'm running the latest versions:
    • agent-shell version: 20260515.1444 (MELPA)
    • acp.el version: 20260503.1851 (MELPA)
    • ACP package: claude-agent-acp@0.36.1
    • Agent CLI: claude 2.1.144
  • For requesting new agent support, I'm including a link to the ACP-capable agent or related ACP package. (N/A — feature request)
  • For issues, I'm including ACP traffic. (N/A - feature request, not a bug)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions