Agents, tool use and MCP

Part 5: Agents and MCP

Agent loop, frameworks, MCP servers, security, multi-agent, coding agents.

Live · updated 26 Nov 2026, 5:11 pm~18 min read
On this page (29 sections)

Like I'm 5: A chatbot only talks. An agent is a helper who can also use tools: open the calendar, search the web, send the email. MCP is the universal plug that lets any helper use any tool.

5.1 Agent fundamentals

Topics to cover, in this order:

  1. What is an AI agent (vs chatbot vs workflow)
  2. The agent loop: think, act, observe
  3. Tool use / function calling in agents
  4. Planning and reasoning patterns (ReAct, plan-and-execute)
  5. Agent memory: short, long, episodic, vector

5.2 Building agents

Topics to cover, in this order:

  1. Workflows vs agents: when to use which
  2. Multi-agent systems: supervisor, swarm, handoffs
  3. Frameworks: LangChain, LangGraph, LlamaIndex, CrewAI, OpenAI Agents SDK, Claude Agent SDK, Vercel AI SDK
  4. What is MCP (Model Context Protocol) and why it exists
  5. MCP architecture: host, client, server

5.3 MCP in depth

Topics to cover, in this order:

  1. MCP primitives: tools, resources, prompts
  2. MCP transports: stdio and Streamable HTTP (check current spec)
  3. Building an MCP server (TypeScript and Python)
  4. Using MCP servers in Claude, ChatGPT connectors, Cursor and IDEs
  5. MCP auth (OAuth) and security risks: tool poisoning, confused deputy

5.4 Standards, safety and real agents

Topics to cover, in this order:

  1. A2A (agent-to-agent) and other standards (AGENTS.md, Skills)
  2. Computer use and browser agents
  3. Human in the loop: approvals and permissions
  4. Agent reliability: loops, errors, timeouts, cost limits
  5. Coding agents, skills, plugins, subagents and hooks

5.1 Agent fundamentals — detailed notes

1. AI agent vs chatbot vs workflow

LIKE I'M 5

A chatbot talks, a workflow follows a fixed recipe, and an agent can choose actions toward a goal.

EXPLAINED SIMPLY

  • A chatbot primarily responds to messages.
  • A workflow follows predefined steps and branches.
  • An AI agent uses a model to choose actions, observe results and continue toward a goal.
  • Agents may use tools, memory and planning, but autonomy is a design choice—not a requirement.
  • Use deterministic workflows when steps are known. Use agents when the path depends on observations or changing conditions.
  • More autonomy adds risk, cost and debugging complexity.

COMPARE WITH LOOKALIKES

ChatbotWorkflowAgent
RespondsFixed stepsChooses actions dynamically
Low autonomyRule-drivenModel-guided
Simple interactionsRepeatable processesVariable tasks

INTERVIEW LENS

Define agent behaviour through goal, model-driven action selection, tools, observations and stopping conditions.

TRAPS

Not every LLM app is an agent. A workflow with one model call is not automatically autonomous.

ONE-LINE RECAP

An agent is a model-guided system that selects actions based on state and observations.

2. The agent loop: think, act, observe

LIKE I'M 5

A robot looks at the room, chooses a move, takes the move and checks what changed.

EXPLAINED SIMPLY

  • The loop begins with a goal and current state.
  • The model chooses an action or a final response.
  • The runtime validates and executes the action.
  • The tool result becomes a new observation.
  • The model decides whether to continue, change plan or stop.
  • Add maximum steps, timeouts, token budgets and explicit stop conditions.
  • Persist state when work must survive restarts.

TRY IT

while (!state.done && state.steps < 5) {
  const action = await planNextAction(state);
  state = await executeAndObserve(action, state);
  state.steps++;
}

INTERVIEW LENS

Explain state transitions, tool execution, observations, stopping criteria and failure recovery.

TRAPS

Unbounded loops waste money. Tool failures must not be treated as successful observations.

ONE-LINE RECAP

Agents repeatedly select actions, observe results and stop when the goal or limits are reached.

3. Tool use / function calling in agents

LIKE I'M 5

A helper can ask a calendar to find a free slot, but the calendar system performs the search.

EXPLAINED SIMPLY

  • Tools expose controlled capabilities such as search, database lookup or sending a message.
  • Each tool needs a clear description and input schema.
  • The model proposes a call; the runtime checks identity, permissions and arguments.
  • Execute with timeouts and idempotency where possible.
  • Return structured results and errors so the model can recover.
  • Use human approval for sensitive actions.

INTERVIEW LENS

Describe tool registration, model selection, validation, execution, observation and approval.

TRAPS

A tool description is not an access-control policy. Validate arguments server-side.

ONE-LINE RECAP

Tools give agents capabilities; the runtime controls whether actions are allowed.

4. Planning and reasoning patterns: ReAct and plan-and-execute

LIKE I'M 5

One helper plans every step first. Another decides the next step after seeing each result.

EXPLAINED SIMPLY

  • ReAct alternates reasoning-oriented decisions with tool actions and observations.
  • Plan-and-execute creates a plan, then carries out its steps.
  • Planning ahead can improve coherence for longer tasks.
  • ReAct adapts better when results change the next action.
  • Plans are hypotheses. Validate each action and replan when observations contradict assumptions.
  • Bound planning depth and tool count.

COMPARE WITH LOOKALIKES

ReActPlan-and-execute
Decide after each observationPlan multiple steps first
AdaptiveMore structured
Can use many turnsPlan may become stale

INTERVIEW LENS

Choose based on uncertainty, task length, observability and need for predictable execution.

TRAPS

A detailed plan can be wrong. ReAct can loop without limits.

ONE-LINE RECAP

Use adaptive loops for uncertainty and explicit plans for stable multi-step tasks.

5. Agent memory: short, long, episodic and vector

LIKE I'M 5

A helper keeps today's notes, a notebook of lasting facts, and a diary of what happened before.

EXPLAINED SIMPLY

  • Short-term memory stores current task state and recent messages.
  • Long-term memory stores selected facts or preferences across sessions.
  • Episodic memory records past events and outcomes.
  • Vector memory retrieves semantically related stored content.
  • Memory needs schemas, ownership, timestamps, retention, access control and correction mechanisms.
  • Retrieve only relevant memories. Stale or irrelevant memories can mislead the agent.
  • Memory storage is not model training.

INTERVIEW LENS

Explain storage, retrieval, ranking, freshness and privacy as separate memory-system components.

TRAPS

Do not store everything. Do not trust old memory without checking its date and source.

ONE-LINE RECAP

Agent memory is external state that must be selected, secured and maintained.

5.2 Building agents — detailed notes

6. Workflows vs agents

LIKE I'M 5

A train follows tracks. A taxi chooses roads based on traffic. Pick the one that fits the journey.

EXPLAINED SIMPLY

  • Workflows provide deterministic steps, explicit branches and predictable controls.
  • Agents choose actions dynamically using model outputs.
  • Workflows are easier to test and audit for stable processes.
  • Agents help when task paths are uncertain and observations influence next steps.
  • Hybrid systems use workflows for guardrails and agents for bounded decisions.
  • Compare completion rate, cost, latency, error rate and human intervention.

INTERVIEW LENS

Prefer deterministic orchestration for known paths; add agent autonomy only where it creates measurable value.

TRAPS

Do not use agents for simple CRUD. Do not assume workflows cannot contain model calls.

ONE-LINE RECAP

Use the least autonomous design that reliably solves the task.

7. Multi-agent systems: supervisor, swarm and handoffs

LIKE I'M 5

A manager gives different jobs to specialists and checks their work.

EXPLAINED SIMPLY

  • A supervisor agent delegates subtasks to specialised agents and combines results.
  • A handoff transfers control to another agent with a defined task and context.
  • Swarm-style systems let agents coordinate more flexibly, depending on framework design.
  • Parallel agents can improve independent research but create merge and consistency problems.
  • Define each agent's role, tools, permissions, input/output contract and stop condition.
  • Measure whether multi-agent complexity beats one agent or a workflow.

INTERVIEW LENS

Discuss decomposition, delegation, shared state, handoff contracts, failure recovery and coordination cost.

TRAPS

More agents do not guarantee better answers. Shared memory can create race conditions.

ONE-LINE RECAP

Multi-agent systems distribute work but require explicit coordination and boundaries.

8. Frameworks: LangChain, LangGraph, LlamaIndex, CrewAI, OpenAI Agents SDK, Claude Agent SDK, Vercel AI SDK

LIKE I'M 5

These are toolkits for building assistants, like different sets of construction blocks.

EXPLAINED SIMPLY

  • LangChain provides components and integrations for model applications.
  • LangGraph focuses on stateful graph-based orchestration and agent workflows.
  • LlamaIndex focuses on data connectors, indexing and retrieval-oriented applications.
  • CrewAI provides abstractions for role-based agent teams and tasks.
  • OpenAI Agents SDK and Claude Agent SDK provide provider ecosystems for agent orchestration and tool use.
  • Vercel AI SDK helps build AI-powered application interfaces and streaming integrations.
  • APIs and features evolve. Compare state handling, tool support, tracing, deployment, provider portability and ecosystem.
  • Learn core concepts first so framework changes do not erase understanding.

INTERVIEW LENS

Choose a framework based on orchestration needs, ecosystem, deployment and observability—not trend.

TRAPS

A framework does not make an agent reliable automatically. Avoid unnecessary abstraction.

ONE-LINE RECAP

Frameworks provide building blocks; architecture and safeguards remain your responsibility.

9. What is MCP and why it exists

LIKE I'M 5

A universal plug lets different devices connect without inventing a new cable for every pair.

EXPLAINED SIMPLY

  • Model Context Protocol (MCP) is an open protocol for connecting AI applications to external tools and context sources.
  • It standardises how clients discover and interact with server capabilities.
  • MCP can expose tools, resources and prompts.
  • It reduces one-off integrations between every AI host and every service.
  • MCP does not decide whether an action is safe or correct; hosts and servers still need security controls.
  • Check the current official specification for protocol changes and transport details.

INTERVIEW LENS

Explain MCP as a client-server protocol that standardises capability discovery and interaction.

TRAPS

MCP is not a model, agent framework or database. It does not guarantee security.

ONE-LINE RECAP

MCP standardises how AI applications connect to external capabilities and context.

10. MCP architecture: host, client and server

LIKE I'M 5

The host is the workshop, the client is the socket, and the server is the tool plugged in.

EXPLAINED SIMPLY

  • The host is the AI application that manages the user experience and model interaction.
  • The MCP client maintains a protocol connection to a server.
  • The MCP server exposes capabilities such as tools, resources and prompts.
  • A host may manage multiple clients and server connections.
  • The client and server exchange protocol messages and capability information.
  • The host decides which model context and user approvals are appropriate.
  • Keep server permissions narrow and inspect the data each capability can access.

INTERVIEW LENS

Draw host → client connection → server, then describe capability discovery and request/response flow.

TRAPS

The model does not usually connect directly to a server. The host controls orchestration.

ONE-LINE RECAP

Host manages the app, client speaks the protocol, server exposes capabilities.

5.3 MCP in depth — detailed notes

11. MCP primitives: tools, resources and prompts

LIKE I'M 5

Tools are actions, resources are information, and prompts are reusable instruction starters.

EXPLAINED SIMPLY

  • Tools are callable operations, such as searching a ticket system or creating an issue.
  • Resources expose data that a client can read, such as files or records.
  • Prompts are reusable prompt templates that a server can offer.
  • Hosts decide how to present and invoke these primitives.
  • Tool calls need validation and user consent where appropriate.
  • Resource access needs permission checks and careful handling of sensitive data.

COMPARE WITH LOOKALIKES

PrimitivePurposeExample
ToolPerform an actionCreate a ticket
ResourceRead contextTicket details
PromptReusable instructionsTriage template

INTERVIEW LENS

Clearly distinguish action, data and reusable prompt templates.

TRAPS

A resource is not automatically a tool. A prompt template does not enforce policy.

ONE-LINE RECAP

MCP separates callable actions, readable context and reusable prompts.

12. MCP transports: stdio and Streamable HTTP

LIKE I'M 5

One connection passes notes through a local pipe. Another sends messages over the network.

EXPLAINED SIMPLY

  • stdio transports messages through standard input and output, commonly for locally launched servers.
  • Streamable HTTP supports network communication over HTTP and streaming responses.
  • Transport choice affects deployment, process lifecycle, networking and authentication.
  • Use stdio for suitable local integrations. Use HTTP for remote or shared services when supported.
  • Configure timeouts, authentication, origin validation and network boundaries.
  • Protocol transport details evolve; check the current MCP specification rather than relying on old examples.

INTERVIEW LENS

Compare local process communication with network transport and explain operational/security implications.

TRAPS

Do not assume old HTTP+SSE examples represent the current recommended transport. Verify spec version.

ONE-LINE RECAP

