MCPcopy Index your code
hub / github.com/CodeGraphContext/CodeGraphContext / __init__

Method __init__

src/codegraphcontext/server.py:129–182  ·  view source on GitHub ↗

Initializes the MCP server and its components. Args: loop: The asyncio event loop to use. If not provided, it gets the current running loop or creates a new one. cwd: Working directory used for context resolution. Defaults to Path.

(self, loop=None, cwd: Path | None = None)

Source from the content-addressed store, hash-verified

127 """
128
129 def __init__(self, loop=None, cwd: Path | None = None):
130 """
131 Initializes the MCP server and its components.
132
133 Args:
134 loop: The asyncio event loop to use. If not provided, it gets the current
135 running loop or creates a new one.
136 cwd: Working directory used for context resolution. Defaults to Path.cwd().
137 """
138 self.cwd = (cwd or Path.cwd()).resolve()
139 self.discovered_child_contexts: List[dict] = []
140 self._context_note_pending = False
141 self.disabled_tools: Set[str] = set()
142
143 try:
144 ctx = resolve_context(cwd=self.cwd)
145 self.resolved_context = ctx
146
147 if ctx.database:
148 os.environ['CGC_RUNTIME_DB_TYPE'] = ctx.database
149
150 self.db_manager = get_database_manager(db_path=ctx.db_path)
151 self.db_manager.get_driver()
152
153 if not ctx.is_local:
154 try:
155 children = discover_child_contexts(self.cwd, max_depth=1)
156 if children:
157 self.discovered_child_contexts = [asdict(c) for c in children]
158 self._context_note_pending = True
159 except Exception:
160 pass
161 except ValueError as e:
162 raise ValueError(f"Database configuration error: {e}")
163
164 # Initialize managers for jobs and file watching.
165 self.job_manager = JobManager()
166
167 # Get the current event loop to pass to thread-sensitive components like the graph builder.
168 if loop is None:
169 try:
170 loop = asyncio.get_running_loop()
171 except RuntimeError:
172 loop = asyncio.new_event_loop()
173 asyncio.set_event_loop(loop)
174 self.loop = loop
175
176 # Initialize all the tool handlers, passing them the necessary managers and the event loop.
177 self.graph_builder = GraphBuilder(self.db_manager, self.job_manager, loop)
178 self.code_finder = CodeFinder(self.db_manager)
179 self.code_watcher = CodeWatcher(self.graph_builder, self.job_manager)
180
181 # Define the tool manifest that will be exposed to the AI assistant.
182 self._init_tools()
183
184 def _init_tools(self):
185 """

Callers

nothing calls this directly

Calls 10

_init_toolsMethod · 0.95
resolve_contextFunction · 0.85
get_database_managerFunction · 0.85
discover_child_contextsFunction · 0.85
JobManagerClass · 0.85
GraphBuilderClass · 0.85
CodeFinderClass · 0.85
CodeWatcherClass · 0.85
resolveMethod · 0.80
get_driverMethod · 0.45

Tested by

no test coverage detected