Skip to main content
Glama
RestDB

Codehooks.io MCP Server

by RestDB

query_collection

Query collections using URL-style, regex, or MongoDB JSON queries. Supports filtering, pagination, sorting, and bulk operations like update or delete.

Instructions

Query data from a collection. Supports URL-style, regex, and MongoDB-style JSON queries with comparison operators. Can also query system collections like '_hooks' which contains deployment metadata including available API endpoints. Using delete, update or replace is very powerful but also dangerous, so use with caution.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name. Use '_hooks' to query deployment metadata and discover available API endpoints.
queryNoQuery expression. Supports multiple formats: URL-style ('name=Polly&type=Parrot'), regex ('name=/^po/'), or MongoDB-style JSON ('{"name": "Polly", "age": {"$gt": 5}}' for complex queries with operators like $gt, $lt, $gte, $lte, $ne, $in, $nin, $exists, $regex). To get the latest deployment info with API endpoints, use: collection='_hooks', limit=1, reverse=true (check the routehooks property for the available API endpoints)
countNoCount query results
deleteNoDelete all items from query result
updateNoPatch all items from query result with JSON string '{...}'
replaceNoReplace all items from query result with JSON string '{...}'
useindexNoUse an indexed field to scan data in query
startNoStart value for index scan
endNoEnd value for index scan
limitNoLimit query result. Use limit=1 and reverse to get latest deployment from _hooks collection
fieldsNoComma separated list of fields to include
sortNoComma separated list of fields to sort by. Use '_id' to sort by creation time
offsetNoSkip items before returning data in query result
enqueueNoAdd query result to queue topic
reverseNoScan index in reverse order. Use with sort='_id' to get newest records first
csvNoOutput data in CSV format
jsonlNoOutput data in JSONL format

Implementation Reference

  • Zod schema definition for query_collection tool inputs. Defines all parameters: collection (required), query, count, delete, update, replace, useindex, start, end, limit, fields, sort, offset, enqueue, reverse, csv, jsonl.
    const queryCollectionSchema = z.object({
        collection: z.string(),
        query: z.string().optional(),
        count: z.boolean().optional(),
        delete: z.boolean().optional(),
        update: z.string().optional(),
        replace: z.string().optional(),
        useindex: z.string().optional(),
        start: z.string().optional(),
        end: z.string().optional(),
        limit: z.number().optional(),
        fields: z.string().optional(),
        sort: z.string().optional(),
        offset: z.number().optional(),
        enqueue: z.string().optional(),
        reverse: z.boolean().optional(),
        csv: z.boolean().optional(),
        jsonl: z.boolean().optional()
    });
  • src/index.ts:208-235 (registration)
    Tool registration entry for query_collection. Defines the tool name, description, and inputSchema for the ListTools response.
    {
        name: "query_collection",
        description: "Query data from a collection. Supports URL-style, regex, and MongoDB-style JSON queries with comparison operators. Can also query system collections like '_hooks' which contains deployment metadata including available API endpoints. Using delete, update or replace is very powerful but also dangerous, so use with caution.",
        schema: queryCollectionSchema,
        inputSchema: {
            type: "object",
            properties: {
                collection: { type: "string", description: "Collection name. Use '_hooks' to query deployment metadata and discover available API endpoints." },
                query: { type: "string", description: "Query expression. Supports multiple formats: URL-style ('name=Polly&type=Parrot'), regex ('name=/^po/'), or MongoDB-style JSON ('{\"name\": \"Polly\", \"age\": {\"$gt\": 5}}' for complex queries with operators like $gt, $lt, $gte, $lte, $ne, $in, $nin, $exists, $regex). To get the latest deployment info with API endpoints, use: collection='_hooks', limit=1, reverse=true (check the routehooks property for the available API endpoints)" },
                count: { type: "boolean", description: "Count query results" },
                delete: { type: "boolean", description: "Delete all items from query result" },
                update: { type: "string", description: "Patch all items from query result with JSON string '{...}'" },
                replace: { type: "string", description: "Replace all items from query result with JSON string '{...}'" },
                useindex: { type: "string", description: "Use an indexed field to scan data in query" },
                start: { type: "string", description: "Start value for index scan" },
                end: { type: "string", description: "End value for index scan" },
                limit: { type: "number", description: "Limit query result. Use limit=1 and reverse to get latest deployment from _hooks collection" },
                fields: { type: "string", description: "Comma separated list of fields to include" },
                sort: { type: "string", description: "Comma separated list of fields to sort by. Use '_id' to sort by creation time" },
                offset: { type: "number", description: "Skip items before returning data in query result" },
                enqueue: { type: "string", description: "Add query result to queue topic" },
                reverse: { type: "boolean", description: "Scan index in reverse order. Use with sort='_id' to get newest records first" },
                csv: { type: "boolean", description: "Output data in CSV format" },
                jsonl: { type: "boolean", description: "Output data in JSONL format" }
            },
            required: ["collection"]
        }
    },
  • Handler implementation for query_collection tool. Parses arguments, builds CLI arguments for the 'coho query' command, executes it via executeCohoCommand(), and returns the result as formatted JSON (or raw CSV/JSONL).
    case "query_collection": {
        const {
            collection,
            query = "",
            count = false,
            delete: shouldDelete = false,
            update,
            replace,
            useindex,
            start,
            end,
            limit = count ? undefined : 100,
            fields,
            sort,
            offset,
            enqueue,
            reverse = false,
            csv = false,
            jsonl = false
        } = args as QueryCollectionArgs;
    
        console.error(`Querying collection: ${collection}`);
    
        const queryArgs = [
            'query',
            '--collection', collection,
            '--project', config.projectId,
            '--space', config.space
        ];
    
        if (query) queryArgs.push('--query', query);
        if (count) queryArgs.push('--count');
        if (shouldDelete) queryArgs.push('--delete');
        if (update) queryArgs.push('--update', update);
        if (replace) queryArgs.push('--replace', replace);
        if (useindex) queryArgs.push('--useindex', useindex);
        if (start) queryArgs.push('--start', start);
        if (end) queryArgs.push('--end', end);
        if (limit) queryArgs.push('--limit', limit.toString());
        if (fields) queryArgs.push('--fields', fields);
        if (sort) queryArgs.push('--sort', sort);
        if (offset) queryArgs.push('--offset', offset.toString());
        if (enqueue) queryArgs.push('--enqueue', enqueue);
        if (reverse) queryArgs.push('--reverse');
        if (csv) queryArgs.push('--csv');
        if (jsonl) queryArgs.push('--jsonl');
    
        const result = await executeCohoCommand(queryArgs);
    
        // If the output is CSV or JSONL format, return as is
        if (csv || jsonl) {
            return {
                content: [
                    {
                        type: "text",
                        text: result
                    }
                ],
                isError: false
            };
        }
    
        // Otherwise parse and format as JSON
        return {
            content: [
                {
                    type: "text",
                    text: JSON.stringify(JSON.parse(result), null, 2)
                }
            ],
            isError: false
        };
    }
Behavior3/5

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

With no annotations, the description carries full burden. It warns about dangerous operations (delete, update, replace) and explains query formats with examples. However, it omits details on error handling, side effects of non-destructive operations, or rate limits.

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

Conciseness4/5

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

The description is concise with a clear front-loaded purpose. The warning about destructive ops is useful. It could be slightly more structured (e.g., separate sentences for distinct points), but overall 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?

Given the tool's complexity (17 params, destructive actions, system collections), the description covers query formats, one use case (_hooks), and a warning. It lacks mention of pagination, error states, or full capability overview, but schema descriptions fill some gaps.

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 baseline is 3. The main description adds minimal parameter semantics beyond the schema (e.g., hints on using limit/reverse for latest data). Most parameter details are already in the schema.

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 it 'Query data from a collection' and lists supported query formats (URL-style, regex, MongoDB-style JSON). This distinctively identifies the tool's function against siblings like 'create_collection' or 'drop_collection'.

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?

The description lacks explicit guidance on when to use this tool vs alternatives. It only hints at querying system collections for deployment metadata but does not compare with other tools like 'docs' or provide scenarios for exclusion.

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/RestDB/codehooks-mcp-server'

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