Skip to main content
Glama

kb_query

Read-onlyIdempotent

Read knowledge-base entities with exact filters or ask typed fact questions to find IDs, tags, source files, predicates, subject properties, and requirement catalogs.

Instructions

Read entities from the KB with exact filters, or ask typed fact questions. Use for lookup by id, type, tags or sourceFile, and for precise questions about modeled facts: predicate facts by name with named arguments (predicate + where), property facts of a subject (subjectKey + propertyKey), the domain view of a subject (factKind 'subject' + subjectKey: its definition, broader and narrower subjects, every current requirement about it and the claims and scenarios on it), or the catalog of facts of one kind (factKind; 'predicate_schema' lists the predicates you can ask about with their argument names and constants). Typed answers return matching fact rows plus factQuery: the schema used, distinct counts, values that do exist when nothing matched, warnings about the question and the next call to make. Read-only. Tags filter by metadata tags only, not entity IDs.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "kb_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
idNoOptional exact entity ID. Example: 'REQ-cli-gc'. If omitted, returns matching entities by other filters.
kbNoOptional KB dependency name from .kb/dependencies.json to read, at its pinned commit, instead of this project's KB.
argsNoPositional argument values for a predicate with no schema; null matches any. Prefer where.
tagsNoOptional tag filter. Matches entities that contain any provided tag. Example: ['security','billing'].
typeNoOptional entity type filter. Allowed: req, scenario, test, adr, flag, event, symbol, fact. Example: 'req'.
limitNoOptional max rows to return after filtering. Default: 100 when omitted. Example: 25.
scopeNoOptional: 'current_requirements' keeps only facts a current (not superseded or retired) requirement requires.
whereNoNamed argument values for predicate, using the names from its schema.
offsetNoOptional zero-based pagination offset. Default: 0. Example: 50 to skip first 50 rows.
distinctNoOptional argument name whose distinct values to count across the matching predicate facts.
factKindNoTyped fact filter: list facts of one kind; 'predicate_schema' returns the catalog of askable predicates.
polarityNoOptional polarity filter for predicate facts. Default: both.
namespaceNoOptional predicate namespace when the same name exists in several. Default: any namespace.
predicateNoTyped fact filter: predicate name to ask about; returns its stored facts with arguments, polarity and effect.
sourceFileNoOptional source-file substring filter. Example: 'src/auth/login.ts'. Uses KB source linkage, not file-system scanning.
subjectKeyNoTyped fact filter: dotted subject key whose property facts to list; combine with propertyKey or factKind 'subject'.
includeBodyNoWith id only: also return the entity's authored Markdown body. Default: false.
propertyKeyNoOptional property key under subjectKey, e.g. 'max_roles'. Returns operator, value and unit of each fact.
workspaceRootNoOptional absolute path of the workspace this call is about, such as your git worktree, when it is not the server's.

Output Schema

