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.
The Web_Search_MCP
project leverages the following key components:
TavilySearchResults
tool from Langchain is used to interact with the Tavily API efficiently..env
file, securely managing sensitive information like API keys.The core of this project lies within the search_web
tool, which provides the following features:
success
or error
), an array of results (if successful), and a timestamp.Before running the project, ensure that you have:
pip install uv
uv init Web_Search_MCP
*** By Running the above code uv creates pyproject.toml
and .venv
in the directory ***main.py
and .env
in the Web_Search_MCP
directory.main.py
and .env
into the files you just create.uv
to install the required Python packages:
uv add "mcp[cli]" python-dotenv langchain-community tavily-python
.env
File:
.env
in the Web_Search_MCP
directory..env
file in the following format:
TAVILY_API_KEY='your_tavily_api_key'
Replace your_tavily_api_key
with your actual Tavily API key.claude_desktop_config.json
:
c:\Users\<Your User Name>\AppData\Roaming\Claude\claude_desktop_config.json
Web_Search_MCP
directory in claude_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"
]
}
}
}
After Congfiguring the claude_desktop_config.json
file, you can start the server from within the Claude desktop application.
Once the server is running, it exposes a single tool called search_web
according to the Model Context Protocol.
search_web
query
(str): The search query you want to submit to the web.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
}
{
"mcpServers": {
"Mcp_Demo": {
"env": {},
"args": [
"--directory",
"path/Web_Search_MCP",
"run",
"main.py"
],
"command": "uv"
}
}
}
Seamless access to top MCP servers powering the future of AI integration.