mcp

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertStatistics

func ConvertStatistics(stats *graph.ProjectStatistics) map[string]any

func FilterExported

func FilterExported(items []any) []any

func GenerateFallbackCypher

func GenerateFallbackCypher(naturalQuery, projectID string) string

Types

type GraphAdapter

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

GraphAdapter provides graph operations needed by MCP server

func NewGraphAdapter

func NewGraphAdapter(driver neo4j.DriverWithContext, service graph.Service) *GraphAdapter

NewGraphAdapter creates a new graph adapter

func (*GraphAdapter) ExecuteQuery

func (a *GraphAdapter) ExecuteQuery(
	ctx context.Context,
	query string,
	params map[string]any,
) ([]map[string]any, error)

ExecuteQuery executes a Cypher query directly

func (*GraphAdapter) GetProjectStatistics

func (a *GraphAdapter) GetProjectStatistics(ctx context.Context, projectID core.ID) (*graph.ProjectStatistics, error)

GetProjectStatistics delegates to the underlying service

type MCPServer

type MCPServer interface {
	AddTool(tool any)
	AddResource(resource any)
	Connect(ctx context.Context, transport any) error
}

MCPServer defines the interface for the MCP server

type ResourceResponse

type ResourceResponse struct {
	Content []any `json:"content"`
}

ResourceResponse represents a response from a resource

type Server

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

Server represents the MCP server

func NewServer

func NewServer(
	config *mcpconfig.Config,
	serviceAdapter ServiceAdapter,
	llmService llm.CypherTranslator,
	contextGenerator llm.ContextGenerator,
	queryBuilder *query.HighLevelBuilder,
) *Server

NewServer creates a new MCP server instance

func (*Server) AddFunctionRelationships

func (s *Server) AddFunctionRelationships(
	ctx context.Context,
	result map[string]any,
	params map[string]any,
	includeCalls, includeCallers bool,
)

AddFunctionRelationships adds calls and callers to function result

func (*Server) AnalyzeFunctionNaming

func (s *Server) AnalyzeFunctionNaming(results []map[string]any) map[string]any

AnalyzeFunctionNaming analyzes function naming patterns

func (*Server) AnalyzeInterfaceNaming

func (s *Server) AnalyzeInterfaceNaming(results []map[string]any) map[string]any

AnalyzeInterfaceNaming analyzes interface naming patterns

func (*Server) AnalyzeNamingConventions

func (s *Server) AnalyzeNamingConventions(ctx context.Context, projectID, _ string) map[string]any

AnalyzeNamingConventions analyzes naming patterns in the codebase

func (*Server) AnalyzeTestCoverage

func (s *Server) AnalyzeTestCoverage(ctx context.Context, projectID, path string) TestCoverage

AnalyzeTestCoverage analyzes test coverage for a given path

func (*Server) AnalyzeTypeNaming

func (s *Server) AnalyzeTypeNaming(results []map[string]any) map[string]any

AnalyzeTypeNaming analyzes struct/type naming patterns

func (*Server) BuildElementLocationQuery

func (s *Server) BuildElementLocationQuery(elementType string) (string, error)

BuildElementLocationQuery builds a query to find an element's location

func (*Server) DetectCommonPatterns

func (s *Server) DetectCommonPatterns(ctx context.Context, projectID, _ string) []map[string]any

DetectCommonPatterns detects common Go programming patterns

func (*Server) DetectErrorPattern

func (s *Server) DetectErrorPattern(ctx context.Context, projectID string) map[string]any

DetectErrorPattern detects error handling patterns

func (*Server) DetectFactoryPattern

func (s *Server) DetectFactoryPattern(ctx context.Context, projectID string) map[string]any

DetectFactoryPattern detects factory function patterns

func (*Server) DetectInterfacePattern

func (s *Server) DetectInterfacePattern(ctx context.Context, projectID string) map[string]any

DetectInterfacePattern detects interface implementation patterns

func (*Server) ExtractCodeContextFromResults

func (s *Server) ExtractCodeContextFromResults(
	results []map[string]any,
	projectID, elementType, name string,
	contextLines int,
) (*ToolResponse, error)

ExtractCodeContextFromResults processes query results and extracts code context

func (*Server) FindTestsForElement

func (s *Server) FindTestsForElement(
	ctx context.Context,
	projectID, _, name, _ string,
) []map[string]any

FindTestsForElement finds test functions that might test a specific element

func (*Server) HandleAnalyzeProjectInternal

func (s *Server) HandleAnalyzeProjectInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

HandleAnalyzeProjectInternal analyzes a Go project and stores results in Neo4j

func (*Server) HandleCheckTestCoverageInternal

func (s *Server) HandleCheckTestCoverageInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleCheckTestCoverage checks test coverage

func (*Server) HandleCodePatternsResource

func (s *Server) HandleCodePatternsResource(_ context.Context, _ map[string]string) ([]byte, error)

handleCodePatternsResource provides code patterns

func (*Server) HandleDetectCircularDepsInternal

func (s *Server) HandleDetectCircularDepsInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleDetectCircularDeps detects circular dependencies

func (*Server) HandleDetectCodePatternsInternal

func (s *Server) HandleDetectCodePatternsInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleDetectCodePatterns detects code patterns

func (*Server) HandleExecuteCypherInternal

func (s *Server) HandleExecuteCypherInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

HandleExecuteCypherInternal executes a custom Cypher query

func (*Server) HandleFindImplementationsInternal

func (s *Server) HandleFindImplementationsInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleFindImplementations finds all implementations of an interface

func (*Server) HandleFindTestsForCodeInternal

func (s *Server) HandleFindTestsForCodeInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleFindTestsForCode finds tests for code elements

