web_search
Perform web searches directly from the MCP Server to retrieve accurate information for LLM interactions in the continue.dev environment. Ideal for enhancing context-aware responses.
Instructions
Search the web for information
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Input Schema (JSON Schema)
{
"properties": {
"query": {
"title": "Query",
"type": "string"
}
},
"required": [
"query"
],
"title": "web_searchArguments",
"type": "object"
}
Implementation Reference
- src/mcps/server.py:67-92 (handler)The web_search tool handler, decorated with @self.mcp.tool(name="web_search"), which implements the tool logic by calling perplexity_search.do_search(query, self.config).@self.mcp.tool(name="web_search", description="Search the web for information") async def web_search(query: str) -> str: """ Performs a web search using the provided query. Find the most relevant pages and return summary result. Args: query: The search query. Returns: The summary of the most relevant search results. """ try: session: ServerSession = self.mcp.get_context().session if session.check_client_capability(ClientCapabilities(roots=RootsCapability())) : result = await session.list_roots() logger.info(f"Result: {result}") for root in result.roots: logger.info(f"Root: {root.name} , location: {root.uri}") else: logger.info("Client does not support roots capability") # Try to get the roots from the environment variable ROOT root_value = os.getenv("ROOT") logger.info(f"ROOT environment variable: {root_value}") except Exception as e: logger.error(f"Error listing roots: {e}") return await perplexity_search.do_search(query, self.config)
- The do_search helper function that performs the actual web search using Perplexity.ai API, including web_search_options in the payload.async def do_search(query: str, config: ServerConfig) -> str: """ Performs a search and returns the results. Args: query: The search query. Returns: The search query string back. """ url = "https://api.perplexity.ai/chat/completions" headers = { "Authorization": f"Bearer {config.perplexity_api_key}", "Content-Type": "application/json" } payload = { "model": "sonar", "messages": [ {"role": "system", "content": "Be precise and concise."}, {"role": "user", "content": query} ], "max_tokens": 1000, "temperature": 0.01, "top_p": 0.9, "return_related_questions": False, "web_search_options": { "search_context_size": "medium" } } async with httpx.AsyncClient() as client: response = await client.post(url, json=payload, headers=headers) response.raise_for_status() return format_response_with_citations(response.json())
- The format_response_with_citations helper function used by do_search to format the API response with citations.def format_response_with_citations(response: dict) -> str: """ Formats the response from Perplexity.ai to include citations as a markdown list. Args: response: The JSON response from Perplexity.ai. Returns: A formatted string with the content and citations. """ content = response.get("choices", [{}])[0].get("message", {}).get("content", "No content available") citations = response.get("citations", []) if citations: citations_md = "\n".join([f"- {url}" for url in citations]) return f"{content}\n\n### Citations\n{citations_md}" return content
- src/mcps/server.py:67-67 (registration)The @self.mcp.tool decorator registers the web_search tool.@self.mcp.tool(name="web_search", description="Search the web for information")