MCP Tools in Codebase-Memory-MCP: 15+ Graph-Based Utilities for LLM Coding Assistants

The DeusData/codebase-memory-mcp server exposes 15+ JSON-RPC MCP tools that enable LLM agents to perform structural code queries, impact analysis, and semantic search over a persistent SQLite-backed knowledge graph.

The DeusData/codebase-memory-mcp repository implements a specialized MCP (Model Context Protocol) server that transforms codebases into queryable knowledge graphs. These MCP tools provide LLM-powered coding assistants with programmatic access to call graphs, architecture summaries, and semantic code relationships through a standardized JSON-RPC interface defined in src/mcp/mcp.c.

Structural Query MCP Tools

search_graph: Pattern-Based Symbol Discovery

The search_graph tool performs structural queries over the knowledge graph using regex name patterns, label filters, degree limits, and file scoping. According to the source implementation in src/mcp/mcp.c, this tool indexes every function, class, and module as nodes with typed relationships.

Typical applications:

  • Find all functions matching naming conventions like .*Handler.*
  • Locate definitions of specific classes across language boundaries
  • Enumerate public APIs by filtering for EXPORT edges
codebase-memory-mcp cli search_graph '{"project":"my-project","label":"Function","name_pattern":".*Handler.*"}'

trace_call_path and trace_path: Execution Flow Analysis

These tools walk the CALLS or IMPORTS edge sets forward or backward with configurable depth limits. The implementation traverses the graph stored in the SQLite backend to reconstruct execution chains.

Typical applications:

  • Track execution flow from an entry point to downstream functions
  • Debug call-chain regressions by identifying which services invoke a given endpoint
  • Verify reachability between components
codebase-memory-mcp cli trace_call_path '{"qualified_name":"cmd.Root.Execute","direction":"both","depth":5}'

get_architecture: System Composition Overview

The get_architecture tool returns a high-level summary including languages, packages, modules, routes, and clusters in a single JSON payload. This aggregates data from the graph's metadata nodes built during the tree-sitter AST parsing phase.

Typical applications:

  • Produce architecture diagrams programmatically
  • Identify technology stack composition across polyglot repositories
  • Detect boundaries between monolithic and micro-service components
codebase-memory-mcp cli get_architecture '{"project":"my-project"}'

Advanced Query and Retrieval MCP Tools

query_graph: Cypher-Like Traversal

The query_graph tool exposes a Cypher-like query language using MATCH … RETURN … syntax for arbitrary graph traversals. This provides flexible access to the underlying graph structure beyond the pre-defined tool interfaces.

Typical applications:

  • Write custom analytics queries (e.g., "all functions that call a deprecated API")
  • Explore cross-repository relationships
  • Generate custom metrics for code quality dashboards

get_code_snippet: Source Text Retrieval

This tool retrieves source text for qualified symbols (functions, classes, methods) with optional context lines. It maps graph nodes back to their original file offsets in the indexed repository.

Typical applications:

  • Show exact implementations when an LLM asks "how is X implemented?"
  • Embed verified code snippets in documentation
  • Create on-demand examples for refactoring discussions
codebase-memory-mcp cli get_code_snippet '{"qualified_name":"handlers.UserService.Create","context_lines":5}'

search_code: Full-Text Search with Graph Filters

The search_code tool combines BM25 full-text search over indexed files with graph-augmented filters. Unlike search_graph, this operates on literal source text rather than structural symbols.

Typical applications:

  • Locate configuration values across multiple files
  • Perform grep-like searches that respect module boundaries
  • Find string literals and comments

Using Nomic embeddings, semantic_query performs vector-based similarity search over the embedded code vocabulary. This enables finding conceptually related code across different languages and naming conventions.

Typical applications:

  • Find semantically related functions across languages
  • Suggest refactoring candidates by identifying duplicated logic
  • Discover similar prompt helpers or utility patterns
codebase-memory-mcp cli semantic_query '["duplicate","clone","copy"]'

Change Management and Impact Analysis MCP Tools

detect_changes: Git Diff Impact Mapping

The detect_changes tool maps uncommitted or staged Git diffs onto affected symbols, annotating risk levels (high/medium/low) based on call-graph distance from entry points. This is implemented by correlating line-based diffs with the graph's source-location indexing.

Typical applications:

  • Perform impact analysis before submitting pull requests
  • Auto-suggest test suites based on affected symbol reachability
  • Highlight potentially breaking changes for reviewer prioritization
codebase-memory-mcp cli detect_changes '' | jq -r '.impacted_symbols[] | .qualified_name'

manage_adr: Architecture Decision Records

This CRUD tool manages Architecture Decision Records (ADRs) stored as nodes in the graph. It keeps design rationale synchronized with the code structure by linking ADRs to relevant modules and services.

Typical applications:

  • Record decisions directly from agent conversations
  • Retrieve contextual ADRs when modifying affected code
  • Update status of technical debt items
codebase-memory-mcp cli manage_adr '{"action":"create","id":"ADR-007","title":"Migrate to GRPC","body":"..."}'

Specialized Analysis MCP Tools

detect_dead_code: Orphan Symbol Identification

Exposed via search_graph with zero CALLS edge constraints, this utility finds symbols with no incoming call edges (excluding known entry points). The scripts/smoke-invariants.sh test harness validates this against the canonical tool list.

Typical applications:

  • Clean up unused utility functions
  • Shrink binary size by identifying unreachable code
  • Enforce "no-orphan" policies in CI pipelines

Accessible via search_graph with edge type HTTP_CALLS, this tool links HTTP route definitions to their call-sites across service boundaries.

Typical applications:

  • Verify that every endpoint is exercised by at least one client
  • Map client-server contracts for API documentation generation
  • Identify orphaned API routes

get_louvain_communities: Module Detection

Implemented internally and exposed via query_graph, this tool runs community detection algorithms on CALLS edges to surface functional modules using the Louvain method.

Typical applications:

  • Suggest micro-service extraction boundaries
  • Identify cohesion clusters for refactoring targets
  • Visualize code organization beyond file structure

Implementation Architecture

All MCP methods share a common JSON-RPC 2.0 transport handled by the request dispatch logic in src/mcp/mcp.c. The server registers exactly 14 tools in the TOOLS[] array at line 503, though the full capability set exceeds 15 tools when including parameter variations and query-based access patterns.

The server builds a persistent SQLite-backed graph during indexing (converting tree-sitter AST output into nodes and edges), then serves these tools without any external runtime dependencies. Because every tool operates on the same canonical graph, agents can compose them in sequences: running detect_changes → trace_call_path on impacted symbols → get_code_snippet to propose updated implementations, all within a single conversational turn.

Documentation for these tools appears in the repository's README.md, with additional evaluation scenarios detailed in docs/EVALUATION_PLAN.md and npm-specific CLI documentation in pkg/npm/README.md.

Summary

  • 15+ graph-based MCP tools are implemented in src/mcp/mcp.c using JSON-RPC 2.0 transport
  • Core capabilities include structural search (search_graph), execution tracing (trace_call_path), and architecture overview (get_architecture)
  • Change detection (detect_changes) maps Git diffs to affected symbols with risk classification
  • Semantic search (semantic_query) uses Nomic embeddings for conceptual code discovery
  • All tools operate on a SQLite-backed knowledge graph built from tree-sitter AST parsing, requiring no external databases
  • Tools compose together enabling complex workflows like impact analysis followed by source retrieval

Frequently Asked Questions

What transport protocol do these MCP tools use?

The codebase-memory-mcp server implements JSON-RPC 2.0 as defined in src/mcp/mcp.c. All tools register in a central TOOLS[] array that handles request dispatch and response formatting.

How many MCP tools are available in the codebase?

The source defines 14 core tools in the TOOLS[] array, though the complete capability set includes 15+ tools when counting specialized query patterns (such as dead code detection via search_graph filters) and community detection algorithms exposed through query_graph.

Do these MCP tools require an external database or cloud service?

No. The server builds a persistent SQLite-backed graph during the indexing phase using tree-sitter AST analysis. Once indexed, all MCP tools operate locally against this graph without network dependencies, making the system suitable for air-gapped environments.

Can developers use these MCP tools outside of LLM agents?

Yes. While designed for LLM integration, every MCP tool is accessible via the bundled CLI. The pkg/npm/README.md documents the command-line interface, allowing developers to invoke codebase-memory-mcp cli <tool_name> directly in shell scripts or CI pipelines.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →