From ede344be5dc0f5828673cb919309721ec5c775d5 Mon Sep 17 00:00:00 2001 From: Igor Ilic <30923996+dexters1@users.noreply.github.com> Date: Wed, 19 Mar 2025 20:37:53 +0100 Subject: [PATCH] fix: Run mcp cognify and codify as background async task [COG-1647] (#655) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …t issues ## Description Resolve issue with MCP timeout by switching cognify and codify to run as background async tasks ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin ## Summary by CodeRabbit - **New Features** - Enhanced feedback messages now inform users when operations are running in the background, providing an estimated wait time of up to 4 minutes. --- cognee-mcp/src/server.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/cognee-mcp/src/server.py b/cognee-mcp/src/server.py index 0842d22fb..f830ceb5b 100755 --- a/cognee-mcp/src/server.py +++ b/cognee-mcp/src/server.py @@ -93,17 +93,29 @@ async def call_tools(name: str, arguments: dict) -> list[types.TextContent]: with open(os.devnull, "w") as fnull: with redirect_stdout(fnull), redirect_stderr(fnull): if name == "cognify": - await cognify( - text=arguments["text"], - graph_model_file=arguments.get("graph_model_file", None), - graph_model_name=arguments.get("graph_model_name", None), + asyncio.create_task( + cognify( + text=arguments["text"], + graph_model_file=arguments.get("graph_model_file"), + graph_model_name=arguments.get("graph_model_name"), + ) ) - return [types.TextContent(type="text", text="Ingested")] + return [ + types.TextContent( + type="text", + text="Background process launched due to MCP timeout limitations. Estimated completion time up to 4 minutes.", + ) + ] if name == "codify": - await codify(arguments.get("repo_path")) + asyncio.create_task(codify(arguments.get("repo_path"))) - return [types.TextContent(type="text", text="Indexed")] + return [ + types.TextContent( + type="text", + text="Background process launched due to MCP timeout limitations. Estimated completion time up to 4 minutes.", + ) + ] elif name == "search": search_results = await search( arguments["search_query"], arguments["search_type"]