cvm-server 0.12.0 → 0.13.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/README.md +183 -157
- package/main.cjs +738 -424
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,204 +1,230 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cvm-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The executable MCP server application for CVM. This is the npm package that users install to run CVM with Claude Desktop.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This app provides:
|
|
8
|
+
- **Executable MCP Server**: Ready-to-run server for Claude Desktop
|
|
9
|
+
- **Configuration Management**: Environment-based configuration
|
|
10
|
+
- **Logging**: Structured logging for debugging
|
|
11
|
+
- **Graceful Shutdown**: Proper cleanup on exit
|
|
12
|
+
- **Version Management**: Automatic version detection
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
## Architecture
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
```
|
|
17
|
+
Claude Desktop
|
|
18
|
+
↓ (stdio)
|
|
19
|
+
cvm-server (this app)
|
|
20
|
+
↓
|
|
21
|
+
CVMMcpServer (@cvm/mcp-server)
|
|
22
|
+
↓
|
|
23
|
+
VMManager (@cvm/vm)
|
|
24
|
+
↓
|
|
25
|
+
Storage + VM Engine
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
12
29
|
|
|
13
|
-
|
|
30
|
+
### For End Users
|
|
14
31
|
|
|
15
|
-
|
|
32
|
+
Add to Claude Desktop's MCP settings:
|
|
16
33
|
|
|
17
|
-
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"mcpServers": {
|
|
37
|
+
"cvm": {
|
|
38
|
+
"command": "npx",
|
|
39
|
+
"args": ["cvm-server@latest"],
|
|
40
|
+
"env": {
|
|
41
|
+
"CVM_STORAGE_TYPE": "file",
|
|
42
|
+
"CVM_DATA_DIR": ".cvm"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
18
48
|
|
|
19
|
-
|
|
20
|
-
- A TODO list that can have loops ("do this 5 times")
|
|
21
|
-
- A TODO list that can have conditions ("if X then do Y")
|
|
22
|
-
- A TODO list that maintains variables between tasks
|
|
23
|
-
- A TODO list shaped like a program
|
|
49
|
+
### For Development
|
|
24
50
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
4. CVM responds: "analyze this file"
|
|
30
|
-
5. Claude does the analysis and submits the result
|
|
31
|
-
6. CVM updates its state and moves to the next instruction
|
|
51
|
+
```bash
|
|
52
|
+
# Clone repository
|
|
53
|
+
git clone https://github.com/LadislavSopko/cvm.git
|
|
54
|
+
cd cvm
|
|
32
55
|
|
|
33
|
-
|
|
56
|
+
# Install dependencies
|
|
57
|
+
npm install
|
|
34
58
|
|
|
35
|
-
|
|
59
|
+
# Build all packages
|
|
60
|
+
npx nx build cvm-server
|
|
36
61
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function main() {
|
|
40
|
-
let count = 0;
|
|
41
|
-
while (count < 5) {
|
|
42
|
-
const next = CC("Current number is " + count + ". What's the next number?");
|
|
43
|
-
count = +next;
|
|
44
|
-
console.log("Count is now: " + count);
|
|
45
|
-
}
|
|
46
|
-
return count; // Returns 5
|
|
47
|
-
}
|
|
48
|
-
main();
|
|
62
|
+
# Run locally
|
|
63
|
+
node apps/cvm-server/dist/main.js
|
|
49
64
|
```
|
|
50
65
|
|
|
51
|
-
|
|
66
|
+
## Configuration
|
|
52
67
|
|
|
53
|
-
|
|
54
|
-
- CVM loads the program and starts execution
|
|
55
|
-
- When it hits `CC()`, CVM creates a task and waits
|
|
56
|
-
- Claude asks CVM for tasks using `getTask()`
|
|
57
|
-
- CVM gives Claude: "Current number is 0. What's the next number?"
|
|
58
|
-
- Claude figures out the answer is "1" and submits it
|
|
59
|
-
- CVM continues the loop with count=1
|
|
60
|
-
- Process repeats until done
|
|
68
|
+
The server uses environment variables for configuration:
|
|
61
69
|
|
|
62
|
-
|
|
70
|
+
### Storage Configuration
|
|
63
71
|
|
|
64
|
-
|
|
72
|
+
```bash
|
|
73
|
+
# File storage (default)
|
|
74
|
+
CVM_STORAGE_TYPE=file
|
|
75
|
+
CVM_DATA_DIR=.cvm
|
|
65
76
|
|
|
77
|
+
# MongoDB storage
|
|
78
|
+
CVM_STORAGE_TYPE=mongodb
|
|
79
|
+
MONGODB_URL=mongodb://localhost:27017/cvm
|
|
66
80
|
```
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
|
|
82
|
+
### Logging Configuration
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Log levels: debug, info, warn, error
|
|
86
|
+
CVM_LOG_LEVEL=info
|
|
87
|
+
|
|
88
|
+
# Log format: pretty (default) or json
|
|
89
|
+
CVM_LOG_FORMAT=pretty
|
|
75
90
|
```
|
|
76
91
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
- ❌ Can't handle real loops or conditions reliably
|
|
83
|
-
|
|
84
|
-
**CVM approach**: State lives in CVM, Claude just processes individual tasks
|
|
85
|
-
- ✅ Perfect state management
|
|
86
|
-
- ✅ Real loops and conditions that work
|
|
87
|
-
- ✅ Claude's context stays clean
|
|
88
|
-
- ✅ Complex workflows become simple task sequences
|
|
89
|
-
|
|
90
|
-
## Real Example
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
function main() {
|
|
94
|
-
const files = fs.listFiles("./docs", { filter: "*.txt" });
|
|
95
|
-
const summaries = [];
|
|
96
|
-
|
|
97
|
-
for (const file of files) {
|
|
98
|
-
// This creates a task for Claude, doesn't "call" Claude
|
|
99
|
-
const content = CC("Read and summarize this file: " + file);
|
|
100
|
-
// Now we can use objects!
|
|
101
|
-
summaries.push({
|
|
102
|
-
filename: file,
|
|
103
|
-
summary: content
|
|
104
|
-
});
|
|
105
|
-
console.log("Processed: " + file);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Convert summaries array to JSON for the final task
|
|
109
|
-
const summariesJson = JSON.stringify(summaries);
|
|
110
|
-
const report = CC("Create a final report from these file summaries: " + summariesJson);
|
|
111
|
-
console.log("Final Report: " + report);
|
|
112
|
-
|
|
113
|
-
return report;
|
|
114
|
-
}
|
|
115
|
-
main();
|
|
92
|
+
### Environment
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Environment: development, production
|
|
96
|
+
NODE_ENV=production
|
|
116
97
|
```
|
|
117
98
|
|
|
118
|
-
|
|
119
|
-
1. Task: "Read and summarize this file: ./docs/file1.txt"
|
|
120
|
-
2. Task: "Read and summarize this file: ./docs/file2.txt"
|
|
121
|
-
3. Task: "Read and summarize this file: ./docs/file3.txt"
|
|
122
|
-
4. Task: "Create a final report from these summaries: [...]"
|
|
99
|
+
## Features
|
|
123
100
|
|
|
124
|
-
|
|
101
|
+
### Automatic Storage Setup
|
|
102
|
+
- Creates storage directories if needed
|
|
103
|
+
- Warns about adding data directory to .gitignore
|
|
104
|
+
- Connects to MongoDB if configured
|
|
125
105
|
|
|
126
|
-
|
|
106
|
+
### Version Detection
|
|
107
|
+
- Attempts to find package.json in multiple locations
|
|
108
|
+
- Works in development and production builds
|
|
109
|
+
- Falls back to hardcoded version if needed
|
|
127
110
|
|
|
128
|
-
###
|
|
129
|
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
- Wait for Claude to ask for the next task
|
|
133
|
-
- Resume when Claude provides a result
|
|
111
|
+
### Graceful Shutdown
|
|
112
|
+
- Handles SIGINT and SIGTERM signals
|
|
113
|
+
- Closes all connections properly
|
|
114
|
+
- Ensures data is saved before exit
|
|
134
115
|
|
|
135
|
-
###
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
139
|
-
- Claude drives everything via MCP tools
|
|
116
|
+
### Error Handling
|
|
117
|
+
- Comprehensive error logging
|
|
118
|
+
- Graceful degradation
|
|
119
|
+
- Clear error messages for debugging
|
|
140
120
|
|
|
141
|
-
|
|
142
|
-
While Claude processes tasks, CVM maintains:
|
|
143
|
-
- All variables and their values
|
|
144
|
-
- Current execution position
|
|
145
|
-
- Loop counters and conditions
|
|
146
|
-
- Arrays, objects, and complex data structures
|
|
121
|
+
## File Structure
|
|
147
122
|
|
|
148
|
-
|
|
123
|
+
```
|
|
124
|
+
apps/cvm-server/
|
|
125
|
+
├── src/
|
|
126
|
+
│ ├── main.ts # Entry point
|
|
127
|
+
│ ├── config.ts # Configuration management
|
|
128
|
+
│ └── logger.ts # Logging setup
|
|
129
|
+
├── bin/
|
|
130
|
+
│ └── cvm-server.cjs # Executable wrapper
|
|
131
|
+
├── package.json # Package metadata
|
|
132
|
+
└── README.md # This file
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Building and Publishing
|
|
149
136
|
|
|
150
|
-
|
|
137
|
+
### Build
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Development build
|
|
141
|
+
npx nx build cvm-server --configuration=development
|
|
142
|
+
|
|
143
|
+
# Production build
|
|
144
|
+
npx nx build cvm-server --configuration=production
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Publish to npm
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Bump version and publish
|
|
151
|
+
npx nx release
|
|
152
|
+
|
|
153
|
+
# Or manually
|
|
154
|
+
cd apps/cvm-server/dist
|
|
155
|
+
npm publish --otp=YOUR_OTP
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Usage
|
|
159
|
+
|
|
160
|
+
Once installed, Claude can interact with CVM through MCP tools:
|
|
161
|
+
|
|
162
|
+
1. Load a program: `mcp__cvm__load`
|
|
163
|
+
2. Start execution: `mcp__cvm__start`
|
|
164
|
+
3. Get tasks: `mcp__cvm__getTask`
|
|
165
|
+
4. Submit results: `mcp__cvm__submitTask`
|
|
166
|
+
|
|
167
|
+
See the main project README for detailed usage examples.
|
|
168
|
+
|
|
169
|
+
## Development Tips
|
|
170
|
+
|
|
171
|
+
### Running Locally
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Set environment variables
|
|
175
|
+
export CVM_STORAGE_TYPE=file
|
|
176
|
+
export CVM_DATA_DIR=.cvm-dev
|
|
177
|
+
export CVM_LOG_LEVEL=debug
|
|
178
|
+
|
|
179
|
+
# Run the server
|
|
180
|
+
node apps/cvm-server/dist/main.js
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Testing with Claude Desktop
|
|
184
|
+
|
|
185
|
+
1. Build the server: `npx nx build cvm-server`
|
|
186
|
+
2. Update MCP config to point to local build:
|
|
151
187
|
```json
|
|
152
188
|
{
|
|
153
189
|
"mcpServers": {
|
|
154
190
|
"cvm": {
|
|
155
|
-
"command": "
|
|
156
|
-
"args": ["cvm-server
|
|
157
|
-
"env": {
|
|
158
|
-
"CVM_STORAGE_TYPE": "file",
|
|
159
|
-
"CVM_DATA_DIR": ".cvm"
|
|
160
|
-
}
|
|
191
|
+
"command": "node",
|
|
192
|
+
"args": ["/path/to/cvm/apps/cvm-server/dist/main.js"]
|
|
161
193
|
}
|
|
162
194
|
}
|
|
163
195
|
}
|
|
164
196
|
```
|
|
165
197
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
Claude uses these tools to interact with CVM:
|
|
169
|
-
|
|
170
|
-
- **`load(programId, source)`** - Load a program into CVM
|
|
171
|
-
- **`loadFile(programId, filePath)`** - Load from file
|
|
172
|
-
- **`start(programId, executionId)`** - Start execution
|
|
173
|
-
- **`getTask(executionId)`** - Get next task (CVM waits for this)
|
|
174
|
-
- **`submitTask(executionId, result)`** - Submit task result
|
|
175
|
-
- **`status(executionId)`** - Check execution state
|
|
198
|
+
### Debugging
|
|
176
199
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
- Object literals and property access
|
|
183
|
-
- `JSON.stringify()` and `JSON.parse()`
|
|
184
|
-
- `CC()` for task creation
|
|
185
|
-
- `fs.listFiles()` for file operations
|
|
186
|
-
- `console.log()` for output
|
|
187
|
-
|
|
188
|
-
[→ Full API Documentation](docs/API.md)
|
|
200
|
+
Enable debug logging:
|
|
201
|
+
```bash
|
|
202
|
+
export CVM_LOG_LEVEL=debug
|
|
203
|
+
export CVM_LOG_FORMAT=pretty
|
|
204
|
+
```
|
|
189
205
|
|
|
190
|
-
|
|
206
|
+
Check logs for:
|
|
207
|
+
- Storage initialization
|
|
208
|
+
- MCP tool calls
|
|
209
|
+
- VM state changes
|
|
210
|
+
- Error traces
|
|
191
211
|
|
|
192
|
-
|
|
193
|
-
- Document analysis pipelines
|
|
194
|
-
- Data extraction from multiple sources
|
|
195
|
-
- Report generation with multiple inputs
|
|
196
|
-
- Any task requiring loops with AI processing
|
|
212
|
+
## Dependencies
|
|
197
213
|
|
|
198
|
-
|
|
214
|
+
### Runtime Dependencies
|
|
215
|
+
- **@modelcontextprotocol/sdk**: MCP protocol implementation
|
|
216
|
+
- **dotenv**: Environment variable loading
|
|
217
|
+
- **mongodb**: MongoDB driver (optional)
|
|
218
|
+
- **typescript**: Type definitions
|
|
219
|
+
- **zod**: Schema validation
|
|
199
220
|
|
|
200
|
-
|
|
221
|
+
### Internal Dependencies
|
|
222
|
+
- **@cvm/mcp-server**: MCP server implementation
|
|
223
|
+
- **@cvm/vm**: Core VM engine
|
|
224
|
+
- **@cvm/storage**: Storage layer
|
|
225
|
+
- **@cvm/parser**: CVM language parser
|
|
226
|
+
- **@cvm/types**: Shared types
|
|
201
227
|
|
|
202
|
-
|
|
228
|
+
## License
|
|
203
229
|
|
|
204
|
-
|
|
230
|
+
Apache 2.0 - See LICENSE file for details
|