orbit

package
v2.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package orbit implements MCP tools for the experimental GitLab Orbit Knowledge Graph API on GitLab.com.

Six read-only handlers wrap the public Orbit endpoints and are exposed as individual tools (gitlab_orbit_*) and a consolidated meta-tool (gitlab_orbit):

  • Status — GET /api/v4/orbit/status (cluster health)
  • Schema — GET /api/v4/orbit/schema (graph ontology)
  • Tools — GET /api/v4/orbit/tools (MCP tool manifest)
  • DSL — GET /api/v4/orbit/schema/dsl (query DSL grammar)
  • Query — POST /api/v4/orbit/query (read-only graph query)
  • GraphStatus — GET /api/v4/orbit/graph_status (indexing status)

Orbit is gated to GitLab.com Premium/Ultimate with the knowledge_graph feature flag enabled. The package returns informative not-found results when the experimental feature is unavailable or the token cannot access a Knowledge Graph-enabled namespace or project.

Reference: https://docs.gitlab.com/api/orbit/

The Query handler accepts the full Orbit query DSL (traversal, aggregation, neighbors, path_finding) described at https://docs.gitlab.com/orbit/remote/queries/. Client-side validation in [validateQuery] only checks the small subset of rules the live API rejects with confusing 400 errors; the canonical schema is served by DSL and changes during the Orbit beta.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionSpecs

func ActionSpecs(client *gitlabclient.Client) []toolutil.ActionSpec

ActionSpecs returns the canonical ActionSpec definitions for all GitLab.com Orbit MCP tools.

Each ActionSpec describes a single public Orbit endpoint (status, schema, tools, dsl, query, graph_status) and is used to project both individual tools and meta-tool routes in the MCP server runtime.

These specs are the single source of truth for tool registration, schema, and documentation.

func FormatDSLMarkdown added in v2.0.5

func FormatDSLMarkdown(out DSLOutput) string

FormatDSLMarkdown returns a Markdown-formatted fenced code block with the Orbit query DSL.

Used to display the DSL grammar or schema for LLMs and users.

func FormatGraphStatusMarkdown

func FormatGraphStatusMarkdown(out GraphStatusOutput) string

FormatGraphStatusMarkdown returns a Markdown-formatted summary of Orbit graph indexing status.

Includes indexed project counts, domain node counts, and indexing pipeline state. Used for LLM and user docs.

func FormatQueryMarkdown

func FormatQueryMarkdown(out QueryOutput) string

FormatQueryMarkdown returns a Markdown-formatted summary of an Orbit query result.

If FormattedText is present, it is rendered as a fenced code block. Otherwise, the result is shown as JSON.

func FormatSchemaMarkdown

func FormatSchemaMarkdown(out SchemaOutput) string

FormatSchemaMarkdown returns a Markdown-formatted summary of the Orbit Knowledge Graph schema.

Includes schema version, domain table, and counts of nodes and edges. Used for LLM and user-facing docs.

func FormatStatusMarkdown

func FormatStatusMarkdown(out StatusOutput) string

FormatStatusMarkdown returns a Markdown-formatted summary of Orbit cluster health for LLM consumption.

Includes status, version, timestamp, and a table of subsystem components with replica counts. If FormattedText is present, it is rendered as a fenced code block.

func FormatToolsMarkdown

func FormatToolsMarkdown(out ToolsOutput) string

FormatToolsMarkdown returns a Markdown-formatted table of Orbit MCP tool definitions.

Each row shows the tool name and description. Used for LLM tool discovery and user docs.

Types

type DSLInput added in v2.0.5

type DSLInput struct {
	ResponseFormatInput
}

DSLInput holds parameters for retrieving the Orbit query DSL.

type DSLOutput added in v2.0.5

type DSLOutput struct {
	toolutil.HintableOutput
	// ResponseFormat echoes the response_format that produced Content
	// ("raw" for the JSON Schema body, "llm" for the text grammar).
	ResponseFormat string `json:"response_format,omitempty"`
	// Content is the DSL body verbatim, encoded as JSON or text
	// depending on ResponseFormat.
	Content string `json:"content,omitempty"`
}

