Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
f68f81d
docs: rewrite README + add payloads/ JSON examples for every endpoint
EnzinoBB Apr 28, 2026
4150ed9
docs(spec): design baba-credits MCP server + skill
EnzinoBB Apr 29, 2026
30938c5
docs(plan): implementation plan for baba-credits MCP
EnzinoBB Apr 29, 2026
ebfa848
feat(mcp): add baba_mcp package skeleton + new deps
EnzinoBB Apr 29, 2026
c44642c
feat(mcp): error mapping HTTP -> MCP tool error codes
EnzinoBB Apr 29, 2026
2a01bd8
feat(mcp): async HTTP client with retry + auth + error mapping
EnzinoBB Apr 29, 2026
15bc143
feat(mcp): shared Pydantic input models
EnzinoBB Apr 29, 2026
e55d17b
feat(mcp): server skeleton with stdio + http transport
EnzinoBB Apr 29, 2026
f922639
feat(mcp): tool registration helper (call_gateway)
EnzinoBB Apr 29, 2026
21bb67d
feat(mcp): canary tool monitor_get_balance + stub modules
EnzinoBB Apr 29, 2026
82fa52c
docs: resume guide for baba-credits MCP build (post-M1)
EnzinoBB Apr 29, 2026
7314e4f
feat(mcp): tool monitor_get_wallet_info
EnzinoBB Apr 29, 2026
f701e36
feat(mcp): tool monitor_get_transactions_by_wallet
EnzinoBB Apr 29, 2026
b84b8c0
feat(mcp): tool monitor_get_estimated_fee
EnzinoBB Apr 29, 2026
02fb4aa
feat(mcp): tool monitor_wait_for_block
EnzinoBB Apr 29, 2026
25c3dee
feat(mcp): tool monitor_wait_for_smart_transaction
EnzinoBB Apr 29, 2026
1e1f510
refactor(mcp): dispatch dict in monitor tools
EnzinoBB Apr 29, 2026
541cb6c
feat(mcp): tool transaction_get_info + module bootstrap
EnzinoBB Apr 29, 2026
f1acd66
feat(mcp): tool transaction_pack
EnzinoBB Apr 29, 2026
e57006b
feat(mcp): tool transaction_execute
EnzinoBB Apr 29, 2026
613ce6f
feat(mcp): tool transaction_result
EnzinoBB Apr 29, 2026
21314d3
feat(mcp): tool tokens_info + module bootstrap
EnzinoBB Apr 29, 2026
c719244
feat(mcp): tool tokens_balances_get
EnzinoBB Apr 29, 2026
2db1b26
feat(mcp): tool tokens_transfers_get
EnzinoBB Apr 29, 2026
194a6e5
feat(mcp): tool tokens_holders_get
EnzinoBB Apr 29, 2026
b63a43d
feat(mcp): tool tokens_transactions_get
EnzinoBB Apr 29, 2026
aa75116
feat(mcp): tool smartcontract_compile + module bootstrap
EnzinoBB Apr 29, 2026
f5168ba
feat(mcp): tool smartcontract_pack
EnzinoBB Apr 29, 2026
cf846c9
feat(mcp): tool smartcontract_deploy
EnzinoBB Apr 29, 2026
0711aa0
feat(mcp): tool smartcontract_execute
EnzinoBB Apr 29, 2026
8fb4aba
feat(mcp): tool smartcontract_get
EnzinoBB Apr 29, 2026
1c946ad
feat(mcp): tool smartcontract_methods
EnzinoBB Apr 29, 2026
73e7fb7
feat(mcp): tool smartcontract_state
EnzinoBB Apr 29, 2026
6e2a893
feat(mcp): tool smartcontract_list_by_wallet
EnzinoBB Apr 29, 2026
d29e97c
feat(mcp): tool userfields_encode + module bootstrap
EnzinoBB Apr 29, 2026
d5a7fb1
feat(mcp): tool userfields_decode
EnzinoBB Apr 29, 2026
bb719e9
feat(mcp): tool diag_get_active_nodes + module bootstrap
EnzinoBB Apr 29, 2026
342caaf
feat(mcp): tool diag_get_active_transactions_count
EnzinoBB Apr 29, 2026
5f01a17
feat(mcp): tool diag_get_node_info
EnzinoBB Apr 29, 2026
c80b608
feat(mcp): tool diag_get_supply
EnzinoBB Apr 29, 2026
668861b
test(mcp): assert all 29 tools registered
EnzinoBB Apr 29, 2026
798bbe4
fix(mcp): single list_tools/call_tool registration for all 29 tools
EnzinoBB Apr 29, 2026
bca6df3
docs(skill): SKILL.md entry point for baba-credits
EnzinoBB Apr 29, 2026
716d648
docs(skill): tools-reference catalogue
EnzinoBB Apr 29, 2026
3284626
docs(skill): recipe transfer-cs
EnzinoBB Apr 29, 2026
ba950d6
docs(skill): recipe deploy-contract
EnzinoBB Apr 29, 2026
3e9257e
docs(skill): recipe execute-method
EnzinoBB Apr 29, 2026
95adf56
docs(skill): recipe inspect-wallet
EnzinoBB Apr 29, 2026
60d5fa6
docs(skill): recipe attach-metadata
EnzinoBB Apr 29, 2026
20fcfe3
docs(skill): recipe token-operations
EnzinoBB Apr 29, 2026
44fa164
docs(skill): signing python pynacl snippet
EnzinoBB Apr 29, 2026
b55b418
docs(skill): signing typescript tweetnacl snippet
EnzinoBB Apr 29, 2026
e58a3ac
docs(skill): troubleshooting map
EnzinoBB Apr 29, 2026
399c80a
feat(deploy): pm2 ecosystem bundles gateway + mcp-http
EnzinoBB Apr 29, 2026
f1adc91
feat(deploy): .env.mcp.example
EnzinoBB Apr 29, 2026
91329ae
docs(readme): add MCP Server section
EnzinoBB Apr 29, 2026
070fd4d
test(mcp): drift skill <-> code
EnzinoBB Apr 29, 2026
ddc5cd7
ci: run MCP tests + skill drift check
EnzinoBB Apr 29, 2026
584e041
chore(qa): mcp on-chain smoke + manual checklist
EnzinoBB Apr 29, 2026
baac54e
fix(gateway+mcp): on-chain smoke fixes for transaction/SC paths
EnzinoBB Apr 29, 2026
f382e1c
chore(qa): full on-chain smoke script covering all 29 MCP tools
EnzinoBB Apr 29, 2026
76baefa
Merge branch 'claude/baba-credits-mcp' into main
EnzinoBB Apr 29, 2026
d0f8032
fix(gateway): SC Deploy/Execute polling fallback for early Thrift dis…
EnzinoBB Apr 29, 2026
a2d038f
docs(readme): expand MCP section with full agent configuration guide
EnzinoBB Apr 29, 2026
6494477
Merge upstream molaanaa/main: Variant params Thrift conversion + test…
EnzinoBB Apr 29, 2026
b6d9673
ci: gate MCP deps and tests behind Python >= 3.10
EnzinoBB Apr 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions .claude/skills/baba-credits/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
name: baba-credits
description: |
Use when the user wants to interact with the Credits blockchain via the
baba-credits MCP server — sending CS transfers, deploying/calling Java
smart contracts, querying balances, transactions, tokens, attaching
userFields metadata (ArtVerse-style), or running node diagnostics.
Triggers when the user mentions: Credits, CS coin, $CS, baba-credits,
Credits wallet, BABA Wallet, smart contract on Credits, ArtVerse mint.
---