func (*Server) HandleGetCodeContextInternal

func (s *Server) HandleGetCodeContextInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleGetCodeContext gets context around a code element

func (*Server) HandleGetFunctionInfoInternal

func (s *Server) HandleGetFunctionInfoInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

HandleGetFunctionInfoInternal gets detailed information about a function

func (*Server) HandleGetNamingConventionsInternal

func (s *Server) HandleGetNamingConventionsInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleGetNamingConventions analyzes naming conventions

func (*Server) HandleGetPackageStructureInternal

func (s *Server) HandleGetPackageStructureInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleGetPackageStructure gets detailed structure of a package

func (*Server) HandleListPackagesInternal

func (s *Server) HandleListPackagesInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleListPackages lists all packages in the project

func (*Server) HandleListProjectsInternal added in v0.0.3

func (s *Server) HandleListProjectsInternal(ctx context.Context, _ map[string]any) (*ToolResponse, error)

HandleListProjectsInternal lists all projects in the database

func (*Server) HandleNaturalLanguageQueryInternal

func (s *Server) HandleNaturalLanguageQueryInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleNaturalLanguageQuery converts natural language to Cypher and executes

func (*Server) HandleProjectInvariantsResource

func (s *Server) HandleProjectInvariantsResource(_ context.Context, params map[string]string) ([]byte, error)

handleProjectInvariantsResource provides project invariants

func (*Server) HandleProjectMetadataResource

func (s *Server) HandleProjectMetadataResource(ctx context.Context, params map[string]string) ([]byte, error)

handleProjectMetadataResource provides project metadata

func (*Server) HandleQueryDependenciesInternal

func (s *Server) HandleQueryDependenciesInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleQueryDependencies finds dependencies for a package or function

func (*Server) HandleQueryTemplatesResource

func (s *Server) HandleQueryTemplatesResource(_ context.Context, _ map[string]string) ([]byte, error)

handleQueryTemplatesResource provides query templates

func (*Server) HandleTraceCallChainInternal

func (s *Server) HandleTraceCallChainInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleTraceCallChain traces call chains between functions

func (*Server) HandleValidateImportPathInternal

func (s *Server) HandleValidateImportPathInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleValidateImportPath validates an import path

func (*Server) HandleValidateProjectInternal added in v0.0.3

func (s *Server) HandleValidateProjectInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

HandleValidateProjectInternal validates if a project exists in the database

func (*Server) HandleVerifyCodeExistsInternal

func (s *Server) HandleVerifyCodeExistsInternal(ctx context.Context, input map[string]any) (*ToolResponse, error)

handleVerifyCodeExists verifies if a code element exists

func (*Server) IsCamelCase

func (s *Server) IsCamelCase(str string) bool

IsCamelCase checks if a string is in camelCase

func (*Server) IsPascalCase

func (s *Server) IsPascalCase(str string) bool

IsPascalCase checks if a string is in PascalCase

func (*Server) IsPathAllowed

func (s *Server) IsPathAllowed(path string) bool

func (*Server) IsStandardLibraryPackage

func (s *Server) IsStandardLibraryPackage(importPath string) bool

IsStandardLibraryPackage checks if an import path is a Go standard library package

func (*Server) ParseCodeContextInput

func (s *Server) ParseCodeContextInput(
	input map[string]any,
) (projectID, elementType, name string, contextLines int, err error)

codeContextParams holds parameters for code context requests ParseCodeContextInput parses and validates input for code context requests

func (*Server) ReadFileContext

func (s *Server) ReadFileContext(filePath string, targetLine, contextLines int) (string, error)

ReadFileContext reads lines around a specific line number in a file

func (*Server) Start

func (s *Server) Start(_ context.Context) error

Start starts the MCP server

type ServiceAdapter

type ServiceAdapter interface {
	// Parse operations
	ParseProject(ctx context.Context, projectPath string) (*parser.ParseResult, error)

	// Analyze operations
	AnalyzeProject(ctx context.Context, projectID core.ID, files []*parser.FileInfo) (*analyzer.AnalysisReport, error)

	// Graph operations
	InitializeProject(ctx context.Context, project *core.Project) error
	BuildAnalysisResult(
		ctx context.Context,
		projectID core.ID,
		parseResult *parser.ParseResult,
		analysisReport *analyzer.AnalysisReport,
	) (*core.AnalysisResult, error)
	ImportAnalysisResult(ctx context.Context, result *core.AnalysisResult) (*graph.ProjectGraph, error)
	GetProjectStatistics(ctx context.Context, projectID core.ID) (*graph.ProjectStatistics, error)
	ExecuteQuery(ctx context.Context, query string, params map[string]any) ([]map[string]any, error)

	// Project management operations
	ListProjects(ctx context.Context) ([]core.Project, error)
	ValidateProject(ctx context.Context, projectID core.ID) (bool, error)
	ClearProject(ctx context.Context, projectID core.ID) error
}

ServiceAdapter provides a unified interface for MCP operations

func NewServiceAdapter

func NewServiceAdapter(
	driver neo4j.DriverWithContext,
	graphService graph.Service,
	parserService parser.Parser,
	analyzerService analyzer.Analyzer,
) ServiceAdapter

NewServiceAdapter creates a new service adapter

type TestCoverage

type TestCoverage struct {
	Percentage   float64          `json:"percentage"`
	CoveredLines int              `json:"covered_lines"`
	TotalLines   int              `json:"total_lines"`
	TestFiles    []map[string]any `json:"test_files"`
}

TestCoverage represents test coverage information

type ToolResponse

type ToolResponse struct {
	Content []any `json:"content"`
}

ToolResponse represents a response from a tool

Jump to

Keyboard shortcuts

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