stdio is a local pipe; Streamable HTTP supports networked communication.

13. Building an MCP server in TypeScript and Python

LIKE I'M 5

Build a small service that introduces its tools and safely performs a job when asked.

EXPLAINED SIMPLY

  • Choose an SDK and implement server initialisation, capability registration and request handlers.
  • Define each tool's name, description and input schema.
  • Validate inputs and return structured content or errors.
  • Keep business logic in ordinary functions so it can be tested without MCP.
  • Add authentication and permission checks for remote or sensitive systems.
  • Log request IDs and safe metadata, not secrets or full private payloads.
  • Test with a protocol inspector/client and include malformed-input cases.

TRY IT

async function searchTickets(query: string) {
  if (!query.trim()) throw new Error("Query is required");
  return ticketService.search(query);
}

This is business logic used by a tool handler, not a complete MCP server.

INTERVIEW LENS

Describe capability registration, schema validation, handler execution, structured results and tests.

TRAPS

Do not expose arbitrary database or shell access. Keep tool scope narrow.

ONE-LINE RECAP

An MCP server safely exposes small, well-defined capabilities.

14. Using MCP servers in hosts and IDEs

LIKE I'M 5

Connect the helper app to a server, see what tools it offers and decide which ones to allow.

EXPLAINED SIMPLY

  • MCP hosts or clients configure connections to available servers.
  • The host discovers capabilities and may display tools or resources to the user/model.
  • Configuration differs across desktop apps, IDEs and hosted services.
  • Review server publisher, source code, requested permissions, network destinations and data access.
  • Test read-only capabilities before enabling write actions.
  • Keep credentials in the host's secure configuration and rotate them.

INTERVIEW LENS

Explain server configuration, capability discovery, user approval and host-specific permission controls.

TRAPS

Installing a server is not the same as trusting it. Tool availability does not imply safe use.

ONE-LINE RECAP

Connect only trusted servers and grant only the capabilities needed.

15. MCP auth and security: OAuth, tool poisoning and confused deputy

LIKE I'M 5

A helper should not use your house key just because a stranger asks. It must check who is asking and what they may do.

EXPLAINED SIMPLY

  • Remote MCP servers may use authentication and authorisation mechanisms such as OAuth, depending on deployment and current specification.
  • Tokens should be scoped, short-lived where possible and stored securely.
  • Tool poisoning hides malicious instructions in tool descriptions or outputs to influence model behaviour.
  • A confused deputy occurs when a privileged host or service is tricked into using its authority for the wrong requester.
  • Validate issuer, audience, scopes, resource ownership and user identity.
  • Treat tool descriptions and results as untrusted data. Require approval for high-impact actions.

INTERVIEW LENS

Explain token scope, identity propagation, least privilege, tool metadata trust and confused-deputy prevention.

TRAPS

Do not forward user tokens to unrelated services. Do not trust tool descriptions as policy.

ONE-LINE RECAP

MCP security depends on strong identity, scoped authority and untrusted-tool handling.

5.4 Standards, safety and real agents — detailed notes

16. A2A, AGENTS.md and Skills

LIKE I'M 5

Different helpers need a way to talk to each other, read project rules and reuse instructions.

EXPLAINED SIMPLY

  • Agent-to-agent (A2A) protocols aim to support communication and task delegation between independent agents.
  • AGENTS.md is a convention for repository-specific instructions to coding agents; support depends on the tool.
  • Skills package reusable instructions and sometimes supporting files or scripts for a defined task.
  • These concepts solve different problems: inter-agent communication, project guidance and reusable capability instructions.
  • Verify the current specification and implementation support before designing around a standard.
  • Treat repository instructions and downloaded skills as untrusted code/content until reviewed.

INTERVIEW LENS

Distinguish protocol interoperability, repository guidance and reusable agent procedures.

TRAPS

A markdown instruction file is not a security boundary. Standards adoption differs by product.

ONE-LINE RECAP

Protocols connect agents; project files guide them; skills package repeatable work.

17. Computer use and browser agents

LIKE I'M 5

A helper sees a screen, moves a pointer, clicks and checks what happened.

EXPLAINED SIMPLY

  • Computer-use agents interact with graphical interfaces through screenshots, pointer actions and keyboard input.
  • Browser agents may use DOM/browser automation, screenshots or a combination.
  • UI changes, latency and ambiguous visual states make these systems fragile.
  • Use stable APIs instead of screen clicks when an API exists.
  • Restrict browser profiles, downloads, network access and logged-in sessions.
  • Require confirmation before purchases, submissions, deletion or messages.
  • Verify the resulting page state after every important action.

INTERVIEW LENS

Compare API automation with GUI automation and explain state verification, permissions and human approval.

TRAPS

A click does not prove success. Browser content can contain prompt injection.

ONE-LINE RECAP

Computer-use agents need restricted environments and verified outcomes.

18. Human in the loop: approvals and permissions

LIKE I'M 5

A helper can prepare a payment, but a person must approve it before money moves.

EXPLAINED SIMPLY

  • Human-in-the-loop design inserts review or approval at important decision points.
  • Use risk tiers: low-risk read operations may be automatic; high-impact writes need confirmation.
  • Show the exact action, target, data and consequences before approval.
  • Bind approval to the action payload so it cannot be changed after confirmation.
  • Record who approved, when and what was executed.
  • Provide cancellation and recovery paths.

INTERVIEW LENS

Explain risk-based approval, least privilege, explicit consent, audit logs and immutable action previews.

TRAPS

A vague “approve?” prompt is not informed consent. Approval must match the exact action.

ONE-LINE RECAP

Require meaningful human approval for actions with real-world consequences.

19. Agent reliability: loops, errors, timeouts and cost limits

LIKE I'M 5

A helper needs a timer, a spending limit and a rule for what to do when a tool is broken.

EXPLAINED SIMPLY

  • Set maximum steps, wall-clock time, model tokens, tool calls and monetary budgets.
  • Use timeouts and cancellation for slow dependencies.
  • Retry only transient failures, with bounded exponential backoff and jitter.
  • Make side-effecting operations idempotent or use deduplication keys.
  • Validate tool outputs and handle partial failures.
  • Persist state for long-running tasks and support safe resume.
  • Trace model calls, tool calls, decisions, latency, cost and final outcome.

INTERVIEW LENS

Describe bounded execution, retries, idempotency, state persistence, observability and fallback behaviour.

TRAPS

Retries can duplicate payments or emails. Infinite loops create runaway cost.

ONE-LINE RECAP

Reliable agents need strict budgets, recovery rules and traceable state.

20. Coding agents, skills, plugins, subagents and hooks

LIKE I'M 5

A coding helper can use special tools, ask smaller helpers for tasks and run checks before finishing.

EXPLAINED SIMPLY

  • Coding agents inspect repositories, plan changes, edit files, run tests and report results.
  • Skills provide reusable procedures and domain guidance.
  • Plugins or tool integrations connect the agent to external systems.
  • Subagents handle bounded subtasks, such as reviewing tests or researching a module.
  • Hooks run deterministic actions at defined lifecycle points, such as formatting or policy checks.
  • Keep permissions narrow, review diffs and run tests in isolated environments.
  • Distinguish instructions (what to do), tools (what can be done) and hooks (when code runs).

INTERVIEW LENS

Explain the roles of reusable skills, external tools, delegated agents and deterministic lifecycle hooks.

TRAPS

Subagents can duplicate work or leak context. Hooks must be trusted code.

ONE-LINE RECAP

Coding-agent systems combine instructions, tools, delegation and deterministic checks.

Part 5 cheat sheet — interview answers

  1. Agent → Model-guided system that selects actions based on observations.
  2. Agent loop → Decide, execute, observe, update state and stop.
  3. Workflow vs agent → Deterministic known path vs adaptive model-guided path.
  4. ReAct → Alternates reasoning-oriented decisions with tool actions and observations.
  5. Multi-agent → Delegates bounded tasks with explicit contracts and coordination.
  6. MCP → Standard protocol for connecting AI apps to external capabilities/context.
  7. Host/client/server → App manages, client speaks protocol, server exposes capabilities.
  8. Tools/resources/prompts → Actions, readable data and reusable instruction templates.
  9. stdio/HTTP → Local process pipe vs network transport.
  10. Tool poisoning → Malicious tool metadata or output attempts to influence behaviour.
  11. Confused deputy → Privileged component misuses its authority for another party.
  12. Computer use → GUI interaction; APIs are usually more reliable when available.
  13. Human approval → Confirm exact high-impact action before execution.
  14. Reliability → Bound steps, time, cost and retries; use idempotency.
  15. Skills/hooks → Reusable procedures vs deterministic lifecycle automation.