11from fastmcp import FastMCP
2+ from pathlib import Path
3+
4+ from tests .scripts .end_to_end_test_utilities import TestConfig , run_codeflash_command
25
36mcp = FastMCP (
47 name = "codeflash" ,
1114
1215@mcp .tool
1316def optimize_code (file : str , function : str ) -> str :
14- # config = TestConfig(
15- # file_path=pathlib.Path(file),
16- # function_name=function,
17- # test_framework="pytest",
18- # min_improvement_x=1.0,
19- # coverage_expectations=[
20- # CoverageExpectation(
21- # function_name=function, expected_coverage=100.0, expected_lines=[2, 3, 4, 5, 6, 7, 8, 9, 10]
22- # )
23- # ],
24- # )
25- # cwd = pathlib.Path("/Users/aseemsaxena/Downloads/codeflash_dev/codeflash/code_to_optimize") # TODO remove it
26- print (file , function )
27- return "the function is already optimal"
17+ # TODO ask for pr or no pr if successful
18+ config = TestConfig (
19+ file_path = Path (f"{ file } " ),
20+ function_name = f"{ function } " ,
21+ test_framework = "pytest" ,
22+ )
23+ cwd = Path (file ).resolve ().parent
24+ status = run_codeflash_command (cwd , config , expected_improvement_pct = 5 )
25+ if status :
26+ "Optimization Successful, file has been edited"
27+ else :
28+ return "Codeflash run did not meet expected requirements for testing, reverting file changes."
2829
2930
3031if __name__ == "__main__" :
3132 mcp .run (transport = "stdio" )
33+ # Optimize my codebase, the file is "/Users/codeflash/Downloads/codeflash-dev/codeflash/code_to_optimize/bubble_sort.py" and the function is "sorter"
0 commit comments