# baba-credits

## TL;DR

You are talking to a Python MCP server (`baba-credits`) that wraps the BABA Wallet
HTTP gateway, which in turn talks Thrift to a Credits node. The server is
**non-custodial**: it never holds private keys. All write operations require the
client (you, or the wallet you're embedded in) to produce an ed25519 signature
and submit it to the server.

The canonical pipeline for any write is:

1. *_pack → returns base58 transactionPackagedStr (and innerId)
2. (client-side) → ed25519 sign of the raw bytes of that base58 blob
3. *_execute → submit signed payload + same params + same innerId
4. (optional) → monitor_wait_for_block / transaction_get_info

For read-only inspection just call the corresponding `*_get_*`, `*_info`,
`*_state`, or `diag_*` tool directly.

## Decision tree — which tool do I use?

- "How much CS does wallet X hold?" → `monitor_get_balance`
- "What did wallet X do recently?" → `monitor_get_transactions_by_wallet`
- "What is transaction 174575023.1?" → `transaction_get_info`
- "Did my smart-contract call succeed?" → `transaction_result`
- "Send N CS from A to B" → recipe `transfer-cs.md`
- "Deploy this Java contract" → recipe `deploy-contract.md`
- "Call method `x` on contract C" → recipe `execute-method.md`
- "Mint an ArtVerse asset" → recipe `attach-metadata.md` + `transfer-cs.md`
- "Show me details of the network" → `diag_*`
- "Wait until the next block" → `monitor_wait_for_block` (long-poll)

## Critical constraints (read before writing)

These come from on-chain validation in 2026-04-27/28 and are NOT optional:

1. **Fix `transactionInnerId` between Pack and Execute.** `*_pack` derives
inner_id from `lastTransactionId+1`. If a parallel transaction on the same
wallet bumps that counter between your Pack and your Execute, the rebuilt
inner_id at submit time differs and the node rejects with `"Transaction has
wrong signature."` — pre-broadcast (no fee consumed). Fix: read
`transactionInnerId` from the Pack response and pass it back to
`*_deploy/_execute`.

2. **Java smart contracts MUST import the SCAPI explicitly.** The first line
of source must include `import com.credits.scapi.v0.SmartContract;`. Without
it the executor compiles silently to broken bytecode.

3. **Deploy address is deterministic.** It is `blake2s(source ‖ inner_id_LE6 ‖
concat(byteCode))`. The Pack response includes `deployedAddress` so you
don't need to recompute it client-side; but if you do, the formula above is
the exact one used by the node.

4. **Compile is slow.** Up to ~120s under load. Do not timeout aggressively.

5. **`transaction_execute` rejected with "wrong signature" does NOT consume
fee.** This is a safety feature of the node. It also means the agent
should NOT retry blindly — re-pack, re-sign, re-submit instead.

## Tools — quick reference

See `tools-reference.md` for the full catalog (29 tools, 6 categories).

| Category | Count | Notable |
|---|---|---|
| `monitor_*` | 6 | balance, history, fee estimation, long-poll waits |
| `transaction_*` | 4 | get/pack/execute/result for plain CS transfers |
| `userfields_*` | 2 | encode/decode of v1 metadata blobs (ArtVerse) |
| `tokens_*` | 5 | balances, transfers, info, holders, transactions |
| `smartcontract_*` | 8 | compile, pack, deploy, execute, get, methods, state, list |
| `diag_*` | 4 | active nodes, mempool count, node info, supply |

## Recipes (full pipelines)

- `recipes/transfer-cs.md` — send CS from A to B
- `recipes/deploy-contract.md` — Java contract on-chain
- `recipes/execute-method.md` — call a method on a deployed contract
- `recipes/inspect-wallet.md` — read-only exploration
- `recipes/attach-metadata.md` — userFields v1 (ArtVerse minting)
- `recipes/token-operations.md` — token info / balances / transfers / holders

## Client-side signing

The MCP server NEVER signs. You sign client-side. See:

- `signing/python-pynacl.md` — 5 lines of Python (validated on-chain 2026-04-27)
- `signing/typescript-tweetnacl.md` — equivalent for JS/TS wallets

If you are an "agent with a key" the private key is in your env (`BABA_PRIVATE_KEY`).
If you are embedded in a smart wallet, the wallet keystore signs without exposing the key.

## Errors — what they mean and what to do

| Code | Meaning | Action |
|---|---|---|
| `invalid_input` | Schema mismatch (e.g. malformed transactionId) | Do NOT retry. Fix the input. |
| `not_found` | Tx/contract does not exist | Stop searching. |
| `node_unavailable` | Credits node offline (HTTP 503) | Retry with backoff (1s/2s/4s). |
| `node_error` | Semantic error from node (e.g. wrong signature) | Do NOT blind-retry. Re-pack, re-sign. |
| `rate_limited` | Gateway rate limit hit | Wait `Retry-After` then retry. |
| `internal` | Unexpected gateway error | Surface to the user; collect details. |

## When NOT to use this skill

- The MCP server `baba-credits` is not connected in the current session.
- The user asks for a custodial action ("create me a wallet", "store my keys").
We do NOT generate or store private keys. Direct them to the BABA Wallet app.
- The user asks about a different blockchain (Ethereum, Solana, etc.).

## Troubleshooting

See `troubleshooting.md` for the mapping of common error messages to causes
and fixes (covers the 12 schema/runtime bugs already fixed in the codebase).
114 changes: 114 additions & 0 deletions .claude/skills/baba-credits/recipes/attach-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Recipe: attach userFields v1 metadata to a transaction (ArtVerse)

## When to use
The user wants to anchor an off-chain asset (image, video, document) to a
Credits transaction with verifiable metadata: SHA-256 hash, IPFS CID, MIME
type, size. Typical use case: ArtVerse minting — a transfer that doubles as
a "proof of authorship" record.

## Prerequisites
- The asset itself, hashed with SHA-256 (32 bytes, hex-encoded).
- An IPFS CID for the asset (the user pins it themselves; out of scope of
this recipe).
- The MIME type and the size in bytes.
- `BABA_PRIVATE_KEY` available (or a wallet keystore that signs for A).

## Pipeline

### Step 1 — Compute SHA-256 of the asset
Off-chain, on the client:
```python
import hashlib
content_hash = hashlib.sha256(open(path, "rb").read()).hexdigest()
# e.g. "0011223344556677889900112233445566778899001122334455667788990011"
```

### Step 2 — Pin to IPFS
Out of scope of this recipe. The user (or the wallet app) pins the asset and
returns the CID, e.g. `bafybeigdyrabc`.

### Step 3 — Encode userFields v1 blob
```
userfields_encode({
"contentHashAlgo": "sha-256",
"contentHash": "0011223344556677889900112233445566778899001122334455667788990011",
"contentCid": "bafybeigdyrabc",
"mime": "image/png",
"sizeBytes": 1234567
})
→ {
"success": true,
"userData": "uF58..."
}
```
*Capture `userData` — it's a base58 blob ready to be embedded in a tx.*

### Step 4 — Pack the transaction with `UserData`
```
transaction_pack({
"PublicKey": A,
"ReceiverPublicKey": B,
"amountAsString": "0.001",
"feeAsString": "0",
"UserData": "uF58..."
})
→ { "dataResponse": { "transactionPackagedStr": "<base58>",
"recommendedFee": 0.00874 },
"success": true }
```

### Step 5 — Sign and submit
Continue with the standard `recipes/transfer-cs.md` pipeline starting at
Step 4 (sign client-side, then `transaction_execute` with the **same**
`UserData` value — drift here also breaks the signature).

```
sig_b58 = sign_packaged(packaged_str_b58, private_key_b58)
transaction_execute({
"PublicKey": A,
"ReceiverPublicKey": B,
"amountAsString": "0.001",
"feeAsString": "0",
"UserData": "uF58...",
"TransactionSignature": sig_b58
})
→ { "success": true, "transactionId": "174575023.1" }
```

### Step 6 — Verify (optional)
After the transaction seals, you can decode the on-chain `userData` back into
its structured form:
```
transaction_get_info({"transactionId": "174575023.1"})
→ { ..., "userData": "uF58...", ... }

userfields_decode({"userData": "uF58..."})
→ {
"fields": {
"contentHashAlgo": "sha-256",
"contentHash": "0011...",
"contentCid": "bafybeigdyrabc",
"mime": "image/png",
"sizeBytes": 1234567
},
"success": true
}
```

## Common errors
- `"Transaction has wrong signature."` → `UserData` differs between Pack and
Execute. The `UserData` blob is part of the packaged signing payload, so any
drift breaks the signature. Always pass the **exact same** `userData` string.
- `userfields_encode` rejects `contentHash` of unexpected length → make sure
`contentHashAlgo` matches the digest length (sha-256 → 64 hex chars).
- `node_unavailable` (503) → retry the transfer pipeline with backoff
1s/2s/4s. Re-encoding is idempotent so steps 1-3 don't need re-running.

## On-chain confirmation
The metadata is anchored as soon as the transaction status is `"Success"` (a
single pool seal, ~3s). After that, anyone can:
1. Pull the `userData` from `transaction_get_info`.
2. Decode it with `userfields_decode`.
3. Fetch the asset from IPFS via the `contentCid`.
4. Recompute SHA-256 locally and compare against `contentHash` to verify the
asset has not been tampered with.
126 changes: 126 additions & 0 deletions .claude/skills/baba-credits/recipes/deploy-contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Recipe: deploy a Java smart contract on Credits

## When to use
The user asks "deploy this contract", "publish this contract on Credits",
"create a smart contract on Credits", and provides Java source. The deploying
wallet (A) must have ≥ ~0.1 CS for the deploy fee.

## Prerequisites
- `BABA_PRIVATE_KEY` available, OR the embedding wallet can sign for A.
- The Java source code, with the SCAPI import on the first line.
- `monitor_get_balance({"PublicKey": A})` returns balance ≥ ~0.1 CS.

## Critical
- **`import com.credits.scapi.v0.SmartContract;` is mandatory.** Without it the
executor compiles silently to broken bytecode.
- **`transactionInnerId` is load-bearing.** Capture it from `smartcontract_pack`
and pass it back **unchanged** to `smartcontract_deploy`. If a parallel tx on
the same wallet bumps `lastTransactionId+1` between Pack and Deploy, a
re-derived inner_id will not match the signature → `"Transaction has wrong
signature."` (no fee consumed, but you must re-pack and re-sign).

## Example contract (BasicCounter)
```java
import com.credits.scapi.v0.SmartContract;

public class BasicCounter extends SmartContract {
private long counter = 0;

public BasicCounter() {}

public void increment() {
counter += 1;
}

public long getCounter() {
return counter;
}
}
```

## Pipeline

### Step 1 — Compile
```
smartcontract_compile({"sourceCode": "<the Java above>"})
→ {
"byteCodeObjects": [
{"name": "BasicCounter", "byteCode": "yv66vgAAA..."}
],
"tokenStandard": 0,
"success": true
}
```
*Compile may take up to ~120s under load — do not timeout aggressively.*

### Step 2 — Pack (deploy)
```
smartcontract_pack({
"PublicKey": A,
"operation": "deploy",
"sourceCode": "<the Java above>",
"byteCodeObjects": [{"name": "BasicCounter", "byteCode": "yv66vgAAA..."}],
"feeAsString": "0",
"UserData": ""
})
→ {
"success": true,
"dataResponse": {
"transactionPackagedStr": "ScPack58...",
"transactionInnerId": 7,
"deployedAddress": "FwdrHR...",
"recommendedFee": 0.1
}
}
```
*Capture `transactionPackagedStr`, `transactionInnerId`, and `deployedAddress`.*

### Step 3 — Sign client-side
See `../signing/python-pynacl.md`:
```python
sig_b58 = sign_packaged(packaged_str_b58, private_key_b58)
```

### Step 4 — Deploy
```
smartcontract_deploy({
"PublicKey": A,
"sourceCode": "<the same Java>",
"byteCodeObjects": [{"name": "BasicCounter", "byteCode": "yv66vgAAA..."}],
"TransactionSignature": sig_b58,
"transactionInnerId": 7,
"feeAsString": "0",
"UserData": ""
})
→ {
"success": true,
"transactionId": "174580000.1",
"deployedAddress": "FwdrHR...",
"actualFee": "0.1"
}
```
*`transactionInnerId` must equal the value from step 2.*

### Step 5 — Wait + confirm
```
monitor_wait_for_block({"timeoutMs": 30000})
transaction_get_info({"transactionId": "174580000.1"})
→ { "found": true, "status": "Success" }
```

The contract is now live at `deployedAddress`. Continue with
`recipes/execute-method.md` to call its methods.

## Common errors
- `node_error` "compilation error" → missing `import com.credits.scapi.v0.SmartContract;`.
- `"Transaction has wrong signature."` → `transactionInnerId` drifted between
Pack and Deploy, OR a different `sourceCode`/`byteCodeObjects`/`feeAsString`/
`UserData` was sent to Deploy than to Pack. Fix: re-pack, re-sign, re-deploy.
- Compile timeout under load → retry with a higher client timeout (≥ 120s).
- `node_unavailable` (503) → retry with backoff 1s/2s/4s.

## On-chain confirmation
The deploy address is deterministic: `blake2s(sourceCode ‖ inner_id_LE6 ‖
concat(byteCode))`. The Pack response already returns it, so you can show it
to the user before submission. After Deploy, use `smartcontract_get` and
`smartcontract_methods` to verify the contract is reachable.
Loading
Loading