Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 49/ 160
03. AI Agents

MCP Clients

Hosts/clients that connect models to MCP servers, manage auth, and route tool calls.

IntermediateHost App · Auth3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

The AI app keeps a connection to each plug-in, tells the AI what each can do, and sends the AI's requests to the right plug-in.

Think of it like…

A switchboard operator: the caller (the model) asks for "Accounts" and the operator knows which line goes where, checks the caller is allowed, connects the call and brings back the answer. The operator also decides which lines are plugged in at all.

Where you’ve seen it

A developer-assistant host connects to four servers: GitHub, a Postgres reader, a docs search server and a filesystem server limited to the project folder. At startup the clients list 61 tools; to keep tool selection accurate, the host exposes only tools from servers enabled for the current workspace and namespaces them (github.create_issue, db.run_query). Write actions such as github.create_issue show an approval prompt with the arguments before executing; read-only tools run without prompts.

Words you’ll hear

Host
The AI application that embeds MCP clients and talks to the model and the user.
Client
A connection manager inside the host, one per server, speaking the MCP protocol.
Capability negotiation
The initialize exchange where each side declares supported features.
Tool routing
Mapping a model's tool call to the server that owns that tool.

Visual diagram

Loading interactive diagram

Theory & deep dive

What the client does

For each configured server the client starts or connects to it (spawning a process for stdio, opening an HTTP connection for remote servers), sends initialize with the protocol version and its own capabilities, receives the server's capabilities, and calls tools/list (and optionally resources and prompts). The host converts the tools to the model provider's tool-definition format and includes them in model calls. When the model emits a tool call, the host maps the tool name to the owning server, sends tools/call, handles errors and timeouts, and appends the result to the conversation. Clients also react to list-change notifications by refreshing tools.

Beyond tools, clients can offer features back to servers: sampling (a server asks the host's model to generate text, with user approval), roots (telling servers which directories or URIs they may operate on) and elicitation (a server asks the user for more input through the host). These put the host in control of model access and user interaction.

A routing table

tools = {"github.create_issue": client_github, "db.run_query": client_db, "docs.search": client_docs}; when the model calls db.run_query, the host looks it up, calls client_db.call_tool("run_query", args) and returns the result. Prefixing names avoids clashes when two servers both offer search.

Key takeaway: Clients connect, discover, translate to model tools, route calls and return results.

Auth, consent and managing many tools

Authentication: remote servers use OAuth-style authorisation; the host obtains tokens on the user's behalf, stores them securely, scopes them narrowly and never sends one server's token to another. Local stdio servers inherit the user's environment, so avoid broad credentials in environment variables. Consent: show users which servers are connected and what tools do; require explicit approval for destructive, costly or external-communication actions (with the actual arguments visible); remember choices carefully and allow revocation. Logging: record tool calls, arguments and results for audit.

Tool overload: dozens of tools degrade selection accuracy and use context. Mitigate by enabling servers per workspace or task, filtering and namespacing tools, grouping rarely used ones behind a search-for-tools step, or using a router model to pick a subset. Trust: tool names, descriptions and results are text the model reads, so a malicious or compromised server can attempt prompt injection or "tool poisoning" (instructions hidden in a description), and a benign server can relay attacker-controlled content from the web. Treat them as untrusted input: pin server versions, review tool descriptions on connection and on change, isolate sensitive tools from servers that touch untrusted content, and keep humans in the loop for impactful actions.

A consent policy

Read-only tools: run automatically. Tools that modify data or send messages: show an approval dialog with arguments. Tools from a newly added server: disabled until the user reviews its tool list. Any change to a tool description triggers re-review.

Key takeaway: Scoped auth, explicit consent, limited tool sets, and suspicion of server-provided text.

How it works, step by step

Step 1 of 4
User + host

1. Configure trusted servers

Choose which servers to connect for a workspace, and review their tools before enabling them.

github · db (read-only) · docs
Key numbers at this step
Default
off until reviewed

When to use it & trade-offs

What it is

In MCP, the host is the AI application the user interacts with (an IDE assistant, a chat app, an agent runtime). Inside the host, one MCP client instance maintains a connection to each MCP server. The client performs the handshake, discovers the server's tools, resources and prompts, passes them to the model as tool definitions, receives the model's tool calls, routes each call to the right server, and returns results. The host is also where user consent, authentication and policy are enforced, since it decides which servers are connected and what the model may do.

Why it matters: Servers expose capabilities, but the host and client decide what actually happens. Connecting ten servers puts hundreds of tools in front of the model, which can overwhelm tool selection and the context window; tools from untrusted servers can inject instructions; and credentials must be handled per server. Building or choosing a host well is about routing, trust, authorisation and user control.

When to reach for it

  • IDE and chat hosts with several MCP servers
  • Enterprise agents connecting internal systems
  • Centralised consent and audit for tool use

When to avoid or be careful

  • Auto-approving write actions from unreviewed servers
  • Sharing one token across servers
  • Dumping every server's tools into every request

Ways to manage many tools

Expose all tools from all servers
Best for: Small setups with few tools

Strengths: Simple; maximum capability.

Watch out: Selection errors and context bloat as tools grow.

Per-workspace or per-task tool sets
Best for: Developer and enterprise hosts

Strengths: Fewer tools; clearer permissions.

Watch out: Needs configuration and UX.

Tool search / router
Best for: Large catalogues

Strengths: Scales to hundreds of tools.

Watch out: Extra step and latency; can miss tools.

Interview signals & numbers to know

When this topic comes up

  • “How does an MCP host work?”
  • “Too many tools hurt accuracy”
  • “How do we handle auth for MCP servers?”
  • Tool poisoning
  • User consent flows

Benchmarks & rules of thumb

1 : 1 -
client instances per server connection
61 → ~15 -
tools listed vs exposed in the example
3 -
client-side features: sampling, roots, elicitation

Common mistakes & follow-ups

Common interview mistakes

  • Connecting a new server and letting the model call its tools without review.
  • Passing a GitHub token to every server through shared environment variables.
  • Not prefixing tool names, so two servers' search tools collide.

Likely interviewer follow-ups

  • What's the difference between an MCP host, client and server?
  • How would you handle tool overload?
  • How do you defend against malicious tool descriptions?
Interview tip: Draw host → clients → servers and put consent and routing on the host. It shows you understand where policy belongs.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply MCP Clients with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
MCP Servers
Next topic
Agent Skills