DSLOutput holds the Orbit query DSL response.

func DSL added in v2.0.5

func DSL(ctx context.Context, client *gitlabclient.Client, input DSLInput) (DSLOutput, error)

DSL retrieves the Orbit query DSL grammar or LLM-friendly schema verbatim from GitLab.com.

Endpoint: GET /api/v4/orbit/schema/dsl. With response_format="raw" the body is a JSON Schema document; with response_format="llm" it is a compact text grammar suitable for inclusion in an LLM prompt.

type GraphStatusDomain

type GraphStatusDomain struct {
	// Name is the domain identifier (e.g. "SDLC").
	Name string `json:"name,omitempty"`
	// Items are the per-node-type counts in this domain.
	Items []GraphStatusDomainItem `json:"items,omitempty"`
}

GraphStatusDomain describes indexing counts for a graph domain.

type GraphStatusDomainItem

type GraphStatusDomainItem struct {
	// Name is the node-type identifier (e.g. "MergeRequest").
	Name string `json:"name,omitempty"`
	// Count is the number of indexed nodes of this type.
	Count int64 `json:"count"`
}

GraphStatusDomainItem describes a count for one Orbit graph node type.

type GraphStatusIndexing

type GraphStatusIndexing struct {
	// State is the indexing pipeline state (e.g. "indexed", "running", "error").
	State string `json:"state,omitempty"`
	// LastStartedAt is the UTC RFC3339 timestamp of the last indexing run start.
	LastStartedAt string `json:"last_started_at,omitempty"`
	// LastCompletedAt is the UTC RFC3339 timestamp of the last successful indexing run.
	LastCompletedAt string `json:"last_completed_at,omitempty"`
	// LastDurationMs is the duration of the last indexing run in milliseconds.
	LastDurationMs int64 `json:"last_duration_ms,omitempty"`
	// LastError is the last indexing error message, or empty when the
	// last run completed successfully.
	LastError string `json:"last_error,omitempty"`
}

GraphStatusIndexing describes the latest indexing pipeline state.

type GraphStatusInput

type GraphStatusInput struct {
	// NamespaceID targets a group by ID. Mutually exclusive with ProjectID
	// and FullPath; exactly one of the three must be set.
	NamespaceID int64 `` /* 132-byte string literal not displayed */
	// ProjectID targets a project by ID. Mutually exclusive with
	// NamespaceID and FullPath; exactly one of the three must be set.
	ProjectID int64 `json:"project_id,omitempty" jsonschema:"Project ID to inspect. Set exactly one of namespace_id, project_id, or full_path."`
	// FullPath targets a group or project by full path
	// (e.g. "gitlab-org/gitlab"). Mutually exclusive with NamespaceID
	// and ProjectID; exactly one of the three must be set.
	FullPath string `` /* 143-byte string literal not displayed */
	ResponseFormatInput
}

GraphStatusInput holds parameters for retrieving Orbit graph indexing status.

type GraphStatusOutput

type GraphStatusOutput struct {
	toolutil.HintableOutput
	// FormattedText is the pre-formatted text body returned by the
	// server when the caller selected the "llm" response format.
	FormattedText string `json:"formatted_text,omitempty"`
	// Projects summarizes the indexed vs. known project counts.
	Projects *GraphStatusProjects `json:"projects,omitempty"`
	// Domains are the per-domain indexing counts.
	Domains []GraphStatusDomain `json:"domains,omitempty"`
	// Indexing is the latest indexing pipeline state.
	Indexing *GraphStatusIndexing `json:"indexing,omitempty"`
}

GraphStatusOutput is the Orbit graph indexing status response.

func GraphStatus

func GraphStatus(ctx context.Context, client *gitlabclient.Client, input GraphStatusInput) (GraphStatusOutput, error)

GraphStatus retrieves Orbit graph indexing status for a single namespace, project, or full path on GitLab.com.

