Skip to content

fix: make the codebase parse non-blocking; #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions codegen-examples/examples/codegen-mcp-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
class CodebaseState:
"""Class to manage codebase state and parsing."""

parse_task: Optional[asyncio.Task] = None
parse_task: Optional[asyncio.Future] = None
parsed_codebase: Optional[Codebase] = None
codebase_path: Optional[str] = None
log_buffer: List[str] = field(default_factory=list)

async def parse(self, path: str) -> Codebase:
"""Parse the codebase at the given path."""
codebase = Codebase(path)

Check failure on line 19 in codegen-examples/examples/codegen-mcp-server/server.py

View workflow job for this annotation

GitHub Actions / mypy

error: Need type annotation for "codebase" [var-annotated]
self.parsed_codebase = codebase
self.codebase_path = path
return codebase

def reset(self) -> None:
Expand Down Expand Up @@ -46,7 +48,7 @@
@mcp.tool(name="parse_codebase", description="Initiate codebase parsing")
async def parse_codebase(codebase_path: Annotated[str, "path to the codebase to be parsed"]) -> Dict[str, str]:
if not state.parse_task or state.parse_task.done():
state.parse_task = asyncio.create_task(state.parse(codebase_path))
state.parse_task = asyncio.get_event_loop().run_in_executor(None, lambda: state.parse(codebase_path))
return {"message": "Codebase parsing initiated, this may take some time depending on the size of the codebase. Use the `check_parsing_status` tool to check if the parse has completed."}
return {"message": "Codebase is already being parsed."}

Expand Down Expand Up @@ -86,7 +88,7 @@
print("starting codegen-mcp-server")
run = mcp.run_stdio_async()
print("codegen-mcp-server started")
asyncio.run(run)
asyncio.get_event_loop().run_until_complete(run)


if __name__ == "__main__":
Expand Down
Loading