Skip to main content
Glama

text_web_search

Search the web by submitting a text query. Customize region, result count, and pages to fetch.

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.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'text_web_search' handler function that performs a text web search using DDGS (DuckDuckGo Search). It accepts query, region, max_results, and pages parameters, and returns a list of search result dictionaries.
    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(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
  • The input schema for the text_web_search tool, defined via type annotations and Pydantic Field descriptors: 'query' (str, required), 'region' (str | None, default 'uk-en'), 'max_results' (int | None, default 10, ge=1, le=100), and 'pages' (int | None, default 1, ge=1, le=10).
    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]]:
  • Tool registration metadata entry for 'text_web_search' in the PyMCP.tools list, with tags 'meta-search', 'text-search', and 'searchexample'. This entry is used by MCPMixin.register_features() to register the tool with FastMCP.
    {
        "fn": "text_web_search",
        "tags": ["meta-search", "text-search", "searchexample"],
    },
  • The register_features loop that iterates over self.tools, looks up the method by fn name (e.g., 'text_web_search') via getattr, and registers it as an MCP tool using mcp.tool().
    for tool in self.tools:
        assert "fn" in tool, "Tool metadata must include the 'fn' key."
        tool_copy = copy.deepcopy(tool)
        fn_name = tool_copy.pop("fn")
        fn = getattr(self, fn_name)
        mcp.tool(**tool_copy)(fn)  # pass remaining metadata as kwargs
  • The tool 'text_web_search' is excluded from response caching because it produces non-deterministic results (line 436-438).
    # Only deterministic tools are included in caching.
    # Tools like 'generate_password', 'text_web_search', 'pirate_summary', and 'vonmises_random' are excluded
    # because they produce non-deterministic or time-sensitive results, and caching their
    # outputs could lead to stale or incorrect responses.
    call_tool_settings=CallToolSettings(
        included_tools=["greet", "permutations"],
        ttl=EnvVars.RESPONSE_CACHE_TTL,
        enabled=EnvVars.RESPONSE_CACHE_TTL > 0,
    ),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states it performs a search. No mention of rate limits, result nature, or any side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise (one sentence) but risks under-specification. It could be more structured without adding excessive length.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the existence of an output schema, the description does not need to detail return values, but it still lacks any mention of output or limitations. Incomplete for behavioral context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. The description adds no additional meaning beyond the schema's parameter descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (perform a text web search) and the resource/query. It distinguishes from sibling tools, which are unrelated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives, or any context-specific usage hints. It lacks any when-not-to-use guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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