register_style_convention
Define and store coding style conventions for consistency across projects. Specify name, description, language, examples, and metadata to standardize code formatting practices.
Instructions
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
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | ||
| examples | No | ||
| language | No | ||
| metadata | No | ||
| name | Yes |
Implementation Reference
- sourcesage/mcp_server.py:153-182 (handler)The handler function decorated as an MCP tool that registers a style convention by calling KnowledgeGraph.add_style_convention and saves the knowledge graph if a storage path is configured.@self.mcp.tool() def register_style_convention( name: str, description: str, language: str | None = None, examples: list[str] | None = None, metadata: dict[str, Any] | None = None, ) -> str: """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 """ convention_id = self.knowledge.add_style_convention( name=name, description=description, language=language, examples=examples, metadata=metadata, ) # Save knowledge if storage path is set if self.storage_path: self.knowledge.save_to_file(self.storage_path) return f"Style convention registered with ID: {convention_id}"
- sourcesage/knowledge.py:77-95 (schema)Dataclass defining the structure and fields for StyleConvention objects stored in the knowledge graph.class StyleConvention: """A coding style convention identified in the codebase.""" # Basic identification convention_id: str name: str description: str # Convention details language: str | None = None examples: list[str] = field(default_factory=list) # Metadata metadata: dict[str, Any] = field(default_factory=dict) # Timestamps created_at: float = field(default_factory=time.time) updated_at: float = field(default_factory=time.time)
- sourcesage/knowledge.py:382-414 (helper)KnowledgeGraph method that implements the core logic for adding a style convention to the graph by instantiating a StyleConvention and storing it in self.style_conventions.def add_style_convention( self, name: str, description: str, language: str | None = None, examples: list[str] | None = None, metadata: dict[str, Any] | None = None, ) -> str: """Add a style convention to the knowledge graph. Args: name: The name of the convention description: Description of the convention language: The programming language examples: Examples of the convention metadata: Additional metadata Returns: The ID of the new convention """ convention_id = self._generate_id("convention") convention = StyleConvention( convention_id=convention_id, name=name, description=description, language=language, examples=examples or [], metadata=metadata or {}, ) self.style_conventions[convention_id] = convention return convention_id
- sourcesage/mcp_server.py:152-152 (registration)The @self.mcp.tool() decorator registers the register_style_convention function as an MCP tool within the _setup_tools method.# Style convention registration tool