A Quick and Simple Explanation of Model Context Protocol-MCP
A Universal Adapter to Connect AI models to Disparate Data Sources
You are building an AI Agent connecting to different knowledge sources like PDFs, Databases, and APIs. You need to write custom code to access each of the tools.
Does it not seem familiar…
Remember the days when different smartphones and laptops had different chargers, such as Micor-USB, Lightning, USB-C, etc., requiring you to carry multiple cables if you had different devices? Then came the shift to USB-C, making charging effortless across devices.
Can we apply the same approach of open standardization and seamless integration to AI Agents to communicate between different LLMs and tools?
Can we have an open standard where the AI agent connects to various tools securely and in real-time, like a USB-C charger plug-and-play?
Model Context Protocol(MCP) is an open standard plug and play approach much like USB-C charger, using client server architecture. MCP allows AI models including LLMs to seamlessly integrate with various external data sources like databases, tools, APIs etc. securely. It has a real-time two way communication between client and server using a lightweight JSON-RPC 2.0 protocol.
Anthropic developed the open standard MCP that allows AI systems to have real-time, secure, two-way communication with external knowledge sources based on access.
The key components of MCP are
MCP Host: The MCP Host acts as a container and coordinator to manage multiple MCP clients. It also manages user authorization and authentication.
MCP Client: The client is the AI Application, which can be any AI model or an LLM like Claude. It is hosted within a host and maintains a 1:1 connection with MCP Servers using MCP Protocol. The client sends the request to the MCP Server and processes the response received from the MCP Server.
MCP Protocol: The MCP protocol uses a lightweight JSON-RPC 2.0 protocol to handle messages and request responses between clients and servers.
MCP Server: The server provides secure access to Tools, Databases or APIs, Context, and Prompts. MCP Server allows dynamic discovery and invocation of the tools.
- The MCP Host will first authenticate and authorize if you have access permission to the MCP Client.
- Once validated, you will prompt Claude(MCP Client) to get the latest Sales data. Claude acts as the MCP Client and maintains a separate connection with each of the MCP Servers.
- Claude sends the query to the MCP Server using JSON RPC 2.0(MCP Protocol) to retrieve the Sales data.
- The MCP Server will authenticate the request.
- MCP Server for the database will translate the query to a database-specific SQL statement.
- The MCP servers execute the query on the database.
- Each MCP Server returns the results to the respective MCP client using JSON RPC 2.0.
How will the AI system work with and without MCP?
Let’s understand the difference using an example where Claude LLM wants to query both PostgreSQL and SQLite databases. Here, Claude acts as the MCP Client.
Without MCP
The developers will have to write custom code for querying Postgres and SQLite, doubling the maintenance effort
- For Postgres, developers will use
psycopg2
library and Postgres-specific queries. - For SQLite, they will use
sqlite3
module to query.
Without MCP, the LLM will make separate, database-specific calls for each database. This would make it difficult for AI agents to seamlessly select and interact with the appropriate tools or data sources in real-time, impacting scalability, maintainability, and increasing complexity.
With MCP
Developers will use the MCP Server for Postgres and the MCP Server for SQLite, and they both have a standardized query_database
command. Claude now only needs to send the standardized query_database
command to query both databases.
The MCP client and server communicate through request and response using JSON format and lightweight JSON-RPC 2.0 protocol.
The MCP Server converts the database-specific syntax automatically. For Postgres, the parameter placeholder used is $1
whereas the parameter placeholder for SqLit is ?
. The MCP Server validates Claude’s permissions to query the data based on the user’s access and returns the results of the query in identical formats in JSON.
No more rewriting code for every new data source.
Benefit of MCP
- MCP allows the AI to seamlessly change or add the MCP Server without impacting the client. All MCP servers return results in standard JSON format. If you want to connect to additional databases like Mongo DB, the LLM will still have the same interface for sending requests and receiving responses.
- MCP ensures compatibility across different languages and tools with the language-agnostic JSON RPC 2.0 open standard to communicate.
- MCP architecture provides two-way secure communication between the MCP client and Server.
- An open standard to communicate with different MCP servers and access different services underneath.
- MCP’s open standard approach to resources, prompts, and tools makes switching between different AI models, resources, and tools seamless and quick.