NameRequiredDescriptionDefault
dataYes
errorNo
statusYes
effectsYes
operationYes
diagnosticsYes
nextActionsYes
kibiProtocolYes
resultVersionYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed30 schema fields changedv0.1.10
    • changedInput schema / properties / args / description
      Previous value: -"Positional argument values for predicate when it has no schema; null matches any value. Example: ['admin', null, null, 'allow']. Prefer where."New value: +"Positional argument values for a predicate with no schema; null matches any. Prefer where."
    • changedInput schema / properties / distinct / description
      Previous value: -"Optional argument name to count distinct values of across the matching predicate facts, e.g. distinct: 'role' with predicate 'has_role' and where {user: 'alice'} answers how many roles alice has."New value: +"Optional argument name whose distinct values to count across the matching predicate facts."
    • removedInput schema / properties / factKind / anyOf
      Removed value: -[
      -  {
      -    "const": "subject",
      -    "type": "string"
      -  },
      -  {
      -    "const": "property_value",
      -    "type": "string"
      -  },
      -  {
      -    "const": "predicate",
      -    "type": "string"
      -  },
      -  {
      -    "const": "predicate_schema",
      -    "type": "string"
      -  },
      -  {
      -    "const": "observation",
      -    "type": "string"
      -  },
      -  {
      -    "const": "meta",
      -    "type": "string"
      -  },
      -  {
      -    "const": "rule",
      -    "type": "string"
      -  },
      -  {
      -    "const": "rule_schema",
      -    "type": "string"
      -  }
      -]
    • changedInput schema / properties / factKind / description
      Previous value: -"Typed fact filter: list facts of one kind with their typed fields. 'predicate_schema' returns the catalog of askable predicates (argument names, constants, fact counts). Example: 'predicate_schema'."New value: +"Typed fact filter: list facts of one kind; 'predicate_schema' returns the catalog of askable predicates."
    • addedInput schema / properties / factKind / enum
      Added value: +[
      +  "subject",
      +  "property_value",
      +  "predicate",
      +  "predicate_schema",
      +  "observation",
      +  "meta",
      +  "rule",
      +  "rule_schema"
      +]
    • addedInput schema / properties / factKind / type
      Added value: +"string"
    • changedInput schema / properties / includeBody / description
      Previous value: -"With id only: also return the entity's authored Markdown body (the prose after its front matter) as body {id, path, text}, so a stale statement in it can be corrected; kb_upsert document.body replaces it. Default: false."New value: +"With id only: also return the entity's authored Markdown body. Default: false."
    • changedInput schema / properties / kb / description
      Previous value: -"Optional KB dependency to read instead of this project's own KB: a name declared in .kb/dependencies.json and pinned in .kb/dependencies.lock.json. The answer comes from that repository's own read-only KB at the pinned commit, kept apart from this project's KB. Omit it to read this project's KB."New value: +"Optional KB dependency name from .kb/dependencies.json to read, at its pinned commit, instead of this project's KB."
    • removedInput schema / properties / polarity / anyOf
      Removed value: -[
      -  {
      -    "const": "assert",
      -    "type": "string"
      -  },
      -  {
      -    "const": "deny",
      -    "type": "string"
      -  }
      -]
    • addedInput schema / properties / polarity / enum
      Added value: +[
      +  "assert",
      +  "deny"
      +]
    • addedInput schema / properties / polarity / type
      Added value: +"string"
    • changedInput schema / properties / predicate / description
      Previous value: -"Typed fact filter: predicate name to ask about, e.g. 'has_role' or 'permission_rule'. Combine with where for named arguments. Returns every stored fact of that predicate with its arguments, polarity and allow/deny effect."New value: +"Typed fact filter: predicate name to ask about; returns its stored facts with arguments, polarity and effect."
    • removedInput schema / properties / scope / anyOf
      Removed value: -[
      -  {
      -    "const": "all",
      -    "type": "string"
      -  },
      -  {
      -    "const": "current_requirements",
      -    "type": "string"
      -  }
      -]
    • addedInput schema / properties / scope / enum
      Added value: +[
      +  "all",
      +  "current_requirements"
      +]
    • addedInput schema / properties / scope / type
      Added value: +"string"
    • changedInput schema / properties / subjectKey / description
      Previous value: -"Typed fact filter: dotted subject key whose property facts to list, e.g. 'user.role_assignment'. Combine with propertyKey for one property, or with factKind 'subject' for the subject's domain view."New value: +"Typed fact filter: dotted subject key whose property facts to list; combine with propertyKey or factKind 'subject'."
    • removedInput schema / properties / type / anyOf
      Removed value: -[
      -  {
      -    "const": "req",
      -    "type": "string"
      -  },
      -  {
      -    "const": "scenario",
      -    "type": "string"
      -  },
      -  {
      -    "const": "test",
      -    "type": "string"
      -  },
      -  {
      -    "const": "adr",
      -    "type": "string"
      -  },
      -  {
      -    "const": "flag",
      -    "type": "string"
      -  },
      -  {
      -    "const": "event",
      -    "type": "string"
      -  },
      -  {
      -    "const": "symbol",
      -    "type": "string"
      -  },
      -  {
      -    "const": "fact",
      -    "type": "string"
      -  }
      -]
    • addedInput schema / properties / type / enum
      Added value: +[
      +  "req",
      +  "scenario",
      +  "test",
      +  "adr",
      +  "flag",
      +  "event",
      +  "symbol",
      +  "fact"
      +]
    • addedInput schema / properties / type / type
      Added value: +"string"
    • changedInput schema / properties / where / description
      Previous value: -"Named argument values for predicate, order-free, using the argument names from the predicate's schema. Example: {actor: 'admin', decision: 'allow'}. An unknown name returns a warning with the declared names; no match returns the values that do exist."New value: +"Named argument values for predicate, using the names from its schema."
    • changedInput schema / properties / workspaceRoot / description
      Previous value: -"Optional absolute path of the workspace this call is about when it differs from the one the server started in, for example the git worktree you are working in. The server answers from that workspace's knowledge base when it is a worktree of the same repository or lies under the client's MCP roots; otherwise it answers from its own workspace and adds a workspace_mismatch diagnostic. Host hooks fill this in automatically where available."New value: +"Optional absolute path of the workspace this call is about, such as your git worktree, when it is not the server's."
    • removedOutput schema / properties / diagnostics / items / properties / severity / anyOf
      Removed value: -[
      -  {
      -    "const": "info",
      -    "type": "string"
      -  },
      -  {
      -    "const": "warning",
      -    "type": "string"
      -  },
      -  {
      -    "const": "error",
      -    "type": "string"
      -  }
      -]
    • addedOutput schema / properties / diagnostics / items / properties / severity / enum
      Added value: +[
      +  "info",
      +  "warning",
      +  "error"
      +]
    • addedOutput schema / properties / diagnostics / items / properties / severity / type
      Added value: +"string"
    • removedOutput schema / properties / effects / items / properties / status / anyOf
      Removed value: -[
      -  {
      -    "const": "completed",
      -    "type": "string"
      -  },
      -  {
      -    "const": "failed",
      -    "type": "string"
      -  },
      -  {
      -    "const": "not_applicable",
      -    "type": "string"
      -  }
      -]
    • addedOutput schema / properties / effects / items / properties / status / enum
      Added value: +[
      +  "completed",
      +  "failed",
      +  "not_applicable"
      +]
    • addedOutput schema / properties / effects / items / properties / status / type
      Added value: +"string"
    • removedOutput schema / properties / status / anyOf
      Removed value: -[
      -  {
      -    "const": "success",
      -    "type": "string"
      -  },
      -  {
      -    "const": "committed_with_repairs",
      -    "type": "string"
      -  },
      -  {
      -    "const": "error",
      -    "type": "string"
      -  }
      -]
    • addedOutput schema / properties / status / enum
      Added value: +[
      +  "success",
      +  "committed_with_repairs",
      +  "error"
      +]
    • addedOutput schema / properties / status / type
      Added value: +"string"
  2. Changed1 schema field changedv0.1.9
    • changedInput schema / properties / subjectKey / description
      Previous value: -"Typed fact filter: dotted subject key whose property facts to list, e.g. 'user.role_assignment'. Combine with propertyKey for one property."New value: +"Typed fact filter: dotted subject key whose property facts to list, e.g. 'user.role_assignment'. Combine with propertyKey for one property, or with factKind 'subject' for the subject's domain view."
  3. Changed1 schema field changedv0.1.8
    • addedInput schema / properties / kb
      Added value: +{
      +  "description": "Optional KB dependency to read instead of this project's own KB: a name declared in .kb/dependencies.json and pinned in .kb/dependencies.lock.json. The answer comes from that repository's own read-only KB at the pinned commit, kept apart from this project's KB. Omit it to read this project's KB.",
      +  "maxLength": 64,
      +  "minLength": 1,
      +  "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$",
      +  "type": "string"
      +}
  4. First observedv0.1.0

TDQS

A3.9/5.0
Behavior4/5

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

Annotations already declare readOnlyHint, idempotentHint and destructiveHint=false, and the description reinforces 'Read-only.' Beyond that it discloses non-obvious return behavior: typed answers return fact rows plus a factQuery block with the schema used, distinct counts, 'values that do exist when nothing matched', warnings and the suggested next call. It also clarifies the metadata-only tag semantics and that sourceFile uses KB source linkage rather than file-system scanning, which is genuinely useful operational context.

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

Conciseness3/5

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

It is front-loaded with the core purpose, and most clauses carry real information, but the body is one dense run-on paragraph with stacked parentheticals (for example the long 'domain view' aside) that is hard to skim. For a tool this complex, a short mode list would have been clearer at similar length.

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?

Given 19 optional parameters, nested objects, an output schema and rich annotations, the description covers the main query modes, the emptiness/debug payload and the tag caveat, which is enough to call it correctly. Remaining details such as includeBody, pagination, the kb dependency pin and workspaceRoot are left to the fully documented schema, which is acceptable here.

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?

Schema description coverage is 100%, so the baseline is 3, but the description adds combinatorial meaning the schema states only piecemeal: predicate facts pair 'predicate + where', property facts pair 'subjectKey + propertyKey', the domain view is 'factKind "subject" + subjectKey', and the catalog is 'factKind' with 'predicate_schema' returning the askable predicate list with argument names and constants. That tells an agent how to combine 19 optional parameters rather than just what each one is.

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?

Opens with a specific verb and resource ('Read entities from the KB') and splits that into two concrete modes: exact-filter entity lookup and typed fact questions. It then enumerates what those modes cover (id/type/tags/sourceFile; predicate, property, subject view, fact catalog). It never names a sibling such as kb_search or kb_model, so the boundary against lexical search is only implied by the phrase 'exact filters'.

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?

Gives explicit triggering conditions: 'Use for lookup by id, type, tags or sourceFile, and for precise questions about modeled facts', followed by the parameter combination for each question shape. It also warns that 'Tags filter by metadata tags only, not entity IDs.' There is no when-not guidance and no named alternative, so an agent still has to infer when to prefer a search or graph tool instead.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.