Skip to main content
Glama
andyfe76

CouchDB MCP Server

by andyfe76

couchdb_search_documents

Search CouchDB database documents using Mango queries to find specific records. Create indexes to improve search performance for faster document retrieval.

Instructions

Search for documents in a database using a Mango query. Works without indexes but creating indexes (via couchdb_create_index) improves performance significantly.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesName of the database
queryYesMango query selector (e.g., {'name': 'John'} for exact match, {'age': {'$gt': 18}} for comparisons)
limitNoMaximum number of documents to return (default: 25)
skipNoNumber of documents to skip (default: 0)

Implementation Reference

  • Main handler implementation for couchdb_search_documents that executes Mango queries using db.find() method with selector, limit, and skip parameters
    async def _search_documents(self, database: str, query: dict, limit: int, skip: int) -> list[TextContent]:
        """Search documents using Mango query."""
        try:
            db = self._get_server()[database]
    
            # Build Mango query using the find() method
            mango_query = {
                "selector": query,
                "limit": limit,
                "skip": skip
            }
    
            # Use the db.find() method (available in CouchDB >= 2.0)
            docs = list(db.find(mango_query))
    
            response = {
                "docs": docs,
                "count": len(docs)
            }
    
            # If no results, provide helpful suggestion
            if len(docs) == 0:
                response["note"] = "No documents matched the query. To verify documents exist, use couchdb_list_documents with include_docs=true"
    
            return [TextContent(type="text", text=json.dumps(response, indent=2))]
        except KeyError:
            return [TextContent(type="text", text=f"Database '{database}' not found")]
        except AttributeError:
            # Fallback to REST API if find() method not available
            return await self._search_documents_fallback(database, query, limit, skip)
        except Exception as e:
            return [TextContent(type="text", text=f"Error searching documents: {str(e)}")]
  • Fallback handler that uses raw REST API (_find endpoint) when db.find() method is not available
    async def _search_documents_fallback(self, database: str, query: dict, limit: int, skip: int) -> list[TextContent]:
        """Fallback search using raw REST API."""
        try:
            db = self._get_server()[database]
    
            mango_query = {
                "selector": query,
                "limit": limit,
                "skip": skip
            }
    
            # Make a request to the _find endpoint
            result = db.resource.post_json('_find', body=mango_query)
    
            docs = result[1].get("docs", [])
            warning = result[1].get("warning", None)
    
            response = {
                "docs": docs,
                "count": len(docs)
            }
    
            if warning:
                response["warning"] = warning
    
            if len(docs) == 0:
                response["note"] = "No documents matched the query. To verify documents exist, use couchdb_list_documents with include_docs=true"
    
            return [TextContent(type="text", text=json.dumps(response, indent=2))]
        except Exception as e:
            return [TextContent(type="text", text=f"Error in fallback search: {str(e)}")]
  • Tool schema definition that defines input parameters (database, query, limit, skip) and their types for couchdb_search_documents
    Tool(
        name="couchdb_search_documents",
        description="Search for documents in a database using a Mango query. Works without indexes but creating indexes (via couchdb_create_index) improves performance significantly.",
        inputSchema={
            "type": "object",
            "properties": {
                "database": {
                    "type": "string",
                    "description": "Name of the database",
                },
                "query": {
                    "type": "object",
                    "description": "Mango query selector (e.g., {'name': 'John'} for exact match, {'age': {'$gt': 18}} for comparisons)",
                },
                "limit": {
                    "type": "integer",
                    "description": "Maximum number of documents to return (default: 25)",
                },
                "skip": {
                    "type": "integer",
                    "description": "Number of documents to skip (default: 0)",
                },
            },
            "required": ["database", "query"],
        },
    ),
  • Registration of the tool handler that routes couchdb_search_documents calls to the _search_documents method with argument extraction
    elif name == "couchdb_search_documents":
        return await self._search_documents(
            arguments["database"],
            arguments["query"],
            arguments.get("limit", 25),
            arguments.get("skip", 0)
        )
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses that the tool 'works without indexes' but performance improves with indexing, which is valuable behavioral context. However, it doesn't mention other important traits like read/write nature (implied read-only but not stated), potential rate limits, error conditions, or what happens with large result sets beyond the limit parameter.

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?

Two concise sentences that are front-loaded with the core purpose. The first sentence states exactly what the tool does, and the second provides important performance context. Every sentence earns its place with no wasted words.

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?

For a search tool with 4 parameters, 100% schema coverage, but no annotations and no output schema, the description is adequate but has gaps. It covers the basic purpose and performance considerations but doesn't address what the tool returns (no output schema) or other behavioral aspects. Given the complexity, it should ideally mention more about the return format or error handling.

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 description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema - it mentions Mango queries but doesn't provide additional semantic context about parameters. The baseline of 3 is appropriate when the schema does the heavy lifting.

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 specific action ('Search for documents') and resource ('in a database'), using the precise method ('using a Mango query'). It distinguishes from siblings like couchdb_list_documents (which likely lists all documents without querying) and couchdb_get_document (which retrieves a single document by ID).

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?

The description provides clear context about when to use this tool (for searching with Mango queries) and mentions performance considerations (indexing via couchdb_create_index). However, it doesn't explicitly state when NOT to use it or directly compare it to alternatives like couchdb_list_documents for simpler listing needs.

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/andyfe76/couchdb_mcp'

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