Sitemap

Model Context Protocol — The Universal Adapter for AI Tools

5 min readMay 5, 2025

In this article, we explore one of the hottest topics in the world of AI today: the Model Context Protocol or MCP is a universal adapter designed to streamline and unify how AI tools interact and operate.

Image source — Medium

Imagine, a big international airport where every airline used to have its own check-in counter, each with different forms, languages and rules. This was highly inconvenient for the travelers who need to learn a new process for every flight.

After racking their brains to come up with a solution to this confusing, time-consuming mess, the airport authorities solve this problem and introduce us to a Universal Check-in Desk. In this new system, travelers do not have to worry about the airline, destination or language. They just have to hand over the passport and ticket to one counter. The staff exactly knows how to process their request, print their boarding pass and send their bags to the right plane. With this standardization, travelers and airline both save time and avoid confusion.

That’s what MCP does for AI tools and data.

MCP is like the Universal Check-in Desk for AI which standardizes how we call a tool (method names, parameters), how the errors are reported, how the authentication is handled and even the responses. Without the MCP, every tool or API might return data in a different JSON structure, require different authentication or need custom code for every integration. Implementing MCP allows the AI/ developer to interact with tools in a consistent way, regardless of what’s happening under the hood.

To give you a better understanding, let’s talk more about the response structure:

When we use MCP, every tool (regardless of what API it wraps) returns results in a standardized format. For example, when we call a tool, the client or agent doesn’t need to parse custom JSON or worry about different field names for every API. The following code can be used to fetch the output from all the tools.

tool_call = await session.call_tool("tool_name",{"tool_parameter":parameter})   
response_json = tool_call.content[0].text

This uniformity is a huge benefit for chaining tools, building agents or integrating with LLMs.

Putting MCP to Test: A Weather Tool Demo

Recently, I tried implementing MCP to see if it could really simplify connecting AI apps with external tools. Here’s how it went, step by step:

1. Setting Up the MCP Server (server.py) :

I started by building a server that exposes two tools:

  • get_weather — This function takes a city name, fetches the current weather data from OpenWeatherMap and returns a tidy dictionary with temperature, humidity, wind and a weather description. Note: There is no need for the client to know how the API work, the server handles all the details.
#server.py
from mcp import FastMCP
mcp = FastMCP("Weather Tools")
@mcp.tool()
def get_weather(location: str) -> str:
open_weathermap_api_key = WEATHER_API_KEY
base_url = "http://api.openweathermap.org/data/2.5/weather?"
complete_url = base_url + "appid=" + open_weathermap_api_key + "&q=" + location
response = requests.get(complete_url)
x = response.json()
print(x)
if x['cod'] != "404":#status code should not return 404, else we might encounter an error
y=x['main']
current_temp = round(y['temp'] - 273.15,2) # converting the scale from Kelvin to Celsius
current_humidity = y['humidity']
wind_speed = x['wind']['speed']
wind_gust = x['wind']['gust']
wind_degree = x['wind']['deg']
description = x['weather'][0]['description']
output = {"temperature":current_temp,
"humidity":current_humidity,
"description":description,"wind_speed":wind_speed,"wind_gust":wind_gust,"wind_deg":wind_degree}
print(output)
return(output)
else:
return f"Error fetching the data from OpenWeatherMap"
  • overall_weather — This tool takes the weather dictionary(from get_weather) as input and with the help from an LLM (using NVIDIA’s NIM API) generates a natural-language summary and travel suggestion. Again, the client doesn’t worry about prompt engineering or the LLM quirks.
@mcp.tool()
def overall_weather(location: str,weather_dict: dict)-> str:

NVIDIA_API_KEY = os.getenv("NVIDIA_API_KEY")
nim_client = OpenAI(base_url = "https://integrate.api.nvidia.com/v1",
api_key = NVIDIA_API_KEY)
prompt = f"""
You are given weather information for {location} in the form of a dictionary: {weather_dict}.

- The dictionary contains details about temperature, humidity, wind speed, and other weather parameters.
- Your task is to analyze these details and provide a comprehensive summary of the weather conditions in natural language.
- Additionally, suggest whether it is a good time to visit {location} based on the weather conditions.
- **Output Format**: Return the summary and suggestion in natural language.

Specific Instructions:
- Just limit the output to details about the weather and if it is a good time to visit that location. Do not include any additional text or message.
-Refrain from adding titles in the output like Weather Summary or suggestion. Just return the output in a natural conversation like structure
"""

response = nim_client.chat.completions.create(
model = "meta/llama-3.1-70b-instruct",
messages = [{"role":"user","content":prompt}]
)
return response.choices[0].message.content

Both tools are registered with FastMCP that lets us expose Python functions as standardized, discoverable actions that any MCP client can find and use, making integration seamless and universal.

2. Building the MCP Client(client.py) :

  • Preparing to connect to the MCP Server — We need to define the server_params with StdioServerParameters. This tells the client to start and communicate with our MCP server (server.py) using standard input/output (STDIO)
  • Establishing the MCP Client Session — We can use async with stdio_client(server_params) to launch the server and establish a connection. Then, we wrap this connection in a ClientSession which handles all MCP protocol details
  • Initializing and Discovering Tools —We use await session.initialize() to set up the session. To get a list of all tools, we call await session.list_tools()
  • User Interaction and Tool Chaining — Here we prompt the user to enter a travel destination, then we call the get_weather tool to extract the weather data as a dictionary. Next, we call the overall_weather tool, passing both location and the weather dictionary to receive a natural language weather summary and suggestion.
#client.py
import asyncio
from mcp.client.stdio import stdio_client
from mcp import ClientSession, StdioServerParameters

async def main():
server_params = StdioServerParameters(
command = 'python',
args = ["weather_server.py"],
env = None
) #connect to mcp server

async with stdio_client(server_params) as (stdio,write):
async with ClientSession(stdio,write) as session:
await session.initialize()
#list avaliable tools
tools_response = await session.list_tools()
print("Available tools:", [tool.name for tool in tools_response.tools])
print("Using the tools...")
location = input("Enter your desired travel destination:")
get_weather = await session.call_tool("get_weather",{"location":location})
response_json = get_weather.content[0].text
result_dict =json.loads(response_json)
# print(result_dict)
overall_weather = await session.call_tool("overall_weather",{"location":location,"weather_dict":result_dict})
final_json = overall_weather.content[0].text
print(final_json)
return final_json

To summarize —

  • Our server.py exposes weather-fetching and summarizing tools via MCP, allowing any compatible client to use them through a standardized, plug and play protocol.
  • Our client.py acts as a smart, protocol driven user interface that — connects to our MCP server, discover available tools, chains them together based on user input and outputs results — all with minimal, maintainable code.

Written by — Shreya Singhee (LinkedIn)

--

--

The Visionary Vectors Blog
The Visionary Vectors Blog

Written by The Visionary Vectors Blog

Managed by two data nuts with a passion for ML & AI.