diff --git a/.github/workflows/shared/mcp/codebase-memory-mcp.md b/.github/workflows/shared/mcp/codebase-memory-mcp.md new file mode 100644 index 00000000000..45c6f7e230b --- /dev/null +++ b/.github/workflows/shared/mcp/codebase-memory-mcp.md @@ -0,0 +1,164 @@ +--- +# Codebase Memory MCP — Structural Code Intelligence +# Wraps the codebase-memory-mcp server for fast code-graph queries, +# semantic search, and architecture analysis across 159 languages. +# The knowledge-graph index is stored in cache-memory so it survives +# between workflow runs; only incremental re-indexing is needed after that. +# +# See: https://github.com/DeusData/codebase-memory-mcp +# +# Usage: +# network: +# allowed: +# - node # Required for npm install -g codebase-memory-mcp +# tools: +# cache-memory: true # REQUIRED: already set by this import +# imports: +# - shared/mcp/codebase-memory-mcp.md + +tools: + cache-memory: true + +mcp-servers: + codebase-memory: + command: "codebase-memory-mcp" + args: [] + allowed: + - index_repository + - index_status + - list_projects + - search_graph + - trace_path + - detect_changes + - query_graph + - get_graph_schema + - get_code_snippet + - get_architecture + - search_code + - ingest_traces + +steps: + - name: Install codebase-memory-mcp + run: | + npm install -g codebase-memory-mcp@0.7.0 --ignore-scripts + # Explicitly run the binary-download postinstall after reviewing it above. + node "$(npm root -g)/codebase-memory-mcp/install.js" + + - name: Set up codebase-memory index cache + run: | + # Symlink ~/.cache/codebase-memory-mcp into cache-memory so the SQLite + # knowledge-graph index persists automatically across workflow runs. + mkdir -p /tmp/gh-aw/cache-memory/codebase-memory-mcp-store + mkdir -p ~/.cache + + if [ ! -e ~/.cache/codebase-memory-mcp ]; then + ln -s /tmp/gh-aw/cache-memory/codebase-memory-mcp-store ~/.cache/codebase-memory-mcp + echo "🔗 Created ~/.cache/codebase-memory-mcp → cache-memory/codebase-memory-mcp-store" + elif [ -d ~/.cache/codebase-memory-mcp ] && [ ! -L ~/.cache/codebase-memory-mcp ]; then + # Plain directory present (e.g. first run after adding this import) — migrate + if ! cp -r ~/.cache/codebase-memory-mcp/. /tmp/gh-aw/cache-memory/codebase-memory-mcp-store/ 2>&1; then + echo "warning: migration copy failed; the existing store may be incomplete. Starting fresh." >&2 + fi + rm -rf ~/.cache/codebase-memory-mcp + ln -s /tmp/gh-aw/cache-memory/codebase-memory-mcp-store ~/.cache/codebase-memory-mcp + echo "🔗 Migrated existing store → cache-memory/codebase-memory-mcp-store" + else + echo "✅ ~/.cache/codebase-memory-mcp already linked to cache-memory store" + fi + + - name: Index repository (incremental) + run: | + # Index or incrementally update the knowledge graph. + # On the first run a full graph is built; subsequent runs detect the + # existing store and only re-index changed files (git-diff-driven). + echo "Indexing ${GITHUB_WORKSPACE}..." + if ! codebase-memory-mcp cli index_repository "{\"repo_path\": \"${GITHUB_WORKSPACE}\"}" 2>&1; then + echo "error: index_repository failed — check the output above for details." >&2 + exit 1 + fi + # index_status is best-effort: the server may not yet have flushed all + # metadata, so a non-zero exit here is not a fatal condition. + codebase-memory-mcp cli index_status "{\"repo_path\": \"${GITHUB_WORKSPACE}\"}" 2>&1 || \ + echo "warning: index_status returned a non-zero exit code (non-fatal)" + echo "✅ Codebase memory index ready" +--- + +