-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
54 lines (45 loc) · 1.65 KB
/
index.ts
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
import { AblyBaseCommand } from '../../base-command.js'
// Track execution in each process run, not globally across all runs
const executionTracker = new class {
private isExecuting = false;
private lastExecutionTimestamp = 0;
done(): void {
this.isExecuting = false;
}
shouldExecute(): boolean {
// If we're already in an execution, don't run again
if (this.isExecuting) return false;
// If this is the first execution or if more than 1 second has passed since the last execution
// (to avoid issues with rapid sequential command execution), allow execution
const now = Date.now();
if (now - this.lastExecutionTimestamp > 1000) {
this.isExecuting = true;
this.lastExecutionTimestamp = now;
return true;
}
return false;
}
}();
export default class McpCommands extends AblyBaseCommand {
static description = 'Experimental Model Context Protocol (MCP) commands for AI tools to interact with Ably'
static examples = [
'<%= config.bin %> <%= command.id %> start-server',
]
async run(): Promise<void> {
// Check if we should execute this command to avoid duplication
if (!executionTracker.shouldExecute()) {
return;
}
try {
// Display available MCP commands
this.log('Model Context Protocol (MCP) commands:')
this.log('')
this.log(' ably mcp start-server - Start an MCP server for AI tools to interact with Ably (currently experimental)')
this.log('')
this.log('Run `ably mcp COMMAND --help` for more information on a command.')
} finally {
// Mark execution as complete
executionTracker.done();
}
}
}