Sub topic 1
What MCP Is and Why Your Application Might Use It
Prerequisites
Assume you can read Python, understand JSON and JSON Schema, and have used an LLM API with tool calling. MCP means Model Context Protocol. It is an open protocol that lets an application connect to external servers that provide context or actions.
Without MCP, each application needs custom adapters for every database, API, or local service. MCP standardizes the connection, discovery, schemas, and messages. Your application can then reuse compatible servers instead of implementing each integration itself.
Hosts, Clients, and Servers
An MCP host is your main application, such as an LLM assistant. The host creates one MCP client for each server connection. An MCP server provides capabilities, such as searching files, querying a database, or calling an API.
The server does not normally decide when the model uses a capability. The host controls the connection and decides which results become part of the model conversation.
| Component | Responsibility |
|---|---|
| Host | Runs the application and applies policy |
| Client | Maintains one protocol connection |
| Server | Exposes tools, resources, or prompts |
Tools, Resources, and Prompts
MCP defines three important primitives:
- Tools are actions that a model may request, such as
add,search, orcreate_ticket. - Resources are readable data identified by URIs, such as a file or document.
- Prompts are reusable message templates that a user or host can select.
Tools are usually model-controlled. Resources are usually application-controlled, because the host chooses when to read them. Prompts are usually user-controlled. This separation helps keep authority explicit.
How Messages and Capabilities Work
MCP messages use JSON-RPC. A request has an identifier and method, such as tools/list. The receiver returns a matching result or an error. Notifications have no identifier and do not receive a response.
During initialization, both sides exchange protocol versions and capabilities. A server might announce that it supports tools but not prompts. The client should use only features the server declares.
Choosing a Transport
stdio starts a local server as a subprocess. The client writes protocol messages to standard input and reads them from standard output. It is simple and keeps communication local.
Streamable HTTP connects to a server over HTTP. It fits remote or separately deployed servers, but requires authentication, network controls, and careful handling of server trust.
Initialization and Connection Lifecycle
A typical connection follows this sequence:
The client must initialize before listing tools or calling them. After initialization, it can discover capabilities and use them until the connection closes.
Exercise
Why should a host inspect capabilities before calling an MCP method?
Show answer
The server may not support that method, and capability negotiation lets the host avoid invalid requests.