MCP (Model Context Protocol)
Model Context Protocol (MCP)
- LLMs, like ChatGPT, can only create text, images, audio, or video.
- They cannot perform actions, such as booking a flight, changing a database, or calling an API.
- To perform actions, we need AI agents.
AI agents interact with:
- Third-party platforms (APIs)
- Internal databases
- User preferences
- LLMs for decision-making
2. What Is an AI Agent?
- AI agents are similar to automation scripts, like VMware orchestrator, Zapier, or Python scripts. However, they can also think using LLMs.
They:
- Process user input with an LLM
- Decide which tools or APIs to use
- Interact with platforms, like flights, hotels, and databases
- Make decisions in loops
- Stop only when the task is complete
- Use memory to store user preferences
- Essentially, old automation scripts combined with LLM reasoning create an AI agent.
3. How AI Agent Workflow Works (Example: Flight Booking)
- User: “I want to fly to North London.”
- Agent → LLM: “What does the user mean?”
- LLM: Destination = London
- Agent → LLM: “Which tools or APIs should I call?”
- Agent calls airline APIs and retrieves flight data.
- Agent fetches user preferences from the database.
- Agent → LLM: “Pick the best flight.”
- LLM chooses one.
- Agent books the flight and sends details to the user.
- Agent and LLM interact multiple times during the workflow.
4. How Do Agents Interact With Platforms? → Tools
- Agents use tools to call third-party APIs.
Example (from pseudocode):
- Airline A: /api/flights
- Airline B: /flights/list
- Airline C: /listFlights
Each API is different, so the agent must know:
- Different endpoints
- Different response formats
- Different input fields
- Doing this manually is difficult. AI should manage it automatically.
5. What Makes This Easy? – MCP (Model Context Protocol)
MCP provides:
- A standard method for AI agents to discover and use APIs
- A common protocol for tools to expose capabilities
- Consistent structure, naming, inputs, and outputs
- In simple words, MCP tells AI agents how to use APIs correctly, with the right context.
Example: Instead of manually coding 50 airline connectors, the AI agent can read the MCP description and automatically understand how to interact with each one.
6. MCP Architecture (High-Level)
MCP uses a client-server structure:
- Integrated inside AI agents (IDEs, apps)
- Communicates with MCP servers
- Exposes tools, APIs, and databases
- Built by companies or developers
Agent → MCP Client → MCP Server → Third-party platform
7. Where Are MCP Clients Used?
MCP clients are embedded in AI-powered development tools, like:
- Cursor IDE
- Windsurf
- Cloud Code
- Cloud Desktop
They help agents:
- Access browser logs
- Access HTML elements
- Access local databases
- Debug UI issues
- Analyze backend and frontend code
- Investigate data issues
8. Real-World MCP Use Cases
1) Web Development
MCP servers provide AI agents access to:
- Browser console logs
- DOM elements
This helps debug UI issues automatically.
2) Data Engineering
With MCP servers for:
- Stripe
- BigQuery
- Data Studio
AI agents can:
- Analyze data
- Find missing transactions
- Trace root causes across datasets
9. Who Builds MCP Servers?
- Companies build their own MCP servers so AI agents can use their APIs.
- Community members also create MCP servers, but use unofficial ones with caution.
Anyone can build an MCP server as long as they understand:
- The platform's APIs
- MCP specifications
Lab
Opening and Configuring Roo-Code in VSCode
Let's check if it's working correctly.
Now that Roo-Code is set up, try exploring some of its capabilities:
- Ask coding questions: "How do I create a Python function?"
- output :
To create a Python function, follow these steps:
1. Use the `def` keyword followed by the function name and parentheses `()` for parameters.
2. End the function header with a colon `:`.
3. Write the function body indented under the header.
4. Optionally, use the `return` statement to return a value from the function.
Example 1: Simple function with no parameters and no return value:
```python
def greet():
print("Hello, world!")
```
Example 2: Function with parameters and a return value:
```python
def add_numbers(a, b):
return a + b
```
Key points:
- Function names should be descriptive and follow Python naming conventions (lowercase, underscores).
- Indentation is critical for defining the function body.
- Use parameters to pass information into functions.
- Use `return` to output results from the function.
This is the standard way to create and use functions in Python.
- Request explanations: "Explain what JSON is and how it's used"
- Get help with tasks: "Can you help me write a simple bash script?"
- Environment exploration: "What files and directories are in the current workspace?"
Note: You now have Roo-Code fully configured! In advanced labs, you'll explore MCP server integration and other advanced capabilities.
Request explanations: "Explain what JSON is and how it's used"
Components Breakdown of MCP (Model Context Protocol)
MCP Architecture & How MCP Works
Lab : Using MCP Server
Using the MCP Inspector
Lab : Building an MCP Server
| Traditional Tool |
UV Equivalent |
|---|---|
pip install package |
uv add package |
python -m venv env |
uv init project |
pip install -r requirements.txt |
uv sync |
- uv init creates a proper Python project with pyproject.toml- mcp[cli] includes both MCP SDK and development tools (MCP Inspector)- This follows the official MCP development workflow
server.py file in your project directoryget_airports() functionfile://airports - MCP resources require proper URI schemes to be correctly identified by AI systems.search_flights() function in server.pycreate_booking() function in server.pyfind_best_flight() function in server.pyhandle_disruption() function in server.pyMCP Client Development
Lab : Building an MCP Client
Running the Basic MCP Client
Now let's test a complete client that combines all MCP capabilities in one comprehensive implementation.
- Examine the complete_client.py file
- Run it to see all features working together
- Observe the phased testing approach
- See how all callbacks work in harmony
Command to run:
cd /home/lab-user/mcp-client
uv run python complete_client.py🌟 Complete client features:
- Server discovery and capability listing
- Tool execution and resource access
- Roots provision for file system access
- Sampling for LLM request handling
- Elicitation for user input handling
- Click on the 🦘 kangaroo icon to open Roo-Code
- Click on the 3 servers icon at the top of Roo-Code
- Go to Edit Project MCP
- Add the following configuration to your MCP settings
📋 Configuration to add:
{
"mcpServers": {
"k8s-mcp-server": {
"command": "sudo",
"args": [
"docker",
"run",
"-i",
"--rm",
"-v",
"/home/lab-user/.kube/config:/home/appuser/.kube/config:ro",
"ginnux/k8s-mcp-server:latest",
"--mode",
"stdio"
]
}
}
}
Configuration Explanation:
sudo docker run- Runs the container with elevated privileges-i --rm- Interactive mode, remove container after use-v /home/lab-user/.kube/config:/home/appuser/.kube/config:ro- Mounts your kubeconfig as read-only--mode stdio- Uses standard I/O for MCP communication
Now that the k8s-mcp-server is configured, let's test the connection and start using it to manage your cluster.
🔗 Connection Test:
- Ask Roo-Code to connect to your Kubernetes cluster
- Verify the connection is working
💬 Try these natural language commands:
- "Connect to my Kubernetes cluster"
- "Show me the status of my cluster"
- "List all namespaces in my cluster"
- "What nodes do I have?"
🎯 Expected Behavior:
- Roo-Code should recognize the k8s-mcp-server
- It should be able to execute kubectl-like commands
- You should see cluster information in natural language
Now let's test the k8s-mcp-server with real Kubernetes operations. We'll create resources and then simulate a troubleshooting scenario.
🚀 Task 1: Create an Nginx Pod
- Ask Roo-Code: "Create an nginx pod with nginx image"
- Verify the pod was created successfully
- Check the pod status using Roo-Code
🔍 Task 2: Verify Pod Creation
- Ask Roo-Code: "Show me the status of the nginx pod"
- Confirm the pod is running
- Check pod details and logs if needed
⚠️ Task 3: Simulate a Broken Scenario
- Create a pod with an incorrect image: "Create a pod named test-pod with image BUSYYBOX"
- Ask Roo-Code to identify the root cause of the issue
- Use natural language to troubleshoot: "Why is my test-pod not starting?"
🎯 Learning Objectives:
- Practice creating Kubernetes resources with AI
- Learn to verify resource creation
- Experience AI-powered troubleshooting
- Understand how to ask for help with broken resources
Comments
Post a Comment