Skip to main content
Glama

query_graph

Execute Datalog or Cypher queries on a code graph to find patterns, nodes, edges, and attributes. Define violations to enforce code invariants.

Instructions

Execute a Datalog or Cypher query on the code graph.

Set language to "cypher" for Cypher queries (e.g., MATCH (n:FUNCTION) RETURN n.name). Default is Datalog.

Available Datalog predicates:

  • type(Id, Type) / node(Id, Type) - match nodes by type

  • edge(Src, Dst, Type) - match edges

  • attr(Id, Name, Value) - match node attributes (name, file, line, etc.)

  • gt(Val, N), lt(Val, N), gte(Val, N), lte(Val, N) - numeric comparisons

  • + - negation (not)

NODE TYPES:

  • MODULE, FUNCTION, METHOD, CLASS, VARIABLE, PARAMETER

  • CALL, PROPERTY_ACCESS, METHOD_CALL, CALL_SITE

  • METRIC (performance metrics: value/unit/source in metadata, OBSERVES → MODULE)

  • ISSUE (analysis problems: category/severity/message in metadata, CONTAINS ← MODULE)

  • http:route, http:request, db:query, socketio:emit, socketio:on

EDGE TYPES:

  • CONTAINS, CALLS, DEPENDS_ON, ASSIGNED_FROM, INSTANCE_OF, PASSES_ARGUMENT

  • OBSERVES (METRIC → MODULE, links performance metric to observed file)

EXAMPLES: violation(X) :- node(X, "MODULE"). violation(X) :- node(X, "FUNCTION"), attr(X, "file", "src/api.js"). violation(X) :- node(X, "CALL"), + edge(X, _, "CALLS"). violation(F, Ms) :- node(M, "METRIC"), attr(M, "name", "parse_ms"), attr(M, "value", Ms), gte(Ms, 500), edge(M, Mod, "OBSERVES"), attr(Mod, "file", F).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesDatalog query (must define violation/1 predicate) or Cypher query (when language is "cypher").
languageNoQuery language: "datalog" (default) or "cypher"
limitNoMax results to return (default: 10, max: 500)
offsetNoSkip first N results for pagination (default: 0)
explainNoShow step-by-step query execution to debug empty results
countNoWhen true, returns only the count of matching results instead of the full result list
Behavior4/5

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

With no annotations, the description fully describes the tool's behavior: it executes queries, supports two languages, and lists predicates and types. It does not mention side effects (likely read-only), error handling, or performance limits beyond the parameters, but the examples provide clear behavioral insight.

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 lengthy but well-structured with clear sections (predicates, node types, edge types, examples). It front-loads the main purpose. Some redundancy could be trimmed, but the structure aids readability.

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 no output schema, the description covers query languages, predicates, node/edge types, and examples. It does not explain the return format but provides enough context for a user to understand what the tool does. It is sufficiently complete for a query tool.

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 coverage is 100%, and the description adds significant context: it explains the query languages, provides example queries, and details the predicates and node/edge types, enriching the meaning beyond the schema's descriptions.

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 executes Datalog or Cypher queries on the code graph, with specific verb 'Execute' and resource 'code graph'. It distinguishes from sibling tools like sim_datalog by specifying the query languages and providing detailed examples.

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?

The description gives comprehensive examples and lists available predicates and node/edge types, implying usage for graph queries. However, it lacks explicit guidance on when not to use this tool versus alternatives like find_nodes or find_calls, which could cover simpler cases.

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/Disentinel/grafema'

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