claude-flow 2.5.0-alpha.138 → 2.5.0-alpha.141

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.
@@ -0,0 +1,221 @@
1
+ import { query } from '@anthropic-ai/claude-code';
2
+ import { RealSessionForking } from './session-forking';
3
+ import { RealQueryController } from './query-control';
4
+ import { RealCheckpointManager } from './checkpoint-manager';
5
+ import { createMathMcpServer, createSessionMcpServer, createCheckpointMcpServer, createQueryControlMcpServer } from './in-process-mcp';
6
+ export class IntegratedClaudeFlowSession {
7
+ forking;
8
+ controller;
9
+ checkpointManager;
10
+ config;
11
+ constructor(config = {}){
12
+ this.config = config;
13
+ if (config.enableSessionForking) {
14
+ this.forking = new RealSessionForking();
15
+ }
16
+ if (config.enableQueryControl) {
17
+ this.controller = new RealQueryController();
18
+ }
19
+ if (config.enableCheckpoints) {
20
+ this.checkpointManager = new RealCheckpointManager({
21
+ autoCheckpointInterval: config.checkpointInterval || 10
22
+ });
23
+ }
24
+ }
25
+ async createIntegratedQuery(prompt, sessionId, options = {}) {
26
+ const mcpServers = {};
27
+ if (this.config.inProcessServers?.math) {
28
+ mcpServers.math = createMathMcpServer();
29
+ }
30
+ if (this.config.inProcessServers?.session) {
31
+ mcpServers.session = createSessionMcpServer();
32
+ }
33
+ if (this.config.inProcessServers?.checkpoint) {
34
+ mcpServers.checkpoint = createCheckpointMcpServer();
35
+ }
36
+ if (this.config.inProcessServers?.queryControl) {
37
+ mcpServers.queryControl = createQueryControlMcpServer();
38
+ }
39
+ const integratedQuery = query({
40
+ prompt,
41
+ options: {
42
+ ...options,
43
+ mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined
44
+ }
45
+ });
46
+ if (this.forking) {
47
+ await this.forking.trackSession(sessionId, integratedQuery);
48
+ }
49
+ if (this.checkpointManager && this.config.enableCheckpoints) {
50
+ await this.checkpointManager.trackSession(sessionId, integratedQuery, true);
51
+ }
52
+ return integratedQuery;
53
+ }
54
+ async forkWithMcpCoordination(baseSessionId, forkDescription) {
55
+ if (!this.forking) {
56
+ throw new Error('Session forking not enabled');
57
+ }
58
+ const fork = await this.forking.fork(baseSessionId, {});
59
+ if (this.checkpointManager) {
60
+ await this.checkpointManager.createCheckpoint(baseSessionId, `Fork created: ${forkDescription}`);
61
+ }
62
+ return fork;
63
+ }
64
+ async pauseWithCheckpoint(activeQuery, sessionId, originalPrompt, checkpointDescription) {
65
+ if (!this.controller) {
66
+ throw new Error('Query control not enabled');
67
+ }
68
+ this.controller.requestPause(sessionId);
69
+ const pausePointId = await this.controller.pauseQuery(activeQuery, sessionId, originalPrompt, {});
70
+ if (this.checkpointManager) {
71
+ await this.checkpointManager.createCheckpoint(sessionId, checkpointDescription || `Paused at ${pausePointId}`);
72
+ }
73
+ return pausePointId;
74
+ }
75
+ async resumeFromCheckpoint(checkpointId, continuePrompt) {
76
+ if (!this.checkpointManager) {
77
+ throw new Error('Checkpoints not enabled');
78
+ }
79
+ return await this.checkpointManager.rollbackToCheckpoint(checkpointId, continuePrompt);
80
+ }
81
+ getMetrics() {
82
+ return {
83
+ queryControl: this.controller?.getMetrics(),
84
+ activeSessions: this.forking?.getActiveSessions(),
85
+ checkpoints: this.checkpointManager ? {
86
+ enabled: true
87
+ } : {
88
+ enabled: false
89
+ }
90
+ };
91
+ }
92
+ }
93
+ export async function exampleClaudeFlowMcpWithSdk() {
94
+ const session = new IntegratedClaudeFlowSession({
95
+ enableSessionForking: true,
96
+ enableQueryControl: true,
97
+ enableCheckpoints: true,
98
+ checkpointInterval: 10,
99
+ mcpToolsConfig: {
100
+ swarmTopology: 'mesh',
101
+ maxAgents: 8,
102
+ enableNeural: true,
103
+ enableMemory: true
104
+ },
105
+ inProcessServers: {
106
+ math: true,
107
+ session: true,
108
+ checkpoint: true,
109
+ queryControl: true
110
+ }
111
+ });
112
+ const mainQuery = await session.createIntegratedQuery(`
113
+ Initialize a mesh swarm with 8 agents using Claude Flow MCP tools.
114
+ Then use the math MCP server to calculate factorial of 10.
115
+ Store results in session and create a checkpoint.
116
+ `, 'integrated-session', {});
117
+ console.log('Created integrated query with:');
118
+ console.log('- SDK: Session forking, checkpoints, query control');
119
+ console.log('- In-process MCP: math, session, checkpoint, queryControl');
120
+ console.log('- Claude Flow MCP tools: swarm_init, agent_spawn, etc.');
121
+ const fork1 = await session.forkWithMcpCoordination('integrated-session', 'Try hierarchical topology');
122
+ console.log('Forked session:', fork1.sessionId);
123
+ if (session['checkpointManager']) {
124
+ const cp = await session['checkpointManager'].createCheckpoint('integrated-session', 'Before swarm initialization');
125
+ console.log('Checkpoint created:', cp);
126
+ }
127
+ const metrics = session.getMetrics();
128
+ console.log('Metrics:', metrics);
129
+ }
130
+ export function exampleNpxIntegration() {
131
+ console.log(`
132
+ ╔════════════════════════════════════════════════════════════╗
133
+ ║ Claude Flow NPX + SDK Integration ║
134
+ ╚════════════════════════════════════════════════════════════╝
135
+
136
+ # Install Claude Flow MCP server
137
+ claude mcp add claude-flow npx claude-flow@alpha mcp start
138
+
139
+ # Optional: Add ruv-swarm for enhanced coordination
140
+ claude mcp add ruv-swarm npx ruv-swarm mcp start
141
+
142
+ # Now use SDK features WITH MCP tools:
143
+
144
+ ## 1. Session Forking + Swarm Coordination
145
+ import { query } from '@anthropic-ai/claude-code';
146
+ import { RealSessionForking } from './sdk/session-forking';
147
+
148
+ const forking = new RealSessionForking();
149
+ const q = query({
150
+ prompt: 'Use mcp__claude-flow__swarm_init to create mesh topology',
151
+ options: {
152
+ // MCP tools are auto-available via 'claude mcp add'
153
+ }
154
+ });
155
+
156
+ await forking.trackSession('swarm-session', q);
157
+ const fork = await forking.fork('swarm-session');
158
+
159
+ ## 2. Checkpoints + Neural Training
160
+ import { RealCheckpointManager } from './sdk/checkpoint-manager';
161
+
162
+ const manager = new RealCheckpointManager();
163
+ const q = query({
164
+ prompt: 'Use mcp__claude-flow__neural_train to train patterns',
165
+ });
166
+
167
+ await manager.trackSession('neural-session', q, true);
168
+ const cp = await manager.createCheckpoint('neural-session', 'Before training');
169
+
170
+ // Train neural patterns with Claude Flow MCP
171
+ // Then rollback if needed:
172
+ await manager.rollbackToCheckpoint(cp);
173
+
174
+ ## 3. Query Control + Task Orchestration
175
+ import { RealQueryController } from './sdk/query-control';
176
+
177
+ const controller = new RealQueryController();
178
+ const q = query({
179
+ prompt: \`
180
+ Use mcp__claude-flow__task_orchestrate to:
181
+ - Break down complex task
182
+ - Distribute to agents
183
+ - Monitor progress
184
+ \`,
185
+ });
186
+
187
+ // Pause if needed
188
+ controller.requestPause('task-session');
189
+ const pauseId = await controller.pauseQuery(q, 'task-session', 'Task', {});
190
+
191
+ // Resume later
192
+ const resumed = await controller.resumeQuery('task-session');
193
+
194
+ ## 4. In-Process MCP + Claude Flow MCP Together
195
+ import { createMathMcpServer } from './sdk/in-process-mcp';
196
+
197
+ const q = query({
198
+ prompt: \`
199
+ Use math server to calculate factorial.
200
+ Use mcp__claude-flow__memory_usage to store result.
201
+ Use mcp__claude-flow__agent_spawn to process result.
202
+ \`,
203
+ options: {
204
+ mcpServers: {
205
+ math: createMathMcpServer(), // In-process (fast!)
206
+ // claude-flow MCP tools auto-available
207
+ }
208
+ }
209
+ });
210
+
211
+ ╔════════════════════════════════════════════════════════════╗
212
+ ║ Key Benefits: ║
213
+ ║ ✅ SDK = In-process, zero overhead ║
214
+ ║ ✅ MCP tools = Coordination, neural, swarms ║
215
+ ║ ✅ Together = Maximum power and flexibility ║
216
+ ╚════════════════════════════════════════════════════════════╝
217
+ `);
218
+ }
219
+ export { IntegratedClaudeFlowSession };
220
+
221
+ //# sourceMappingURL=claude-flow-mcp-integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/sdk/claude-flow-mcp-integration.ts"],"sourcesContent":["/**\n * Claude Flow MCP Integration - SDK + Existing MCP Tools\n * Claude-Flow v2.5-alpha.130+\n *\n * Integrates SDK-powered features WITH existing Claude Flow MCP tools:\n * - Uses SDK for session management, forking, checkpoints\n * - Uses Claude Flow MCP tools for swarm coordination, neural features\n * - Combines both for maximum power\n *\n * VERIFIED: Real integration of SDK + MCP tools\n */\n\nimport { query, type Query, type Options } from '@anthropic-ai/claude-code';\nimport { RealSessionForking } from './session-forking';\nimport { RealQueryController } from './query-control';\nimport { RealCheckpointManager } from './checkpoint-manager';\nimport {\n createMathMcpServer,\n createSessionMcpServer,\n createCheckpointMcpServer,\n createQueryControlMcpServer,\n} from './in-process-mcp';\n\n/**\n * Integration Configuration\n */\nexport interface ClaudeFlowIntegrationConfig {\n // SDK features\n enableSessionForking?: boolean;\n enableQueryControl?: boolean;\n enableCheckpoints?: boolean;\n checkpointInterval?: number;\n\n // MCP tool configuration\n mcpToolsConfig?: {\n swarmTopology?: 'hierarchical' | 'mesh' | 'ring' | 'star';\n maxAgents?: number;\n enableNeural?: boolean;\n enableMemory?: boolean;\n };\n\n // In-process MCP servers\n inProcessServers?: {\n math?: boolean;\n session?: boolean;\n checkpoint?: boolean;\n queryControl?: boolean;\n };\n}\n\n/**\n * Integrated Claude Flow Session\n *\n * Combines SDK features with Claude Flow MCP tools\n */\nexport class IntegratedClaudeFlowSession {\n private forking?: RealSessionForking;\n private controller?: RealQueryController;\n private checkpointManager?: RealCheckpointManager;\n private config: ClaudeFlowIntegrationConfig;\n\n constructor(config: ClaudeFlowIntegrationConfig = {}) {\n this.config = config;\n\n // Initialize SDK features based on config\n if (config.enableSessionForking) {\n this.forking = new RealSessionForking();\n }\n\n if (config.enableQueryControl) {\n this.controller = new RealQueryController();\n }\n\n if (config.enableCheckpoints) {\n this.checkpointManager = new RealCheckpointManager({\n autoCheckpointInterval: config.checkpointInterval || 10,\n });\n }\n }\n\n /**\n * Create a query that uses BOTH SDK features AND Claude Flow MCP tools\n */\n async createIntegratedQuery(\n prompt: string,\n sessionId: string,\n options: Partial<Options> = {}\n ): Promise<Query> {\n // Build MCP servers configuration\n const mcpServers: Record<string, any> = {};\n\n // Add in-process servers if enabled\n if (this.config.inProcessServers?.math) {\n mcpServers.math = createMathMcpServer();\n }\n if (this.config.inProcessServers?.session) {\n mcpServers.session = createSessionMcpServer();\n }\n if (this.config.inProcessServers?.checkpoint) {\n mcpServers.checkpoint = createCheckpointMcpServer();\n }\n if (this.config.inProcessServers?.queryControl) {\n mcpServers.queryControl = createQueryControlMcpServer();\n }\n\n // Add Claude Flow MCP tools (these use stdio/subprocess)\n // The MCP server is already configured globally via `claude mcp add claude-flow`\n // So we don't need to add it here - it's automatically available\n\n // Create the query\n const integratedQuery = query({\n prompt,\n options: {\n ...options,\n mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined,\n },\n });\n\n // Track with SDK features\n if (this.forking) {\n await this.forking.trackSession(sessionId, integratedQuery);\n }\n\n if (this.checkpointManager && this.config.enableCheckpoints) {\n await this.checkpointManager.trackSession(\n sessionId,\n integratedQuery,\n true // Auto-checkpoint\n );\n }\n\n return integratedQuery;\n }\n\n /**\n * Fork a session (SDK) while using Claude Flow MCP tools for coordination\n */\n async forkWithMcpCoordination(\n baseSessionId: string,\n forkDescription: string\n ) {\n if (!this.forking) {\n throw new Error('Session forking not enabled');\n }\n\n // Fork using SDK\n const fork = await this.forking.fork(baseSessionId, {\n // In-process servers are inherited\n });\n\n // Create checkpoint for fork point\n if (this.checkpointManager) {\n await this.checkpointManager.createCheckpoint(\n baseSessionId,\n `Fork created: ${forkDescription}`\n );\n }\n\n return fork;\n }\n\n /**\n * Pause a query (SDK) and create checkpoint\n */\n async pauseWithCheckpoint(\n activeQuery: Query,\n sessionId: string,\n originalPrompt: string,\n checkpointDescription: string\n ) {\n if (!this.controller) {\n throw new Error('Query control not enabled');\n }\n\n // Request pause\n this.controller.requestPause(sessionId);\n\n // Pause query\n const pausePointId = await this.controller.pauseQuery(\n activeQuery,\n sessionId,\n originalPrompt,\n {}\n );\n\n // Create checkpoint at pause point\n if (this.checkpointManager) {\n await this.checkpointManager.createCheckpoint(\n sessionId,\n checkpointDescription || `Paused at ${pausePointId}`\n );\n }\n\n return pausePointId;\n }\n\n /**\n * Resume from checkpoint\n */\n async resumeFromCheckpoint(checkpointId: string, continuePrompt?: string) {\n if (!this.checkpointManager) {\n throw new Error('Checkpoints not enabled');\n }\n\n // Rollback to checkpoint using SDK\n return await this.checkpointManager.rollbackToCheckpoint(\n checkpointId,\n continuePrompt\n );\n }\n\n /**\n * Get comprehensive metrics\n */\n getMetrics() {\n return {\n queryControl: this.controller?.getMetrics(),\n activeSessions: this.forking?.getActiveSessions(),\n checkpoints: this.checkpointManager\n ? {\n // Would need to track total checkpoints across sessions\n enabled: true,\n }\n : { enabled: false },\n };\n }\n}\n\n/**\n * Example: Use Claude Flow MCP tools WITH SDK features\n */\nexport async function exampleClaudeFlowMcpWithSdk() {\n const session = new IntegratedClaudeFlowSession({\n enableSessionForking: true,\n enableQueryControl: true,\n enableCheckpoints: true,\n checkpointInterval: 10,\n mcpToolsConfig: {\n swarmTopology: 'mesh',\n maxAgents: 8,\n enableNeural: true,\n enableMemory: true,\n },\n inProcessServers: {\n math: true,\n session: true,\n checkpoint: true,\n queryControl: true,\n },\n });\n\n // Create query that uses BOTH:\n // - In-process MCP servers (SDK)\n // - Claude Flow MCP tools (stdio)\n const mainQuery = await session.createIntegratedQuery(\n `\n Initialize a mesh swarm with 8 agents using Claude Flow MCP tools.\n Then use the math MCP server to calculate factorial of 10.\n Store results in session and create a checkpoint.\n `,\n 'integrated-session',\n {}\n );\n\n console.log('Created integrated query with:');\n console.log('- SDK: Session forking, checkpoints, query control');\n console.log('- In-process MCP: math, session, checkpoint, queryControl');\n console.log('- Claude Flow MCP tools: swarm_init, agent_spawn, etc.');\n\n // Fork the session to try different approaches\n const fork1 = await session.forkWithMcpCoordination(\n 'integrated-session',\n 'Try hierarchical topology'\n );\n\n console.log('Forked session:', fork1.sessionId);\n\n // Create checkpoint before major changes\n if (session['checkpointManager']) {\n const cp = await session['checkpointManager'].createCheckpoint(\n 'integrated-session',\n 'Before swarm initialization'\n );\n console.log('Checkpoint created:', cp);\n }\n\n // Get metrics\n const metrics = session.getMetrics();\n console.log('Metrics:', metrics);\n}\n\n/**\n * NPX Command Integration\n *\n * Show how to use Claude Flow NPX commands with SDK features\n */\nexport function exampleNpxIntegration() {\n console.log(`\n╔════════════════════════════════════════════════════════════╗\n║ Claude Flow NPX + SDK Integration ║\n╚════════════════════════════════════════════════════════════╝\n\n# Install Claude Flow MCP server\nclaude mcp add claude-flow npx claude-flow@alpha mcp start\n\n# Optional: Add ruv-swarm for enhanced coordination\nclaude mcp add ruv-swarm npx ruv-swarm mcp start\n\n# Now use SDK features WITH MCP tools:\n\n## 1. Session Forking + Swarm Coordination\nimport { query } from '@anthropic-ai/claude-code';\nimport { RealSessionForking } from './sdk/session-forking';\n\nconst forking = new RealSessionForking();\nconst q = query({\n prompt: 'Use mcp__claude-flow__swarm_init to create mesh topology',\n options: {\n // MCP tools are auto-available via 'claude mcp add'\n }\n});\n\nawait forking.trackSession('swarm-session', q);\nconst fork = await forking.fork('swarm-session');\n\n## 2. Checkpoints + Neural Training\nimport { RealCheckpointManager } from './sdk/checkpoint-manager';\n\nconst manager = new RealCheckpointManager();\nconst q = query({\n prompt: 'Use mcp__claude-flow__neural_train to train patterns',\n});\n\nawait manager.trackSession('neural-session', q, true);\nconst cp = await manager.createCheckpoint('neural-session', 'Before training');\n\n// Train neural patterns with Claude Flow MCP\n// Then rollback if needed:\nawait manager.rollbackToCheckpoint(cp);\n\n## 3. Query Control + Task Orchestration\nimport { RealQueryController } from './sdk/query-control';\n\nconst controller = new RealQueryController();\nconst q = query({\n prompt: \\`\n Use mcp__claude-flow__task_orchestrate to:\n - Break down complex task\n - Distribute to agents\n - Monitor progress\n \\`,\n});\n\n// Pause if needed\ncontroller.requestPause('task-session');\nconst pauseId = await controller.pauseQuery(q, 'task-session', 'Task', {});\n\n// Resume later\nconst resumed = await controller.resumeQuery('task-session');\n\n## 4. In-Process MCP + Claude Flow MCP Together\nimport { createMathMcpServer } from './sdk/in-process-mcp';\n\nconst q = query({\n prompt: \\`\n Use math server to calculate factorial.\n Use mcp__claude-flow__memory_usage to store result.\n Use mcp__claude-flow__agent_spawn to process result.\n \\`,\n options: {\n mcpServers: {\n math: createMathMcpServer(), // In-process (fast!)\n // claude-flow MCP tools auto-available\n }\n }\n});\n\n╔════════════════════════════════════════════════════════════╗\n║ Key Benefits: ║\n║ ✅ SDK = In-process, zero overhead ║\n║ ✅ MCP tools = Coordination, neural, swarms ║\n║ ✅ Together = Maximum power and flexibility ║\n╚════════════════════════════════════════════════════════════╝\n `);\n}\n\nexport { IntegratedClaudeFlowSession };\n"],"names":["query","RealSessionForking","RealQueryController","RealCheckpointManager","createMathMcpServer","createSessionMcpServer","createCheckpointMcpServer","createQueryControlMcpServer","IntegratedClaudeFlowSession","forking","controller","checkpointManager","config","enableSessionForking","enableQueryControl","enableCheckpoints","autoCheckpointInterval","checkpointInterval","createIntegratedQuery","prompt","sessionId","options","mcpServers","inProcessServers","math","session","checkpoint","queryControl","integratedQuery","Object","keys","length","undefined","trackSession","forkWithMcpCoordination","baseSessionId","forkDescription","Error","fork","createCheckpoint","pauseWithCheckpoint","activeQuery","originalPrompt","checkpointDescription","requestPause","pausePointId","pauseQuery","resumeFromCheckpoint","checkpointId","continuePrompt","rollbackToCheckpoint","getMetrics","activeSessions","getActiveSessions","checkpoints","enabled","exampleClaudeFlowMcpWithSdk","mcpToolsConfig","swarmTopology","maxAgents","enableNeural","enableMemory","mainQuery","console","log","fork1","cp","metrics","exampleNpxIntegration"],"mappings":"AAYA,SAASA,KAAK,QAAkC,4BAA4B;AAC5E,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,mBAAmB,QAAQ,kBAAkB;AACtD,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SACEC,mBAAmB,EACnBC,sBAAsB,EACtBC,yBAAyB,EACzBC,2BAA2B,QACtB,mBAAmB;AAkC1B,OAAO,MAAMC;IACHC,QAA6B;IAC7BC,WAAiC;IACjCC,kBAA0C;IAC1CC,OAAoC;IAE5C,YAAYA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ACA;gBAAEA,SAAS;YAAM;QACvB;IACF;AACF;AAKA,OAAO,eAAeC;IACpB,MAAM/B,UAAU,IAAIjB,4BAA4B;QAC9CK,sBAAsB;QACtBC,oBAAoB;QACpBC,mBAAmB;QACnBE,oBAAoB;QACpBwC,gBAAgB;YACdC,eAAe;YACfC,WAAW;YACXC,cAAc;YACdC,cAAc;QAChB;QACAtC,kBAAkB;YAChBC,MAAM;YACNC,SAAS;YACTC,YAAY;YACZC,cAAc;QAChB;IACF;IAKA,MAAMmC,YAAY,MAAMrC,QAAQP,qBAAqB,CACnD,CAAC;;;;IAID,CAAC,EACD,sBACA,CAAC;IAGH6C,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IAGZ,MAAMC,QAAQ,MAAMxC,QAAQS,uBAAuB,CACjD,sBACA;IAGF6B,QAAQC,GAAG,CAAC,mBAAmBC,MAAM7C,SAAS;IAG9C,IAAIK,OAAO,CAAC,oBAAoB,EAAE;QAChC,MAAMyC,KAAK,MAAMzC,OAAO,CAAC,oBAAoB,CAACc,gBAAgB,CAC5D,sBACA;QAEFwB,QAAQC,GAAG,CAAC,uBAAuBE;IACrC;IAGA,MAAMC,UAAU1C,QAAQ0B,UAAU;IAClCY,QAAQC,GAAG,CAAC,YAAYG;AAC1B;AAOA,OAAO,SAASC;IACdL,QAAQC,GAAG,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsFb,CAAC;AACH;AAEA,SAASxD,2BAA2B,GAAG"}
@@ -0,0 +1,374 @@
1
+ import { createSdkMcpServer, tool } from '@anthropic-ai/claude-code';
2
+ import { z } from 'zod';
3
+ export function createMathMcpServer() {
4
+ return createSdkMcpServer({
5
+ name: 'math-operations',
6
+ version: '1.0.0',
7
+ tools: [
8
+ tool({
9
+ name: 'add',
10
+ description: 'Add two numbers together',
11
+ parameters: z.object({
12
+ a: z.number().describe('First number'),
13
+ b: z.number().describe('Second number')
14
+ }),
15
+ execute: async ({ a, b })=>{
16
+ return {
17
+ result: a + b
18
+ };
19
+ }
20
+ }),
21
+ tool({
22
+ name: 'multiply',
23
+ description: 'Multiply two numbers',
24
+ parameters: z.object({
25
+ a: z.number().describe('First number'),
26
+ b: z.number().describe('Second number')
27
+ }),
28
+ execute: async ({ a, b })=>{
29
+ return {
30
+ result: a * b
31
+ };
32
+ }
33
+ }),
34
+ tool({
35
+ name: 'factorial',
36
+ description: 'Calculate factorial of a number',
37
+ parameters: z.object({
38
+ n: z.number().int().min(0).describe('Number to calculate factorial of')
39
+ }),
40
+ execute: async ({ n })=>{
41
+ let result = 1;
42
+ for(let i = 2; i <= n; i++){
43
+ result *= i;
44
+ }
45
+ return {
46
+ result
47
+ };
48
+ }
49
+ })
50
+ ]
51
+ });
52
+ }
53
+ export function createSessionMcpServer() {
54
+ const sessions = new Map();
55
+ return createSdkMcpServer({
56
+ name: 'session-manager',
57
+ version: '1.0.0',
58
+ tools: [
59
+ tool({
60
+ name: 'session_create',
61
+ description: 'Create a new session with initial data',
62
+ parameters: z.object({
63
+ sessionId: z.string().describe('Session identifier'),
64
+ data: z.record(z.any()).optional().describe('Initial session data')
65
+ }),
66
+ execute: async ({ sessionId, data = {} })=>{
67
+ if (sessions.has(sessionId)) {
68
+ return {
69
+ error: 'Session already exists'
70
+ };
71
+ }
72
+ sessions.set(sessionId, {
73
+ data,
74
+ created: Date.now()
75
+ });
76
+ return {
77
+ success: true,
78
+ sessionId,
79
+ created: sessions.get(sessionId).created
80
+ };
81
+ }
82
+ }),
83
+ tool({
84
+ name: 'session_get',
85
+ description: 'Get session data by ID',
86
+ parameters: z.object({
87
+ sessionId: z.string().describe('Session identifier')
88
+ }),
89
+ execute: async ({ sessionId })=>{
90
+ const session = sessions.get(sessionId);
91
+ if (!session) {
92
+ return {
93
+ error: 'Session not found'
94
+ };
95
+ }
96
+ return {
97
+ sessionId,
98
+ data: session.data,
99
+ created: session.created
100
+ };
101
+ }
102
+ }),
103
+ tool({
104
+ name: 'session_update',
105
+ description: 'Update session data (merges with existing)',
106
+ parameters: z.object({
107
+ sessionId: z.string().describe('Session identifier'),
108
+ data: z.record(z.any()).describe('Data to merge')
109
+ }),
110
+ execute: async ({ sessionId, data })=>{
111
+ const session = sessions.get(sessionId);
112
+ if (!session) {
113
+ return {
114
+ error: 'Session not found'
115
+ };
116
+ }
117
+ session.data = {
118
+ ...session.data,
119
+ ...data
120
+ };
121
+ return {
122
+ success: true,
123
+ sessionId,
124
+ data: session.data
125
+ };
126
+ }
127
+ }),
128
+ tool({
129
+ name: 'session_delete',
130
+ description: 'Delete a session',
131
+ parameters: z.object({
132
+ sessionId: z.string().describe('Session identifier')
133
+ }),
134
+ execute: async ({ sessionId })=>{
135
+ const existed = sessions.delete(sessionId);
136
+ return {
137
+ success: existed,
138
+ sessionId
139
+ };
140
+ }
141
+ }),
142
+ tool({
143
+ name: 'session_list',
144
+ description: 'List all active sessions',
145
+ parameters: z.object({}),
146
+ execute: async ()=>{
147
+ const sessionList = Array.from(sessions.entries()).map(([id, session])=>({
148
+ sessionId: id,
149
+ created: session.created,
150
+ dataKeys: Object.keys(session.data)
151
+ }));
152
+ return {
153
+ sessions: sessionList,
154
+ count: sessionList.length
155
+ };
156
+ }
157
+ })
158
+ ]
159
+ });
160
+ }
161
+ export function createCheckpointMcpServer() {
162
+ const { checkpointManager } = require('./checkpoint-manager');
163
+ return createSdkMcpServer({
164
+ name: 'checkpoint-manager',
165
+ version: '1.0.0',
166
+ tools: [
167
+ tool({
168
+ name: 'checkpoint_create',
169
+ description: 'Create a checkpoint for a session',
170
+ parameters: z.object({
171
+ sessionId: z.string().describe('Session identifier'),
172
+ description: z.string().describe("Checkpoint description")
173
+ }),
174
+ execute: async ({ sessionId, description })=>{
175
+ try {
176
+ const checkpointId = await checkpointManager.createCheckpoint(sessionId, description);
177
+ return {
178
+ success: true,
179
+ checkpointId,
180
+ description
181
+ };
182
+ } catch (error) {
183
+ return {
184
+ success: false,
185
+ error: error instanceof Error ? error.message : String(error)
186
+ };
187
+ }
188
+ }
189
+ }),
190
+ tool({
191
+ name: 'checkpoint_list',
192
+ description: 'List all checkpoints for a session',
193
+ parameters: z.object({
194
+ sessionId: z.string().describe('Session identifier')
195
+ }),
196
+ execute: async ({ sessionId })=>{
197
+ const checkpoints = checkpointManager.listCheckpoints(sessionId);
198
+ return {
199
+ sessionId,
200
+ checkpoints: checkpoints.map((c)=>({
201
+ id: c.id,
202
+ description: c.description,
203
+ timestamp: c.timestamp,
204
+ messageCount: c.messageCount,
205
+ totalTokens: c.totalTokens,
206
+ filesModified: c.filesModified
207
+ })),
208
+ count: checkpoints.length
209
+ };
210
+ }
211
+ }),
212
+ tool({
213
+ name: 'checkpoint_get',
214
+ description: 'Get checkpoint details',
215
+ parameters: z.object({
216
+ checkpointId: z.string().describe('Checkpoint identifier')
217
+ }),
218
+ execute: async ({ checkpointId })=>{
219
+ const checkpoint = checkpointManager.getCheckpoint(checkpointId);
220
+ if (!checkpoint) {
221
+ return {
222
+ error: 'Checkpoint not found'
223
+ };
224
+ }
225
+ return {
226
+ checkpoint: {
227
+ id: checkpoint.id,
228
+ sessionId: checkpoint.sessionId,
229
+ description: checkpoint.description,
230
+ timestamp: checkpoint.timestamp,
231
+ messageCount: checkpoint.messageCount,
232
+ totalTokens: checkpoint.totalTokens,
233
+ filesModified: checkpoint.filesModified
234
+ }
235
+ };
236
+ }
237
+ }),
238
+ tool({
239
+ name: 'checkpoint_delete',
240
+ description: 'Delete a checkpoint',
241
+ parameters: z.object({
242
+ checkpointId: z.string().describe('Checkpoint identifier')
243
+ }),
244
+ execute: async ({ checkpointId })=>{
245
+ try {
246
+ await checkpointManager.deleteCheckpoint(checkpointId);
247
+ return {
248
+ success: true,
249
+ checkpointId
250
+ };
251
+ } catch (error) {
252
+ return {
253
+ success: false,
254
+ error: error instanceof Error ? error.message : String(error)
255
+ };
256
+ }
257
+ }
258
+ }),
259
+ tool({
260
+ name: 'checkpoint_diff',
261
+ description: 'Compare two checkpoints',
262
+ parameters: z.object({
263
+ fromId: z.string().describe('From checkpoint ID'),
264
+ toId: z.string().describe('To checkpoint ID')
265
+ }),
266
+ execute: async ({ fromId, toId })=>{
267
+ try {
268
+ const diff = checkpointManager.getCheckpointDiff(fromId, toId);
269
+ return {
270
+ success: true,
271
+ diff
272
+ };
273
+ } catch (error) {
274
+ return {
275
+ success: false,
276
+ error: error instanceof Error ? error.message : String(error)
277
+ };
278
+ }
279
+ }
280
+ })
281
+ ]
282
+ });
283
+ }
284
+ export function createQueryControlMcpServer() {
285
+ const { queryController } = require('./query-control');
286
+ return createSdkMcpServer({
287
+ name: 'query-control',
288
+ version: '1.0.0',
289
+ tools: [
290
+ tool({
291
+ name: 'query_pause_request',
292
+ description: 'Request a query to pause at next safe point',
293
+ parameters: z.object({
294
+ sessionId: z.string().describe('Session identifier')
295
+ }),
296
+ execute: async ({ sessionId })=>{
297
+ queryController.requestPause(sessionId);
298
+ return {
299
+ success: true,
300
+ sessionId,
301
+ status: 'pause_requested'
302
+ };
303
+ }
304
+ }),
305
+ tool({
306
+ name: 'query_pause_cancel',
307
+ description: 'Cancel a pause request',
308
+ parameters: z.object({
309
+ sessionId: z.string().describe('Session identifier')
310
+ }),
311
+ execute: async ({ sessionId })=>{
312
+ queryController.cancelPauseRequest(sessionId);
313
+ return {
314
+ success: true,
315
+ sessionId,
316
+ status: 'pause_cancelled'
317
+ };
318
+ }
319
+ }),
320
+ tool({
321
+ name: 'query_paused_list',
322
+ description: 'List all paused queries',
323
+ parameters: z.object({}),
324
+ execute: async ()=>{
325
+ const paused = queryController.listPausedQueries();
326
+ return {
327
+ paused,
328
+ count: paused.length
329
+ };
330
+ }
331
+ }),
332
+ tool({
333
+ name: 'query_paused_get',
334
+ description: 'Get paused query state',
335
+ parameters: z.object({
336
+ sessionId: z.string().describe('Session identifier')
337
+ }),
338
+ execute: async ({ sessionId })=>{
339
+ const state = queryController.getPausedState(sessionId);
340
+ if (!state) {
341
+ return {
342
+ error: 'Paused query not found'
343
+ };
344
+ }
345
+ return {
346
+ sessionId,
347
+ pausePointMessageId: state.pausePointMessageId,
348
+ pausedAt: state.pausedAt,
349
+ messageCount: state.messages.length
350
+ };
351
+ }
352
+ }),
353
+ tool({
354
+ name: 'query_metrics',
355
+ description: 'Get query control metrics',
356
+ parameters: z.object({}),
357
+ execute: async ()=>{
358
+ const metrics = queryController.getMetrics();
359
+ return {
360
+ metrics: {
361
+ totalPauses: metrics.totalPauses,
362
+ totalResumes: metrics.totalResumes,
363
+ averagePauseDuration: metrics.averagePauseDuration,
364
+ longestPause: metrics.longestPause
365
+ }
366
+ };
367
+ }
368
+ })
369
+ ]
370
+ });
371
+ }
372
+ export { createMathMcpServer, createSessionMcpServer, createCheckpointMcpServer, createQueryControlMcpServer };
373
+
374
+ //# sourceMappingURL=in-process-mcp.js.map