Skip to main content
Glama

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
NameRequiredDescriptionDefault
queryYesThe search query to fetch results for. It should be a non-empty string.
regionNoOptional region to search in.uk-en
max_resultsNoThe maximum number of results to return. Default is 10, maximum is 100.
pagesNoThe number of pages to fetch. Default is 1, maximum is 10.

Implementation Reference

  • 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
  • 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"],
    },
  • 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]]:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/anirbanbasu/pymcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server