The Model Context Protocol (MCP) provides a standard way for AI applications to connect with external tools and data. Before MCP, developers had to build a custom integration for every service an AI needed to use. This guide provides a complete model context protocol explained, covering its architecture, request flow, and security model.

Key takeaways

  • MCP is an open protocol, not a product. It standardizes how AI applications connect to external capabilities.
  • It uses a host-client-server architecture. The AI application (host) manages connections (clients) to tool providers (servers).
  • The protocol defines three main primitives. These are Tools (actions), Resources (data), and Prompts (reusable templates).
  • MCP provides a contract for communication. It does not automatically make integrations secure. Developers must implement robust consent and authorization.
  • It complements, rather than replaces, existing APIs. MCP provides a standardized layer for AI model interaction.

What is the Model Context Protocol (MCP)?

The Model Context Protocol (MCP) is an open standard that defines how AI applications communicate with external services. It solves a common integration problem where every AI application needs custom code to talk to every tool. MCP creates a shared model, allowing any compatible AI application to use any compatible service without bespoke engineering for each connection.

Imagine you have three different AI assistants (N) and you want each to access four different services (M), like a calendar, a weather API, a project manager, and a database. Without a standard, you would need to write and maintain 12 unique integrations (N x M).

MCP aims to reduce this complexity. A service provider can expose its capabilities through a single MCP server, and any AI application that speaks the MCP protocol can then connect to that server. This aims to significantly reduce duplicated connector work by creating a shared integration model where each assistant and service needs to support MCP once.

MCP is not a replacement for traditional APIs (Source). Instead, an MCP server typically wraps an existing API, making its functions available to an AI model in a structured way.

How Does MCP Work? A Step-by-Step Breakdown

MCP works using a host-client-server architecture to manage the flow of information from a user's request to the final AI-generated answer. The host application orchestrates the process, using a client to communicate with a server that provides tools or data. The host remains in control of the AI model, user permissions, and final output.

Here is the end-to-end flow:

User -> Host App -> AI Model -> Host App -> MCP Client -> MCP Server -> External Service

The response follows the reverse path.

  1. Initialization. The Host application starts an MCP Client. The Client connects to an MCP Server and they perform a handshake. During this step, they negotiate the protocol version and declare which optional features they support, a process called capability negotiation (Source). While many features are optional, implementations must support the base protocol and lifecycle management.
  2. User Request. A user gives a prompt to the Host application, such as an AI assistant.
  3. Model Invocation. The Host sends the user's prompt to a large language model. It also includes a list of available tools discovered from the connected MCP Server.
  4. Tool Selection. The model analyzes the prompt. It determines that it needs an external tool to answer the request and generates a structured response asking to call a specific function with certain arguments.
  5. Consent and Execution. The Host receives the model's request to call a tool. It validates the request and, if necessary, asks the user for permission. Once approved, the Host instructs the Client to execute the tool call on the Server.
  6. Server Action. The Server receives the request from the Client, typically as a JSON-RPC message (Source). The Server validates the request again, checks permissions, and performs the underlying action, like querying a database or calling another API.
  7. Response. The Server returns the result to the Client. The Client then passes this result back to the Host.
  8. Final Answer. The Host formats the result as new context and sends it back to the model with the original conversation. The model uses this new information to generate a final, natural language response for the user.

An End-to-End Example: An Assistant Reading Your Calendar

