An MCP server that provides web search capabilities and weather data retrieval.
AI Makerspace: MCP Session Repo for Session 13
This project is a demonstration of the MCP (Model Context Protocol) server, which utilizes the Tavily API for web search capabilities. The server is designed to run in a standard input/output (stdio) transport mode.
Project Overview
The MCP server is set up to handle web search queries using the Tavily API. It is built with the following key components:
- TavilyClient: A client for interacting with the Tavily API to perform web searches.
Prerequisites
- Python 3.13 or higher
- A valid Tavily API key
⚠️NOTE FOR WINDOWS:⚠️
You'll need to install this on the Windows side of your OS.
This will require getting two CLI tool for Powershell, which you can do as follows:
winget install astral-sh.uvwinget install --id Git.Git -e --source winget
After you have those CLI tools, please open Cursor into Windows.
Then, you can clone the repository using the following command in your Cursor terminal:
git clone https://AI-Maker-Space/AIE8-MCP-Session.git
After that, you can follow from Step 2. below!
Installation
Clone the repository:
git clone <repository-url> cd <repository-directory>Configure environment variables: Copy the
.env.sampleto.envand add your Tavily API key:TAVILY_API_KEY=your_tavily_api_key_here WEATHER_API_KEY=your_weather_api_key_here OPENAI_API_KEY=your_openai_api_key_hereTo get a WeatherAPI key:
- Visit https://www.weatherapi.com/
- Sign up for a free account (provides 1 million calls/month)
- Get your API key from the dashboard
🏗️ Add a new tool to your MCP Server 🏗️
Create a new tool in the server.py file, that's it!
Running the MCP Server
To start the MCP server, you will need to add the following to your MCP Profile in Cursor:
NOTE: To get to your MCP config. you can use the Command Pallete (CMD/CTRL+SHIFT+P) and select "View: Open MCP Settings" and replace the contents with the JSON blob below.
{
"mcpServers": {
"mcp-server": {
"command" : "uv",
"args" : ["--directory", "/PATH/TO/REPOSITORY", "run", "server.py"]
}
}
}
The server will start and listen for commands via standard input/output.
Usage
The server provides a web_search tool that can be used to search the web for information about a given query. This is achieved by calling the web_search function with the desired query string.
Activities:
There are a few activities for this assignment!
🏗️ Activity #1:
Choose an API that you enjoy using - and build an MCP server for it!
🏗️ Activity #2:
Build a simple LangGraph application that interacts with your MCP Server.
You can find details here!
Running the LangGraph Application
To run the LangGraph application that uses your MCP server:
python3 langgraph_app.py
Or try the demo version to see all MCP tools in action:
python3 demo_langgraph.py
The application provides an interactive command-line interface where you can:
- Ask about weather: "What's the weather in Seattle?"
- Search the web: "Search for information about Python"
- Roll dice: "Roll 2d20k1" or "Roll a die"
The app intelligently routes your requests to the appropriate MCP tools and provides responses using the LLM when needed.
What's Included:
langgraph_app.py- Full interactive LangGraph application with LLM integrationdemo_langgraph.py- Quick demo showing all MCP tools working together
Tools (1)
web_searchPerforms web searches to retrieve information about a given query.Environment Variables
TAVILY_API_KEYrequiredAPI key for Tavily web search servicesWEATHER_API_KEYrequiredAPI key for WeatherAPI servicesOPENAI_API_KEYrequiredAPI key for OpenAI LLM integrationConfiguration
{"mcpServers": {"mcp-server": {"command": "uv", "args": ["--directory", "/PATH/TO/REPOSITORY", "run", "server.py"]}}}