1. What Problem Does MCP Solve?
Before MCP, integration was fragmented:- The Custom Wrapper Mess: If you had 5 developer IDEs and 5 databases, you had to write 25 separate integration adapters.
- Lack of Standardization: There was no standard format defining how a database should advertise its tables, or how a web search API should register its parameters with an LLM.
2. Architecture & Core Components
The Model Context Protocol divides responsibility among three distinct layers:2.1 The Host
The orchestration application that communicates with the LLM and manages security permissions (e.g., Claude Desktop, Antigravity IDE, or your custom Python agent). The Host instantiates the clients.2.2 The Client
A protocol component running inside the Host. It initiates connection sessions to MCP servers and translates tool schemas for the LLM.2.3 The Server
A lightweight background process that exposes resources, prompts, and tools to the client.- Resources: Read-only data sources (like local files, database records, or API responses).
- Prompts: Reusable prompt templates (like code review formats).
- Tools: Executable actions (like creating a GitHub issue, writing a file, or running a SQL query).
3. Connecting to an Existing MCP Server
MCP servers communicate with clients using transports. The most common transport is Stdio, where the host launches the server as a subprocess and communicates via standard input (stdin) and standard output (stdout).
Step 1: Install Python MCP SDK
To build MCP clients and servers, install the official SDK:Step 2: Configure Client Connection
To query an existing server (like the official GitHub MCP server), we initialize astdio_client connection by launching the server process:
Step 3: Retrieve and Execute Tools
Once connected, the client session queries the server to list its available tools and requests execution:4. Combined Client Code Project
Below is a complete, runnable script illustrating how to connect to the GitHub MCP server to fetch repository details:5. Practice Exercises
Practice 1: Tool Parameters Audit
Explain why the client passes arguments as a dictionary (e.g.{"username": "octocat"}) during session.call_tool(), and how the server knows what parameters to expect.
Solution
Solution
- Schema Validation: During the handshake,
session.list_tools()returns a list of tool objects, each containing aninputSchema(defined in JSON Schema format). - API Contract: The server advertises exactly what keys and data types it expects (e.g.,
usernamemust be a string). The client uses a standard dictionary to structure these arguments, allowing the server to validate them before executing the API request.