MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / _run_loop

Method _run_loop

src/codegraphcontext/server.py:705–791  ·  view source on GitHub ↗
(self, loop)

Source from the content-addressed store, hash-verified

703 warning_logger(f"Error during server shutdown: {exc}")
704
705 async def _run_loop(self, loop):
706 request_count = 0
707 while True:
708 try:
709 if request_count and request_count % 50 == 0:
710 self.job_manager.cleanup_old_jobs(max_age_hours=24)
711 # Read a request from the standard input.
712 line = await loop.run_in_executor(None, sys.stdin.readline)
713 if not line:
714 debug_logger("Client disconnected (EOF received). Shutting down.")
715 break
716
717 request = json.loads(line.strip())
718 method = request.get('method')
719 params = request.get('params', {})
720 request_id = request.get('id')
721 request_count += 1
722
723 response = {}
724 # Route the request based on the JSON-RPC method.
725 if method == 'initialize':
726 response = {
727 "jsonrpc": "2.0", "id": request_id,
728 "result": {
729 "protocolVersion": "2025-03-26",
730 "serverInfo": {
731 "name": "CodeGraphContext", "version": self._get_version(),
732 "instructionsAvailable": True
733 },
734 "capabilities": {"tools": {"listTools": True}},
735 "instructions": LLM_SYSTEM_PROMPT,
736 }
737 }
738 elif method == 'tools/list':
739 # Return the list of tools defined in _init_tools.
740 response = {
741 "jsonrpc": "2.0", "id": request_id,
742 "result": {"tools": list(self.tools.values())}
743 }
744 elif method == 'tools/call':
745 # Execute a tool call and return the result.
746 tool_name = params.get('name')
747 args = params.get('arguments', {})
748 result = await self.handle_tool_call(tool_name, args)
749 result = _strip_workspace_prefix(result)
750
751 if "error" in result:
752 response = {
753 "jsonrpc": "2.0", "id": request_id,
754 "error": {"code": -32000, "message": "Tool execution error", "data": result}
755 }
756 else:
757 response_text = encode_response(result)
758 response_text = _apply_response_token_limit(tool_name, response_text)
759 response = {
760 "jsonrpc": "2.0", "id": request_id,
761 "result": {"content": [{"type": "text", "text": response_text}]}
762 }

Callers 1

runMethod · 0.95

Calls 10

_get_versionMethod · 0.95
handle_tool_callMethod · 0.95
debug_loggerFunction · 0.90
error_loggerFunction · 0.90
_strip_workspace_prefixFunction · 0.85
encode_responseFunction · 0.85
cleanup_old_jobsMethod · 0.80
valuesMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected