MCP Servers
Model Context Protocol servers that expose tools and resources with a shared interface.
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
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.
@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.
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.
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.
How it works, step by step
Step 1 of 41. Decide what to expose
Choose a small set of task-level tools and any resources or prompts, and define the access each needs.
- 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
Strengths: Standard protocol; write once, use in many clients.
Watch out: Another component to run and secure.
Strengths: Simple; no extra process.
Watch out: Not reusable by other clients.
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?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply MCP Servers with generative AI interview Q&A and hands-on practice.