Skip to main content

📝 Model Context Protocol (MCP)

Description

< What is it? >

The Model Context Protocol (MCP) is an open protocol for connecting an AI application to external tools and context through a standard interface. An MCP server can expose capabilities such as a documentation search, browser, GitHub integration, or database, without every AI client needing a custom integration.

  • MCP architecture
┌──────────┐
│ User │
└────┬─────┘

┌───────────────────────────────┐
│ MCP Host │
│ ChatGPT, Claude Desktop, IDE │
│ │
│ ┌────────────┐ │
│ │ LLM/Agent │ │
│ └─────┬──────┘ │
│ │ chooses a tool │
│ ┌─────▼──────┐ │
│ │ MCP Client │ │
│ └─────┬──────┘ │
└────────┼──────────────────────┘
│ MCP/JSON-RPC <-- Communication via pipes (stdin/stdout)
▼ Server dies when client exits
┌───────────────────────────────┐
│ MCP Server │
│ │
│ convert_currency(...) │
└──────────────┬────────────────┘

Exchange-rate API

mcp_arch
  • MCP workflow
mcp_flow
  • MCP interaction sequence diagram
mcp_seq_diagram

< Core roles >

PartRole
MCP hostThe AI application that needs external capabilities
ex1. The AI application where users type their financial questions & receive responses.
ex2. Determines which external connections are needed based on the user's query.
MCP clientThe connection inside the host that communicates with a server
ex1. Receives tool definitions from the server & executes the corresponding requests.
ex2. Establishes a session with the MCP server using JSON-RPC messaging.
MCP serverThe service that exposes tools or context to the client
ex1. Translates complex banking API calls into a consistent, easy-to-use format.
ex2. Can run locally on machine or be hosted in the cloud.

< Primitives >

  • Tools:
    • Actions the LLM can perform
    • Querying a database, searching documentation, running code, or booking a flight
  • Resources:
    • Context the LLM can use to answer questions
    • Documents, code, or database records that is too large to fit in a prompt
  • Prompts:
    • Pre-defined workflows and instructions that can be invoked by the LLM
    • Saves users from having to write complex prompts for every task
prompt-resource-workflow

Key points

  • Tools let an agent take actions or retrieve live results, such as searching documentation or creating an issue.
  • Context gives an agent relevant information from an external source instead of placing everything in its prompt.
  • MCP servers may run locally through stdio or remotely through Streamable HTTP.
  • MCP expands an agent's access; it does not change the underlying model's knowledge or reasoning ability.
  • Treat each server as a security boundary: enable only trusted servers and grant the least access needed.

Ecosystem

  • Use third-party server

    • Benefits:
      • Speed: filesystem and database access without writing a server
      • Maintained by others: you focus on the client and application
      • Integration: client code can be shared and reused for different MCP servers
    • Considerations:
      • Security: trust the server to handle your data and not leak it. It requires careful management of private data and credentials. The server runs code and may call external APIs → check these sources.
      • Surface area: more tools mean more the LLM can do; be aware of what each server exposes
      • Availability: if the server is down, your client may not work
      • Cost: some servers may charge for usage
  • Awesome MCP Servers (mcpservers.org): A collection of servers for the Model Context Protocol

  • MCP Open Library (8enSmith | github)

  • Model Context Protocol (modelcontextprotocol.io)

    • Interested in creating your own MCP server? Visit the official documentation at modelcontextprotocol.io for comprehensive guides, best practices, and technical details on implementing MCP servers.

Implementation

  • mcp example (iddv | github)
    • A reference implementation of the Model Context Protocol (MCP) enabling seamless tool calling between LLMs and applications. Features client/server architecture with HTTP APIs, local CLI execution, and AWS Bedrock integration in a production-ready, extensible framework.

Crash course

Reference