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 48/ 160
03. AI Agents

MCP Servers

Model Context Protocol servers that expose tools and resources with a shared interface.

IntermediateTools/Resources · Protocol3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

An MCP server is a plug-in that tells any compatible AI app what it can do and lets the AI use it in a standard way.

Think of it like…

A USB-C port for AI tools: instead of every device needing its own cable for every peripheral, one standard connector lets any laptop use any monitor or drive, as long as each side speaks the standard.

Where you’ve seen it

A company writes a Postgres MCP server exposing list_tables, describe_table and a read-only run_query tool (limited to SELECT, a 10-second timeout and 1,000 rows), plus a resource for the schema documentation. The same server works from their IDE assistant, a chat app and an internal agent. A separate write-capable tool is not exposed at all; analysts use a read-only database role that the server connects with, so even a prompt-injected query can't modify data.

Words you’ll hear

Tools
Functions the model may call; described with names, descriptions and JSON Schemas.
Resources
Readable data identified by URI (files, records, documents) that clients can load into context.
Prompts
Reusable, parameterised prompt templates the server offers to users.
Transport
How client and server communicate: stdio for local processes, Streamable HTTP for remote servers.

Visual diagram

Loading interactive diagram

Theory & deep dive

What a server exposes

On connection, client and server exchange an initialize handshake to agree on protocol version and capabilities. The client then calls tools/list to discover tools (each with name, description and inputSchema) and tools/call to run one; resources/list and resources/read for data; and prompts/list and prompts/get for templates. Servers can send notifications when their lists change. SDKs for TypeScript, Python and other languages handle the protocol so you mostly write functions: a decorator or registration call turns a function and its type hints into a tool definition.

Transports: stdio launches the server as a subprocess of the host (simple, local, uses the user's own credentials, good for desktop and developer tools); Streamable HTTP runs a remote service that many users can reach, requiring authentication, session handling and deployment concerns. Tool results can include text, images and structured content, and errors are reported in a way the model can read and react to.

A tool in a Python server (sketch)

@mcp.tool() def run_query(sql: str) -> list[dict]: """Run a read-only SQL SELECT (max 1,000 rows, 10 s).""" The SDK derives the input schema from the type hints and publishes it through tools/list.

Key takeaway: Servers publish tools, resources and prompts over JSON-RPC; SDKs make functions into tools.

Designing servers well and securely

Design for the model: a small set of task-oriented tools with precise descriptions and tight schemas beats a mirror of a raw API with 100 endpoints. Return concise, useful output (summaries and identifiers instead of full dumps), paginate, and give actionable error messages. Name tools clearly and describe when to use each. Version your server and keep behaviour stable, since clients and prompts depend on it.

Security is the main concern. Apply least privilege at the backend: a read-only database role, scoped API tokens, per-user credentials rather than one shared admin token. Validate every argument (the model controls them), restrict what a tool can touch (allow-listed paths and hosts, SQL limited to SELECT), add timeouts and rate limits, and log calls for audit. For remote servers, implement the protocol's OAuth-based authorisation, don't pass tokens through to unrelated services, and protect against SSRF and confused-deputy issues. Remember that tool descriptions and results are read by a model: a compromised or malicious server can try tool poisoning or prompt injection, so users and hosts should only connect to trusted servers and review what tools do.

Guardrails inside a query tool

Reject anything that isn't a single SELECT statement, run it in a read-only transaction with SET statement_timeout = '10s', wrap it in LIMIT 1000, and connect as a role granted SELECT on approved schemas only.

Key takeaway: Few, clear tools; least-privilege backends; validated inputs; trusted servers only.

How it works, step by step

Step 1 of 4
Design

1. Decide what to expose

Choose a small set of task-level tools and any resources or prompts, and define the access each needs.

list_tables · describe_table · run_query
Key numbers at this step
Read-only
by default

When to use it & trade-offs

What it is

The Model Context Protocol (MCP), introduced by Anthropic in late 2024 and since adopted widely, is an open standard for connecting AI applications to tools and data. An MCP server is a small program that exposes capabilities in a standard way: tools (functions the model can call), resources (data it can read, like files or records) and prompts (reusable templates). It speaks JSON-RPC 2.0 over a transport, either stdio (a local subprocess) or Streamable HTTP (a remote service). Write a server once and any MCP-capable client can use it.

Why it matters: Before MCP, every AI app needed custom integrations for every system: N applications × M tools. A shared protocol reduces that to N + M, and lets teams publish a "GitHub server" or "database server" that works across clients. But MCP servers run with real permissions, so server design (clear tools, least privilege, authentication, safe outputs) decides whether integrations are useful and secure.

When to reach for it

  • Exposing internal databases, tickets and docs to assistants
  • Sharing one integration across IDE, chat and agents
  • Providing curated read-only access to systems

When to avoid or be careful

  • Mirroring a huge raw API as hundreds of tools
  • Powerful shared credentials in the server
  • Connecting to untrusted third-party servers without review

Ways to give a model tools

MCP server
Best for: Reusable integrations shared across AI apps

Strengths: Standard protocol; write once, use in many clients.

Watch out: Another component to run and secure.

In-app function tools
Best for: Tools specific to one application

Strengths: Simple; no extra process.

Watch out: Not reusable by other clients.

Provider-hosted tools
Best for: Built-in capabilities (search, code execution)

Strengths: Managed by the provider.

Watch out: Limited customisation; vendor-specific.

Interview signals & numbers to know

When this topic comes up

  • “What is MCP?”
  • “How do we connect our database to AI assistants?”
  • “Tool poisoning in MCP”
  • stdio vs HTTP transport
  • Least-privilege tool design

Benchmarks & rules of thumb

3 -
server primitives: tools, resources, prompts
2 -
main transports: stdio and Streamable HTTP
N + M -
integrations needed instead of N × M

Common mistakes & follow-ups

Common interview mistakes

  • Giving the server an admin database role and relying on prompts to prevent writes.
  • Returning entire tables from a tool, flooding the model's context.
  • Installing a community MCP server without reading what its tools do.

Likely interviewer follow-ups

  • What problem does MCP solve?
  • How would you secure an MCP server that queries production data?
  • When would you use a local versus a remote MCP server?
Interview tip: Explain MCP as N + M instead of N × M integrations, then spend your time on least-privilege and validation. Security details are what make the answer strong.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

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

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Long-term Memory
Next topic
MCP Clients