Skip to main content
Glama

search_policies

Search cached ASF policy documents for a query and retrieve ranked excerpts with surrounding context.

Instructions

Search across cached ASF policy documents for a query term or phrase.

Returns ranked excerpts with surrounding context. Only searches policies already in the local cache — run refresh_cache first to ensure all policies are available.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
max_resultsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The search_policies function is the handler for the tool. It searches cached ASF policy documents for a query term, ranks excerpts by relevance score, deduplicates nearby lines, and returns formatted results.
    @mcp.tool()
    def search_policies(query: str, max_results: int = 10) -> str:
        """Search across cached ASF policy documents for a query term or phrase.
    
        Returns ranked excerpts with surrounding context.
        Only searches policies already in the local cache — run refresh_cache first
        to ensure all policies are available.
        """
        if not query.strip():
            return "Please provide a search query."
    
        cache = fetcher.load_cache()
        query_words = set(query.lower().split())
        results: list[dict[str, Any]] = []
        skipped: list[str] = []
    
        for key in POLICY_SOURCES:
            entry = cache.get(key, {})
            text = str(entry.get("text", ""))
            if not text or text.startswith("[Error"):
                skipped.append(key)
                continue
            lines = text.split("\n")
            for i, line in enumerate(lines):
                score = sum(1 for w in query_words if w in line.lower())
                if score:
                    start = max(0, i - 2)
                    end = min(len(lines), i + 3)
                    results.append({
                        "key": key,
                        "title": POLICY_SOURCES[key]["title"],
                        "url": POLICY_SOURCES[key]["url"],
                        "score": score,
                        "excerpt": "\n".join(lines[start:end]).strip(),
                        "line": i,
                    })
    
        results.sort(key=lambda r: -r["score"])
    
        seen: dict[str, list[int]] = {}
        deduped: list[dict[str, Any]] = []
        for r in results:
            prior = seen.get(r["key"], [])
            if not any(abs(r["line"] - p) < 5 for p in prior):
                deduped.append(r)
                seen.setdefault(r["key"], []).append(r["line"])
            if len(deduped) >= max_results:
                break
    
        if not deduped:
            msg = f"No results found for **{query!r}**."
            if skipped:
                msg += f"\n\n_{len(skipped)} policies not yet cached were skipped. Run `refresh_cache` to fetch them._"
            return msg
    
        out = [f"# Search Results for '{query}'\n"]
        for r in deduped:
            out.append(f"## [{r['title']}]({r['url']})  (`{r['key']}`)\n")
            out.append("```")
            out.append(r["excerpt"])
            out.append("```\n")
        if skipped:
            out.append(f"_Note: {len(skipped)} uncached policies were not searched. Run `refresh_cache` to include them._")
        return "\n".join(out)
  • The @mcp.tool() decorator on line 62 registers search_policies as a FastMCP tool on the 'asf-policy' MCP server (mcp defined on line 14). No separate registration file exists; the decorator is the registration mechanism.
    @mcp.tool()
  • The schema is defined by the function signature: `query: str` (required) and `max_results: int = 10` (optional, default 10). The return type is `str`. FastMCP infers the JSON schema from these type annotations.
    @mcp.tool()
Behavior3/5

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

No annotations provided, so description carries full burden. Describes return format (ranked excerpts with context) and cache dependency. Does not disclose read-only nature or other behavioral details like rate limits or error conditions.

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

Conciseness5/5

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

Three sentences, each adding value: first states purpose, second specifies return format, third gives prerequisite. No filler. Information is front-loaded and efficient.

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

Completeness3/5

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

Output schema exists, so return details are covered. Description gives a high-level sense of output (ranked excerpts). However, missing parameter details and lack of behavioral nuance about caching status make it slightly less complete than ideal for a search tool.

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

Parameters2/5

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

Schema coverage is 0%, meaning no descriptions in schema. Description only mentions 'query term or phrase' for the query parameter, but does not explain the max_results parameter or provide any additional semantics beyond the parameter names.

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?

Description clearly states verb 'search' and resource 'cached ASF policy documents', distinguishing it from siblings get_policy (retrieve specific), list_policies (list all), and refresh_cache (update). It specifies ranking and excerpts.

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

Usage Guidelines4/5

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

Explicitly states prerequisite 'run refresh_cache first', advising when the tool is usable. Does not explicitly state when not to use or directly contrast with siblings, but the context is clear enough.

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/justinmclean/PolicyMCP'

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