Skip to content

Commit 36c83b3

Browse files
committed
works without hardcoded, need to remove cwd line
1 parent 5439c2d commit 36c83b3

File tree

2 files changed

+74
-16
lines changed

2 files changed

+74
-16
lines changed

myclient.py

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,66 @@
1-
import asyncio
2-
from fastmcp import Client
1+
# import asyncio
2+
# from fastmcp import Client
3+
#
4+
# client = Client("myserver.py")
5+
#
6+
# async def call_tool(file: str, function: str)-> None:
7+
# async with client:
8+
# result = await client.call_tool("optimize_code", {"file": f"{file}", "function":f"{function}"})
9+
# print(result)
10+
#
11+
# asyncio.run(call_tool("Ford","Mustang"))
312

4-
client = Client("myserver.py")
513

6-
async def call_tool(file: str, function: str)-> None:
7-
async with client:
8-
result = await client.call_tool("optimize_code", {"file": f"{file}", "function":f"{function}"})
9-
print(result)
14+
import anthropic
15+
from rich import print
1016

11-
asyncio.run(call_tool("Ford","Mustang"))
17+
# Your server URL (replace with your actual URL)
18+
url = 'https://0de03d07f8b9.ngrok-free.app'
19+
20+
client = anthropic.Anthropic()
21+
22+
#file and fn names are hard coded for now
23+
response = client.beta.messages.create(
24+
model="claude-sonnet-4-20250514",
25+
max_tokens=1000,
26+
messages=[{"role": "user", "content": "Optimize my codebase, the file is \"/Users/codeflash/Downloads/codeflash-dev/codeflash/code_to_optimize/bubble_sort.py\" and the function is \"sorter\""}],
27+
mcp_servers=[
28+
{
29+
"type": "url",
30+
"url": f"{url}/mcp/",
31+
"name": "HelpfulAssistant",
32+
}
33+
],
34+
extra_headers={
35+
"anthropic-beta": "mcp-client-2025-04-04"
36+
}
37+
)
38+
39+
print(response.content)
40+
41+
42+
# import anthropic
43+
# from rich import print
44+
#
45+
# # Your server URL (replace with your actual URL)
46+
# url = 'https://0de03d07f8b9.ngrok-free.app'
47+
#
48+
# client = anthropic.Anthropic()
49+
#
50+
# response = client.beta.messages.create(
51+
# model="claude-sonnet-4-20250514",
52+
# max_tokens=1000,
53+
# messages=[{"role": "user", "content": "Roll a few dice!"}],
54+
# mcp_servers=[
55+
# {
56+
# "type": "url",
57+
# "url": f"{url}/mcp/",
58+
# "name": "Dice Roller",
59+
# }
60+
# ],
61+
# extra_headers={
62+
# "anthropic-beta": "mcp-client-2025-04-04"
63+
# }
64+
# )
65+
#
66+
# print(response.content)

myserver.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
import os
21
import pathlib
32

43
from fastmcp import FastMCP
54

65
from tests.scripts.end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codeflash_command
76

8-
mcp = FastMCP("My MCP Server")
7+
mcp = FastMCP(name="HelpfulAssistant",
8+
instructions="""
9+
This server provides code optimization tools.
10+
Call optimize_code(file, function) to optimize your code.
11+
""",)
912

1013
@mcp.tool
11-
def optimize_code(file: str, function: str) -> bool: #todo add file and function name as arguments
14+
def optimize_code(file: str, function: str) -> bool:
1215
config = TestConfig(
13-
file_path=pathlib.Path("/Users/codeflash/Downloads/codeflash-dev/codeflash/code_to_optimize/bubble_sort.py"),
14-
function_name="sorter",
16+
file_path=pathlib.Path(file),
17+
function_name=function,
1518
test_framework="pytest",
1619
min_improvement_x=1.0,
1720
coverage_expectations=[
1821
CoverageExpectation(
19-
function_name="sorter", expected_coverage=100.0, expected_lines=[2, 3, 4, 5, 6, 7, 8, 9, 10]
22+
function_name=function, expected_coverage=100.0, expected_lines=[2, 3, 4, 5, 6, 7, 8, 9, 10]
2023
)
2124
],
2225
)
23-
cwd = (pathlib.Path(__file__).parent/ "code_to_optimize").resolve()
26+
cwd = (pathlib.Path(__file__).parent/ "code_to_optimize").resolve() # todo remove it
2427
return run_codeflash_command(
2528
cwd, config, 100, ['print("codeflash stdout: Sorting list")', 'print(f"result: {arr}")']
2629
)
2730

2831
if __name__ == "__main__":
29-
mcp.run()
32+
mcp.run(transport="http", port=8000)

0 commit comments

Comments
 (0)