Endpoint: GET /api/v4/orbit/graph_status. Exactly one of namespace_id, project_id, or full_path must be set. Useful for verifying that the indexer has caught up before running Query.

type GraphStatusProjects

type GraphStatusProjects struct {
	// Indexed is the number of projects whose Knowledge Graph is
	// up to date in the index.
	Indexed int64 `json:"indexed"`
	// TotalKnown is the total number of projects eligible for indexing.
	TotalKnown int64 `json:"total_known"`
}

GraphStatusProjects describes indexed and known project counts.

type QueryInput

type QueryInput struct {
	Query map[string]any `` /* 199-byte string literal not displayed */
	ResponseFormatInput
}

QueryInput holds parameters for executing an Orbit Knowledge Graph query.

The Query field is the live Orbit query DSL. GitLab validates the shape server-side against a JSON Schema with four `oneOf` alternatives keyed on `query_type`:

  1. traversal — {query_type, node|nodes, relationships?, filters?, columns?, limit, cursor?, order_by?, options?}
  2. aggregation — {query_type, nodes, aggregations, group_by?, aggregation_sort?, limit, options?}
  3. neighbors — {query_type, node, neighbors: {node, direction?, rel_types?}, options?, limit}
  4. path_finding — {query_type, nodes: [2+], path: {type, from, to, max_depth, rel_types?}, options?, limit}

Top-level fields (only `query_type` is required):

  • node|nodes: one or more node selectors. Use `node` for a single node, `nodes: [array]` for multiple.
  • relationships: [{type, from, to, direction?, min_hops?, max_hops?, filters?}]. Joins node selectors by alias.
  • aggregations: [{function: count|sum|avg|min|max, target, property?, alias}]. Required for aggregation.
  • group_by: [{kind: node|property, node, property?, alias?}] — buckets aggregation rows.
  • aggregation_sort: {column, direction: ASC|DESC} — sorts aggregation results.
  • order_by: {node, property, direction: ASC|DESC} — sorts traversal results.
  • limit: integer, 1..1000. Default 30.
  • cursor: {page_size, offset} — pagination. `page_size + offset` must be <= `limit`.
  • path: required for path_finding. {type: shortest|all_shortest|any, from, to, max_depth: 1..3, rel_types?}.
  • neighbors: required for neighbors. {node, direction?: outgoing|incoming|both, rel_types?}.
  • options: {dynamic_columns?: default|*, include_debug_sql?, skip_dedup?, ...} for performance/debug knobs.

Node selector fields:

  • id: string, local alias. Referenced by relationships, aggregations, path, and neighbors.
  • entity: string, ontology node type (Project, MergeRequest, File, Vulnerability, etc.).
  • columns: string[] of properties to return, or "*" for all non-restricted columns.
  • filters: {property: value_or_op_object} — see operators below.
  • node_ids: int[] of exact ids. Maximum 500 per selector.
  • id_range: {start, end}. Span must be <= 100,000 to count as scope.
  • id_property: optional. Property used by node_ids and id_range. Default "id".

Filter operators ({op, value}):

eq, gt, gte, lt, lte, in, contains, starts_with, ends_with,
is_null, is_not_null, token_match, all_tokens, any_tokens.

Simple equality is also accepted: {property: "value"}.

Scope rules: traversal and aggregation queries MUST have at least one node with `node_ids`, `filters`, or `id_range` (span <= 100K). Otherwise the server rejects the request to avoid full edge table scans. Neighbors and path_finding reference nodes by their top-level `id` (a string), not by entity name.

Examples:

  • Find projects in plens1: {query_type:"traversal", node:{id:"p",entity:"Project", filters:{full_path:{op:"starts_with",value:"plens1/"}}}}

  • Count MRs per project (group_by node): {query_type:"aggregation", nodes:[{id:"p",entity:"Project",filters:{...}}, {id:"mr",entity:"MergeRequest",columns:["id"]}], relationships:[{type:"IN_PROJECT",from:"mr",to:"p"}], group_by:[{kind:"node",node:"p"}], aggregations:[{function:"count",target:"mr",alias:"mr_count"}], aggregation_sort:{column:"mr_count",direction:"DESC"}}

  • Find a path between two nodes (max depth 3): {query_type:"path_finding", nodes:[{id:"u",entity:"User",node_ids:[...]}, {id:"p",entity:"Project",node_ids:[...]}], path:{type:"shortest",from:"u",to:"p",max_depth:3}}

