TOLK Compiler MCP Server
by lpq66
README.md
# TOLK Compiler MCP Server
An MCP (Model Context Protocol) server that wraps the [TON Tolk compiler](https://github.com/ton-blockchain/tolk-js), enabling AI agents to compile Tolk smart contracts directly.
**Bounty:** [ton-society/grants-and-bounties#1200](https://github.com/ton-society/grants-and-bounties/issues/1200) — $500
## What It Does
Give any AI agent the ability to compile TON smart contracts written in Tolk. The agent can write code, compile it, and get the resulting FIFT assembly and BOC bytecode — all without leaving the conversation.
## Tools
| Tool | Description |
|------|-------------|
| `get_compiler_version` | Returns the Tolk compiler version |
| `compile_tolk` | Compiles Tolk source → FIFT code + BOC bytecode |
| `get_stdlib_modules` | Lists available standard library modules |
### compile_tolk Parameters
| Param | Type | Default | Description |
|-------|------|---------|-------------|
| `source` | string | required | Tolk source code |
| `filename` | string | `main.tolk` | Entrypoint filename |
| `optimization_level` | int | 2 | 0-2, controls stack optimizer |
| `with_stack_comments` | bool | false | Include stack comments in FIFT |
| `with_src_line_comments` | bool | false | Include source line comments |
### Response (success)
```json
{
"status": "success",
"fift_code": "PROGRAM{ ... }END>c\n",
"code_boc_base64": "te6ccgEBAgEAGgAB...",
"code_hash_hex": "F30B38CAC72F065A...",
"tolk_version": "1.3.0"
}
```
### Response (error)
```json
{
"status": "error",
"error": "main.tolk:1:12: error: expected parameter list, got `{`"
}
```
## Example Usage
```
Agent: "Write me a simple TOLK counter contract"
User: "Sure, here's one..."
Agent calls: compile_tolk with the source code
→ Gets back FIFT code + BOC bytecode
→ Can provide deployment link or verify it compiles
```
## Installation
### Prerequisites
- Python 3.11+
- Node.js (for tolk-js WASM runtime)
- `mcp` Python package
### Setup
```bash
# Clone
git clone <repo-url>
cd tolk-mcp-server
# Install Node.js dependency
npm install
# Install Python dependency
pip install mcp
```
### With Claude Desktop
Add to your MCP config:
```json
{
"mcpServers": {
"tolk-compiler": {
"command": "python3",
"args": ["/path/to/tolk-mcp-server/server.py"]
}
}
}
```
### Standalone
```bash
python3 server.py
```
## Architecture
```
AI Agent → MCP Protocol → server.py → @ton/tolk-js CLI → Tolk WASM Compiler
↓
FIFT + BOC bytecode
```
The server uses the `@ton/tolk-js` CLI under the hood. Source code is written to a temp directory, compiled via the CLI, and the JSON output is parsed and returned as MCP tool results.
## Standard Library
Tolk includes 8 standard library modules embedded in the compiler — no additional files needed:
- `common` — common utilities
- `exotic-cells` — exotic cell operations
- `gas-payments` — gas and payment helpers
- `lisp-lists` — list data structures
- `reflection` — type reflection
- `strings` — string handling
- `tvm-dicts` — TVM dictionary operations
- `tvm-lowlevel` — low-level TVM operations
Import them directly in your Tolk code — the compiler resolves them automatically.
## License
MIT
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues