MCP server to cache codebase as graph
What is sarathsp06 sourcesage
SourceSage: Efficient Code Memory for LLMs
SourceSage is an MCP (Model Context Protocol) server that efficiently memorizes key aspects of a codebase—logic, style, and standards—while allowing dynamic updates and fast retrieval. It's designed to be language-agnostic, leveraging the LLM's understanding of code across multiple languages.
Features
- Language Agnostic: Works with any programming language the LLM understands
- Knowledge Graph Storage: Efficiently stores code entities, relationships, patterns, and style conventions
- LLM-Driven Analysis: Relies on the LLM to analyze code and provide insights
- Token-Efficient Storage: Optimizes for minimal token usage while maximizing memory capacity
- Incremental Updates: Updates knowledge when code changes without redundant storage
- Fast Retrieval: Enables quick and accurate retrieval of relevant information
How It Works
SourceSage uses a novel approach where:
- The LLM analyzes code files (in any language)
- The LLM uses MCP tools to register entities, relationships, patterns, and style conventions
- SourceSage stores this knowledge in a token-efficient graph structure
- The LLM can later query this knowledge when needed
This approach leverages the LLM's inherent language understanding while focusing the MCP server on efficient memory management.
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
# Run the server
sourcesage
# Or run directly from the repository
python -m sourcesage.mcp_server
Connecting to Claude for Desktop
- Open Claude for Desktop
- Go to Settings > Developer > Edit Config
- 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"
]
},
}
- Restart Claude for Desktop
Available Tools
SourceSage provides the following MCP tools:
-
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
-
Analyze Code: Ask Claude to analyze your code files
"Please analyze this Python file and register the key entities and relationships."
-
Register Entities: Claude will use the register_entity tool to store code entities
"I'll register the main class in this file."
-
Register Relationships: Claude will use the register_relationship tool to store relationships
"I'll register the inheritance relationship between these classes."
-
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?"
-
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 It's Different
Unlike traditional code analysis tools, SourceSage:
- Leverages LLM Understanding: Uses the LLM's ability to understand code semantics across languages
- Stores Semantic Knowledge: Focuses on meaning and relationships, not just syntax
- Is Language Agnostic: Works with any programming language the LLM understands
- Optimizes for Token Efficiency: Stores knowledge in a way that minimizes token usage
- Evolves with LLM Capabilities: As LLMs improve, so does code understanding
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Leave a Comment
Frequently Asked Questions
What is MCP?
MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.
What are MCP Servers?
MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.
How do MCP Servers work?
MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.
Are MCP Servers secure?
Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.
Related MCP Servers
chrisdoc hevy mcp
sylphlab pdf reader mcp
An MCP server built with Node.js/TypeScript that allows AI agents to securely read PDF files (local or URL) and extract text, metadata, or page counts. Uses pdf-parse.
aashari mcp server atlassian bitbucket
Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MCP interface.
aashari mcp server atlassian confluence
Node.js/TypeScript MCP server for Atlassian Confluence. Provides tools enabling AI systems (LLMs) to list/get spaces & pages (content formatted as Markdown) and search via CQL. Connects AI seamlessly to Confluence knowledge bases using the standard MCP interface.
prisma prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
Zzzccs123 mcp sentry
mcp sentry for typescript sdk
zhuzhoulin dify mcp server
zhongmingyuan mcp my mac
zhixiaoqiang desktop image manager mcp
MCP 服务器,用于管理桌面图片、查看详情、压缩、移动等(完全让Trae实现)
zhixiaoqiang antd components mcp
An MCP service for Ant Design components query | 一个减少 Ant Design 组件代码生成幻觉的 MCP 服务,包含系统提示词、组件文档、API 文档、代码示例和更新日志查询
Submit Your MCP Server
Share your MCP server with the community
Submit Now