Reference: https://docs.gitlab.com/orbit/remote/queries/

type QueryOutput

type QueryOutput struct {
	toolutil.HintableOutput
	// FormattedText is the pre-formatted text body returned by the
	// server when the caller selected the "llm" response format.
	FormattedText string `json:"formatted_text,omitempty"`
	// Result is the decoded result envelope returned for the
	// "raw" or "json" response format. Its shape depends on the
	// query_type: traversal returns a list of row objects,
	// aggregation returns aggregation rows, neighbors returns the
	// neighbor expansion, and path_finding returns the matching paths.
	Result any `json:"result,omitempty"`
	// QueryType echoes the query_type that produced this result
	// (traversal, aggregation, neighbors, or path_finding).
	QueryType string `json:"query_type,omitempty"`
	// RawQueryStrings are the SQL strings the server executed for
	// the request; useful for debugging slow or unexpected queries.
	RawQueryStrings []string `json:"raw_query_strings,omitempty"`
	// RowCount is the number of rows in the result envelope.
	RowCount int64 `json:"row_count,omitempty"`
}

QueryOutput is the result envelope returned by Orbit query execution.

func Query

func Query(ctx context.Context, client *gitlabclient.Client, input QueryInput) (QueryOutput, error)

Query executes a read-only Orbit Knowledge Graph query on GitLab.com.

Endpoint: POST /api/v4/orbit/query. The query body is validated by [validateQuery] before being forwarded; see QueryInput for the full DSL shape.

The live API exposes four `oneOf` query_type variants:

  • traversal — multi-node joins with relationships, ordering, paging.
  • aggregation — group-by plus count|sum|avg|min|max functions.
  • neighbors — one-hop or two-hop expansion from a single node.
  • path_finding — shortest path between two top-level nodes (depth 1..3).

When response_format is omitted, the handler defaults to "raw" (structured JSON) rather than the API server-side default of "llm" (compact TOON text). Structured JSON is strictly more useful for an MCP tool: the LLM can iterate over result nodes directly, the SDK decodes row_count, and downstream markdown formatters pretty-print the envelope. Callers who want the compact TOON text can pass response_format="llm" explicitly.

type ResponseFormatInput

type ResponseFormatInput struct {
	// ResponseFormat selects the Orbit response shape. Allowed values:
	//   - "raw"  — structured JSON (or TOON JSON, depending on endpoint)
	//   - "llm"  — compact text optimized for LLM consumption
	//   - "json" — explicit JSON request (accepted by /orbit/status, /orbit/schema,
	//              /orbit/tools, and /orbit/query as an alias of "raw")
	//
	// When empty, status / schema / tools / dsl fall back to the GitLab API
	// server-side default (currently "raw" for /orbit/dsl, "json" for
	// /orbit/status, /orbit/schema, and /orbit/tools). [Query] is the
	// exception: when the field is omitted, [Query] forces "raw" rather
	// than letting the server apply its "llm" default, because structured
	// JSON is strictly more useful for an MCP tool (the LLM can iterate
	// over result nodes directly, the SDK decodes row_count, and the
	// downstream markdown formatter pretty-prints the envelope). Callers
	// who want the compact TOON text can pass response_format="llm"
	// explicitly.
	ResponseFormat string `` /* 194-byte string literal not displayed */
}

ResponseFormatInput is the shared response_format selector used by the status, dsl, and query Orbit endpoints.

type SchemaDomain

type SchemaDomain struct {
	// Name is the domain identifier (e.g. "core", "sdlc").
	Name string `json:"name,omitempty"`
	// Description is the human-readable domain summary.
	Description string `json:"description,omitempty"`
	// NodeNames are the ontology node types in the domain.
	NodeNames []string `json:"node_names,omitempty"`
}

