Skip to content

Commit 6a67768

Browse files
authored
Merge pull request #6 from juntao/patch-1
Improve MCP tool descriptions
2 parents 418863b + 65b5dce commit 6a67768

File tree

4 files changed

+133
-35
lines changed

4 files changed

+133
-35
lines changed

Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ RUN apt-get update && apt-get install -y curl build-essential && \
1010
ENV PATH="/root/.cargo/bin:${PATH}"
1111

1212
# Directly download and install OpenMCP from source to avoid binary compatibility issues
13-
RUN apt-get install -y git && \
14-
git clone https://github.com/decentralized-mcp/proxy.git && \
15-
cd proxy && \
16-
cargo build --release && \
17-
cp target/release/openmcp /usr/local/bin/ && \
18-
chmod +x /usr/local/bin/openmcp && \
19-
cd .. && \
20-
rm -rf proxy
13+
# RUN apt-get install -y git && \
14+
# git clone https://github.com/decentralized-mcp/proxy.git && \
15+
# cd proxy && \
16+
# cargo build --release && \
17+
# cp target/release/openmcp /usr/local/bin/ && \
18+
# chmod +x /usr/local/bin/openmcp && \
19+
# cd .. && \
20+
# rm -rf proxy
21+
22+
# Install openmcp proxy via the installer
23+
RUN curl -sSfL 'https://raw.githubusercontent.com/decentralized-mcp/proxy/refs/heads/master/install.sh' | bash
2124

2225
# Set working directory
2326
WORKDIR /app

README.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,13 @@ curl -X POST http://localhost:8000/compile \
146146

147147
```
148148
{
149-
"success":true,
150-
"files":["Cargo.toml","src/main.rs"],
151-
"build_output":"Build successful",
152-
"run_output":"Hello, World!\n"
149+
"success": true,
150+
"files": [
151+
"Cargo.toml",
152+
"src/main.rs"
153+
],
154+
"build_output": "Build successful",
155+
"run_output": "Hello, World!\n"
153156
}
154157
```
155158

@@ -182,17 +185,28 @@ curl -X POST http://localhost:8000/compile-and-fix \
182185
#### 📤 Response:
183186

184187
```
185-
[filename: Cargo.toml]
186-
[package]
187-
name = "hello_world"
188-
version = "0.1.0"
189-
edition = "2021"
190-
191-
[dependencies]
192-
193-
[filename: src/main.rs]
194-
fn main() {
195-
println!("Hello, World!"); // Missing closing parenthesis
188+
{
189+
"success": true,
190+
"attempts": [
191+
{
192+
"attempt": 1,
193+
"success": false,
194+
"output": " Compiling hello_world v0.1.0 (/tmp/tmpk_0n65md)\nerror: mismatched closing delimiter: `}`\n --> src/main.rs:2:13\n |\n1 | fn main() {\n | - closing delimiter possibly meant for this\n2 | println!(\"Hello, World!\" // Missing closing parenthesis\n | ^ unclosed delimiter\n3 | }\n | ^ mismatched closing delimiter\n\nerror: could not compile `hello_world` (bin \"hello_world\") due to 1 previous error\n"
195+
},
196+
{
197+
"attempt": 2,
198+
"success": true,
199+
"output": null
200+
}
201+
],
202+
"final_files": {
203+
"Cargo.toml": "[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]",
204+
"src/main.rs": "fn main() {\n println!(\"Hello, World!\");\n}"
205+
},
206+
"build_output": "Build successful",
207+
"run_output": "Hello, World!\n",
208+
"similar_project_used": false,
209+
"combined_text": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\");\n}"
196210
}
197211
```
198212

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

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424
environment:
2525
- API_HOST=api # Use service name within Docker network
2626
- API_PORT=8000
27-
- MCP_TRANSPORT=sse
27+
- MCP_TRANSPORT=stdio # We use openmcp to map the STDIO MCP server to SSE on our desired port
2828
depends_on:
2929
- api
3030

0 commit comments

Comments
 (0)