To make the process concrete, let’s walk through a simple, illustrative example. An AI assistant uses an MCP server to access your calendar.

  • User Prompt: "What's on my schedule for tomorrow morning?"

  • Host and Model: The Host application sends this prompt to an AI model. It also provides the definition of a tool available from its connected MCP calendar server: get_calendar_events(start_time: string, end_time: string). The model recognizes the request and responds with a structured request to call that tool.

    • Illustrative Model Output: call_tool('get_calendar_events', start_time='2026-10-26T00:00:00Z', end_time='2026-10-26T12:00:00Z')
  • Host and Consent: The Host application receives this tool call request. Since reading a calendar involves personal data, the Host displays a confirmation prompt to the user.

    • UI Prompt: "Allow Assistant to read your calendar events for tomorrow morning? [Approve] [Deny]"
    • The user clicks "Approve."
  • Client and Server Communication: The Host instructs its MCP client to send the request to the MCP server. The client formats the request as a JSON-RPC message.

    JSON
    {
      "jsonrpc": "2.0",
      "method": "tool/execute",
      "params": {
        "name": "get_calendar_events",
        "arguments": {
          "start_time": "2026-10-26T00:00:00Z",
          "end_time": "2026-10-26T12:00:00Z"
        }
      },
      "id": "request-123"
    }
  • Server Response: The MCP server receives the request. It validates the parameters and queries the actual calendar service (e.g., Google Calendar API). It then returns a JSON object containing the events.

    • Illustrative Server Response: {\"events\": [{\"summary\": \"Standup\", \"start\": \"09:00\"}, {\"summary\": \"Project Sync\", \"start\": \"10:30\"}]}
  • Final Output: The Host receives this data. It provides the event list back to the model as context. The model then generates a user-friendly summary.

    • Final AI Answer: "You have two events tomorrow morning: Standup at 9:00 AM and a Project Sync at 10:30 AM."

What are MCP Tools, Resources, and Prompts?

The Model Context Protocol standardizes communication around three core concepts: tools, resources, and prompts (Source). Each serves a distinct purpose in providing an AI with external capabilities.

Primitive Description Example
Tool An executable function that the AI model can discover and request to invoke to perform an action or query (Source). send_email(to, subject, body)
Resource A piece of data or context that the host application provides to the model, often identified by a URI (Source). The content of a specific file, like file://path/to/document.txt.
Prompt A reusable, server-provided message template that a client can retrieve and use for complex tasks (Source). A prompt named summarize_code_changes that takes a git commit hash.

MCP vs. Direct API Integration

MCP is often compared to other technologies like direct API calls. While related, they operate at different levels of standardization and solve different problems.

Technology What it Standardizes Who Performs the Work Key Benefit
MCP The client-server protocol for discovering and using tools, resources, and prompts. The Host manages the model and consent; the Server executes the underlying logic. Interoperability
Direct API Call Only the specific API's own contract (e.g., a REST API's endpoints and schemas). The developer writes custom code inside the AI application to call the API. Full control

How Does MCP Handle Security and Permissions?

The Model Context Protocol defines communication rules but is not a security solution on its own. Developers who implement MCP are responsible for building secure systems (Source). Security relies on a clear division of responsibility between the host application and the server.

The Host's Role: Consent and Permission

The host application acts as the user's agent. Its primary security duty is to manage consent.

  • User Approval: The host must obtain explicit user permission before executing any tool that modifies data, incurs costs, or accesses sensitive information.
  • Scope Management: It should request the narrowest possible permissions needed for a task.
  • Validation: The host should perform initial validation on the model's requested tool call before sending it to the server.

The Server's Role: Validation and Authorization

The server must operate on a "zero trust" basis, never assuming that incoming requests are safe or authorized.

  • Input Validation: The server must rigorously validate all arguments from the client. A malicious user could use prompt injection to trick the model into generating dangerous arguments.
  • Authentication & Authorization: The server is responsible for its own authentication and authorization logic. It must verify the identity of the user on whose behalf the request is made.
  • Token Validation: When using bearer tokens (like with OAuth), the server has a critical responsibility. It must validate that the token was issued specifically for it, not for some other service (Source). This prevents a compromised client from using a token to access the wrong server.

Local vs. Remote Servers

The security model changes based on where the server is located.

  • Local Servers: A server running on the user's own machine operates within a different security context. While its transport layer may be simpler (e.g., standard I/O instead of HTTPS), this does not imply it is inherently more secure. The host application still needs to manage permissions carefully to prevent the AI from accessing unauthorized local files or running arbitrary commands.
  • Remote Servers: A server running on the public internet requires robust security. All communication must be encrypted (e.g., with TLS). It must use a strong authentication mechanism like OAuth2 to identify users and enforce permissions.

What to learn next

Sources and further reading