@robosystems/mcp 0.3.8 → 0.3.9
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/index.js +65 -54
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -754,7 +754,7 @@ class RoboSystemsMCPClient {
|
|
|
754
754
|
`${this.baseUrl}/v1/graphs/${this.primaryGraphId}/mcp/call-tool`,
|
|
755
755
|
{
|
|
756
756
|
method: 'POST',
|
|
757
|
-
headers: this.headers,
|
|
757
|
+
headers: { ...this.headers, Accept: 'application/json' },
|
|
758
758
|
body: JSON.stringify({
|
|
759
759
|
name: 'create-workspace',
|
|
760
760
|
arguments: { name, description, fork_parent, subgraph_type },
|
|
@@ -849,7 +849,12 @@ class RoboSystemsMCPClient {
|
|
|
849
849
|
// Handle "primary" alias
|
|
850
850
|
const targetGraphId = workspace_id === 'primary' ? this.primaryGraphId : workspace_id
|
|
851
851
|
|
|
852
|
-
// Validate workspace exists
|
|
852
|
+
// Validate workspace exists — if not found locally, refresh from server first
|
|
853
|
+
if (!this.workspaces.has(targetGraphId)) {
|
|
854
|
+
console.error(`Workspace "${targetGraphId}" not in local cache, refreshing from server...`)
|
|
855
|
+
await this._refreshWorkspacesCache()
|
|
856
|
+
}
|
|
857
|
+
|
|
853
858
|
if (!this.workspaces.has(targetGraphId)) {
|
|
854
859
|
return {
|
|
855
860
|
type: 'text',
|
|
@@ -857,7 +862,7 @@ class RoboSystemsMCPClient {
|
|
|
857
862
|
{
|
|
858
863
|
error: 'Unknown workspace',
|
|
859
864
|
workspace_id: targetGraphId,
|
|
860
|
-
message: `Workspace "${targetGraphId}" not found
|
|
865
|
+
message: `Workspace "${targetGraphId}" not found.`,
|
|
861
866
|
available_workspaces: Array.from(this.workspaces.keys()),
|
|
862
867
|
},
|
|
863
868
|
null,
|
|
@@ -917,7 +922,7 @@ class RoboSystemsMCPClient {
|
|
|
917
922
|
`${this.baseUrl}/v1/graphs/${this.primaryGraphId}/mcp/call-tool`,
|
|
918
923
|
{
|
|
919
924
|
method: 'POST',
|
|
920
|
-
headers: this.headers,
|
|
925
|
+
headers: { ...this.headers, Accept: 'application/json' },
|
|
921
926
|
body: JSON.stringify({
|
|
922
927
|
name: 'delete-workspace',
|
|
923
928
|
arguments: { workspace_id, force },
|
|
@@ -1003,20 +1008,14 @@ class RoboSystemsMCPClient {
|
|
|
1003
1008
|
}
|
|
1004
1009
|
}
|
|
1005
1010
|
|
|
1006
|
-
async
|
|
1011
|
+
async _refreshWorkspacesCache() {
|
|
1007
1012
|
try {
|
|
1008
|
-
console.error('Listing workspaces via MCP tool')
|
|
1009
|
-
|
|
1010
|
-
// Call the MCP tool endpoint (server provides the list)
|
|
1011
1013
|
const response = await fetch(
|
|
1012
1014
|
`${this.baseUrl}/v1/graphs/${this.primaryGraphId}/mcp/call-tool`,
|
|
1013
1015
|
{
|
|
1014
1016
|
method: 'POST',
|
|
1015
|
-
headers: this.headers,
|
|
1016
|
-
body: JSON.stringify({
|
|
1017
|
-
name: 'list-workspaces',
|
|
1018
|
-
arguments: {},
|
|
1019
|
-
}),
|
|
1017
|
+
headers: { ...this.headers, Accept: 'application/json' },
|
|
1018
|
+
body: JSON.stringify({ name: 'list-workspaces', arguments: {} }),
|
|
1020
1019
|
}
|
|
1021
1020
|
)
|
|
1022
1021
|
|
|
@@ -1027,7 +1026,6 @@ class RoboSystemsMCPClient {
|
|
|
1027
1026
|
|
|
1028
1027
|
const data = await response.json()
|
|
1029
1028
|
|
|
1030
|
-
// Parse the result
|
|
1031
1029
|
let result
|
|
1032
1030
|
if (data.result && data.result.type === 'text' && data.result.text) {
|
|
1033
1031
|
try {
|
|
@@ -1039,18 +1037,7 @@ class RoboSystemsMCPClient {
|
|
|
1039
1037
|
result = data.result || data
|
|
1040
1038
|
}
|
|
1041
1039
|
|
|
1042
|
-
// Check for errors from server
|
|
1043
|
-
if (result.error) {
|
|
1044
|
-
console.error(`Server error listing workspaces: ${result.message}`)
|
|
1045
|
-
return {
|
|
1046
|
-
type: 'text',
|
|
1047
|
-
text: JSON.stringify(result, null, 2),
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
// Update client tracking with server's workspace list
|
|
1052
1040
|
if (result.workspaces) {
|
|
1053
|
-
// Clear and rebuild workspace tracking from server data
|
|
1054
1041
|
this.workspaces.clear()
|
|
1055
1042
|
for (const ws of result.workspaces) {
|
|
1056
1043
|
this.workspaces.set(ws.workspace_id, {
|
|
@@ -1061,39 +1048,20 @@ class RoboSystemsMCPClient {
|
|
|
1061
1048
|
created_at: ws.created_at ? new Date(ws.created_at).getTime() : Date.now(),
|
|
1062
1049
|
})
|
|
1063
1050
|
}
|
|
1064
|
-
|
|
1065
|
-
// Validate that the current activeGraphId still exists
|
|
1066
|
-
if (!this.workspaces.has(this.activeGraphId)) {
|
|
1067
|
-
console.error(
|
|
1068
|
-
`Active workspace ${this.activeGraphId} no longer exists on server, switching to primary`
|
|
1069
|
-
)
|
|
1070
|
-
this.activeGraphId = this.primaryGraphId
|
|
1071
|
-
this.metrics.workspaceSwitches++
|
|
1072
|
-
}
|
|
1073
1051
|
}
|
|
1074
1052
|
|
|
1075
|
-
|
|
1076
|
-
const workspaces = result.workspaces.map((ws) => ({
|
|
1077
|
-
...ws,
|
|
1078
|
-
active: ws.workspace_id === this.activeGraphId,
|
|
1079
|
-
}))
|
|
1080
|
-
|
|
1081
|
-
return {
|
|
1082
|
-
type: 'text',
|
|
1083
|
-
text: JSON.stringify(
|
|
1084
|
-
{
|
|
1085
|
-
primary_graph_id: result.primary_graph_id,
|
|
1086
|
-
active_workspace: this.activeGraphId,
|
|
1087
|
-
total_workspaces: workspaces.length,
|
|
1088
|
-
workspaces,
|
|
1089
|
-
},
|
|
1090
|
-
null,
|
|
1091
|
-
2
|
|
1092
|
-
),
|
|
1093
|
-
}
|
|
1053
|
+
return result
|
|
1094
1054
|
} catch (error) {
|
|
1095
|
-
console.error(`Failed to
|
|
1055
|
+
console.error(`Failed to refresh workspaces cache: ${error.message}`)
|
|
1056
|
+
return null
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
async _handleListWorkspaces() {
|
|
1061
|
+
console.error('Listing workspaces via MCP tool')
|
|
1062
|
+
const result = await this._refreshWorkspacesCache()
|
|
1096
1063
|
|
|
1064
|
+
if (!result) {
|
|
1097
1065
|
// Fallback to client-side tracking
|
|
1098
1066
|
const workspaces = Array.from(this.workspaces.entries()).map(([id, meta]) => ({
|
|
1099
1067
|
workspace_id: id,
|
|
@@ -1120,6 +1088,49 @@ class RoboSystemsMCPClient {
|
|
|
1120
1088
|
),
|
|
1121
1089
|
}
|
|
1122
1090
|
}
|
|
1091
|
+
|
|
1092
|
+
if (result.error) {
|
|
1093
|
+
console.error(`Server error listing workspaces: ${result.message}`)
|
|
1094
|
+
return {
|
|
1095
|
+
type: 'text',
|
|
1096
|
+
text: JSON.stringify(result, null, 2),
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
if (!result.workspaces) {
|
|
1101
|
+
return {
|
|
1102
|
+
type: 'text',
|
|
1103
|
+
text: JSON.stringify(result, null, 2),
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// Validate that the current activeGraphId still exists
|
|
1108
|
+
if (!this.workspaces.has(this.activeGraphId)) {
|
|
1109
|
+
console.error(
|
|
1110
|
+
`Active workspace ${this.activeGraphId} no longer exists on server, switching to primary`
|
|
1111
|
+
)
|
|
1112
|
+
this.activeGraphId = this.primaryGraphId
|
|
1113
|
+
this.metrics.workspaceSwitches++
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
const workspaces = result.workspaces.map((ws) => ({
|
|
1117
|
+
...ws,
|
|
1118
|
+
active: ws.workspace_id === this.activeGraphId,
|
|
1119
|
+
}))
|
|
1120
|
+
|
|
1121
|
+
return {
|
|
1122
|
+
type: 'text',
|
|
1123
|
+
text: JSON.stringify(
|
|
1124
|
+
{
|
|
1125
|
+
primary_graph_id: result.primary_graph_id,
|
|
1126
|
+
active_workspace: this.activeGraphId,
|
|
1127
|
+
total_workspaces: workspaces.length,
|
|
1128
|
+
workspaces,
|
|
1129
|
+
},
|
|
1130
|
+
null,
|
|
1131
|
+
2
|
|
1132
|
+
),
|
|
1133
|
+
}
|
|
1123
1134
|
}
|
|
1124
1135
|
|
|
1125
1136
|
cleanup() {
|
package/package.json
CHANGED