Skip to content

Instantly share code, notes, and snippets.

@mimoo
Last active June 6, 2025 13:59
Show Gist options
  • Save mimoo/d1388f63d911b821427aae0bfe19936f to your computer and use it in GitHub Desktop.
Save mimoo/d1388f63d911b821427aae0bfe19936f to your computer and use it in GitHub Desktop.

Give vscode agent mode the power to do web searches

You need uv, then:

  1. add websearch.py to some folder FOLDER
  2. add the file .vscode/mcp.json if it doesn't exist, with your new websearch MCP server (and edit the FOLDER part). You can also do this by fuzzy searching for "MCP: Add Server" and adding the command uv --directory FOLDER run python websearch.py --stdio in the prompt.
  3. in the mcp.json you might want to put the full path to you uv instead of just uv. (do which uv in your terminal to get that full path)
  4. voila
{
"servers": {
"websearch-mcp": {
"type": "stdio",
"command": "uv",
"args": [
"--directory",
"FOLDER",
"run",
"python",
"websearch.py",
"--stdio"
]
}
}
}
[project]
name = "websearch-mcp-server"
version = "0.1.0"
description = "search the web!"
requires-python = ">=3.12"
dependencies = [
"duckduckgo-search>=8.0.2",
"faiss-cpu>=1.10.0",
"fastmcp>=2.2.6",
]
from __future__ import annotations
from fastmcp import FastMCP
from pydantic import BaseModel
from agents import Agent, Runner, WebSearchTool
mcp_web = FastMCP(
"openai-websearch-server",
version="0.1.0",
)
websearch_agent = Agent(
name="Websearch Agent",
instructions="Search the web and provide a summary (with references) of the results based on the user's query.",
tools=[WebSearchTool()],
model="gpt-4.1-mini", # important: 4.1-mini is 10x cheaper than 4.1
)
class WebSearchArgs(BaseModel):
query: str
@mcp_web.tool()
async def search_web(args: WebSearchArgs) -> str:
"""Perform a web search using the query, and summarize the results."""
result = await Runner.run(
websearch_agent,
args.query,
)
return result.final_output
if __name__ == "__main__":
import argparse
import uvicorn
parser = argparse.ArgumentParser()
parser.add_argument("--stdio", action="store_true", help="Run on STDIO")
parser.add_argument("--port", type=int, default=8003, help="Port for SSE")
opts = parser.parse_args()
if opts.stdio:
mcp_web.run(transport="stdio")
else:
uvicorn.run(mcp_web.sse_app(), host="127.0.0.1", port=opts.port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment