Model Context Protocol

I want to know more about Model Context Protocol, so I am going to read about it.

Date Created:
1 9

References



Notes


The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you're building an AI-powered IDE, enhancing a chat interface, or creating a custom AI workspace, MCP provides a standardized way to connect LLMs with the context they need.

MCP is an open protocol that standardizes how applications provide context to LLMs. MCP provides a standardized way to connect AI models to different data sources and tools. MCP helps you build agents and complex workflows on top of LLMs. LLMs frequently need to integrate with data and tools, and MCP provides:

  • A growing list of pre-built integrations that your LLM can directly plug into
  • The flexibility to switch between LLM providers and vendors
  • Best practices for securing your data within your infrastructure

MCP General Architecture

  • MCP Hosts: Programs like Claude Desktop, IDEs, or AI tools that want to access data through MCPs
  • MCP Clients: Protocol clients that maintain 1:1 connections with servers
  • MCP Servers: Lightweight programs that each expose specific capabilities through the standardized Model Context Protocol
  • Local Data Sources: Your computer's files, databases, and services that MCP can securely access
  • Remote Services: External systems available over the internet that MCP servers can connect to

For Server Developers

MCP servers can provide three main types of capabilities:

  1. Resources: File-like data that can be read by clients (like API responses or file contents)
  2. Tools: Functions that can be called by the LLM (with user approval)
  3. Prompts: Pre-written templates that help users accomplish specific tasks

Core Architecture

MCP follows a client-server architecture where:

  • Hosts are LLM applications that initiate connections
  • Clients maintain 1:1 connections with servers, inside the host application
  • Servers provide context, tools, and prompts to clients

Core Architecture

Core Components

  • The Protocol Layer handles message framing, request/response linking, and high-level communication patterms
  • The Transport Layer handles the actual communication between clients and servers. MCP supports multiple transport mechanisms:
    • Stdio transport
      • Uses standard input/output for communication
      • Ideal for local processes
    • HTTP with SSE transport
      • Uses Server-Sent Events for server-to-client messages
      • HTTP POST for client-to-server messages
  • Message Types: MCP has these main types of messages:
    • Requests expect a response from the other side
    • Results are successful responses to requests
    • Errors indicate that a request failed
    • Notifications are one-way messages that don't expect a response

Connection Lifecycle

  1. Initialization

Connection Lifecycle - Initialization

    1. Client sends initialize request with protocol version and capabilities
    2. Server responds with its protocol version and capabilities
    3. Client sends initialized notification as acknowledgement
    4. Normal message exchange begins


  1. Message Exchange
    1. After initialization, the following patterns are supported:
      1. Request-Response: Client or server sends requests, the other responds
      2. Notifications: Either party sends one-way messages
  2. Termination
    1. Either party can terminate the connection
      1. Clean shutdown via close()
      2. Transport disconnection
      3. Error conditions

Resources

Resources are a core primitive in the Model Context Protocol (MCP) that allows servers to expose data and content to be read by clients and used as context for LLM interactions. Resources are designed to be application-controlled, meaning that the client application can decide how and when they should be used. Different MCP clients may handle resources differently. Resources represent any kind of data that an MCP server wants to make available to clients.

Resource Types:

  • Text resources should be UTF-8 encoded
  • Binary Resources should contain raw data encoded in base64
    • Images
    • PDFs
    • Audio/Video files

Prompts

Prompts enable servers to define reusable prompt templates and workflows that clients can easily surface to users and LLMs. They provide a powerful way to standardize and share common LLM interactions.

Tools

Tools are a powerful primitive in the Model Context Protocol (MCP) that enable servers to expose executable functionality to clients. Through tools, LLMs can interact with external systems, perform computations, and take actions in the real world. Key aspects of tools:

  • Discovery: Clients can list available tools through tools/list endpoint
  • Invocation: Tools are called using the tools/call endpoint, where servers perform the requested operation and return results
  • Flexibility: Tools can range from simple calculations to complex API interactions

Sampling

Sampling is a powerful MCP feature that allows servers to request LLM completions through the client, enabling the sophisticated agentic behaviors while maintaining security and privacy.

Roots

Roots are a concept in MCP that define the boundaries where servers can operate. They provide a way for clients to inform servers about relevant resources and their locations.

Transports

Transports in the Model Context Protocol (MCP) provide the foundation for communication between clients and servers. A transport handles the underlying mechanics of how messages are sent and received.

You can read more about how comments are sorted in this blog post.

User Comments