-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.js
More file actions
163 lines (134 loc) · 3.98 KB
/
demo.js
File metadata and controls
163 lines (134 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env node
import { spawn } from 'child_process';
import readline from 'readline';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log('🚀 Nativelink MCP Server Demo\n');
console.log('This demo shows the MCP server responding to tool requests.\n');
// Start the server
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
let requestId = 1;
function sendRequest(request) {
return new Promise((resolve) => {
const jsonRequest = JSON.stringify({
jsonrpc: '2.0',
...request,
id: requestId++
}) + '\n';
server.stdin.write(jsonRequest);
const handler = (data) => {
const lines = data.toString().split('\n');
for (const line of lines) {
if (line.trim()) {
try {
const response = JSON.parse(line);
if (response.id === requestId - 1) {
server.stdout.removeListener('data', handler);
resolve(response);
}
} catch (e) {
// Continue collecting
}
}
}
};
server.stdout.on('data', handler);
});
}
async function demo() {
console.log('1️⃣ Listing available tools...\n');
const toolsList = await sendRequest({
method: 'tools/list'
});
console.log('Available tools:');
toolsList.result.tools.forEach(tool => {
console.log(` • ${tool.name}: ${tool.description}`);
});
console.log('\n2️⃣ Generating Bazel config for a Rust project...\n');
const bazelConfig = await sendRequest({
method: 'tools/call',
params: {
name: 'get-bazel-config',
arguments: {
projectType: 'rust',
features: ['remote_cache', 'remote_execution']
}
}
});
console.log('Generated Bazel configuration:');
console.log('---');
console.log(bazelConfig.result.content[0].text.substring(0, 500) + '...');
console.log('---');
console.log('\n3️⃣ Getting Nativelink setup documentation...\n');
const docs = await sendRequest({
method: 'tools/call',
params: {
name: 'get-nativelink-docs',
arguments: {
topic: 'setup',
maxTokens: 2000
}
}
});
console.log('Documentation excerpt:');
console.log('---');
console.log(docs.result.content[0].text.substring(0, 400) + '...');
console.log('---');
console.log('\n4️⃣ Analyzing build performance...\n');
const analysis = await sendRequest({
method: 'tools/call',
params: {
name: 'analyze-build-performance',
arguments: {
metrics: {
cacheHitRate: 0.45,
totalTime: 600,
networkTransferSize: 1024 * 1024 * 500
},
targetOptimization: 'speed'
}
}
});
console.log('Performance analysis:');
console.log('---');
console.log(analysis.result.content[0].text.substring(0, 400) + '...');
console.log('---');
console.log('\n5️⃣ Generating Kubernetes deployment config...\n');
const deployment = await sendRequest({
method: 'tools/call',
params: {
name: 'generate-deployment-config',
arguments: {
platform: 'kubernetes',
scale: 'medium',
features: ['monitoring', 'autoscaling']
}
}
});
console.log('Kubernetes deployment (excerpt):');
console.log('---');
console.log(deployment.result.content[0].text.substring(0, 400) + '...');
console.log('---');
console.log('\n✅ Demo completed successfully!');
console.log('\nTo use this MCP server with Cursor or Claude Code:');
console.log('1. Install: npm install -g @nativelink/mcp-server');
console.log('2. Add to your MCP configuration');
console.log('3. Use "use nativelink" in your prompts\n');
server.kill();
process.exit(0);
}
// Handle errors
server.on('error', (error) => {
console.error('Error:', error);
process.exit(1);
});
server.stderr.on('data', (data) => {
console.error('Server error:', data.toString());
});
// Run demo
console.log('Starting MCP server...\n');
setTimeout(demo, 1000);