text_web_search
Search the web for information using text queries to retrieve relevant results from the internet.
Instructions
Perform a text web search using the provided query using DDGS.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query to fetch results for. It should be a non-empty string. | |
| region | No | Optional region to search in. | uk-en |
| max_results | No | The maximum number of results to return. Default is 10, maximum is 100. | |
| pages | No | The number of pages to fetch. Default is 1, maximum is 10. |
Implementation Reference
- src/pymcp/server.py:176-217 (handler)The main handler function for the 'text_web_search' tool, which performs a web search using the DDGS library based on the provided query, region, max_results, and pages parameters. It logs the search and returns the list of results.async def text_web_search( self, ctx: Context, query: Annotated[ str, Field( ..., description="The search query to fetch results for. It should be a non-empty string.", ), ], region: Annotated[ str | None, Field(default="uk-en", description="Optional region to search in."), ] = "uk-en", max_results: Annotated[ int | None, Field( default=10, ge=1, le=100, description="The maximum number of results to return. Default is 10, maximum is 100.", ), ] = 10, pages: Annotated[ int | None, Field( default=1, ge=1, le=10, description="The number of pages to fetch. Default is 1, maximum is 10.", ), ] = 1, ) -> list[dict[str, Any]]: """Perform a text web search using the provided query using DDGS.""" await ctx.info(f"Performing text web search for query: {query}") results = DDGS().text( # ty: ignore[unresolved-attribute] query=query, region=region, max_results=max_results, page=pages ) if results: await ctx.info(f"Found {len(results)} results for the query.") return results
- src/pymcp/server.py:62-65 (registration)Registration of the 'text_web_search' tool in the PyMCP class's tools list, including its function name and tags.{ "fn": "text_web_search", "tags": ["meta-search", "text-search", "searchexample"], },
- src/pymcp/server.py:176-208 (schema)Input schema defined via Pydantic Annotated types and Field descriptions for the tool parameters: query (required str), region (optional str, default 'uk-en'), max_results (optional int, 1-100, default 10), pages (optional int, 1-10, default 1). Output is list[dict[str, Any]].async def text_web_search( self, ctx: Context, query: Annotated[ str, Field( ..., description="The search query to fetch results for. It should be a non-empty string.", ), ], region: Annotated[ str | None, Field(default="uk-en", description="Optional region to search in."), ] = "uk-en", max_results: Annotated[ int | None, Field( default=10, ge=1, le=100, description="The maximum number of results to return. Default is 10, maximum is 100.", ), ] = 10, pages: Annotated[ int | None, Field( default=1, ge=1, le=10, description="The number of pages to fetch. Default is 1, maximum is 10.", ), ] = 1, ) -> list[dict[str, Any]]: