mcp

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Overview

@index In-memory TTL cache for repeat MCP read-tool responses with background eviction.

@index Dependency contracts and injected services for MCP handlers.

@index Namespace and git provenance evidence builders for namespace-scoped MCP responses.

@index MCP handlers for impact, flow, change-risk, dead-code, and suspect-edge analyses over the stored graph.

@index MCP context handlers that summarize graph state for downstream tool selection.

@index MCP handler exposing materialized cross-namespace references as a repository dependency map.

@index MCP handlers for DB-backed documentation search and safe generated-document reads.

@index MCP handlers for graph summaries: stored flows, communities, and architecture overviews.

@index MCP handler that enumerates graph namespaces for cross-namespace discovery.

@index MCP handlers for source parsing, full/incremental graph builds, and postprocess orchestration.

@index MCP handlers for node lookup, search, predefined graph queries, and graph statistics.

@index Shared handler helpers and response utilities for MCP tools.

@index HTTP safety helpers for MCP server endpoints.

@index Namespace filesystem path resolution shared by namespace-scoped doc handlers.

@index MCP prompt handlers that compose graph queries into review, debug, onboarding, and pre-merge workflows.

@index Prompt registration for curated MCP workflows.

@index MCP server. Exposes code analysis capabilities to AI through multiple tools and 5 prompt templates.

@index MCP tool registration for analysis-oriented graph operations.

@index MCP tool registration for lightweight context discovery.

@index MCP tool registration for DB-backed documentation search and generated document reads.

@index MCP tool registration for graph summaries and architecture views.

@index MCP tool registration for parsing, graph build, and postprocess execution.

@index MCP tool registration for node lookup and graph query primitives.

@index Top-level MCP tool registration orchestration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitHTTPBody

func LimitHTTPBody(next http.Handler) http.Handler

@intent cap request memory usage before MCP handlers allocate or parse large request bodies. @ensures requests larger than the configured limit are rejected with 413. @sideEffect wraps the request body with a MaxBytesReader.

func NewServer

func NewServer(deps *Deps) *server.MCPServer

NewServer creates and configures the MCP server with all tools and prompts. @intent Configures a server instance that exposes code graph features as MCP tools and prompts. @requires deps != nil @ensures The returned server is registered with MCP tools and prompts. @sideEffect Logs server metadata to the logger. @see mcp.Deps

Types

type AnalysisToolsDeps

type AnalysisToolsDeps struct {
	Impact      ImpactAnalyzer
	Flow        FlowTracer
	Changes     ChangeAnalyzer
	Reader      analyze.GraphReadRepository
	CrossImpact ImpactAnalyzer
	CrossFlow   FlowTracer
	CrossRefs   CrossRefLister
}

AnalysisToolsDeps owns bounded impact, flow, and git-change analysis dependencies. @intent group only configured application analyzers and their read-model port. @domainRule CrossImpact/CrossFlow/CrossRefs are optional; when nil the cross-namespace analysis surface reports itself unconfigured.

type BuildToolsDeps

type BuildToolsDeps struct {
	Store       ingest.GraphStore
	Walkers     map[string]Parser
	UnitOfWork  ingest.UnitOfWork
	Search      ingest.SearchWriter
	Maintenance document.Maintenance
	FlowBuilder FlowBuilder
	Incremental IncrementalSyncer
}

BuildToolsDeps owns graph mutation and postprocess dependencies. @intent group only the dependencies required by parse, build, update, and postprocess tools.

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a simple in-memory TTL cache safe for concurrent use. @intent Reuses MCP read-tool responses in memory for frequently repeated queries.

func NewCache

func NewCache(ttl time.Duration) *Cache

NewCache creates a Cache with the given TTL and starts a background cleanup goroutine. Call Close() when the cache is no longer needed to stop the goroutine. @intent Creates a TTL-based memory cache and starts the expired entry cleanup loop. @param ttl The maximum duration each entry remains valid. @ensures The returned Cache has an empty entry map and an active cleanup goroutine. @sideEffect Starts a background cleanup goroutine.

func (*Cache) Close

func (c *Cache) Close()

Close stops the background cleanup goroutine. @intent Safely stops the cleanup goroutine when the cache is no longer used. @sideEffect Closes stopCh to terminate the cleanup loop. @mutates c.stopCh

func (*Cache) Flush

func (c *Cache) Flush()

Flush removes all entries from the cache. @intent Invalidates all cached read results after a graph or index update. @mutates c.entries

func (*Cache) Get

func (c *Cache) Get(key string) (string, bool)

Get returns the cached value and true if the key exists and has not expired. @intent Returns only cached responses that are still within their validity period. @param key The cache key to look up. @return Returns the value and true if the key exists and is not expired.

func (*Cache) Set

func (c *Cache) Set(key string, value string)

Set stores the value under key with the cache's configured TTL. @intent Stores read-tool results in the cache with the configured TTL. @param key The cache key to store under. @mutates c.entries

type ChangeAnalyzer

type ChangeAnalyzer interface {
	AnalyzePage(ctx context.Context, repoDir, baseRef string, limit, offset int) (changes.Result, error)
	ChangedNodeIDs(ctx context.Context, repoDir, baseRef string) ([]uint, error)
}

ChangeAnalyzer is the application change-risk surface consumed by tools and prompts. @intent inject a configured application change service without exposing Git or persistence implementations.

type CrossRefLister

type CrossRefLister interface {
	ListOutboundCrossRefs(ctx context.Context, fromNamespace string) ([]graph.CrossRef, error)
	ListInboundCrossRefs(ctx context.Context, toNamespace string) ([]graph.CrossRef, error)
}

CrossRefLister exposes materialized cross-namespace references for listing tools. @intent let handlers enumerate repository-level dependencies without a store implementation dependency.

