-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmcp_server.py
More file actions
65 lines (53 loc) · 2.3 KB
/
mcp_server.py
File metadata and controls
65 lines (53 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
from typing import Any
import httpx
from mcp.server.fastmcp import FastMCP
# Initialize FastMCP server
mcp = FastMCP("zkvm-nexus-server")
# Constants
ZKVM_API_ENDPOINT = "http://127.0.0.1:8080/package"
@mcp.tool()
async def create_zkvm_proof(code: str) -> str:
"""Create a Nexus zkVM proof from Rust code to verify correct execution.
The Nexus zkVM (Zero-Knowledge Virtual Machine) provides cryptographic proofs that
a given Rust code snippet executes correctly, without revealing the execution details.
Requirements:
- Code must be no_std Rust compatible
- Do not use any imports
- The snippet will be placed inside a main function, so write code accordingly
- Use an assert statement to verify the result of the code
- Do NOT use any file system operations, networking, environment variables or any other operations that are part of the standard library. We are in a no_std environment.
- Do NOT pass in a function, just the snippet of code that should be inserted into a main function.
- Do NOT use any print statements, we are in a no_std environment.
```rust
let x:u128 = 1322;
let result:u128 = x * x * x * x;
assert_eq!(result, 3054399363856);
```
Args:
code: Valid no_std Rust code to be processed by the zkVM. Include all imports in the snippet.
Returns:
Response from the zkVM server, including proof details or error messages.
"""
headers = {
"Content-Type": "text/plain"
}
async with httpx.AsyncClient() as client:
try:
response = await client.post(
ZKVM_API_ENDPOINT,
content=code,
headers=headers,
timeout=60.0
)
response.raise_for_status()
return f"Successfully created zkVM proof. Response: {response.text}"
except httpx.HTTPStatusError as e:
return f"Error creating zkVM proof: HTTP {e.response.status_code} - {e.response.text}"
except httpx.RequestError as e:
return f"Error creating zkVM proof: {str(e)}"
except Exception as e:
return f"Unexpected error creating zkVM proof: {str(e)}"
if __name__ == "__main__":
# Initialize and run the server
mcp.run(transport='stdio')