@conquest-eth/tools 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +259 -0
- package/dist/cli-tool-generator.d.ts +22 -0
- package/dist/cli-tool-generator.d.ts.map +1 -0
- package/dist/cli-tool-generator.js +217 -0
- package/dist/cli-tool-generator.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +76 -0
- package/dist/cli.js.map +1 -0
- package/dist/contracts/space-info.d.ts +7 -0
- package/dist/contracts/space-info.d.ts.map +1 -0
- package/dist/contracts/space-info.js +34 -0
- package/dist/contracts/space-info.js.map +1 -0
- package/dist/fleet/index.d.ts +4 -0
- package/dist/fleet/index.d.ts.map +1 -0
- package/dist/fleet/index.js +7 -0
- package/dist/fleet/index.js.map +1 -0
- package/dist/fleet/manager.d.ts +70 -0
- package/dist/fleet/manager.d.ts.map +1 -0
- package/dist/fleet/manager.js +92 -0
- package/dist/fleet/manager.js.map +1 -0
- package/dist/fleet/resolve.d.ts +51 -0
- package/dist/fleet/resolve.d.ts.map +1 -0
- package/dist/fleet/resolve.js +140 -0
- package/dist/fleet/resolve.js.map +1 -0
- package/dist/fleet/send.d.ts +29 -0
- package/dist/fleet/send.d.ts.map +1 -0
- package/dist/fleet/send.js +81 -0
- package/dist/fleet/send.js.map +1 -0
- package/dist/helpers/index.d.ts +14 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +28 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +143 -0
- package/dist/index.js.map +1 -0
- package/dist/planet/acquire.d.ts +16 -0
- package/dist/planet/acquire.d.ts.map +1 -0
- package/dist/planet/acquire.js +27 -0
- package/dist/planet/acquire.js.map +1 -0
- package/dist/planet/exit.d.ts +17 -0
- package/dist/planet/exit.d.ts.map +1 -0
- package/dist/planet/exit.js +56 -0
- package/dist/planet/exit.js.map +1 -0
- package/dist/planet/index.d.ts +4 -0
- package/dist/planet/index.d.ts.map +1 -0
- package/dist/planet/index.js +6 -0
- package/dist/planet/index.js.map +1 -0
- package/dist/planet/manager.d.ts +106 -0
- package/dist/planet/manager.d.ts.map +1 -0
- package/dist/planet/manager.js +253 -0
- package/dist/planet/manager.js.map +1 -0
- package/dist/storage/interface.d.ts +93 -0
- package/dist/storage/interface.d.ts.map +1 -0
- package/dist/storage/interface.js +2 -0
- package/dist/storage/interface.js.map +1 -0
- package/dist/storage/json-storage.d.ts +28 -0
- package/dist/storage/json-storage.d.ts.map +1 -0
- package/dist/storage/json-storage.js +148 -0
- package/dist/storage/json-storage.js.map +1 -0
- package/dist/tools/acquire_planets.d.ts +7 -0
- package/dist/tools/acquire_planets.d.ts.map +1 -0
- package/dist/tools/acquire_planets.js +63 -0
- package/dist/tools/acquire_planets.js.map +1 -0
- package/dist/tools/exit_planets.d.ts +5 -0
- package/dist/tools/exit_planets.d.ts.map +1 -0
- package/dist/tools/exit_planets.js +31 -0
- package/dist/tools/exit_planets.js.map +1 -0
- package/dist/tools/get_my_planets.d.ts +5 -0
- package/dist/tools/get_my_planets.d.ts.map +1 -0
- package/dist/tools/get_my_planets.js +30 -0
- package/dist/tools/get_my_planets.js.map +1 -0
- package/dist/tools/get_pending_exits.d.ts +3 -0
- package/dist/tools/get_pending_exits.d.ts.map +1 -0
- package/dist/tools/get_pending_exits.js +37 -0
- package/dist/tools/get_pending_exits.js.map +1 -0
- package/dist/tools/get_pending_fleets.d.ts +3 -0
- package/dist/tools/get_pending_fleets.d.ts.map +1 -0
- package/dist/tools/get_pending_fleets.js +41 -0
- package/dist/tools/get_pending_fleets.js.map +1 -0
- package/dist/tools/get_planets_around.d.ts +7 -0
- package/dist/tools/get_planets_around.d.ts.map +1 -0
- package/dist/tools/get_planets_around.js +41 -0
- package/dist/tools/get_planets_around.js.map +1 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/resolve_fleet.d.ts +5 -0
- package/dist/tools/resolve_fleet.d.ts.map +1 -0
- package/dist/tools/resolve_fleet.js +37 -0
- package/dist/tools/resolve_fleet.js.map +1 -0
- package/dist/tools/send_fleet.d.ts +16 -0
- package/dist/tools/send_fleet.d.ts.map +1 -0
- package/dist/tools/send_fleet.js +62 -0
- package/dist/tools/send_fleet.js.map +1 -0
- package/dist/tools/verify_exit_status.d.ts +5 -0
- package/dist/tools/verify_exit_status.d.ts.map +1 -0
- package/dist/tools/verify_exit_status.js +39 -0
- package/dist/tools/verify_exit_status.js.map +1 -0
- package/dist/types.d.ts +126 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +34 -0
- package/dist/types.js.map +1 -0
- package/dist/util/hashing.d.ts +33 -0
- package/dist/util/hashing.d.ts.map +1 -0
- package/dist/util/hashing.js +38 -0
- package/dist/util/hashing.js.map +1 -0
- package/dist/util/time.d.ts +43 -0
- package/dist/util/time.d.ts.map +1 -0
- package/dist/util/time.js +55 -0
- package/dist/util/time.js.map +1 -0
- package/package.json +78 -0
- package/src/cli-tool-generator.ts +287 -0
- package/src/cli.ts +109 -0
- package/src/contracts/space-info.ts +41 -0
- package/src/fleet/index.ts +8 -0
- package/src/fleet/manager.ts +140 -0
- package/src/fleet/resolve.ts +187 -0
- package/src/fleet/send.ts +112 -0
- package/src/helpers/index.ts +59 -0
- package/src/index.ts +181 -0
- package/src/planet/acquire.ts +41 -0
- package/src/planet/exit.ts +71 -0
- package/src/planet/index.ts +6 -0
- package/src/planet/manager.ts +335 -0
- package/src/storage/interface.ts +111 -0
- package/src/storage/json-storage.ts +184 -0
- package/src/tools/acquire_planets.ts +81 -0
- package/src/tools/exit_planets.ts +35 -0
- package/src/tools/get_my_planets.ts +30 -0
- package/src/tools/get_pending_exits.ts +37 -0
- package/src/tools/get_pending_fleets.ts +41 -0
- package/src/tools/get_planets_around.ts +44 -0
- package/src/tools/index.ts +10 -0
- package/src/tools/resolve_fleet.ts +37 -0
- package/src/tools/send_fleet.ts +68 -0
- package/src/tools/verify_exit_status.ts +43 -0
- package/src/types.ts +178 -0
- package/src/util/hashing.ts +60 -0
- package/src/util/time.ts +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Ronan Sandford
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# MCP for Conquest.eth v0
|
|
2
|
+
|
|
3
|
+
A dual-mode CLI tool for interacting with the Conquest.eth blockchain game. It can run as an **MCP server** for AI assistant integration or execute **tools directly** from the command line.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **MCP Server Mode**: Integrate with AI assistants via the Model Context Protocol
|
|
8
|
+
- **CLI Mode**: Execute game commands directly from your terminal
|
|
9
|
+
- **Dynamic Command Generation**: CLI commands are auto-generated from tool definitions
|
|
10
|
+
- **Comprehensive Game Tools**: Acquire planets, send fleets, resolve fleets, manage exits, and more
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm install
|
|
16
|
+
pnpm build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### CLI Mode (Direct Command Execution)
|
|
22
|
+
|
|
23
|
+
Show help and available commands:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
node dist/cli.js --help
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### Global Options
|
|
30
|
+
|
|
31
|
+
| Option | Environment Variable | Description | Default |
|
|
32
|
+
| --------------------------- | -------------------- | -------------------------------- | ------------------------ |
|
|
33
|
+
| `--rpc-url <url>` | `RPC_URL` | RPC URL for the Ethereum network | (required) |
|
|
34
|
+
| `--game-contract <address>` | `GAME_CONTRACT` | Game contract address | (required) |
|
|
35
|
+
| `--storage <type>` | `STORAGE_TYPE` | Storage backend: json or sqlite | json |
|
|
36
|
+
| `--storage-path <path>` | `STORAGE_PATH` | Storage directory path | ./data |
|
|
37
|
+
| `--private-key <key>` | `PRIVATE_KEY` | Private key for transactions | (required for write ops) |
|
|
38
|
+
|
|
39
|
+
#### MCP Server Options
|
|
40
|
+
|
|
41
|
+
| Option | Environment Variable | Description | Default |
|
|
42
|
+
| ------------ | -------------------- | ---------------------------- | ------- |
|
|
43
|
+
| `--ethereum` | `ETHEREUM_TOOLS` | Include tools-ethereum tools | false |
|
|
44
|
+
|
|
45
|
+
#### Using Environment Variables
|
|
46
|
+
|
|
47
|
+
Set up your environment:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
export RPC_URL=https://rpc.gnosischain.com
|
|
51
|
+
export GAME_CONTRACT=0x322813fd9a801c5507c9de605d63cea4f2ce6c44
|
|
52
|
+
export PRIVATE_KEY=0x...
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then run commands without repeating options:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
node dist/cli.js get_my_planets --radius 10
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Available Commands
|
|
62
|
+
|
|
63
|
+
| Command | Description |
|
|
64
|
+
| -------------------- | --------------------------------------- |
|
|
65
|
+
| `acquire_planets` | Acquire/stake multiple planets |
|
|
66
|
+
| `send_fleet` | Send a fleet from one planet to another |
|
|
67
|
+
| `resolve_fleet` | Resolve a committed fleet |
|
|
68
|
+
| `exit_planets` | Start the exit process for planets |
|
|
69
|
+
| `get_my_planets` | Get all planets owned by you |
|
|
70
|
+
| `get_planets_around` | Get planets near a location |
|
|
71
|
+
| `get_pending_exits` | Get pending exit operations |
|
|
72
|
+
| `get_pending_fleets` | Get pending fleets |
|
|
73
|
+
| `verify_exit_status` | Check a planet's exit status |
|
|
74
|
+
|
|
75
|
+
#### Examples
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Get your planets
|
|
79
|
+
node dist/cli.js get_my_planets --radius 10
|
|
80
|
+
|
|
81
|
+
# Find planets near a location
|
|
82
|
+
node dist/cli.js get_planets_around --center-x 0 --center-y 0 --radius 20
|
|
83
|
+
|
|
84
|
+
# Acquire planets
|
|
85
|
+
node dist/cli.js acquire_planets --planet-ids 1,2,3,4,5
|
|
86
|
+
|
|
87
|
+
# Send a fleet
|
|
88
|
+
node dist/cli.js send_fleet --from-x 10 --from-y 20 --to-x 15 --to-y 25 --quantity 100
|
|
89
|
+
|
|
90
|
+
# Resolve a fleet
|
|
91
|
+
node dist/cli.js resolve_fleet --fleet-id "your-fleet-id"
|
|
92
|
+
|
|
93
|
+
# Exit planets
|
|
94
|
+
node dist/cli.js exit_planets --planet-ids 1,2,3
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
See [`EXAMPLES.md`](./EXAMPLES.md) for more detailed usage examples.
|
|
98
|
+
|
|
99
|
+
### MCP Server Mode
|
|
100
|
+
|
|
101
|
+
Start the MCP server for AI assistant integration:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
node dist/cli.js mcp --rpc-url https://rpc.gnosischain.com --game-contract 0x322813fd9a801c5507c9de605d63cea4f2ce6c44
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Or use the MCP Inspector for testing:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pnpm mcp:inspector node dist/cli.js --game-contract 0xD833d4dBBb0C19aF1EEf76540d66E2076a5e9D72 --rpc-url https://rpc.gnosis.gateway.fm
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
For Conquest 2025-1 edition, use:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pnpm mcp:inspector node dist/cli.js --game-contract 0xD833d4dBBb0C19aF1EEf76540d66E2076a5e9D72 --rpc-url https://rpc.gnosis.gateway.fm
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Architecture
|
|
120
|
+
|
|
121
|
+
The CLI follows a dual-mode architecture:
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
125
|
+
│ CLI Tool │
|
|
126
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
127
|
+
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐ │
|
|
128
|
+
│ │ Root Program │ │ MCP Command │ │ Dynamic Tool Cmds │ │
|
|
129
|
+
│ │ --global-opt │ │ mcp server │ │ (generated per tool) │ │
|
|
130
|
+
│ └──────────────┘ └──────────────┘ └──────────────────────┘ │
|
|
131
|
+
│ │ │ │ │
|
|
132
|
+
│ ▼ ▼ ▼ │
|
|
133
|
+
│ ┌─────────────────────────────────────────────────────────┐ │
|
|
134
|
+
│ │ Tool Definitions │ │
|
|
135
|
+
│ │ - description - Zod schema - execute(env, params) │ │
|
|
136
|
+
│ └─────────────────────────────────────────────────────────┘ │
|
|
137
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Tool Development
|
|
141
|
+
|
|
142
|
+
Tools are defined with a standardized pattern:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import {z} from 'zod';
|
|
146
|
+
import {createTool} from '../types.js';
|
|
147
|
+
|
|
148
|
+
export const example_tool = createTool({
|
|
149
|
+
description: 'Description of what this tool does',
|
|
150
|
+
schema: z.object({
|
|
151
|
+
param1: z.string().describe('First parameter'),
|
|
152
|
+
param2: z.number().optional().describe('Optional parameter'),
|
|
153
|
+
}),
|
|
154
|
+
execute: async (env, {param1, param2}) => {
|
|
155
|
+
// Access fleetManager and planetManager via env
|
|
156
|
+
const result = await env.planetManager.getMyPlanets(10);
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
success: true,
|
|
160
|
+
result: {
|
|
161
|
+
message: `Processed ${param1}`,
|
|
162
|
+
data: result,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Output Format
|
|
170
|
+
|
|
171
|
+
All CLI commands return JSON output:
|
|
172
|
+
|
|
173
|
+
**Success:**
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"planets": [
|
|
178
|
+
{
|
|
179
|
+
"planetId": "1",
|
|
180
|
+
"location": {"id": "1", "x": 10, "y": 20},
|
|
181
|
+
"numSpaceships": 500
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Error:**
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"error": "No planet found at coordinates",
|
|
192
|
+
"stack": "Error: No planet found at coordinates\n at ..."
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Install dependencies
|
|
200
|
+
pnpm install
|
|
201
|
+
|
|
202
|
+
# Build
|
|
203
|
+
pnpm build
|
|
204
|
+
|
|
205
|
+
# Watch for changes and rebuild
|
|
206
|
+
pnpm dev
|
|
207
|
+
|
|
208
|
+
# Run tests
|
|
209
|
+
pnpm test
|
|
210
|
+
|
|
211
|
+
# Format code
|
|
212
|
+
pnpm format
|
|
213
|
+
|
|
214
|
+
# Start the MCP server with auto-reload
|
|
215
|
+
pnpm start
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Project Structure
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
lobsters/mcp/src/
|
|
222
|
+
├── cli.ts # CLI entry point (dual-mode)
|
|
223
|
+
├── cli-tool-generator.ts # Dynamic CLI command generation
|
|
224
|
+
├── index.ts # MCP server setup
|
|
225
|
+
├── types.ts # Type definitions
|
|
226
|
+
├── helpers/
|
|
227
|
+
│ └── index.ts # Helper functions
|
|
228
|
+
├── tools/
|
|
229
|
+
│ ├── index.ts # Tool exports
|
|
230
|
+
│ ├── acquire_planets.ts # Tool implementations
|
|
231
|
+
│ ├── send_fleet.ts
|
|
232
|
+
│ ├── resolve_fleet.ts
|
|
233
|
+
│ └── ...
|
|
234
|
+
├── fleet/
|
|
235
|
+
│ ├── manager.ts # Fleet operations manager
|
|
236
|
+
│ ├── send.ts
|
|
237
|
+
│ └── resolve.ts
|
|
238
|
+
├── planet/
|
|
239
|
+
│ ├── manager.ts # Planet operations manager
|
|
240
|
+
│ ├── acquire.ts
|
|
241
|
+
│ └── exit.ts
|
|
242
|
+
└── storage/
|
|
243
|
+
├── interface.ts # Storage interface
|
|
244
|
+
└── json-storage.ts # JSON storage implementation
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT
|
|
250
|
+
|
|
251
|
+
## Contributing
|
|
252
|
+
|
|
253
|
+
Contributions are welcome! Please read the project documentation and open issues for discussion.
|
|
254
|
+
|
|
255
|
+
## Related Documentation
|
|
256
|
+
|
|
257
|
+
- [`EXAMPLES.md`](./EXAMPLES.md) - Detailed usage examples
|
|
258
|
+
- [`../../plans/cli-implementation-plan.md`](../../plans/cli-implementation-plan.md) - Implementation plan
|
|
259
|
+
- [`../../plans/cli-refactoring-guide.md`](../../plans/cli-refactoring-guide.md) - Refactoring guide
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { Tool, StorageConfig } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* CLI configuration parameters
|
|
6
|
+
*/
|
|
7
|
+
export interface CliConfig {
|
|
8
|
+
chain: any;
|
|
9
|
+
privateKey?: `0x${string}`;
|
|
10
|
+
gameContract: `0x${string}`;
|
|
11
|
+
ethereum?: boolean;
|
|
12
|
+
storageConfig: StorageConfig;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generate a single tool command from tool definition
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateToolCommand(program: Command, toolName: string, tool: Tool<z.ZodObject<any>>): void;
|
|
18
|
+
/**
|
|
19
|
+
* Register all tool commands from a tools object
|
|
20
|
+
*/
|
|
21
|
+
export declare function registerAllToolCommands(program: Command, tools: Record<string, Tool>): void;
|
|
22
|
+
//# sourceMappingURL=cli-tool-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-tool-generator.d.ts","sourceRoot":"","sources":["../src/cli-tool-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAC,IAAI,EAAmB,aAAa,EAAC,MAAM,YAAY,CAAC;AAWrE;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,GAAG,CAAC;IACX,UAAU,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,YAAY,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,aAAa,CAAC;CAC7B;AA6HD;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAC1B,IAAI,CAuHN;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAQ3F"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getClients } from 'tools-ethereum/helpers';
|
|
3
|
+
import { getChain } from 'tools-ethereum/helpers';
|
|
4
|
+
import { createSpaceInfo } from './contracts/space-info.js';
|
|
5
|
+
import { JsonFleetStorage } from './storage/json-storage.js';
|
|
6
|
+
import { FleetManager } from './fleet/manager.js';
|
|
7
|
+
import { PlanetManager } from './planet/manager.js';
|
|
8
|
+
import { Abi_IOuterSpace } from 'conquest-eth-v0-contracts/abis/IOuterSpace.js';
|
|
9
|
+
/**
|
|
10
|
+
* Convert Zod schema field to commander.js option definition
|
|
11
|
+
*/
|
|
12
|
+
function zodFieldToOption(name, field) {
|
|
13
|
+
if (field instanceof z.ZodBoolean) {
|
|
14
|
+
return `--${name}`;
|
|
15
|
+
}
|
|
16
|
+
return `--${name} <value>`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse option value based on Zod type
|
|
20
|
+
*/
|
|
21
|
+
function parseOptionValue(field, value) {
|
|
22
|
+
if (field instanceof z.ZodArray) {
|
|
23
|
+
return typeof value === 'string' ? value.split(',').map((v) => v.trim()) : value;
|
|
24
|
+
}
|
|
25
|
+
if (field instanceof z.ZodNumber) {
|
|
26
|
+
return Number(value);
|
|
27
|
+
}
|
|
28
|
+
if (field instanceof z.ZodBoolean) {
|
|
29
|
+
return value === true || value === 'true';
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extract description from Zod schema field
|
|
35
|
+
*/
|
|
36
|
+
function getFieldDescription(field) {
|
|
37
|
+
return field.description || 'No description available';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if a Zod field is optional
|
|
41
|
+
*/
|
|
42
|
+
function isOptionalField(field) {
|
|
43
|
+
return field instanceof z.ZodOptional || field.isOptional?.();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a CLI tool environment for executing tools
|
|
47
|
+
*/
|
|
48
|
+
async function createCliToolEnvironment(config) {
|
|
49
|
+
const { gameContract: gameContractAddress, chain, storageConfig } = config;
|
|
50
|
+
// Get clients
|
|
51
|
+
const clients = getClients({ chain, privateKey: config.privateKey });
|
|
52
|
+
// Initialize game contract
|
|
53
|
+
const gameContract = {
|
|
54
|
+
address: gameContractAddress,
|
|
55
|
+
abi: Abi_IOuterSpace,
|
|
56
|
+
};
|
|
57
|
+
// Initialize SpaceInfo
|
|
58
|
+
const { spaceInfo, contractConfig } = await createSpaceInfo(clients, gameContract);
|
|
59
|
+
// Initialize storage
|
|
60
|
+
const storage = new JsonFleetStorage(storageConfig.dataDir || './data');
|
|
61
|
+
// Initialize managers
|
|
62
|
+
const fleetManager = new FleetManager(clients, gameContract, spaceInfo, contractConfig, storage);
|
|
63
|
+
const planetManager = new PlanetManager(clients, gameContract, spaceInfo, contractConfig, storage);
|
|
64
|
+
return {
|
|
65
|
+
fleetManager,
|
|
66
|
+
planetManager,
|
|
67
|
+
sendStatus: async (message) => {
|
|
68
|
+
console.log(`[Status] ${message}`);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Parse and validate parameters against Zod schema
|
|
74
|
+
*/
|
|
75
|
+
async function parseAndValidateParams(schema, options) {
|
|
76
|
+
try {
|
|
77
|
+
return await schema.parseAsync(options);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error instanceof z.ZodError) {
|
|
81
|
+
console.error('Parameter validation error:');
|
|
82
|
+
for (const err of error.issues) {
|
|
83
|
+
console.error(` - ${err.path.join('.')}: ${err.message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Format tool result for CLI output
|
|
91
|
+
*/
|
|
92
|
+
function formatToolResult(result) {
|
|
93
|
+
if (result.success) {
|
|
94
|
+
console.log(JSON.stringify(result.result, null, 2));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
console.error(JSON.stringify({ error: result.error, ...(result.stack ? { stack: result.stack } : {}) }, null, 2));
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Generate a single tool command from tool definition
|
|
103
|
+
*/
|
|
104
|
+
export function generateToolCommand(program, toolName, tool) {
|
|
105
|
+
const shape = tool.schema.shape;
|
|
106
|
+
const cmd = program.command(toolName).description(tool.description);
|
|
107
|
+
// Add options for each schema field
|
|
108
|
+
for (const [fieldName, field] of Object.entries(shape)) {
|
|
109
|
+
const actualField = isOptionalField(field)
|
|
110
|
+
? field.unwrap()
|
|
111
|
+
: field;
|
|
112
|
+
// Handle nested objects by flattening them
|
|
113
|
+
if (actualField instanceof z.ZodObject) {
|
|
114
|
+
const nestedShape = actualField.shape;
|
|
115
|
+
for (const [nestedKey, nestedField] of Object.entries(nestedShape)) {
|
|
116
|
+
const optionName = `${fieldName}-${nestedKey}`;
|
|
117
|
+
const optionDef = zodFieldToOption(optionName, nestedField);
|
|
118
|
+
const description = getFieldDescription(nestedField);
|
|
119
|
+
cmd.option(optionDef, description);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const optionDef = zodFieldToOption(fieldName, actualField);
|
|
124
|
+
const description = getFieldDescription(actualField);
|
|
125
|
+
if (isOptionalField(field)) {
|
|
126
|
+
cmd.option(optionDef, description);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
cmd.requiredOption(optionDef, description);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
cmd.action(async (options) => {
|
|
134
|
+
try {
|
|
135
|
+
const globalOptions = program.opts();
|
|
136
|
+
// Get global options
|
|
137
|
+
const rpcUrl = options.rpcUrl || globalOptions.rpcUrl || process.env.RPC_URL;
|
|
138
|
+
const gameContract = options.gameContract || globalOptions.gameContract || process.env.GAME_CONTRACT;
|
|
139
|
+
const ethereum = options.ethereum ?? globalOptions.ethereum ?? process.env.ETHEREUM_TOOLS === 'true';
|
|
140
|
+
const privateKey = options.privateKey || globalOptions.privateKey || process.env.PRIVATE_KEY;
|
|
141
|
+
const storageType = options.storage || globalOptions.storage || process.env.STORAGE_TYPE || 'json';
|
|
142
|
+
const storagePath = options.storagePath || globalOptions.storagePath || process.env.STORAGE_PATH || './data';
|
|
143
|
+
// Validate required options
|
|
144
|
+
if (!rpcUrl) {
|
|
145
|
+
console.error('Error: --rpc-url option or RPC_URL environment variable is required');
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
if (!gameContract) {
|
|
149
|
+
console.error('Error: --game-contract option or GAME_CONTRACT environment variable is required');
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
// Get chain
|
|
153
|
+
const chain = await getChain(rpcUrl);
|
|
154
|
+
// Parse and validate parameters
|
|
155
|
+
const params = {};
|
|
156
|
+
for (const [fieldName, field] of Object.entries(shape)) {
|
|
157
|
+
const actualField = isOptionalField(field)
|
|
158
|
+
? field.unwrap()
|
|
159
|
+
: field;
|
|
160
|
+
if (actualField instanceof z.ZodObject) {
|
|
161
|
+
// Handle nested object - reconstruct from flattened options
|
|
162
|
+
const nestedResult = {};
|
|
163
|
+
const nestedShape = actualField.shape;
|
|
164
|
+
for (const [nestedKey, nestedField] of Object.entries(nestedShape)) {
|
|
165
|
+
const optionName = `${fieldName}-${nestedKey}`;
|
|
166
|
+
if (options[optionName] !== undefined) {
|
|
167
|
+
nestedResult[nestedKey] = parseOptionValue(nestedField, options[optionName]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
params[fieldName] = nestedResult;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const value = options[fieldName];
|
|
174
|
+
if (value !== undefined) {
|
|
175
|
+
params[fieldName] = parseOptionValue(actualField, value);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const validatedParams = await parseAndValidateParams(tool.schema, params);
|
|
180
|
+
// Create environment and execute
|
|
181
|
+
const env = await createCliToolEnvironment({
|
|
182
|
+
chain,
|
|
183
|
+
privateKey: privateKey,
|
|
184
|
+
gameContract: gameContract,
|
|
185
|
+
ethereum,
|
|
186
|
+
storageConfig: {
|
|
187
|
+
type: storageType,
|
|
188
|
+
dataDir: storagePath,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
const result = await tool.execute(env, validatedParams);
|
|
192
|
+
formatToolResult(result);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (error instanceof Error) {
|
|
196
|
+
console.error(JSON.stringify({ error: error.message, ...(error.stack ? { stack: error.stack } : {}) }, null, 2));
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
console.error(JSON.stringify({ error: String(error) }, null, 2));
|
|
200
|
+
}
|
|
201
|
+
process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Register all tool commands from a tools object
|
|
207
|
+
*/
|
|
208
|
+
export function registerAllToolCommands(program, tools) {
|
|
209
|
+
for (const [toolName, tool] of Object.entries(tools)) {
|
|
210
|
+
// Skip the file that's not a tool
|
|
211
|
+
if (toolName === 'default')
|
|
212
|
+
continue;
|
|
213
|
+
// Keep snake_case for CLI command names (1:1 mapping with tool names)
|
|
214
|
+
generateToolCommand(program, toolName, tool);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=cli-tool-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-tool-generator.js","sourceRoot":"","sources":["../src/cli-tool-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAC,eAAe,EAAC,MAAM,+CAA+C,CAAC;AAa9E;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAmB;IAC1D,IAAI,KAAK,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC;QACnC,OAAO,KAAK,IAAI,EAAE,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,IAAI,UAAU,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,KAAmB,EAAE,KAAU;IACxD,IAAI,KAAK,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;QACjC,OAAO,OAAO,KA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,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAgB,EAAE,KAA2B;IACpF,KAAK,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACtD,kCAAkC;QAClC,IAAI,QAAQ,KAAK,SAAS;YAAE,SAAS;QAErC,sEAAsE;QACtE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;AACF,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { createServer } from './index.js';
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import pkg from '../package.json' with { type: 'json' };
|
|
6
|
+
import { getChain } from 'tools-ethereum/helpers';
|
|
7
|
+
import { loadEnv } from 'ldenv';
|
|
8
|
+
import * as tools from './tools/index.js';
|
|
9
|
+
import { registerAllToolCommands } from './cli-tool-generator.js';
|
|
10
|
+
loadEnv();
|
|
11
|
+
const program = new Command();
|
|
12
|
+
// Get the binary name from package.json
|
|
13
|
+
const binName = Object.keys(pkg.bin || {})[0];
|
|
14
|
+
program
|
|
15
|
+
.name(binName)
|
|
16
|
+
.description(pkg.description || 'Conquest.eth CLI - MCP server and direct tool execution')
|
|
17
|
+
.version(pkg.version)
|
|
18
|
+
// Global options available to all commands
|
|
19
|
+
.option('--rpc-url <url>', 'RPC URL for the Ethereum network', process.env.RPC_URL || '')
|
|
20
|
+
.option('--game-contract <address>', 'Contract address of the game', process.env.GAME_CONTRACT || '')
|
|
21
|
+
.option('--storage <type>', 'Storage backend: json or sqlite', process.env.STORAGE_TYPE || 'json')
|
|
22
|
+
.option('--storage-path <path>', 'Path to storage directory', process.env.STORAGE_PATH || './data')
|
|
23
|
+
.option('--private-key <key>', 'Private key for sending transactions', process.env.PRIVATE_KEY || '')
|
|
24
|
+
.action(() => {
|
|
25
|
+
program.help();
|
|
26
|
+
});
|
|
27
|
+
// MCP subcommand - starts the MCP server
|
|
28
|
+
program
|
|
29
|
+
.command('mcp')
|
|
30
|
+
.description('Start the MCP server')
|
|
31
|
+
.option('--ethereum', 'Whether to also provide tools-ethereum tools', process.env.ETHEREUM_TOOLS === 'true')
|
|
32
|
+
.action(async () => {
|
|
33
|
+
const options = program.opts();
|
|
34
|
+
const mcpOptions = program.commands.find((cmd) => cmd.name() === 'mcp')?.opts() || {};
|
|
35
|
+
const rpcUrl = options.rpcUrl;
|
|
36
|
+
const gameContract = options.gameContract;
|
|
37
|
+
const ethereum = mcpOptions.ethereum ?? process.env.ETHEREUM_TOOLS === 'true';
|
|
38
|
+
const privateKey = options.privateKey;
|
|
39
|
+
const storage = options.storage;
|
|
40
|
+
const storagePath = options.storagePath;
|
|
41
|
+
// Validate required options
|
|
42
|
+
if (!rpcUrl) {
|
|
43
|
+
console.error('Error: --rpc-url option or RPC_URL environment variable is required');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
if (!gameContract) {
|
|
47
|
+
console.error('Error: --game-contract option or GAME_CONTRACT environment variable is required');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
// Warn if private key is not provided for write operations
|
|
51
|
+
if (!privateKey) {
|
|
52
|
+
console.warn('Warning: PRIVATE_KEY environment variable is required for sending transactions');
|
|
53
|
+
}
|
|
54
|
+
else if (!privateKey.startsWith('0x')) {
|
|
55
|
+
console.error('Error: PRIVATE_KEY must start with 0x');
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
const chain = await getChain(rpcUrl);
|
|
59
|
+
const transport = new StdioServerTransport();
|
|
60
|
+
const server = createServer({
|
|
61
|
+
chain,
|
|
62
|
+
privateKey: privateKey,
|
|
63
|
+
gameContract: gameContract,
|
|
64
|
+
}, {
|
|
65
|
+
ethereum,
|
|
66
|
+
storageConfig: {
|
|
67
|
+
type: storage,
|
|
68
|
+
dataDir: storagePath,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
await server.connect(transport);
|
|
72
|
+
});
|
|
73
|
+
// Register all tool commands dynamically
|
|
74
|
+
registerAllToolCommands(program, tools);
|
|
75
|
+
program.parse(process.argv);
|
|
76
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,oBAAoB,EAAC,MAAM,2CAA2C,CAAC;AAC/E,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAM,IAAI,EAAE,MAAM,EAAC,CAAC;AACtD,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,uBAAuB,EAAC,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,CAAC;AAEV,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,wCAAwC;AACxC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9C,OAAO;KAC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AC,CAAC,CAAC;AAEJ,yCAAyC;AACzC,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAExC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SpaceInfo } from 'conquest-eth-v0-contracts';
|
|
2
|
+
import type { ClientsWithOptionalWallet, ContractConfig, GameContract } from '../types.js';
|
|
3
|
+
export declare function createSpaceInfo(clients: ClientsWithOptionalWallet, gameContract: GameContract): Promise<{
|
|
4
|
+
spaceInfo: SpaceInfo;
|
|
5
|
+
contractConfig: ContractConfig;
|
|
6
|
+
}>;
|
|
7
|
+
//# sourceMappingURL=space-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space-info.d.ts","sourceRoot":"","sources":["../../src/contracts/space-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AACpD,OAAO,KAAK,EAAC,yBAAyB,EAAE,cAAc,EAAE,YAAY,EAAC,MAAM,aAAa,CAAC;AAEzF,wBAAsB,eAAe,CACpC,OAAO,EAAE,yBAAyB,EAClC,YAAY,EAAE,YAAY,GACxB,OAAO,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,cAAc,EAAE,cAAc,CAAA;CAAC,CAAC,CAkCjE"}
|