LEARN. PRACTICE. EXPLAIN.
Learning paths & interview practiceP
Forward deployed & AI engineering foundations
LESSON 3 OF 4 · ABOUT 16 MINUTES + EXERCISE

How do MCP servers expose tools safely to agents?

THE IDEA

What it is

The Model Context Protocol (MCP) standardizes how an AI host discovers and calls tools, resources, and prompts exposed by external servers. Each tool has a name, description, input schema, and execution handler—and the server remains the sole authoritative security boundary.

Why you need it

An agent can be tricked by ambiguous tool descriptions into picking the wrong action, or manipulated by prompt injection into passing another tenant’s ID as a tool argument.

How it works

  1. Design mutually exclusive verb-object tool names with explicit exclusion notes.
  2. Validate incoming tool arguments strictly against schemas before running side effects.
  3. Resolve caller identity and tenant scope from trusted server context—not model parameters.
  4. Enforce step limits, loop detection, and human confirmation for destructive operations.
JavaScript

Enforcing tenant scope inside an MCP tool handler

function handleGetTicket(trustedActor, args) {
  if (typeof args.ticketId !== "string") throw new Error("Invalid ticketId")
  const ticket = tickets.get(args.ticketId)
  if (!ticket || ticket.organizationId !== trustedActor.organizationId) {
    throw new Error("Ticket not found")
  }
  return ticket
}

Even if a prompt tells the model to pass organizationId: "other-org", the handler ignores client-supplied tenancy and checks trustedActor.organizationId.

Good practices and why

  • Expose only context-relevant tools and clearly state when NOT to use similar tools.
  • Distinguish terminal tool errors (missing data, forbidden) from transient errors so agent loops stop instead of burning budget.

Common mistakes

  • Trusting a model-supplied userEmail or tenantId without server-side verification.
  • Giving an agent 30 overlapping tools with vague one-line descriptions.
GUIDED IMPLEMENTATION

Try it yourself

Design schemas for lookup_ticket and update_ticket_status, then trace what happens when an untrusted message asks the agent to read another customer’s record or retry a missing-field error repeatedly.

What a successful result looks like

Cross-tenant reads are rejected at the tool boundary, and terminal errors halt the retry loop.

0 / 6000 characters · Saved on this device. Do not include passwords or private data.

Check your understanding

Where must tenant authorization be enforced for an MCP tool call?

Answer the understanding check correctly to record exercise completion.

PUT THE IDEA UNDER PRESSURE

Related interview practice

These scenarios add constraints and follow-up questions to the concepts you just learned.

Further reading

Selected primary references · reviewed 2026-10-09. Examples are educational; use your framework’s documented integration guidance when building a deployed system.

AlifBay Prep