Skip to main content
Glama
martoc

MCP Spark Documentation Server

by martoc

search_documentation

Search Apache Spark documentation using keyword queries with full-text search and optional section filters to find relevant topics.

Instructions

Search Apache Spark documentation by keyword query.

Args: query: Search terms to find in the documentation. Supports full-text search with stemming (e.g., "stream" matches "streaming", "streams"). section: Optional section to filter results. Common sections include: 'sql-ref', 'api', 'streaming', 'mllib', 'graphx', 'structured-streaming', etc. limit: Maximum number of results to return (default: 10, max: 50).

Returns: JSON-formatted search results with title, URL, snippet, and relevance score.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
sectionNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'search_documentation' - registered via @mcp.tool() decorator, delegates to _search_documentation_impl
    @mcp.tool()
    def search_documentation(
        query: str,
        section: str | None = None,
        limit: int = 10,
    ) -> str:
        """Search Apache Spark documentation by keyword query.
    
        Args:
            query: Search terms to find in the documentation. Supports
                   full-text search with stemming (e.g., "stream" matches
                   "streaming", "streams").
            section: Optional section to filter results. Common sections include:
                     'sql-ref', 'api', 'streaming', 'mllib', 'graphx',
                     'structured-streaming', etc.
            limit: Maximum number of results to return (default: 10, max: 50).
    
        Returns:
            JSON-formatted search results with title, URL, snippet, and relevance score.
        """
        return _search_documentation_impl(query, section, limit)
  • Core implementation of search_documentation - validates limit, calls db.search(), and formats JSON output
    def _search_documentation_impl(
        query: str,
        section: str | None = None,
        limit: int = 10,
    ) -> str:
        """Core implementation of search_documentation.
    
        Args:
            query: Search terms to find in the documentation.
            section: Optional section to filter results.
            limit: Maximum number of results to return.
    
        Returns:
            JSON-formatted search results.
        """
        db = get_database()
    
        # Validate and cap limit
        limit = min(max(1, limit), 50)
    
        results = db.search(query, section=section, limit=limit)
    
        if not results:
            return json.dumps(
                {
                    "message": f"No results found for query: '{query}'",
                    "results": [],
                }
            )
    
        output = {
            "query": query,
            "section_filter": section,
            "result_count": len(results),
            "results": [
                {
                    "title": r.title,
                    "url": r.url,
                    "path": r.path,
                    "section": r.section,
                    "snippet": r.snippet,
                    "relevance_score": round(r.score, 4),
                }
                for r in results
            ],
        }
    
        return json.dumps(output, indent=2)
  • Tool registration via FastMCP @mcp.tool() decorator on line 122
    @mcp.tool()
    def search_documentation(
        query: str,
        section: str | None = None,
        limit: int = 10,
    ) -> str:
        """Search Apache Spark documentation by keyword query.
  • Database search method using FTS5 full-text search with optional section filter and BM25 ranking
    def search(self, query: str, section: str | None = None, limit: int = 10) -> list[SearchResult]:
        """Search documents using FTS5.
    
        Args:
            query: Search query string.
            section: Optional section filter.
            limit: Maximum number of results.
    
        Returns:
            List of SearchResult instances ordered by relevance.
        """
        with self._get_connection() as conn:
            # Build query with optional section filter
            sql = """
                SELECT
                    d.path,
                    d.title,
                    d.url,
                    d.section,
                    snippet(documents_fts, 2, '<mark>', '</mark>', '...', 64) as snippet,
                    bm25(documents_fts, 5.0, 2.0, 1.0) as score
                FROM documents_fts
                JOIN documents d ON documents_fts.rowid = d.id
                WHERE documents_fts MATCH ?
            """
            params: list[str | int] = [query]
    
            if section:
                sql += " AND d.section = ?"
                params.append(section)
    
            sql += " ORDER BY score LIMIT ?"
            params.append(limit)
    
            cursor = conn.execute(sql, params)
            results = []
            for row in cursor.fetchall():
                results.append(
                    SearchResult(
                        path=row["path"],
                        title=row["title"],
                        url=row["url"],
                        section=row["section"],
                        snippet=row["snippet"],
                        score=abs(row["score"]),  # BM25 returns negative scores
                    )
                )
            return results
  • SearchResult dataclass model used to structure search results returned by search_documentation
    @dataclass
    class SearchResult:
        """Represents a search result."""
    
        path: str
        title: str
        url: str
        snippet: str
        score: float
        section: str
Behavior3/5

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

The description mentions stemming and default/max limit, which adds some behavioral context. However, with no annotations, it fails to disclose other traits like rate limits, authentication needs, or result ordering. It is adequate but not rich.

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?

The description is concise, using an Args/Returns structure that is easy to parse. Every sentence adds value with no redundancy.

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

Completeness4/5

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

The description covers parameters and return format adequately. Lacks examples or error handling details, but for a search tool with an output schema described, it is fairly complete.

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

Parameters4/5

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

With 0% schema description coverage, the description adds meaningful semantics: explains full-text search with stemming for query, lists common sections, and specifies limit default/max. This compensates well for the schema gap.

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 'Search Apache Spark documentation by keyword query', identifying the specific action (search) and resource (documentation). The sibling tool 'read_documentation' implies a distinct purpose, helping the agent differentiate.

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

Usage Guidelines3/5

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

The description explains parameters but does not explicitly state when to use this tool versus the sibling 'read_documentation'. Usage context is implied (search vs read) but not spelled out.

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/martoc/mcp-spark-documentation'

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