Web_Search_MCP
An MCP(Model Context Protocol) Server with a web search tool
memohib
README
Web_Search_MCP
An MCP(Model Context Protocol) Server with a web search tool
This project demonstrates how to create a web search tool using the Tavily API and integrate it with MCP (Model Context Protocol) for seamless interaction with AI Systems. This allows you to provide real-time web search capabilities to your language models or applications.
Overview
The Web_Search_MCP
project leverages the following key components:
- Tavily API: A powerful search API that provides real-time, comprehensive web search results, including answers, raw content, and relevant metadata.
- FastMCP: The FastMCP class uses Python type hints and docstrings to automatically generate tool definitions, making it easy to create and maintain MCP tools.
- Langchain: Specifically, the
TavilySearchResults
tool from Langchain is used to interact with the Tavily API efficiently. - Dotenv: A library for loading environment variables from a
.env
file, securely managing sensitive information like API keys. - uv: A very fast Python package installer and resolver, used to manage and run this project.
Functionality
The core of this project lies within the search_web
tool, which provides the following features:
- Web Search: Accepts a search query as input and retrieves relevant search results from the web using the Tavily API.
- Detailed Results: Provides detailed information from the search results, including the website's content, URL, a relevancy score, the content type, and a direct answer (if available).
- Formatted Output: Returns the search results in a well-structured JSON format. The output includes a status indicator (
success
orerror
), an array of results (if successful), and a timestamp. - Error Handling: Gracefully handles errors during the search process and returns an informative error message in JSON format.
- Asynchronous processing: The search tool is based on asynchronous, which can handle many requests at the same time.
Prerequisites
Before running the project, ensure that you have:
- Python 3.8+: Python 3.8 or a later version installed on your system.
- Tavily API Key: A valid Tavily API key, obtainable by signing up on the Tavily website.
- uv: The uv package manager for Python. You can install it using:
pip install uv
Installation
- Create Project Directory: Create a directory for the project and navigate into it:
*** By Running the above code uv createsuv init Web_Search_MCP
pyproject.toml
and.venv
in the directory *** - Create Project Files: Create the files
main.py
and.env
in theWeb_Search_MCP
directory. - Activate Venv: Navigate into .venv/Scripts/activate and activate the Vritual Environment
- Copy code: copy the code in the
main.py
and.env
into the files you just create. - Install Dependencies: Use
uv
to install the required Python packages:uv add "mcp[cli]" python-dotenv langchain-community tavily-python
Configuration
-
.env
File:- Create a file named
.env
in theWeb_Search_MCP
directory. - Add your Tavily API key to the
.env
file in the following format:
ReplaceTAVILY_API_KEY='your_tavily_api_key'
your_tavily_api_key
with your actual Tavily API key.
- Create a file named
-
claude_desktop_config.json
:- This file is used by the Claude desktop application (if you are using it) to discover and run the FastMCP server.
- It should reside in
c:\Users\<Your User Name>\AppData\Roaming\Claude\claude_desktop_config.json
- Ensure the path to your
Web_Search_MCP
directory inclaude_desktop_config.json
is accurate. If your project is not in path/Web_Search_MCP, please modify the
args` field in the config file.
{ "mcpServers": { "Mcp_Demo": { "command": "uv", "args": [ "--directory", "path/Web_Search_MCP", "run", "main.py" ] } } }
Running the MCP Server
After Congfiguring the claude_desktop_config.json
file, you can start the server from within the Claude desktop application.
Usage
Once the server is running, it exposes a single tool called search_web
according to the Model Context Protocol.
- Tool Name:
search_web
- Input:
query
(str): The search query you want to submit to the web.
- Output: A JSON formatted string containing the search results.
Example JSON Response (Success):
{
"status": "success",
"results": [
{
"title": "...",
"url": "...",
"content": "text",
"score": 0.9,
"raw_content": "..."
},
{
"title": "...",
"url": "...",
"content": "text",
"score": 0.9,
"raw_content": "..."
}
],
"timestamp": 1708849844.064655
}
Recommended Servers
Crypto Price & Market Analysis MCP Server
A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.
MCP PubMed Search
Server to search PubMed (PubMed is a free, online database that allows users to search for biomedical and life sciences literature). I have created on a day MCP came out but was on vacation, I saw someone post similar server in your DB, but figured to post mine.
dbt Semantic Layer MCP Server
A server that enables querying the dbt Semantic Layer through natural language conversations with Claude Desktop and other AI assistants, allowing users to discover metrics, create queries, analyze data, and visualize results.
mixpanel
Connect to your Mixpanel data. Query events, retention, and funnel data from Mixpanel analytics.

Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Nefino MCP Server
Provides large language models with access to news and information about renewable energy projects in Germany, allowing filtering by location, topic (solar, wind, hydrogen), and date range.
Vectorize
Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.
Mathematica Documentation MCP server
A server that provides access to Mathematica documentation through FastMCP, enabling users to retrieve function documentation and list package symbols from Wolfram Mathematica.
kb-mcp-server
An MCP server aimed to be portable, local, easy and convenient to support semantic/graph based retrieval of txtai "all in one" embeddings database. Any txtai embeddings db in tar.gz form can be loaded
Research MCP Server
The server functions as an MCP server to interact with Notion for retrieving and creating survey data, integrating with the Claude Desktop Client for conducting and reviewing surveys.