Skip to content

Commit 6a4bb89

Browse files
authored
Improve MCP tool descriptions
1 parent 612a3be commit 6a4bb89

File tree

1 file changed

+92
-11
lines changed

1 file changed

+92
-11
lines changed

app/mcp_tools.py

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,116 @@
1818

1919
@mcp.tool()
2020
async def generate(description: str, requirements: str) -> str:
21-
"""Generate a new Rust cargo project from the description and requirements"""
21+
"""
22+
Generate a new Rust cargo project from the description and requirements. The input arguments are
2223
23-
async with httpx.AsyncClient() as client:
24-
response = await client.post(f"{API_BASE_URL}/generate-sync", json={'description': description, 'requirements': requirements})
25-
return response.text
24+
* description: a text string description of the generated Rust project.
25+
* requiremenets: functional requirements on what the generated Rust project.
26+
27+
The return value is a text string that contains all files in the project. Each file is seperated by a [filename: path_to_file] line. For example, a project that contains a Cargo.toml file and a src/main.rs file will be returned as the following.
28+
29+
[filename: Cargo.toml]
30+
[package]
31+
name = "a_command_line_calcu"
32+
version = "0.1.0"
33+
edition = "2021"
34+
35+
[dependencies]
36+
37+
38+
[filename: src/main.rs]
39+
fn main() {
40+
println!("Hello, world!");
41+
}
42+
43+
"""
44+
45+
async with httpx.AsyncClient(timeout=60.0) as client:
46+
try:
47+
response = await client.post(f"{API_BASE_URL}/generate-sync", json={'description': description, 'requirements': requirements})
48+
response.raise_for_status()
49+
return response.text
50+
except httpx.HTTPError as e:
51+
print(f"HTTP error occurred: {e}")
52+
return f"Error trying to generate a Rust project: {str(e)}"
2653

2754
@mcp.tool()
2855
async def compile_and_fix(code: str, description: str = "A Rust project", max_attempts: int = 3) -> str:
29-
"""Compile a Rust cargo project and fix any compiler errors"""
56+
"""
57+
Compile a Rust cargo project and fix any compiler errors.
58+
59+
The argument `code` is a text string that contains all files in the project. Each file is seperated by a [filename: path_to_file] line. For example, a project that contains a Cargo.toml file and a src/main.rs file will be returned as the following.
60+
61+
[filename: Cargo.toml]
62+
[package]
63+
name = "a_command_line_calcu"
64+
version = "0.1.0"
65+
edition = "2021"
3066
67+
[dependencies]
68+
69+
70+
[filename: src/main.rs]
71+
fn main() {
72+
println!("Hello, world!");
73+
}
74+
75+
The return value is also a text string that contains all files in the project. It is in the same format as the input `code` argument.
76+
"""
3177
async with httpx.AsyncClient(timeout=60.0) as client:
3278
try:
3379
response = await client.post(
3480
f"{API_BASE_URL}/compile-and-fix",
3581
json={'code': code, 'description': description, 'max_attempts': max_attempts}
3682
)
3783
response.raise_for_status()
38-
return response.text
84+
85+
resp_json = json.loads(response.text)
86+
if "combined_text" in resp_json:
87+
return ["combined_text"]
88+
else:
89+
return "Cannot fix the Rust compiler error."
90+
# return response.text
3991
except httpx.HTTPError as e:
4092
print(f"HTTP error occurred: {e}")
41-
return f"Error calling compile-and-fix API: {str(e)}"
93+
return f"Error trying to fixing the Rust compiler error: {str(e)}"
4294

4395
@mcp.tool()
4496
async def compile(code: str) -> str:
45-
"""Compile a Rust cargo project"""
97+
"""
98+
Compile a Rust cargo project and return the compiler output.
99+
100+
The argument `code` is a text string that contains all files in the project. Each file is seperated by a [filename: path_to_file] line. For example, a project that contains a Cargo.toml file and a src/main.rs file will be returned as the following.
101+
102+
[filename: Cargo.toml]
103+
[package]
104+
name = "a_command_line_calcu"
105+
version = "0.1.0"
106+
edition = "2021"
107+
108+
[dependencies]
46109
47-
async with httpx.AsyncClient() as client:
48-
response = await client.post(f"{API_BASE_URL}/compile", json={'code': code})
49-
return response.text
110+
111+
[filename: src/main.rs]
112+
fn main() {
113+
println!("Hello, world!");
114+
}
115+
116+
The return value is a text string that contains the Rust compiler output.
117+
"""
118+
async with httpx.AsyncClient(timeout=60.0) as client:
119+
try:
120+
response = await client.post(f"{API_BASE_URL}/compile", json={'code': code})
121+
response.raise_for_status()
122+
123+
resp_json = json.loads(response.text)
124+
if "build_output" in resp_json:
125+
return ["build_output"]
126+
else:
127+
return "Rust compiler error."
128+
except httpx.HTTPError as e:
129+
print(f"HTTP error occurred: {e}")
130+
return f"Rust compiler error: {str(e)}"
50131

51132
if __name__ == "__main__":
52133
# Use transport from environment variable or default to stdio

0 commit comments

Comments
 (0)