SchemaDomain describes a logical grouping of Orbit graph node types.

type SchemaEdge

type SchemaEdge struct {
	// Name is the edge type identifier (e.g. "AUTHORED", "IN_PROJECT").
	Name string `json:"name,omitempty"`
	// Description is the human-readable edge summary.
	Description string `json:"description,omitempty"`
	// Variants are the valid source/target node-type pairs.
	Variants []SchemaEdgeVariant `json:"variants,omitempty"`
}

SchemaEdge describes an Orbit graph edge type.

type SchemaEdgeVariant

type SchemaEdgeVariant struct {
	// SourceType is the source node type (e.g. "User").
	SourceType string `json:"source_type,omitempty"`
	// TargetType is the target node type (e.g. "Issue").
	TargetType string `json:"target_type,omitempty"`
}

SchemaEdgeVariant describes a valid source/target pair for an Orbit edge.

type SchemaInput

type SchemaInput struct {
	// Expand lists node names whose full properties and relationships
	// should be hydrated in the response.
	Expand []string `json:"expand,omitempty" jsonschema:"Node names to expand with full properties and relationships."`
	// Format selects the schema response shape. Allowed values: "raw",
	// "llm", "json". Empty uses the API server-side default ("json").
	Format string `` /* 137-byte string literal not displayed */
	// ResponseFormat is an alias for Format, accepted for compatibility
	// with the public Orbit API documentation. Must match Format when
	// both are set; Format wins when only one is set.
	ResponseFormat string `json:"response_format,omitempty" jsonschema:"Alias for format. Must match format when both are set."`
}

SchemaInput holds parameters for retrieving the Orbit graph schema.

type SchemaOutput

type SchemaOutput struct {
	toolutil.HintableOutput
	// SchemaVersion is the Orbit ontology version string.
	SchemaVersion string `json:"schema_version,omitempty"`
	// Domains are the logical groupings of node types.
	Domains []SchemaDomain `json:"domains,omitempty"`
	// Nodes are the decoded node-type definitions. The Orbit API
	// evolves the node shape, so the SDK exposes the list as raw JSON
	// values rather than fixed Go types.
	Nodes []any `json:"nodes,omitempty"`
	// Edges are the graph edge types.
	Edges []SchemaEdge `json:"edges,omitempty"`
}

SchemaOutput is the Orbit graph ontology response.

func Schema

func Schema(ctx context.Context, client *gitlabclient.Client, input SchemaInput) (SchemaOutput, error)

Schema retrieves the Orbit graph ontology (domains, node types, edge types) from GitLab.com.

Endpoint: GET /api/v4/orbit/schema. The expand parameter hydrates the named node types with full properties; format selects raw, llm, or json response shapes.

type StatusComponent

type StatusComponent struct {
	// Name is the subsystem identifier (e.g. "clickhouse", "api").
	Name string `json:"name,omitempty"`
	// Status is the subsystem health label (e.g. "healthy").
	Status string `json:"status,omitempty"`
	// Replicas are the ready/desired counts, or nil when the
	// subsystem is stateless.
	Replicas *StatusReplicas `json:"replicas,omitempty"`
	// Metrics is the decoded raw JSON metrics payload for the subsystem.
	Metrics any `json:"metrics,omitempty"`
}

StatusComponent describes an Orbit subsystem status entry.

type StatusInput

type StatusInput struct {
	ResponseFormatInput
}

StatusInput holds parameters for retrieving Orbit cluster status.

type StatusOutput

type StatusOutput struct {
	toolutil.HintableOutput
	// User mirrors the user-level access object from the nested
	// response shape, or nil for the flat shape.
	User *StatusUser `json:"user,omitempty"`
	// System mirrors the cluster health object from the nested
	// response shape, or nil for the flat shape.
	System *StatusSystem `json:"system,omitempty"`
	// FormattedText is the pre-formatted text body returned by the
	// server when the caller selected the "llm" response format.
	FormattedText string `json:"formatted_text,omitempty"`
	// Status is the cluster-level health label.
	Status string `json:"status,omitempty"`
	// Timestamp is the server-side snapshot time, RFC3339.
	Timestamp string `json:"timestamp,omitempty"`
	// Version is the Orbit service version.
	Version string `json:"version,omitempty"`
	// Components are the per-subsystem status entries.
	Components []StatusComponent `json:"components,omitempty"`
}

StatusOutput is the Orbit cluster health response.

The flat fields (FormattedText, Status, Timestamp, Version, Components) are always populated: the SDK promotes the nested system object's fields into them for backward compatibility. User and System carry the new nested shape directly when the server emits it, and are nil for the old flat shape.

func Status

func Status(ctx context.Context, client *gitlabclient.Client, input StatusInput) (StatusOutput, error)

Status retrieves the Orbit cluster health snapshot from GitLab.com.

Endpoint: GET /api/v4/orbit/status. Returns subsystem components, replica counts, version, and timestamp. Falls back to an informative not-found result when the Orbit feature is not enabled.

type StatusReplicas

type StatusReplicas struct {
	// Ready is the current number of healthy replicas.
	Ready int64 `json:"ready"`
	// Desired is the target number of replicas.
	Desired int64 `json:"desired"`
}

StatusReplicas describes ready and desired replica counts for an Orbit component.

type StatusSystem added in v2.3.0

type StatusSystem struct {
	// FormattedText is the pre-formatted text body, when present.
	FormattedText string `json:"formatted_text,omitempty"`
	// Status is the cluster-level health label.
	Status string `json:"status,omitempty"`
	// Timestamp is the server-side snapshot time, RFC3339.
	Timestamp string `json:"timestamp,omitempty"`
	// Version is the Orbit service version.
	Version string `json:"version,omitempty"`
	// Error is the backend error message emitted when the gRPC
	// cluster is unreachable, or empty otherwise.
	Error string `json:"error,omitempty"`
	// Components are the per-subsystem status entries.
	Components []StatusComponent `json:"components,omitempty"`
}

StatusSystem mirrors the cluster health object returned in the new nested shape of the Orbit status response. It carries the same health fields as the flat shape, plus an Error field emitted when the backend cannot reach the gRPC cluster (Status is "unknown" in that case). Present only for the nested shape; nil otherwise.

type StatusUser added in v2.3.0

type StatusUser struct {
	// Available reports whether the calling user has access to the
	// Knowledge Graph.
	Available bool `json:"available"`
}

StatusUser mirrors the user-level access object returned in the new nested shape of the Orbit status response. It is present only when the server emits the nested shape; nil for the old flat shape.

type ToolDefinition

type ToolDefinition struct {
	// Name is the tool name as Orbit exposes it.
	Name string `json:"name,omitempty"`
	// Description is the tool's human-readable description.
	Description string `json:"description,omitempty"`
	// Parameters is the decoded JSON Schema for the tool's input.
	Parameters any `json:"parameters,omitempty"`
}

ToolDefinition describes one MCP tool manifest entry served by Orbit.

type ToolsInput

type ToolsInput struct{}

ToolsInput is the input for listing the Orbit MCP tool manifest. The endpoint accepts no parameters; the type exists so the handler signature is uniform with the other Orbit handlers.

type ToolsOutput

type ToolsOutput struct {
	toolutil.HintableOutput
	// Tools is the list of MCP tools Orbit exposes.
	Tools []ToolDefinition `json:"tools,omitempty"`
}

ToolsOutput is the Orbit MCP tool manifest response.

func Tools

func Tools(ctx context.Context, client *gitlabclient.Client, _ ToolsInput) (ToolsOutput, error)

Tools retrieves the Orbit MCP tool manifest and parameter schemas.

Endpoint: GET /api/v4/orbit/tools. The manifest lists the tools Orbit exposes alongside the JSON Schema of each tool's parameters; use it to learn the canonical query shapes before calling Query.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL