Skip to content
mentoor

Topic 3 of 5 · 4 min read

Limiting which MCP tools an agent may call

Goal: Restrict a connected server to the tools and token scopes a task needs and justify each removal.

Connecting a server is not the same as trusting every tool on it: allow the few tools the task needs, deny the rest, and cap the damage with a narrow token. There are two separate controls, and you want both.

Check yourself · 1 of 3

A deny rule and an allow rule both match the same MCP tool. In Claude Code, what happens?

Choose one answer

Why it matters

A server often exposes more than you need. A tracker server may offer list_issues and also delete_project. If the agent can call both, one confused step or one injected instruction can use the second. Limiting tools shrinks what can go wrong, and fewer tools also means fewer definitions for the model to read each turn.

Control one: the agent's permission rules

Most coding agents let you write allow, deny and ask rules for tools. In Claude Code, MCP tools are named mcp__<server>__<tool>, and rules live in a settings file. A deny rule wins over an allow rule.

{
  "permissions": {
    "allow": ["mcp__issues__list_issues", "mcp__issues__get_issue"],
    "ask":   ["mcp__issues__create_comment"],
    "deny":  ["mcp__issues__delete_project", "mcp__issues__update_issue"]
  }
}

Reads run freely, a comment needs your approval each time, and destructive tools are blocked.

Control two: the credential itself

Rules live in the agent. A token lives in the world. If a rule is wrong, a read-only token still cannot delete anything. Issue the narrowest token the server allows: read-only, one project, short expiry.

How to do it

  1. List the tools the server exposes.
  2. Write down the task in a sentence, and mark the tools it needs.
  3. Allow the reads. Put anything that writes under ask. Deny anything destructive or unrelated.
  4. Use a token whose scopes match the allowed list.
  5. Test: ask the agent to do a denied action and confirm it is refused.

Before and after

Weak: "allow": ["mcp__issues"] plus an admin token. The whole server is open, and the token can do anything.

Fixed: the per-tool list above, with a token that has read access to one project. If a deny rule is mistyped, the token still limits the harm.

What goes wrong

  • Allowing a whole server by name when only two tools are needed.
  • Relying on a rule alone while the token is an admin key.
  • Forgetting that a project settings file is shared, so a loose rule reaches teammates.
  • Never testing a deny rule, then finding a typo in the tool name after an incident.

Examples

A review bot's tool list

A bot summarizes pull requests. It needs get_pull_request and list_comments. Those two are allowed. merge_pull_request and delete_branch are denied, and the token is read-only. Even if a diff contains injected text, the bot cannot merge.

Typo in a deny rule

A team denies mcp__db__drop_table, but the real tool is mcp__db__drop_tables. The rule matches nothing. Their read-only database user is what actually saved them. They then add a test prompt to confirm denials.

Key points

  • Use two controls together: permission rules in the agent and a narrow scope on the credential.
  • Allow named tools one by one rather than a whole server, and put write actions under approval.
  • Deny rules should cover destructive tools the task never needs.
  • A read-only token still protects you when a rule is wrong or the model is manipulated.
  • Test a deny rule by asking for the blocked action, since a mistyped tool name fails silently.

Common mistakes

  • Allowing a whole server because listing tools felt tedious.
  • Pairing careful rules with an admin-level token.
  • Copying a permissive rule into a shared project settings file.
  • Never checking that a deny rule blocks the action it names.

Check yourself · 2 of 3

Why use a read-only token even when you have already denied the write tools?

Choose one answer

Check yourself · 3 of 3

Which allow list best fits a task that only summarizes open issues?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic