Skip to main content
Glama

SourceSage: LLM のための効率的なコードメモリ

SourceSageは、コードベースの主要な側面(ロジック、スタイル、標準)を効率的に記憶し、動的な更新と高速な取得を可能にするMCP(Model Context Protocol)サーバーです。LLMの複数言語にわたるコード理解を活用し、言語に依存しないように設計されています。

特徴

  • 言語に依存しない: LLMが理解できるあらゆるプログラミング言語で動作します

  • ナレッジグラフストレージ: コードエンティティ、関係、パターン、スタイル規則を効率的に保存します

  • LLM駆動型分析:LLMを利用してコードを分析し、洞察を提供する

  • トークン効率の高いストレージ: メモリ容量を最大化しながらトークンの使用を最小限に抑えるように最適化します。

  • 増分更新:冗長ストレージなしでコードが変更されたときに知識を更新します

  • 高速検索:関連情報を迅速かつ正確に検索できます

Related MCP server: Logseq MCP Tools

仕組み

SourceSage は次のような斬新なアプローチを採用しています:

  1. LLMはコードファイル(あらゆる言語)を分析します

  2. LLMはMCPツールを使用して、エンティティ、関係、パターン、およびスタイル規則を登録します。

  3. SourceSageはこの知識をトークン効率の良いグラフ構造に保存する

  4. LLMは必要に応じてこの知識を後で照会できる。

このアプローチは、LLM の固有の言語理解を活用しながら、MCP サーバーを効率的なメモリ管理に重点を置きます。

インストール

# Clone the repository
git clone https://github.com/yourusername/sourcesage.git
cd sourcesage

# Install the package
pip install -e .

使用法

MCPサーバーの実行

# Run the server
sourcesage

# Or run directly from the repository
python -m sourcesage.mcp_server

Claude for Desktop への接続

  1. デスクトップ版Claudeを開く

  2. 設定 > 開発者 > 設定の編集に移動します

  3. claude_desktop_config.jsonに以下を追加します。

パッケージをインストールした場合:

{
  "mcpServers": {
    "sourcesage": {
      "command": "sourcesage",
      "args": []
    }
  }
}

インストールせずにローカル ディレクトリから実行している場合:

{
  "sourcesage": {
      "command": "uv", 
      "args": [
        "--directory",
        "/path/to/sourcesage",
        "run",
        "main.py"
      ]
    },
}
  1. デスクトップ版のClaudeを再起動

利用可能なツール

SourceSage は次の MCP ツールを提供します。

  1. register_entity : ナレッジグラフにコードエンティティを登録する

    Input:
      - name: Name of the entity (e.g., class name, function name)
      - entity_type: Type of entity (class, function, module, etc.)
      - summary: Brief description of the entity
      - signature: Entity signature (optional)
      - language: Programming language (optional)
      - observations: List of observations about the entity (optional)
      - metadata: Additional metadata (optional)
    Output: Confirmation message with entity ID
  2. register_relationship : エンティティ間の関係を登録する

    Input:
      - from_entity: Name of the source entity
      - to_entity: Name of the target entity
      - relationship_type: Type of relationship (calls, inherits, imports, etc.)
      - metadata: Additional metadata (optional)
    Output: Confirmation message with relationship ID
  3. register_pattern : コードパターンを登録する

    Input:
      - name: Name of the pattern
      - description: Description of the pattern
      - language: Programming language (optional)
      - example: Example code demonstrating the pattern (optional)
      - metadata: Additional metadata (optional)
    Output: Confirmation message with pattern ID
  4. register_style_convention : コーディングスタイル規約を登録する

    Input:
      - name: Name of the convention
      - description: Description of the convention
      - language: Programming language (optional)
      - examples: Example code snippets demonstrating the convention (optional)
      - metadata: Additional metadata (optional)
    Output: Confirmation message with convention ID
  5. add_entity_observation : エンティティに観測を追加する

    Input:
      - entity_name: Name of the entity
      - observation: Observation to add
    Output: Confirmation message
  6. query_entities : ナレッジグラフ内のクエリエンティティ

    Input:
      - entity_type: Filter by entity type (optional)
      - language: Filter by programming language (optional)
      - name_pattern: Filter by name pattern (regex, optional)
      - limit: Maximum number of results to return (optional)
    Output: List of matching entities
  7. get_entity_details : エンティティの詳細情報を取得する

    Input:
      - entity_name: Name of the entity
    Output: Detailed information about the entity
  8. query_patterns : ナレッジグラフ内のクエリコードパターン

    Input:
      - language: Filter by programming language (optional)
      - pattern_name: Filter by pattern name (optional)
    Output: List of matching patterns
  9. query_style_conventions : クエリコーディングスタイルの規約

    Input:
      - language: Filter by programming language (optional)
      - convention_name: Filter by convention name (optional)
    Output: List of matching style conventions
  10. get_knowledge_statistics : ナレッジグラフに関する統計情報を取得する

Input: None
Output: Statistics about the knowledge graph
  1. clear_knowledge : グラフからすべての知識をクリアします

Input: None
Output: Confirmation message

クロードによるワークフローの例

  1. コードの分析: Claude にコードファイルの分析を依頼します

    "Please analyze this Python file and register the key entities and relationships."
  2. エンティティの登録: Claudeはregister_entityツールを使用してコードエンティティを保存します。

    "I'll register the main class in this file."
  3. 関係の登録: Claudeはregister_relationshipツールを使用して関係を保存します

    "I'll register the inheritance relationship between these classes."
  4. クエリ知識: 後で、Claudeにコードベースについて質問します

    "What classes are defined in my codebase?"
    "Show me the details of the User class."
    "What's the relationship between the User and Profile classes?"
  5. コーディングパターンを入手する: コーディングパターンについてクロードに質問する

    "What design patterns are used in my codebase?"
    "Show me examples of the Factory pattern in my code."

どう違うのか

従来のコード分析ツールとは異なり、SourceSage は次のことを行います。

  1. LLMの理解を活用: LLMの能力を活用して言語間のコードセマンティクスを理解します

  2. 意味的知識を保存: 構文だけでなく意味と関係性に焦点を当てます

  3. 言語に依存しない: LLMが理解できるあらゆるプログラミング言語で動作します

  4. トークン効率を最適化: トークンの使用を最小限に抑える方法で知識を保存します

  5. LLMの機能とともに進化: LLMが進化するにつれて、コードの理解も向上します

貢献

貢献を歓迎します!お気軽にプルリクエストを送信してください。

ライセンス

このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細については LICENSE ファイルを参照してください。

Available Tools

13 tools
add_entity_observationC

Add an observation to an entity.

Args: entity_name: Name of the entity observation: Observation to add

Inputs: entity_name (required), observation (required).

clear_knowledgeA

Clear all knowledge from the graph.

Inputs: no named parameters.

dump_project_understandingA

Dump understanding of an entire project at once.

This tool provides a comprehensive dump of all knowledge related to a project, including all entities, relationships, patterns, and style conventions.

Args: project_path: Path to the project root directory include_observations: Whether to include detailed observations

Inputs: project_path (required), include_observations.

get_entity_detailsC

Get detailed information about an entity.

Args: entity_name: Name of the entity

Inputs: entity_name (required).

get_knowledge_statisticsC

Get statistics about the knowledge graph.

Inputs: no named parameters.

load_project_understandingB

Load understanding of an entire project at once.

This tool should be used by MCP clients to quickly get project understanding if available, instead of reading all the files individually. It loads all entities, relationships, patterns, and style conventions related to the project.

Args: project_path: Path to the project root directory

Inputs: project_path (required).

query_entitiesB

Query entities in the knowledge graph.

Args: entity_type: Filter by entity type (class, function, module, etc.) language: Filter by programming language name_pattern: Filter by name pattern (regex) limit: Maximum number of results to return

Inputs: entity_type, language, limit, name_pattern.

query_patternsB

Query code patterns in the knowledge graph.

Args: language: Filter by programming language pattern_name: Filter by pattern name

Inputs: language, pattern_name.

query_style_conventionsA

Query coding style conventions in the knowledge graph.

Args: language: Filter by programming language convention_name: Filter by convention name

Inputs: convention_name, language.

register_entityB

Register a code entity in the knowledge graph.

Args: name: Name of the entity (e.g., class name, function name) entity_type: Type of entity (class, function, module, etc.) summary: Brief description of the entity signature: Entity signature (e.g., function signature) language: Programming language observations: List of observations about the entity metadata: Additional metadata as key-value pairs

Inputs: entity_type (required), name (required), summary (required), language, +3 more.

register_patternB

Register a code pattern.

Args: name: Name of the pattern description: Description of the pattern language: Programming language example: Example code demonstrating the pattern metadata: Additional metadata as key-value pairs

Inputs: description (required), name (required), example, language, +1 more.

register_relationshipC

Register a relationship between entities.

Args: from_entity: Name of the source entity to_entity: Name of the target entity relationship_type: Type of relationship (calls, inherits, imports, etc.) metadata: Additional metadata as key-value pairs

Inputs: from_entity (required), relationship_type (required), to_entity (required), metadata.

register_style_conventionC

Register a coding style convention.

Args: name: Name of the convention description: Description of the convention language: Programming language examples: Example code snippets demonstrating the convention metadata: Additional metadata as key-value pairs

Inputs: description (required), name (required), examples, language, +1 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 13 tools

    Disambiguation4/5

    Most tools have distinct purposes focused on different aspects of knowledge graph management (entities, patterns, relationships, style conventions). However, there is some potential overlap between dump_project_understanding and load_project_understanding as both handle project-level data, though their descriptions clarify one is for output and the other for input.

    Naming Consistency5/5

    All tools follow a consistent snake_case naming pattern with clear verb_noun structure (e.g., add_entity_observation, get_entity_details, query_entities, register_entity). The naming is predictable and uniform across all 13 tools.

    Tool Count5/5

    With 13 tools, this is well-scoped for a knowledge graph server covering entities, patterns, relationships, and style conventions. Each tool serves a specific function in the CRUD/lifecycle operations, and none appear redundant or out of place.

    Completeness4/5

    The toolset provides comprehensive coverage for managing a knowledge graph, including registration, querying, and statistics. Minor gaps exist, such as no explicit update or delete operations for entities/patterns/relationships/conventions, but agents can work around this by re-registering or using clear_knowledge.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      A
      maintenance
      This is an MCP server for PostgREST. It allows LLMs perform database queries and operations on Postgres databases via PostgREST. This server works with both Supabase projects (which use PostgREST) and standalone PostgREST servers.
      2,128 npm
      3,017
      Apache 2.0
    • A
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that provides AI assistants with structured access to your Logseq knowledge graph, enabling retrieval, searching, analysis, and creation of content within your personal knowledge base.
      70
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      An MCP server that connects to a Swagger specification and helps an AI to build all the required models to generate a MCP server for that service.
      5
      167
      MIT