@robosystems/mcp 0.3.5 → 0.3.6

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.
Files changed (3) hide show
  1. package/README.md +10 -9
  2. package/index.js +257 -196
  3. package/package.json +13 -1
package/README.md CHANGED
@@ -7,13 +7,14 @@ Official MCP (Model Context Protocol) client adapter for connecting AI agents to
7
7
 
8
8
  ## Features
9
9
 
10
- - **Workspace Management** - Create isolated environments for experimentation
11
- - **MCP-compliant server** for Claude Desktop and other AI agents
10
+ - **AI Memory Graphs** - Persistent agent memory with built-in Concept/Observation/Session schema
11
+ - **Workspace Management** - Create isolated subgraphs for memory, data workspaces, and experimentation
12
+ - **Dynamic Schema Extension** - Add custom node and relationship tables to subgraphs via MCP tools
13
+ - **MCP-compliant server** for Claude Desktop, Claude Code, Cursor, and other AI agents
12
14
  - **Streaming support** for memory-efficient processing of large result sets
13
15
  - **Connection pooling** for optimal SSE performance
14
16
  - **Smart caching** for frequently accessed schemas and metadata
15
17
  - **Automatic retry logic** with exponential backoff
16
- - **Real-time progress tracking** for long-running operations
17
18
 
18
19
  ## Quick Start
19
20
 
@@ -37,11 +38,11 @@ Add to your MCP servers configuration:
37
38
 
38
39
  ## Environment Variables
39
40
 
40
- | Variable | Description | Example |
41
- |----------|-------------|---------|
42
- | `ROBOSYSTEMS_API_URL` | The RoboSystems API endpoint | `https://api.robosystems.ai` |
43
- | `ROBOSYSTEMS_API_KEY` | Your API key | `rfs...` |
44
- | `ROBOSYSTEMS_GRAPH_ID` | The primary graph database ID (parent for workspaces) | `kg...` or `sec` |
41
+ | Variable | Description | Example |
42
+ | ---------------------- | ----------------------------------------------------- | ---------------------------- |
43
+ | `ROBOSYSTEMS_API_URL` | The RoboSystems API endpoint | `https://api.robosystems.ai` |
44
+ | `ROBOSYSTEMS_API_KEY` | Your API key | `rfs...` |
45
+ | `ROBOSYSTEMS_GRAPH_ID` | The primary graph database ID (parent for workspaces) | `kg...` or `sec` |
45
46
 
46
47
  ## Resources
47
48
 
@@ -60,4 +61,4 @@ Add to your MCP servers configuration:
60
61
 
61
62
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
62
63
 
63
- MIT © 2025 RFS LLC
64
+ MIT © 2026 RFS LLC
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * This client connects to the RoboSystems HTTP API and exposes it as MCP tools.
7
7
  * It handles multiple response formats (JSON, SSE, NDJSON) and provides a
8
8
  * unified interface to AI agents like Claude Desktop.
9
- *
9
+ *
10
10
  * Features:
11
11
  * - SSE connection pooling for performance
12
12
  * - Smart caching for frequently accessed data
@@ -17,10 +17,7 @@
17
17
 
18
18
  import { Server } from '@modelcontextprotocol/sdk/server/index.js'
19
19
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
20
- import {
21
- CallToolRequestSchema,
22
- ListToolsRequestSchema,
23
- } from '@modelcontextprotocol/sdk/types.js'
20
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js'
24
21
  import { EventSource } from 'eventsource'
25
22
  import { readFileSync } from 'fs'
26
23
  import { fileURLToPath } from 'url'
@@ -133,12 +130,14 @@ class ResultCache {
133
130
  return obj
134
131
  }
135
132
  if (Array.isArray(obj)) {
136
- return obj.map(item => this._sortObjectKeys(item))
133
+ return obj.map((item) => this._sortObjectKeys(item))
137
134
  }
138
135
  const sortedObj = {}
139
- Object.keys(obj).sort().forEach(key => {
140
- sortedObj[key] = this._sortObjectKeys(obj[key])
141
- })
136
+ Object.keys(obj)
137
+ .sort()
138
+ .forEach((key) => {
139
+ sortedObj[key] = this._sortObjectKeys(obj[key])
140
+ })
142
141
  return sortedObj
143
142
  }
144
143
 
@@ -162,7 +161,7 @@ class ResultCache {
162
161
  set(tool, args, result, ttlSeconds = 300, workspaceId = null) {
163
162
  const key = this.generateKey(tool, args, workspaceId)
164
163
  this.cache.set(key, result)
165
- this.cacheExpiry.set(key, Date.now() + (ttlSeconds * 1000))
164
+ this.cacheExpiry.set(key, Date.now() + ttlSeconds * 1000)
166
165
  }
167
166
 
168
167
  clear() {
@@ -179,9 +178,9 @@ class RoboSystemsMCPClient {
179
178
  constructor(baseUrl, apiKey, graphId) {
180
179
  this.baseUrl = baseUrl.replace(/\/$/, '') // Remove trailing slash
181
180
  this.apiKey = apiKey
182
- this.primaryGraphId = graphId // Parent graph (never changes)
183
- this.activeGraphId = graphId // Currently active graph (can switch to workspaces)
184
- this.graphId = graphId // Deprecated: kept for backward compatibility
181
+ this.primaryGraphId = graphId // Parent graph (never changes)
182
+ this.activeGraphId = graphId // Currently active graph (can switch to workspaces)
183
+ this.graphId = graphId // Deprecated: kept for backward compatibility
185
184
  this.headers = {
186
185
  'X-API-Key': apiKey,
187
186
  'Content-Type': 'application/json',
@@ -201,7 +200,7 @@ class RoboSystemsMCPClient {
201
200
  type: 'primary',
202
201
  name: 'main',
203
202
  created_at: Date.now(),
204
- parent_graph_id: null
203
+ parent_graph_id: null,
205
204
  })
206
205
 
207
206
  // Simple metrics
@@ -216,12 +215,9 @@ class RoboSystemsMCPClient {
216
215
  async getTools() {
217
216
  try {
218
217
  console.error(`Fetching tools from ${this.baseUrl}/v1/graphs/${this.activeGraphId}/mcp/tools`)
219
- const response = await fetch(
220
- `${this.baseUrl}/v1/graphs/${this.activeGraphId}/mcp/tools`,
221
- {
222
- headers: this.headers,
223
- }
224
- )
218
+ const response = await fetch(`${this.baseUrl}/v1/graphs/${this.activeGraphId}/mcp/tools`, {
219
+ headers: this.headers,
220
+ })
225
221
 
226
222
  if (!response.ok) {
227
223
  const text = await response.text()
@@ -234,8 +230,13 @@ class RoboSystemsMCPClient {
234
230
  console.error(`Got ${tools.length} tools from API`)
235
231
 
236
232
  // Add client-side workspace tools (if not already provided by server)
237
- const workspaceToolNames = ['create-workspace', 'switch-workspace', 'delete-workspace', 'list-workspaces']
238
- const hasWorkspaceTools = tools.some(t => workspaceToolNames.includes(t.name))
233
+ const workspaceToolNames = [
234
+ 'create-workspace',
235
+ 'switch-workspace',
236
+ 'delete-workspace',
237
+ 'list-workspaces',
238
+ ]
239
+ const hasWorkspaceTools = tools.some((t) => workspaceToolNames.includes(t.name))
239
240
 
240
241
  if (!hasWorkspaceTools) {
241
242
  const workspaceTools = this._getWorkspaceToolDefinitions()
@@ -255,68 +256,78 @@ class RoboSystemsMCPClient {
255
256
  return [
256
257
  {
257
258
  name: 'create-workspace',
258
- description: 'Create an isolated workspace (subgraph) for experimentation. Data and queries are isolated from the main graph.',
259
+ description:
260
+ 'Create an isolated workspace (subgraph) for experimentation. Data and queries are isolated from the main graph.',
259
261
  inputSchema: {
260
262
  type: 'object',
261
263
  properties: {
262
264
  name: {
263
265
  type: 'string',
264
- description: 'Workspace name (alphanumeric only, 1-20 characters)'
266
+ description: 'Workspace name (alphanumeric only, 1-20 characters)',
265
267
  },
266
268
  description: {
267
269
  type: 'string',
268
- description: 'Optional workspace description'
270
+ description: 'Optional workspace description',
269
271
  },
270
272
  fork_parent: {
271
273
  type: 'boolean',
272
274
  description: 'Copy data from parent graph to workspace',
273
- default: false
274
- }
275
+ default: false,
276
+ },
277
+ subgraph_type: {
278
+ type: 'string',
279
+ enum: ['static', 'memory'],
280
+ description:
281
+ 'Type of subgraph: "static" for standard isolated workspace, "memory" for memory-enabled workspace',
282
+ default: 'static',
283
+ },
275
284
  },
276
- required: ['name']
277
- }
285
+ required: ['name'],
286
+ },
278
287
  },
279
288
  {
280
289
  name: 'switch-workspace',
281
- description: 'Switch to a different workspace or back to the primary graph. All subsequent operations will use the active workspace.',
290
+ description:
291
+ 'Switch to a different workspace or back to the primary graph. All subsequent operations will use the active workspace.',
282
292
  inputSchema: {
283
293
  type: 'object',
284
294
  properties: {
285
295
  workspace_id: {
286
296
  type: 'string',
287
- description: 'Workspace ID to switch to, or "primary" for main graph'
288
- }
297
+ description: 'Workspace ID to switch to, or "primary" for main graph',
298
+ },
289
299
  },
290
- required: ['workspace_id']
291
- }
300
+ required: ['workspace_id'],
301
+ },
292
302
  },
293
303
  {
294
304
  name: 'delete-workspace',
295
- description: 'Delete a workspace and all its data. Cannot delete the primary graph. Switches back to primary if deleting active workspace.',
305
+ description:
306
+ 'Delete a workspace and all its data. Cannot delete the primary graph. Switches back to primary if deleting active workspace.',
296
307
  inputSchema: {
297
308
  type: 'object',
298
309
  properties: {
299
310
  workspace_id: {
300
311
  type: 'string',
301
- description: 'Workspace ID to delete'
312
+ description: 'Workspace ID to delete',
302
313
  },
303
314
  force: {
304
315
  type: 'boolean',
305
316
  description: 'Force deletion even if workspace contains data',
306
- default: false
307
- }
317
+ default: false,
318
+ },
308
319
  },
309
- required: ['workspace_id']
310
- }
320
+ required: ['workspace_id'],
321
+ },
311
322
  },
312
323
  {
313
324
  name: 'list-workspaces',
314
325
  description: 'List all workspaces and show which one is currently active',
315
326
  inputSchema: {
316
327
  type: 'object',
317
- properties: {}
318
- }
319
- }
328
+ properties: {},
329
+ },
330
+ },
320
331
  ]
321
332
  }
322
333
 
@@ -354,7 +365,7 @@ class RoboSystemsMCPClient {
354
365
  try {
355
366
  const headers = {
356
367
  ...this.headers,
357
- 'Accept': 'text/event-stream, application/x-ndjson, application/json',
368
+ Accept: 'text/event-stream, application/x-ndjson, application/json',
358
369
  }
359
370
 
360
371
  const response = await fetch(
@@ -386,7 +397,7 @@ class RoboSystemsMCPClient {
386
397
  try {
387
398
  const parsedText = JSON.parse(data.result.text)
388
399
  result = { type: 'text', text: JSON.stringify(parsedText, null, 2) }
389
- } catch (e) {
400
+ } catch (_e) {
390
401
  // If it's not JSON, just use it as-is
391
402
  result = data.result
392
403
  }
@@ -394,13 +405,13 @@ class RoboSystemsMCPClient {
394
405
  result = data.result || { type: 'text', text: 'No result' }
395
406
  }
396
407
  }
397
-
408
+
398
409
  // Cache the result if appropriate
399
410
  if (this.isCacheable(name)) {
400
411
  const ttl = this.getCacheTTL(name)
401
412
  this.resultCache.set(name, args, result, ttl, this.activeGraphId)
402
413
  }
403
-
414
+
404
415
  return result
405
416
  } catch (error) {
406
417
  this.metrics.errors++
@@ -411,30 +422,32 @@ class RoboSystemsMCPClient {
411
422
 
412
423
  async executeWithRetry(fn) {
413
424
  let lastError = null
414
-
425
+
415
426
  for (let attempt = 0; attempt < this.maxRetries; attempt++) {
416
427
  try {
417
428
  return await fn()
418
429
  } catch (error) {
419
430
  lastError = error
420
-
431
+
421
432
  // Don't retry on auth errors or client errors
422
- if (error.message.includes('401') ||
423
- error.message.includes('403') ||
424
- error.message.includes('400')) {
433
+ if (
434
+ error.message.includes('401') ||
435
+ error.message.includes('403') ||
436
+ error.message.includes('400')
437
+ ) {
425
438
  break
426
439
  }
427
-
440
+
428
441
  if (attempt < this.maxRetries - 1) {
429
442
  const delay = this.baseRetryDelay * Math.pow(2, attempt)
430
- await new Promise(resolve => setTimeout(resolve, delay))
443
+ await new Promise((resolve) => setTimeout(resolve, delay))
431
444
  }
432
445
  }
433
446
  }
434
-
435
- return {
436
- type: 'text',
437
- text: `Error after ${this.maxRetries} attempts: ${lastError?.message || 'Unknown error'}`
447
+
448
+ return {
449
+ type: 'text',
450
+ text: `Error after ${this.maxRetries} attempts: ${lastError?.message || 'Unknown error'}`,
438
451
  }
439
452
  }
440
453
 
@@ -442,13 +455,9 @@ class RoboSystemsMCPClient {
442
455
  return new Promise((resolve, reject) => {
443
456
  const events = []
444
457
  const operationId = response.headers.get('x-operation-id') || `sse-${Date.now()}`
445
-
446
- const eventSource = this.connectionPool.getConnection(
447
- operationId,
448
- response.url,
449
- this.headers
450
- )
451
-
458
+
459
+ const eventSource = this.connectionPool.getConnection(operationId, response.url, this.headers)
460
+
452
461
  const timeout = setTimeout(() => {
453
462
  this.connectionPool.closeConnection(operationId)
454
463
  reject(new Error('SSE timeout after 5 minutes'))
@@ -483,7 +492,7 @@ class RoboSystemsMCPClient {
483
492
  try {
484
493
  const data = JSON.parse(event.data)
485
494
  reject(new Error(data.error || data.message || 'Operation failed'))
486
- } catch (e) {
495
+ } catch (_e) {
487
496
  reject(new Error('Operation failed'))
488
497
  }
489
498
  })
@@ -491,7 +500,7 @@ class RoboSystemsMCPClient {
491
500
  eventSource.addEventListener('error', () => {
492
501
  clearTimeout(timeout)
493
502
  this.connectionPool.closeConnection(operationId)
494
-
503
+
495
504
  if (events.length > 0) {
496
505
  const result = this.aggregateStreamedResults(events, toolName)
497
506
  resolve(result)
@@ -514,7 +523,7 @@ class RoboSystemsMCPClient {
514
523
  try {
515
524
  const data = JSON.parse(event.data)
516
525
  console.error(`Progress: ${data.message || 'Processing...'}`)
517
- } catch (e) {
526
+ } catch (_e) {
518
527
  // Ignore progress parsing errors
519
528
  }
520
529
  })
@@ -525,7 +534,7 @@ class RoboSystemsMCPClient {
525
534
  const data = JSON.parse(event.data)
526
535
  const progress = data.percentage ? `${data.percentage}% - ` : ''
527
536
  console.error(`Progress: ${progress}${data.message || 'Processing...'}`)
528
- } catch (e) {
537
+ } catch (_e) {
529
538
  // Ignore progress parsing errors
530
539
  }
531
540
  })
@@ -580,10 +589,12 @@ class RoboSystemsMCPClient {
580
589
 
581
590
  if (data.queued && data.queue_id) {
582
591
  console.error(`Query queued with ID: ${data.queue_id}`)
583
-
584
- const statusUrl = data.status_url ||
592
+
593
+ const statusUrl =
594
+ data.status_url ||
585
595
  `${this.baseUrl}/v1/graphs/${this.activeGraphId}/query/${data.queue_id}/status`
586
- const resultUrl = data.result_url ||
596
+ const resultUrl =
597
+ data.result_url ||
587
598
  `${this.baseUrl}/v1/graphs/${this.activeGraphId}/query/${data.queue_id}/result`
588
599
 
589
600
  // Simple polling with exponential backoff
@@ -592,14 +603,14 @@ class RoboSystemsMCPClient {
592
603
  const maxAttempts = 30
593
604
 
594
605
  while (attempts < maxAttempts) {
595
- await new Promise(resolve => setTimeout(resolve, delay))
606
+ await new Promise((resolve) => setTimeout(resolve, delay))
596
607
 
597
608
  try {
598
609
  const statusResponse = await fetch(statusUrl, { headers: this.headers })
599
610
 
600
611
  if (statusResponse.ok) {
601
612
  const status = await statusResponse.json()
602
-
613
+
603
614
  if (status.status === 'completed') {
604
615
  const resultResponse = await fetch(resultUrl, { headers: this.headers })
605
616
  if (resultResponse.ok) {
@@ -628,7 +639,7 @@ class RoboSystemsMCPClient {
628
639
 
629
640
  aggregateStreamedResults(events) {
630
641
  // Check for errors
631
- const errorEvent = events.find(e => e.event === 'error' || e.event === 'operation_error')
642
+ const errorEvent = events.find((e) => e.event === 'error' || e.event === 'operation_error')
632
643
  if (errorEvent) {
633
644
  return {
634
645
  type: 'text',
@@ -637,22 +648,19 @@ class RoboSystemsMCPClient {
637
648
  }
638
649
 
639
650
  // Check for non-streaming query results first (fallback path)
640
- const queryResult = events.find(e => e.event === 'query_result')
651
+ const queryResult = events.find((e) => e.event === 'query_result')
641
652
  if (queryResult && queryResult.data) {
642
653
  const result = queryResult.data.result
643
654
  if (result) {
644
655
  return {
645
656
  type: 'text',
646
- text: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
657
+ text: typeof result === 'string' ? result : JSON.stringify(result, null, 2),
647
658
  }
648
659
  }
649
660
  }
650
661
 
651
662
  // Aggregate query chunks - check for both possible event names
652
- const queryChunks = events.filter(e =>
653
- e.event === 'query_chunk' ||
654
- e.event === 'data_chunk'
655
- )
663
+ const queryChunks = events.filter((e) => e.event === 'query_chunk' || e.event === 'data_chunk')
656
664
  if (queryChunks.length > 0) {
657
665
  const allRows = []
658
666
  let columns = null
@@ -670,28 +678,33 @@ class RoboSystemsMCPClient {
670
678
  if (allRows.length > 0 || columns) {
671
679
  return {
672
680
  type: 'text',
673
- text: JSON.stringify({
674
- columns: columns || [],
675
- data: allRows,
676
- row_count: allRows.length,
677
- }, null, 2),
681
+ text: JSON.stringify(
682
+ {
683
+ columns: columns || [],
684
+ data: allRows,
685
+ row_count: allRows.length,
686
+ },
687
+ null,
688
+ 2
689
+ ),
678
690
  }
679
691
  }
680
692
  }
681
693
 
682
694
  // Look for completion event - match what server actually sends
683
- const resultEvent = events.find(e =>
684
- e.event === 'operation_completed' ||
685
- e.event === 'complete' ||
686
- e.event === 'query_complete' ||
687
- e.event === 'result' ||
688
- e.event === 'query_result'
695
+ const resultEvent = events.find(
696
+ (e) =>
697
+ e.event === 'operation_completed' ||
698
+ e.event === 'complete' ||
699
+ e.event === 'query_complete' ||
700
+ e.event === 'result' ||
701
+ e.event === 'query_result'
689
702
  )
690
703
  if (resultEvent) {
691
704
  const result = resultEvent.data.result || resultEvent.data
692
- return {
693
- type: 'text',
694
- text: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
705
+ return {
706
+ type: 'text',
707
+ text: typeof result === 'string' ? result : JSON.stringify(result, null, 2),
695
708
  }
696
709
  }
697
710
 
@@ -700,27 +713,24 @@ class RoboSystemsMCPClient {
700
713
  }
701
714
 
702
715
  isCacheable(toolName) {
703
- const cacheableTools = [
704
- 'get-graph-schema',
705
- 'get-graph-info',
706
- 'describe-graph-structure',
707
- ]
716
+ const cacheableTools = ['get-graph-schema', 'get-graph-info', 'describe-graph-structure']
708
717
  return cacheableTools.includes(toolName)
709
718
  }
710
719
 
711
720
  getCacheTTL(toolName) {
712
721
  const ttlMap = {
713
- 'get-graph-schema': 3600, // 1 hour
714
- 'get-graph-info': 300, // 5 minutes
722
+ 'get-graph-schema': 3600, // 1 hour
723
+ 'get-graph-info': 300, // 5 minutes
715
724
  'describe-graph-structure': 1800, // 30 minutes
716
725
  }
717
726
  return ttlMap[toolName] || 300
718
727
  }
719
728
 
720
729
  getMetrics() {
721
- const cacheHitRate = this.metrics.totalRequests > 0
722
- ? (this.metrics.cacheHits / this.metrics.totalRequests * 100).toFixed(1) + '%'
723
- : '0%'
730
+ const cacheHitRate =
731
+ this.metrics.totalRequests > 0
732
+ ? ((this.metrics.cacheHits / this.metrics.totalRequests) * 100).toFixed(1) + '%'
733
+ : '0%'
724
734
 
725
735
  return {
726
736
  totalRequests: this.metrics.totalRequests,
@@ -737,10 +747,19 @@ class RoboSystemsMCPClient {
737
747
  // Workspace management methods
738
748
 
739
749
  async _handleCreateWorkspace(args) {
740
- const { name, description, fork_parent = false } = args
750
+ const { name, description, fork_parent = false, subgraph_type = 'static' } = args
751
+ const validSubgraphTypes = ['static', 'memory']
752
+
753
+ if (!validSubgraphTypes.includes(subgraph_type)) {
754
+ throw new Error(
755
+ `Invalid subgraph_type "${subgraph_type}". Must be one of: ${validSubgraphTypes.join(', ')}`
756
+ )
757
+ }
741
758
 
742
759
  try {
743
- console.error(`Creating workspace via MCP tool: ${name} (fork_parent: ${fork_parent})`)
760
+ console.error(
761
+ `Creating workspace via MCP tool: ${name} (fork_parent: ${fork_parent}, type: ${subgraph_type})`
762
+ )
744
763
 
745
764
  // Call the MCP tool endpoint (server handles the creation)
746
765
  const response = await fetch(
@@ -750,8 +769,8 @@ class RoboSystemsMCPClient {
750
769
  headers: this.headers,
751
770
  body: JSON.stringify({
752
771
  name: 'create-workspace',
753
- arguments: { name, description, fork_parent }
754
- })
772
+ arguments: { name, description, fork_parent, subgraph_type },
773
+ }),
755
774
  }
756
775
  )
757
776
 
@@ -767,7 +786,7 @@ class RoboSystemsMCPClient {
767
786
  if (data.result && data.result.type === 'text' && data.result.text) {
768
787
  try {
769
788
  result = JSON.parse(data.result.text)
770
- } catch (e) {
789
+ } catch (_e) {
771
790
  result = { message: data.result.text }
772
791
  }
773
792
  } else {
@@ -779,7 +798,7 @@ class RoboSystemsMCPClient {
779
798
  console.error(`Server error creating workspace: ${result.message}`)
780
799
  return {
781
800
  type: 'text',
782
- text: JSON.stringify(result, null, 2)
801
+ text: JSON.stringify(result, null, 2),
783
802
  }
784
803
  }
785
804
 
@@ -793,7 +812,7 @@ class RoboSystemsMCPClient {
793
812
  name,
794
813
  description: result.description || description,
795
814
  created_at: Date.now(),
796
- forked_from_parent: fork_parent
815
+ forked_from_parent: fork_parent,
797
816
  })
798
817
 
799
818
  // Automatically switch to the new workspace
@@ -805,25 +824,33 @@ class RoboSystemsMCPClient {
805
824
 
806
825
  return {
807
826
  type: 'text',
808
- text: JSON.stringify({
809
- success: true,
810
- workspace_id: workspaceId,
811
- name,
812
- previous_workspace: previousGraph,
813
- active: true,
814
- forked_from_parent: fork_parent,
815
- message: `Created workspace "${name}" and switched to it. All operations now use this isolated environment.`
816
- }, null, 2)
827
+ text: JSON.stringify(
828
+ {
829
+ success: true,
830
+ workspace_id: workspaceId,
831
+ name,
832
+ previous_workspace: previousGraph,
833
+ active: true,
834
+ forked_from_parent: fork_parent,
835
+ message: `Created workspace "${name}" and switched to it. All operations now use this isolated environment.`,
836
+ },
837
+ null,
838
+ 2
839
+ ),
817
840
  }
818
841
  } catch (error) {
819
842
  console.error(`Failed to create workspace: ${error.message}`)
820
843
  return {
821
844
  type: 'text',
822
- text: JSON.stringify({
823
- error: 'Failed to create workspace',
824
- message: error.message,
825
- workspace_name: name
826
- }, null, 2)
845
+ text: JSON.stringify(
846
+ {
847
+ error: 'Failed to create workspace',
848
+ message: error.message,
849
+ workspace_name: name,
850
+ },
851
+ null,
852
+ 2
853
+ ),
827
854
  }
828
855
  }
829
856
  }
@@ -838,12 +865,16 @@ class RoboSystemsMCPClient {
838
865
  if (!this.workspaces.has(targetGraphId)) {
839
866
  return {
840
867
  type: 'text',
841
- text: JSON.stringify({
842
- error: 'Unknown workspace',
843
- workspace_id: targetGraphId,
844
- message: `Workspace "${targetGraphId}" not found. Use list-workspaces to see available workspaces.`,
845
- available_workspaces: Array.from(this.workspaces.keys())
846
- }, null, 2)
868
+ text: JSON.stringify(
869
+ {
870
+ error: 'Unknown workspace',
871
+ workspace_id: targetGraphId,
872
+ message: `Workspace "${targetGraphId}" not found. Use list-workspaces to see available workspaces.`,
873
+ available_workspaces: Array.from(this.workspaces.keys()),
874
+ },
875
+ null,
876
+ 2
877
+ ),
847
878
  }
848
879
  }
849
880
 
@@ -851,11 +882,15 @@ class RoboSystemsMCPClient {
851
882
  if (this.activeGraphId === targetGraphId) {
852
883
  return {
853
884
  type: 'text',
854
- text: JSON.stringify({
855
- success: true,
856
- workspace_id: targetGraphId,
857
- message: `Already in workspace "${targetGraphId}"`
858
- }, null, 2)
885
+ text: JSON.stringify(
886
+ {
887
+ success: true,
888
+ workspace_id: targetGraphId,
889
+ message: `Already in workspace "${targetGraphId}"`,
890
+ },
891
+ null,
892
+ 2
893
+ ),
859
894
  }
860
895
  }
861
896
 
@@ -869,13 +904,17 @@ class RoboSystemsMCPClient {
869
904
 
870
905
  return {
871
906
  type: 'text',
872
- text: JSON.stringify({
873
- success: true,
874
- switched_from: previousGraph,
875
- switched_to: targetGraphId,
876
- workspace_type: workspace.type,
877
- message: `Switched to ${workspace.type === 'primary' ? 'primary graph' : `workspace "${workspace.name}"`}. All operations now use this environment.`
878
- }, null, 2)
907
+ text: JSON.stringify(
908
+ {
909
+ success: true,
910
+ switched_from: previousGraph,
911
+ switched_to: targetGraphId,
912
+ workspace_type: workspace.type,
913
+ message: `Switched to ${workspace.type === 'primary' ? 'primary graph' : `workspace "${workspace.name}"`}. All operations now use this environment.`,
914
+ },
915
+ null,
916
+ 2
917
+ ),
879
918
  }
880
919
  }
881
920
 
@@ -893,8 +932,8 @@ class RoboSystemsMCPClient {
893
932
  headers: this.headers,
894
933
  body: JSON.stringify({
895
934
  name: 'delete-workspace',
896
- arguments: { workspace_id, force }
897
- })
935
+ arguments: { workspace_id, force },
936
+ }),
898
937
  }
899
938
  )
900
939
 
@@ -910,7 +949,7 @@ class RoboSystemsMCPClient {
910
949
  if (data.result && data.result.type === 'text' && data.result.text) {
911
950
  try {
912
951
  result = JSON.parse(data.result.text)
913
- } catch (e) {
952
+ } catch (_e) {
914
953
  result = { message: data.result.text }
915
954
  }
916
955
  } else {
@@ -922,7 +961,7 @@ class RoboSystemsMCPClient {
922
961
  console.error(`Server error deleting workspace: ${result.message}`)
923
962
  return {
924
963
  type: 'text',
925
- text: JSON.stringify(result, null, 2)
964
+ text: JSON.stringify(result, null, 2),
926
965
  }
927
966
  }
928
967
 
@@ -939,27 +978,39 @@ class RoboSystemsMCPClient {
939
978
  this.metrics.workspaceSwitches++
940
979
  }
941
980
 
942
- console.error(`Deleted workspace: ${workspace_id}${switchedBack ? ' (switched back to primary)' : ''}`)
981
+ console.error(
982
+ `Deleted workspace: ${workspace_id}${switchedBack ? ' (switched back to primary)' : ''}`
983
+ )
943
984
 
944
985
  return {
945
986
  type: 'text',
946
- text: JSON.stringify({
947
- success: true,
948
- deleted: workspace_id,
949
- active_workspace: this.activeGraphId,
950
- switched_back_to_primary: switchedBack,
951
- message: result.message || `Deleted workspace "${workspace_id}"${switchedBack ? ' and switched back to primary graph' : ''}.`
952
- }, null, 2)
987
+ text: JSON.stringify(
988
+ {
989
+ success: true,
990
+ deleted: workspace_id,
991
+ active_workspace: this.activeGraphId,
992
+ switched_back_to_primary: switchedBack,
993
+ message:
994
+ result.message ||
995
+ `Deleted workspace "${workspace_id}"${switchedBack ? ' and switched back to primary graph' : ''}.`,
996
+ },
997
+ null,
998
+ 2
999
+ ),
953
1000
  }
954
1001
  } catch (error) {
955
1002
  console.error(`Failed to delete workspace: ${error.message}`)
956
1003
  return {
957
1004
  type: 'text',
958
- text: JSON.stringify({
959
- error: 'Failed to delete workspace',
960
- message: error.message,
961
- workspace_id
962
- }, null, 2)
1005
+ text: JSON.stringify(
1006
+ {
1007
+ error: 'Failed to delete workspace',
1008
+ message: error.message,
1009
+ workspace_id,
1010
+ },
1011
+ null,
1012
+ 2
1013
+ ),
963
1014
  }
964
1015
  }
965
1016
  }
@@ -976,8 +1027,8 @@ class RoboSystemsMCPClient {
976
1027
  headers: this.headers,
977
1028
  body: JSON.stringify({
978
1029
  name: 'list-workspaces',
979
- arguments: {}
980
- })
1030
+ arguments: {},
1031
+ }),
981
1032
  }
982
1033
  )
983
1034
 
@@ -993,7 +1044,7 @@ class RoboSystemsMCPClient {
993
1044
  if (data.result && data.result.type === 'text' && data.result.text) {
994
1045
  try {
995
1046
  result = JSON.parse(data.result.text)
996
- } catch (e) {
1047
+ } catch (_e) {
997
1048
  result = { message: data.result.text }
998
1049
  }
999
1050
  } else {
@@ -1005,7 +1056,7 @@ class RoboSystemsMCPClient {
1005
1056
  console.error(`Server error listing workspaces: ${result.message}`)
1006
1057
  return {
1007
1058
  type: 'text',
1008
- text: JSON.stringify(result, null, 2)
1059
+ text: JSON.stringify(result, null, 2),
1009
1060
  }
1010
1061
  }
1011
1062
 
@@ -1019,32 +1070,38 @@ class RoboSystemsMCPClient {
1019
1070
  name: ws.name,
1020
1071
  description: ws.description,
1021
1072
  parent_graph_id: ws.parent_graph_id,
1022
- created_at: ws.created_at ? new Date(ws.created_at).getTime() : Date.now()
1073
+ created_at: ws.created_at ? new Date(ws.created_at).getTime() : Date.now(),
1023
1074
  })
1024
1075
  }
1025
1076
 
1026
1077
  // Validate that the current activeGraphId still exists
1027
1078
  if (!this.workspaces.has(this.activeGraphId)) {
1028
- console.error(`Active workspace ${this.activeGraphId} no longer exists on server, switching to primary`)
1079
+ console.error(
1080
+ `Active workspace ${this.activeGraphId} no longer exists on server, switching to primary`
1081
+ )
1029
1082
  this.activeGraphId = this.primaryGraphId
1030
1083
  this.metrics.workspaceSwitches++
1031
1084
  }
1032
1085
  }
1033
1086
 
1034
1087
  // Mark active workspace in response
1035
- const workspaces = result.workspaces.map(ws => ({
1088
+ const workspaces = result.workspaces.map((ws) => ({
1036
1089
  ...ws,
1037
- active: ws.workspace_id === this.activeGraphId
1090
+ active: ws.workspace_id === this.activeGraphId,
1038
1091
  }))
1039
1092
 
1040
1093
  return {
1041
1094
  type: 'text',
1042
- text: JSON.stringify({
1043
- primary_graph_id: result.primary_graph_id,
1044
- active_workspace: this.activeGraphId,
1045
- total_workspaces: workspaces.length,
1046
- workspaces
1047
- }, null, 2)
1095
+ text: JSON.stringify(
1096
+ {
1097
+ primary_graph_id: result.primary_graph_id,
1098
+ active_workspace: this.activeGraphId,
1099
+ total_workspaces: workspaces.length,
1100
+ workspaces,
1101
+ },
1102
+ null,
1103
+ 2
1104
+ ),
1048
1105
  }
1049
1106
  } catch (error) {
1050
1107
  console.error(`Failed to list workspaces: ${error.message}`)
@@ -1057,18 +1114,22 @@ class RoboSystemsMCPClient {
1057
1114
  description: meta.description,
1058
1115
  active: id === this.activeGraphId,
1059
1116
  created_at: new Date(meta.created_at).toISOString(),
1060
- parent_graph_id: meta.parent_graph_id
1117
+ parent_graph_id: meta.parent_graph_id,
1061
1118
  }))
1062
1119
 
1063
1120
  return {
1064
1121
  type: 'text',
1065
- text: JSON.stringify({
1066
- primary_graph_id: this.primaryGraphId,
1067
- active_workspace: this.activeGraphId,
1068
- total_workspaces: workspaces.length,
1069
- workspaces,
1070
- _note: 'Fallback to client-side tracking due to error'
1071
- }, null, 2)
1122
+ text: JSON.stringify(
1123
+ {
1124
+ primary_graph_id: this.primaryGraphId,
1125
+ active_workspace: this.activeGraphId,
1126
+ total_workspaces: workspaces.length,
1127
+ workspaces,
1128
+ _note: 'Fallback to client-side tracking due to error',
1129
+ },
1130
+ null,
1131
+ 2
1132
+ ),
1072
1133
  }
1073
1134
  }
1074
1135
  }
@@ -1148,10 +1209,12 @@ async function main() {
1148
1209
  } catch (error) {
1149
1210
  console.error(`Error calling tool ${request.params.name}: ${error.message}`)
1150
1211
  return {
1151
- content: [{
1152
- type: 'text',
1153
- text: `Error: ${error.message}`,
1154
- }],
1212
+ content: [
1213
+ {
1214
+ type: 'text',
1215
+ text: `Error: ${error.message}`,
1216
+ },
1217
+ ],
1155
1218
  }
1156
1219
  }
1157
1220
  })
@@ -1168,7 +1231,9 @@ async function main() {
1168
1231
  await server.connect(transport)
1169
1232
 
1170
1233
  console.error('RoboSystems MCP server running')
1171
- console.error('Features: Workspace management, connection pooling, smart caching, retry logic, progress tracking')
1234
+ console.error(
1235
+ 'Features: Workspace management, connection pooling, smart caching, retry logic, progress tracking'
1236
+ )
1172
1237
  console.error(`Active workspace: ${remoteClient.activeGraphId}`)
1173
1238
 
1174
1239
  // Log metrics every 5 minutes
@@ -1199,20 +1264,16 @@ process.on('SIGINT', cleanup)
1199
1264
  process.on('SIGTERM', cleanup)
1200
1265
 
1201
1266
  // Export for programmatic use
1202
- export {
1203
- RoboSystemsMCPClient,
1204
- SSEConnectionPool,
1205
- ResultCache
1206
- }
1267
+ export { RoboSystemsMCPClient, SSEConnectionPool, ResultCache }
1207
1268
 
1208
1269
  // Only run as server if this is the main module
1209
1270
  // Check if we're being run directly (not imported)
1210
1271
  // This works with both `node index.js` and `npx` invocations
1211
1272
  const isMainModule =
1212
1273
  import.meta.url === `file://${process.argv[1]}` ||
1213
- process.argv[1]?.endsWith('/mcp') || // npx binary name
1274
+ process.argv[1]?.endsWith('/mcp') || // npx binary name
1214
1275
  process.argv[1]?.endsWith('/@robosystems/mcp') || // alternative npx name
1215
- process.argv[1]?.includes('robosystems-mcp'); // package name in path
1276
+ process.argv[1]?.includes('robosystems-mcp') // package name in path
1216
1277
 
1217
1278
  // Don't run in test mode
1218
1279
  const isTestMode = process.env.VITEST === 'true' || process.env.NODE_ENV === 'test'
@@ -1223,4 +1284,4 @@ if (isMainModule && !isTestMode) {
1223
1284
  console.error(`Fatal error: ${error.message}`)
1224
1285
  process.exit(1)
1225
1286
  })
1226
- }
1287
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robosystems/mcp",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "MCP client adapter for connecting AI agents to RoboSystems Financial Knowledge Graph API endpoints with workspace support",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -15,8 +15,15 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "start": "node index.js",
18
+ "format": "prettier . --write",
19
+ "format:check": "prettier . --check",
20
+ "lint": "eslint .",
21
+ "lint:fix": "eslint . --fix",
22
+ "validate:fix": "npm run format && npm run lint:fix",
23
+ "validate": "npm run validate:fix && npm run lint",
18
24
  "test": "vitest run",
19
25
  "test:watch": "vitest",
26
+ "test:all": "npm run validate && npm run test",
20
27
  "feature:create": "./bin/create-feature.sh",
21
28
  "release:create": "./bin/create-release.sh",
22
29
  "pr:create": "./bin/create-pr.sh"
@@ -36,7 +43,12 @@
36
43
  "eventsource": "^4.0.0"
37
44
  },
38
45
  "devDependencies": {
46
+ "@eslint/js": "^9.39.2",
47
+ "eslint": "^9.39.2",
48
+ "eslint-config-prettier": "^10.0.0",
49
+ "eslint-plugin-prettier": "^5.0.0",
39
50
  "happy-dom": "^20.0.8",
51
+ "prettier": "^3.0.0",
40
52
  "vitest": "^4.0.3"
41
53
  },
42
54
  "engines": {