SourceSage MCP server

Maintains a persistent knowledge graph of code entities, relationships, patterns, and style conventions with hierarchical compression for efficient code memory management across sessions.
Back to servers
Setup instructions
Provider
Sarath Sadasivan Pillai
Release date
Mar 24, 2025
Language
Python
Stats
5 stars

This MCP server efficiently memorizes and retrieves key aspects of your codebase including logic, style, and standards through a knowledge graph structure. SourceSage works with any programming language the LLM understands and optimizes for token efficiency while enabling incremental updates and fast retrieval.

Installation

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

# Install the package
pip install -e .

Usage

Running the MCP Server

You can run the SourceSage server using either of these methods:

# Run the server after installation
sourcesage

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

Connecting to Claude for Desktop

  1. Open Claude for Desktop
  2. Go to Settings > Developer > Edit Config
  3. Add the following to your claude_desktop_config.json:

If you've installed the package:

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

If you're running from a local directory without installing:

{
  "sourcesage": {
      "command": "uv", 
      "args": [
        "--directory",
        "/path/to/sourcesage",
        "run",
        "main.py"
      ]
    },
}
  1. Restart Claude for Desktop

Available Tools

SourceSage provides the following MCP tools that Claude can use to analyze and store information about your code:

register_entity

Register a code entity in the knowledge graph

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

register_relationship

Register a relationship between entities

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

register_pattern

Register a code 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

register_style_convention

Register a coding 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

add_entity_observation

Add an observation to an entity

Input:
  - entity_name: Name of the entity
  - observation: Observation to add
Output: Confirmation message

query_entities

Query entities in the knowledge graph

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

get_entity_details

Get detailed information about an entity

Input:
  - entity_name: Name of the entity
Output: Detailed information about the entity

query_patterns

Query code patterns in the knowledge graph

Input:
  - language: Filter by programming language (optional)
  - pattern_name: Filter by pattern name (optional)
Output: List of matching patterns

query_style_conventions

Query coding style conventions

Input:
  - language: Filter by programming language (optional)
  - convention_name: Filter by convention name (optional)
Output: List of matching style conventions

get_knowledge_statistics

Get statistics about the knowledge graph

Input: None
Output: Statistics about the knowledge graph

clear_knowledge

Clear all knowledge from the graph

Input: None
Output: Confirmation message

Example Workflow with Claude

Here's how to use SourceSage with Claude:

  1. Analyze Code: Ask Claude to analyze your code files

    "Please analyze this Python file and register the key entities and relationships."
    
  2. Register Entities: Claude will use the register_entity tool to store code entities

    "I'll register the main class in this file."
    
  3. Register Relationships: Claude will use the register_relationship tool to store relationships

    "I'll register the inheritance relationship between these classes."
    
  4. Query Knowledge: Later, ask Claude about your codebase

    "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. Get Coding Patterns: Ask Claude about coding patterns

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

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "sourcesage" '{"command":"sourcesage","args":[]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later