Skip to main content
Glama
jimpick

MCP JSON Document Collection Server

by jimpick

query_json_docs_from_db

Query JSON documents from a database and sort them by a specified field to organize and retrieve structured data efficiently.

Instructions

Query JSON documents sorted by a field from a document database. If no sortField is provided, use the _id field.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNameYes
sortFieldYes

Implementation Reference

  • Handler function for the 'query_json_docs_from_db' tool. Parses input arguments using the schema, retrieves or initializes the Fireproof database, queries documents sorted by the specified field in descending order, and returns the JSON documents as a text response.
    case "query_json_docs_from_db": {
      const parsed = QueryJsonDocsFromDbArgsSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(`Invalid arguments for query_json_docs_from_db: ${parsed.error}`);
      }
    
      const dbName = parsed.data.databaseName;
      if (!dbs[dbName]) {
        const newDb = fireproof(dbName);
        dbs[dbName] = { db: newDb };
      }
      const db = dbs[dbName].db;
    
      const results = await db.query(parsed.data.sortField, {
        includeDocs: true,
        descending: true,
      });
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(results.rows.map((row) => row.doc)),
          },
        ],
      };
    }
  • Zod schema defining the input arguments for the 'query_json_docs_from_db' tool: databaseName (string) and sortField (string). Used for validation in the handler and converted to JSON schema for tool registration.
    const QueryJsonDocsFromDbArgsSchema = z.object({
      databaseName: z.string(),
      sortField: z.string(),
    });
  • src/index.ts:146-152 (registration)
    Tool registration in the ListTools response, specifying name, description, input schema (derived from Zod schema), and required fields.
    {
      name: "query_json_docs_from_db",
      description: "Query JSON documents sorted by a field from a document database. " +
        "If no sortField is provided, use the _id field.",
      inputSchema: zodToJsonSchema(QueryJsonDocsFromDbArgsSchema) as ToolInput,
      required: ["sortField"],
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes the sorting behavior and default, but lacks critical details: whether this is a read-only operation, if it requires specific permissions, what the output format looks like (e.g., list of documents, pagination), error conditions, or performance implications. For a query tool with zero annotation coverage, this leaves significant gaps.

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 extremely concise—two sentences with zero waste. It front-loads the core purpose and follows with a specific behavioral detail about sorting. Every word earns its place, making it easy to parse quickly.

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

Completeness2/5

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

Given the complexity (query operation with 2 parameters, no annotations, no output schema), the description is incomplete. It covers sorting but omits essential context: output format, error handling, permissions, query capabilities beyond sorting (e.g., filtering), and how it differs from siblings. For a tool that interacts with a database, this leaves too many unknowns for effective use.

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 0%, so the description must compensate. It adds meaning for 'sortField' by explaining the default behavior when not provided (use '_id'), which clarifies its optional nature despite being marked as required in the schema—this is valuable. However, it doesn't explain 'databaseName' (e.g., what databases are available, format constraints) or other aspects like query filters or limits, leaving parameters partially documented.

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?

The description clearly states the tool's purpose: querying JSON documents sorted by a field from a document database. It specifies the verb ('query'), resource ('JSON documents'), and sorting behavior. However, it doesn't explicitly differentiate from sibling tools like 'load_json_doc_from_db' (which might retrieve a single document) or 'list_json_doc_databases' (which lists databases rather than documents).

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 provides no guidance on when to use this tool versus alternatives. It mentions default sorting behavior if 'sortField' is not provided, but this is a parameter detail rather than usage context. There's no indication of prerequisites (e.g., database must exist), limitations, or comparisons to sibling tools like 'load_json_doc_from_db' for single-document retrieval.

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/jimpick/mcp-json-db-collection-server'

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