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, stemming, and optional section filters to find relevant results quickly.

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

  • Core implementation of the search_documentation tool. Calls DocumentDatabase.search() with the query, optional section filter, and limit, then formats results as JSON. This is the actual business logic invoked by the tool handler.
    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)
  • Registration of the search_documentation tool via the @mcp.tool() decorator. The function is the public-facing MCP tool entry point that 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)
  • The DocumentDatabase.search() method performs the actual FTS5 full-text search using SQLite. Accepts a query, optional section filter, and limit. Returns SearchResult objects with BM25 relevance scoring.
    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
    
    def get_document(self, path: str) -> Document | None:
        """Retrieve a document by path.
    
        Args:
            path: Relative path to the document.
    
        Returns:
            Document instance or None if not found.
        """
        with self._get_connection() as conn:
            cursor = conn.execute(
                "SELECT * FROM documents WHERE path = ?",
                (path,),
            )
            row = cursor.fetchone()
            if row:
                return Document(
                    path=row["path"],
                    title=row["title"],
                    description=row["description"],
                    section=row["section"],
                    content=row["content"],
                    url=row["url"],
                )
            return None
    
    def clear(self) -> None:
        """Clear all documents from the database."""
        with self._get_connection() as conn:
            conn.execute("DELETE FROM documents")
            conn.commit()
    
    def get_document_count(self) -> int:
        """Return the total number of indexed documents.
    
        Returns:
            Count of documents in the database.
        """
        with self._get_connection() as conn:
            cursor = conn.execute("SELECT COUNT(*) FROM documents")
            result = cursor.fetchone()
            return int(result[0]) if result else 0
  • SearchResult dataclass used as the return type from the database search, containing path, title, url, snippet, score, and section fields.
    @dataclass
    class SearchResult:
        """Represents a search result."""
    
        path: str
        title: str
        url: str
        snippet: str
        score: float
        section: str
Behavior4/5

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

Describes search behavior (full-text, stemming), default and max limit, and return format. No annotations provided, so description carries full burden; insufficient on auth or pagination but adequate for functional use.

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?

Well-structured with clear sections (description, args, returns). Every sentence adds value; no fluff.

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?

Covers all 3 parameters and output format. Sibling tool mentioned but without differentiation. Slight gap in not explaining when to choose over read_documentation.

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

Parameters5/5

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

Adds significant meaning beyond schema: query describes stemming support, section lists common values, limit specifies default and max. Schema coverage is 0%, so description fully compensates.

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

Purpose4/5

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

Clearly states it searches Apache Spark documentation by keyword. Implicitly differentiates from sibling 'read_documentation' which likely retrieves a specific page, but no explicit distinction.

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?

No explicit when or when-not to use. Context implies usage for searching vs reading, but lacks guidance on alternatives or exclusion criteria.

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