mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-04 08:13:37 +08:00
MCP server that indexes codebases into a queryable knowledge graph. Single Go binary, SQLite storage, 12 languages via tree-sitter. Features: call graph, cross-service HTTP linking, dead code detection, route nodes, Cypher queries, incremental reindex, JSON config scanning.
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
func (s *Server) handleListProjects(_ context.Context, _ *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
projects, err := s.store.ListProjects()
|
|
if err != nil {
|
|
return errResult(fmt.Sprintf("list projects: %v", err)), nil
|
|
}
|
|
|
|
type projectInfo struct {
|
|
Name string `json:"name"`
|
|
RootPath string `json:"root_path"`
|
|
IndexedAt string `json:"indexed_at"`
|
|
Nodes int `json:"nodes"`
|
|
Edges int `json:"edges"`
|
|
}
|
|
|
|
result := make([]projectInfo, 0, len(projects))
|
|
for _, p := range projects {
|
|
nc, _ := s.store.CountNodes(p.Name)
|
|
ec, _ := s.store.CountEdges(p.Name)
|
|
result = append(result, projectInfo{
|
|
Name: p.Name,
|
|
RootPath: p.RootPath,
|
|
IndexedAt: p.IndexedAt,
|
|
Nodes: nc,
|
|
Edges: ec,
|
|
})
|
|
}
|
|
|
|
return jsonResult(result), nil
|
|
}
|
|
|
|
func (s *Server) handleDeleteProject(_ context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
args, err := parseArgs(req)
|
|
if err != nil {
|
|
return errResult(err.Error()), nil
|
|
}
|
|
|
|
name := getStringArg(args, "project_name")
|
|
if name == "" {
|
|
return errResult("project_name is required"), nil
|
|
}
|
|
|
|
// Verify project exists
|
|
proj, err := s.store.GetProject(name)
|
|
if err != nil || proj == nil {
|
|
return errResult(fmt.Sprintf("project not found: %s", name)), nil
|
|
}
|
|
|
|
if err := s.store.DeleteProject(name); err != nil {
|
|
return errResult(fmt.Sprintf("delete failed: %v", err)), nil
|
|
}
|
|
|
|
return jsonResult(map[string]any{
|
|
"deleted": name,
|
|
"status": "ok",
|
|
}), nil
|
|
}
|