type Deps

type Deps struct {
	Build    BuildToolsDeps
	Graph    GraphToolsDeps
	Analysis AnalysisToolsDeps
	Docs     DocsToolsDeps
	Runtime  RuntimeToolsDeps
}

Deps groups MCP dependencies by registered tool surface. @intent make each MCP capability's required application contracts explicit at composition time.

type DocsToolsDeps

type DocsToolsDeps struct {
	Retrieval *retrieval.Service
}

DocsToolsDeps owns DB-primary documentation retrieval. @intent group the configured application retrieval service used by documentation tools.

type FlowBuilder

type FlowBuilder interface {
	Rebuild(ctx context.Context, cfg flowspkg.Config) ([]flowspkg.Stats, error)
}

FlowBuilder defines the persisted flow rebuild contract. @intent Injects a builder into the MCP handler that regenerates stored flow post-processing results. @see mcp.handlers.runPostprocess

type FlowTracer

type FlowTracer interface {
	TraceFlowBounded(ctx context.Context, startNodeID uint, opts flowspkg.TraceOptions) (*flowspkg.TraceResult, error)
}

FlowTracer defines the bounded call-flow tracing contract for graph nodes. @intent inject a node-capped call-flow tracer so a deep call chain cannot expand into an unbounded traversal. @see mcp.handlers.traceFlow

type GraphToolsDeps

type GraphToolsDeps struct {
	Store      analyze.GraphLookup
	Query      QueryService
	Search     retrieval.CandidateSearcher
	Statistics analyze.StatisticsReader
	Reader     analyze.GraphReadRepository
}

GraphToolsDeps owns graph lookup, query, search, and aggregate dependencies. @intent group only the dependencies required by graph and search read tools.

type ImpactAnalyzer

type ImpactAnalyzer interface {
	ImpactRadiusBounded(ctx context.Context, nodeID uint, depth int, opts impactpkg.RadiusOptions) (*impactpkg.RadiusResult, error)
}

ImpactAnalyzer defines the bounded blast-radius analysis contract for graph nodes. @intent inject a node/depth-capped blast-radius analyzer so a single MCP request cannot expand into an unbounded graph walk. @see mcp.handlers.getImpactRadius

type IncrementalSyncer

type IncrementalSyncer interface {
	Sync(ctx context.Context, files map[string]incremental.FileInfo) (*incremental.SyncStats, error)
	SyncWithExisting(ctx context.Context, files map[string]incremental.FileInfo, existingFiles []string) (*incremental.SyncStats, error)
}

IncrementalSyncer defines the incremental graph synchronization contract. @intent Injects a syncer that reflects only changed files into the graph without full re-parsing. @see mcp.handlers.buildOrUpdateGraph

type Parser

type Parser interface {
	Parse(filePath string, content []byte) ([]graph.Node, []graph.Edge, error)
	ParseWithContext(ctx context.Context, filePath string, content []byte) ([]graph.Node, []graph.Edge, error)
}

Parser defines the source parser contract used by MCP graph builds. @intent Injects an abstract parser to combine language-specific parsing implementations on the server. @see mcp.Deps

type QueryService

type QueryService interface {
	CallersOf(ctx context.Context, nodeID uint) ([]graph.Node, error)
	CalleesOf(ctx context.Context, nodeID uint) ([]graph.Node, error)
	CallersOfPage(ctx context.Context, nodeID uint, opts query.QueryOptions) (query.PagedNodes, error)
	CalleesOfPage(ctx context.Context, nodeID uint, opts query.QueryOptions) (query.PagedNodes, error)
	CallersOfWithOptions(ctx context.Context, nodeID uint, opts query.QueryOptions) ([]graph.Node, error)
	CalleesOfWithOptions(ctx context.Context, nodeID uint, opts query.QueryOptions) ([]graph.Node, error)
	ImportsOf(ctx context.Context, nodeID uint) ([]graph.Node, error)
	ImportersOf(ctx context.Context, nodeID uint) ([]graph.Node, error)
	ImportsOfPage(ctx context.Context, nodeID uint, opts query.QueryOptions) (query.PagedNodes, error)
	ImportersOfPage(ctx context.Context, nodeID uint, opts query.QueryOptions) (query.PagedNodes, error)
	ChildrenOf(ctx context.Context, nodeID uint) ([]graph.Node, error)
	ChildrenOfPage(ctx context.Context, nodeID uint, opts query.QueryOptions) (query.PagedNodes, error)
	TestsFor(ctx context.Context, nodeID uint) ([]graph.Node, error)
	TestsForPage(ctx context.Context, nodeID uint, opts query.QueryOptions) (query.PagedNodes, error)
	InheritorsOf(ctx context.Context, nodeID uint) ([]graph.Node, error)
	InheritorsOfPage(ctx context.Context, nodeID uint, opts query.QueryOptions) (query.PagedNodes, error)
	FileSummaryOf(ctx context.Context, filePath string) (*query.FileSummary, error)
	FindExactNameMatches(ctx context.Context, target string, limit int) ([]query.CandidateMatch, error)
}

QueryService defines predefined graph query operations exposed over MCP. @intent Simplifies handlers by abstracting standard graph queries into a single service interface. @see mcp.handlers.queryGraph

type RuntimeToolsDeps

type RuntimeToolsDeps struct {
	Logger              *slog.Logger
	Cache               *Cache
	RagIndexDir         string
	RagProjectDesc      string
	NamespaceRoot       string
	RepoRoot            string
	MaxFileBytes        int64
	MaxTotalParsedBytes int64
}

RuntimeToolsDeps owns cross-cutting cache, logging, paths, and request limits. @intent group transport runtime configuration separately from capability dependencies.

Jump to

Keyboard shortcuts

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