Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayhack committed Feb 25, 2025
1 parent c43a710 commit 3b07cb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 12 additions & 2 deletions codegen-examples/examples/codegen-mcp-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,17 @@ def sync_wrapper():
state.codemod_tasks[name] = {"task": task, "name": name, "description": description, "language": language, "started_at": loop.time()}

# Return immediately
return {"status": "initiated", "message": f"Codemod '{name}' creation initiated. Use view_codemods to check status."}
return {
"status": "initiated",
"message": f"""
Codemod '{name}' creation initiated.
Next steps:
- Use `view_codemods` tool to check status
- Use `run_codemod` tool to run the codemod. Important! Use this tool instead of directly executing the codemod file - this ensures it uses a properly-parsed codebase.
- Use `reset` tool to revert to the current state of the codebase if you need to make modifications to the codemod itself.
""",
}


@mcp.tool(name="view_codemods", description="View all available codemods and their creation status")
Expand Down Expand Up @@ -336,7 +346,7 @@ async def view_codemods() -> Dict[str, Any]:
if codemod_dir.is_dir():
codemod_file = codemod_dir / f"{codemod_dir.name}.py"
if codemod_file.exists():
result["available_codemods"].append({"name": codemod_dir.name, "path": str(codemod_file)})
result["available_codemods"].append({"name": codemod_dir.name, "path": str(codemod_file), "run_with": f"run_codemod('{codemod_dir.name}')"})

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

View workflow job for this annotation

GitHub Actions / mypy

error: "Collection[Any]" has no attribute "append" [attr-defined]
except Exception as e:
result["error"] = f"Error listing codemods: {str(e)}"

Expand Down
6 changes: 5 additions & 1 deletion src/codegen/cli/codemod/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


def convert_to_cli(input: str, language: str, name: str) -> str:
return f"""import codegen
return f"""
# Run this codemod using `codegen run {name}` OR the `run_codemod` MCP tool.
# Important: if you run this as a regular python file, you MUST run it such that
# the base directory './' is the base of your codebase, otherwise it will not work.
import codegen
from codegen import Codebase
Expand Down

0 comments on commit 3b07cb8

Please sign in to comment.