graph

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package graph is the exported source-code model shared between the discovery pass and every analyzer that reasons about dataflow: symbols, imports, the call graph and the MCP capabilities found in it

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Text    string `json:"text"`              // source text of the argument expression
	Literal bool   `json:"literal"`           // true when Text is a plain string literal
	Value   string `json:"value,omitempty"`   // the literal's decoded value, if Literal
	Keyword string `json:"keyword,omitempty"` // keyword/named-argument name, if any

	// HandlerID is set when this argument is itself an inline function literal -
	// `server.tool("x", "y", async ({ path }) => {...})`, the form the MCP SDKs' own examples
	// register a handler with - rather than a reference to a named one
	HandlerID SymbolID `json:"handler_id,omitempty"`
}

Arg is one static argument to a call

type Call

type Call struct {
	Caller     SymbolID `json:"caller,omitempty"` // "" for module/top-level code
	Callee     SymbolID `json:"callee,omitempty"` // "" when unresolved
	CalleeText string   `json:"callee_text"`      // raw callee expression, always set
	Resolved   bool     `json:"resolved"`
	InLoop     bool     `json:"in_loop,omitempty"`
	// IsDecorator is true when this call is itself a decorator expression (Python's
	// `@mcp.tool()`, a call syntactically), not an invocation at the point it appears
	IsDecorator bool   `json:"is_decorator,omitempty"`
	File        string `json:"file"`
	Line        int    `json:"line"`
	Args        []Arg  `json:"args,omitempty"`
}

Call is one call expression, resolved within the repo where possible

type Capability

type Capability struct {
	Kind CapabilityKind `json:"kind"`

	Name         string `json:"name,omitempty"`
	NameResolved bool   `json:"name_resolved"`

	Description         string `json:"description,omitempty"`
	DescriptionResolved bool   `json:"description_resolved"`

	Handler     SymbolID `json:"handler,omitempty"`
	HandlerText string   `json:"handler_text,omitempty"`

	// Form is how the registration was found: direct | decorator | wrapper |
	// table | loop | factory | request_handler. request_handler is the
	// low-level SDK's split form - a ListXRequestSchema/@app.list_x()
	// handler declares the capabilities, a separate Call*/Get*RequestSchema
	// handler dispatches every call by name - see the registration package
	Form string `json:"form"`

	File string `json:"file"`
	Line int    `json:"line"`
}

Capability is one discovered MCP tool/prompt/resource registration

type CapabilityKind

type CapabilityKind string

CapabilityKind is what an MCP registration declares

const (
	CapabilityTool     CapabilityKind = "tool"
	CapabilityPrompt   CapabilityKind = "prompt"
	CapabilityResource CapabilityKind = "resource"
)

type File

type File struct {
	Path     string   `json:"path"`
	Language string   `json:"language"`
	Imports  []Import `json:"imports,omitempty"`
	// MaxBytes is nonzero when the walk that produced this file found it over the per-file size
	// limit: only the first MaxBytes bytes were read and parsed
	MaxBytes int64 `json:"max_bytes,omitempty"`
	// Constants maps unambiguous same-file string constants to their values:
	// Python module assignments, Java string fields and Rust const or static items
	Constants map[string]string `json:"constants,omitempty"`
}

File is one parsed source file

type Graph

type Graph struct {
	Root         string               `json:"root"`
	Files        map[string]*File     `json:"files"`
	Symbols      map[SymbolID]*Symbol `json:"symbols"`
	Calls        []Call               `json:"calls"`
	Capabilities []Capability         `json:"capabilities"`
}

Graph is the whole-tree symbol table, call graph and MCP capability list

func New

func New(root string) *Graph

func (*Graph) CallsFrom

func (g *Graph) CallsFrom(id SymbolID) []Call

CallsFrom returns every call made directly by id ("" for top-level calls)

func (*Graph) Reachable

func (g *Graph) Reachable(id SymbolID) (symbols map[SymbolID]bool, sawUnknown bool)

Reachable does a breadth-first walk of the call graph starting at id and returns every resolved symbol it can reach, plus whether the walk ever had to cross an unresolved call to keep going

type Import

type Import struct {
	Path  string `json:"path"` // module/package path as written
	Alias string `json:"alias,omitempty"`
	File  string `json:"file"`
	Line  int    `json:"line"`
}

Import is one import/use/require statement, normalized across languages

type Symbol

type Symbol struct {
	ID         SymbolID   `json:"id"`
	Kind       SymbolKind `json:"kind"`
	Name       string     `json:"name"`
	Receiver   string     `json:"receiver,omitempty"` // method receiver type, or enclosing class
	File       string     `json:"file"`
	Line       int        `json:"line"`
	EndLine    int        `json:"end_line"`
	Params     []string   `json:"params,omitempty"`
	Doc        string     `json:"doc,omitempty"`        // docstring or leading comment, best-effort
	Decorators []string   `json:"decorators,omitempty"` // raw decorator/annotation source text
	// DecoratorArgs holds parsed decorator, annotation or attribute arguments,
	// aligned with Decorators and nil when absent. Registration uses these arguments
	// to avoid mistaking text inside a string for an argument key.
	DecoratorArgs [][]Arg `json:"decorator_args,omitempty"`
	// ReturnLiteral holds the keyed fields of a composite/object/dict literal
	// returned by this function, when its body is simply `return <literal>`.
	// It is how a factory function's static shape (`return &mcp.Tool{Name:
	// "x"}`) is readable without a type checker.
	ReturnLiteral []Arg `json:"return_literal,omitempty"`

	// ReturnText is the raw source text of the same `return <value>` statement ReturnLiteral
	// reads, kept regardless of whether that value is itself a literal ReturnLiteral could
	// flatten
	ReturnText string `json:"return_text,omitempty"`
}

Symbol is a function, method or class definition

type SymbolID

type SymbolID string

SymbolID identifies a symbol uniquely within one Graph. It is built from the file and name so it stays stable across a rebuild of the same tree.

func MakeSymbolID

func MakeSymbolID(file, name string, line int) SymbolID

MakeSymbolID builds a stable identifier for a definition at file:line, unique enough for name-based resolution and readable enough for debugging and finding paths

type SymbolKind

type SymbolKind string

SymbolKind is what kind of definition a Symbol records

const (
	KindFunction SymbolKind = "function"
	KindMethod   SymbolKind = "method"
	KindClass    SymbolKind = "class"
)

Jump to

Keyboard shortcuts

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