# solc-mcp: Contract Compile

The `solc-mcp` module allows agents to securely compile Solidity smart contracts without relying on third-party explorers or IDEs.

It wraps the official `solc-js` compiler in a controlled MCP server that can:

* Compile a given Solidity source string
* Return the ABI, bytecode, and metadata
* Detect syntax and compiler errors
* Support version pinning (via pragma or param)

This lets your agents prepare smart contracts for deployment or audit — completely from natural language prompts.

***

### What It Does

* Receives raw Solidity contract source
* Resolves the appropriate `solc` version
* Compiles source with safe defaults
* Returns ABI, bytecode, errors (if any)

This server does **not deploy contracts** — it only compiles them.

***

### Architecture

```plaintext
Agent → solc-mcp → solc-js → Compiled Output → signer (optional)
```

* Used before passing bytecode to `metamask-mcp` for deployment
* Can also be used for simulation or code validation

***

### Tool Name: `solc.compile`

#### Request

```json
{
  "tool": "solc.compile",
  "args": {
    "source": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\ncontract Hello { string public greet = 'hi'; }"
  }
}
```

#### Response

```json
{
  "abi": [ { "inputs": [], "name": "greet", "outputs": [{ "type": "string" }], ... } ],
  "bytecode": "0x608060405234...",
  "compilerVersion": "0.8.19",
  "warnings": [],
  "errors": []
}
```

If there are compile-time issues, the `errors` array will be populated with structured messages from the compiler.

***

### Server Setup

To run `solc-mcp` locally:

```bash
git clone https://github.com/pilso-os/mcp-servers
cd mcp-servers/solc-mcp
npm install
npm start
```

Default port: `3050`

Update your `pilso.config.json`:

```json
"tools": [
  "http://localhost:3050"
]
```

***

### Compiler Version Resolution

By default, `solc-mcp`:

* Parses `pragma` directives to match the required version
* Falls back to `solc@latest` if unspecified
* Uses `solc-js` via npm package or binary cache

Optional flag:

```json
"version": "0.8.17"
```

You can force a version via explicit parameter in the request.

***

### Output Format

| Field             | Description                       |
| ----------------- | --------------------------------- |
| `abi`             | Standard ABI JSON                 |
| `bytecode`        | Hex-encoded deployable bytecode   |
| `compilerVersion` | Actual compiler version used      |
| `warnings`        | Non-blocking issues               |
| `errors`          | Critical blocking issues (if any) |

All outputs are structured to be consumed directly by `metamask-mcp` or logged for agent interpretation.

***

### Test Call Locally

```bash
npx pilso call \
  --tool solc.compile \
  --args '{"source": "pragma solidity ^0.8.19; contract A { uint x; }"}'
```

***

### Safety Notes

* Compilation is **fully isolated** — no contract is ever deployed from this tool
* It can be safely exposed to most agent roles, including `developer`, `auditor`, and `reviewer`
* Avoid giving compile + sign access to general-purpose roles unless tightly scoped

***

### Future Additions

* Support for source map + opcode output
* AI-assisted static analysis hooks
* Bytecode diff tools for version comparison

***

### ✅ Summary

| Property          | Value                        |
| ----------------- | ---------------------------- |
| **Tool name**     | `solc.compile`               |
| **Port**          | `3050` (default)             |
| **Signature**     | No — compiles only           |
| **Chain Support** | EVM-based chains only        |
| **Depends on**    | `solc-js`, pragma resolution |

The `solc-mcp` module gives your PILSO agent the power to **understand, compile, and prepare contracts** — safely and reproducibly, from source code to deployable bytecode.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pil.so/mcp-server-models/solc-mcp-contract-compile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
