@robosystems/mcp 0.3.8 → 0.3.10
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/bin/create-feature.sh +5 -3
- package/index.js +115 -65
- package/package.json +2 -3
package/bin/create-feature.sh
CHANGED
|
@@ -9,7 +9,7 @@ set -e
|
|
|
9
9
|
BRANCH_TYPE=${1:-feature}
|
|
10
10
|
BRANCH_NAME=${2:-}
|
|
11
11
|
BASE_BRANCH=${3:-main}
|
|
12
|
-
UPDATE_DEPS=${4:-
|
|
12
|
+
UPDATE_DEPS=${4:-no}
|
|
13
13
|
|
|
14
14
|
# Validate branch type
|
|
15
15
|
if [[ "$BRANCH_TYPE" != "feature" && "$BRANCH_TYPE" != "bugfix" && "$BRANCH_TYPE" != "hotfix" && "$BRANCH_TYPE" != "chore" && "$BRANCH_TYPE" != "refactor" ]]; then
|
|
@@ -80,7 +80,9 @@ git push -u origin $FULL_BRANCH
|
|
|
80
80
|
echo ""
|
|
81
81
|
echo "🎉 Successfully created and checked out $FULL_BRANCH"
|
|
82
82
|
|
|
83
|
-
# Update dependencies
|
|
83
|
+
# Update dependencies only when explicitly requested (default: no).
|
|
84
|
+
# Pass "yes" as the 4th arg to refresh deps on the new branch; otherwise
|
|
85
|
+
# branch creation leaves the lockfile untouched.
|
|
84
86
|
if [[ "$UPDATE_DEPS" == "yes" ]]; then
|
|
85
87
|
echo ""
|
|
86
88
|
echo "📦 Updating dependencies..."
|
|
@@ -93,7 +95,7 @@ echo "📝 Next steps:"
|
|
|
93
95
|
echo " 1. Make your changes and commit them"
|
|
94
96
|
echo " 2. Push your changes: git push"
|
|
95
97
|
echo " 3. Create a PR: gh pr create --base $BASE_BRANCH --title \"Your PR title\" --body \"Your PR description\""
|
|
96
|
-
echo " or
|
|
98
|
+
echo " or in a Claude Code session: /create-pr"
|
|
97
99
|
|
|
98
100
|
# Check if we had stashed changes and auto-apply them
|
|
99
101
|
if git stash list | grep -q "Auto-stash before creating branch $FULL_BRANCH"; then
|
package/index.js
CHANGED
|
@@ -181,6 +181,7 @@ class RoboSystemsMCPClient {
|
|
|
181
181
|
this.primaryGraphId = graphId // Parent graph (never changes)
|
|
182
182
|
this.activeGraphId = graphId // Currently active graph (can switch to workspaces)
|
|
183
183
|
this.graphId = graphId // Deprecated: kept for backward compatibility
|
|
184
|
+
this.instructions = null // Per-graph routing guidance for the active graph (set by getTools)
|
|
184
185
|
this.headers = {
|
|
185
186
|
'X-API-Key': apiKey,
|
|
186
187
|
'Content-Type': 'application/json',
|
|
@@ -227,6 +228,10 @@ class RoboSystemsMCPClient {
|
|
|
227
228
|
|
|
228
229
|
const data = await response.json()
|
|
229
230
|
let tools = data.tools || []
|
|
231
|
+
// Per-graph routing guidance for the active graph. Surfaced to the host
|
|
232
|
+
// via the handshake `instructions` field (primary graph) and inline in
|
|
233
|
+
// switch-workspace results (switched graph).
|
|
234
|
+
this.instructions = data.instructions ?? null
|
|
230
235
|
console.error(`Got ${tools.length} tools from API`)
|
|
231
236
|
|
|
232
237
|
// Add client-side workspace tools (if not already provided by server)
|
|
@@ -248,6 +253,7 @@ class RoboSystemsMCPClient {
|
|
|
248
253
|
} catch (error) {
|
|
249
254
|
console.error(`Failed to get tools: ${error.message}`)
|
|
250
255
|
console.error(`Stack: ${error.stack}`)
|
|
256
|
+
this.instructions = null
|
|
251
257
|
return []
|
|
252
258
|
}
|
|
253
259
|
}
|
|
@@ -754,7 +760,7 @@ class RoboSystemsMCPClient {
|
|
|
754
760
|
`${this.baseUrl}/v1/graphs/${this.primaryGraphId}/mcp/call-tool`,
|
|
755
761
|
{
|
|
756
762
|
method: 'POST',
|
|
757
|
-
headers: this.headers,
|
|
763
|
+
headers: { ...this.headers, Accept: 'application/json' },
|
|
758
764
|
body: JSON.stringify({
|
|
759
765
|
name: 'create-workspace',
|
|
760
766
|
arguments: { name, description, fork_parent, subgraph_type },
|
|
@@ -849,7 +855,12 @@ class RoboSystemsMCPClient {
|
|
|
849
855
|
// Handle "primary" alias
|
|
850
856
|
const targetGraphId = workspace_id === 'primary' ? this.primaryGraphId : workspace_id
|
|
851
857
|
|
|
852
|
-
// Validate workspace exists
|
|
858
|
+
// Validate workspace exists — if not found locally, refresh from server first
|
|
859
|
+
if (!this.workspaces.has(targetGraphId)) {
|
|
860
|
+
console.error(`Workspace "${targetGraphId}" not in local cache, refreshing from server...`)
|
|
861
|
+
await this._refreshWorkspacesCache()
|
|
862
|
+
}
|
|
863
|
+
|
|
853
864
|
if (!this.workspaces.has(targetGraphId)) {
|
|
854
865
|
return {
|
|
855
866
|
type: 'text',
|
|
@@ -857,7 +868,7 @@ class RoboSystemsMCPClient {
|
|
|
857
868
|
{
|
|
858
869
|
error: 'Unknown workspace',
|
|
859
870
|
workspace_id: targetGraphId,
|
|
860
|
-
message: `Workspace "${targetGraphId}" not found
|
|
871
|
+
message: `Workspace "${targetGraphId}" not found.`,
|
|
861
872
|
available_workspaces: Array.from(this.workspaces.keys()),
|
|
862
873
|
},
|
|
863
874
|
null,
|
|
@@ -890,6 +901,16 @@ class RoboSystemsMCPClient {
|
|
|
890
901
|
const workspace = this.workspaces.get(targetGraphId)
|
|
891
902
|
console.error(`Switched from ${previousGraph} to ${targetGraphId}`)
|
|
892
903
|
|
|
904
|
+
// The handshake `instructions` field is immutable mid-session, so surface
|
|
905
|
+
// the now-active graph's routing guidance inline in the switch result.
|
|
906
|
+
let instructions
|
|
907
|
+
try {
|
|
908
|
+
await this.getTools()
|
|
909
|
+
instructions = this.instructions || undefined
|
|
910
|
+
} catch (error) {
|
|
911
|
+
console.error(`Could not load instructions for ${targetGraphId}: ${error.message}`)
|
|
912
|
+
}
|
|
913
|
+
|
|
893
914
|
return {
|
|
894
915
|
type: 'text',
|
|
895
916
|
text: JSON.stringify(
|
|
@@ -899,6 +920,7 @@ class RoboSystemsMCPClient {
|
|
|
899
920
|
switched_to: targetGraphId,
|
|
900
921
|
workspace_type: workspace.type,
|
|
901
922
|
message: `Switched to ${workspace.type === 'primary' ? 'primary graph' : `workspace "${workspace.name}"`}. All operations now use this environment.`,
|
|
923
|
+
...(instructions ? { instructions } : {}),
|
|
902
924
|
},
|
|
903
925
|
null,
|
|
904
926
|
2
|
|
@@ -917,7 +939,7 @@ class RoboSystemsMCPClient {
|
|
|
917
939
|
`${this.baseUrl}/v1/graphs/${this.primaryGraphId}/mcp/call-tool`,
|
|
918
940
|
{
|
|
919
941
|
method: 'POST',
|
|
920
|
-
headers: this.headers,
|
|
942
|
+
headers: { ...this.headers, Accept: 'application/json' },
|
|
921
943
|
body: JSON.stringify({
|
|
922
944
|
name: 'delete-workspace',
|
|
923
945
|
arguments: { workspace_id, force },
|
|
@@ -1003,20 +1025,14 @@ class RoboSystemsMCPClient {
|
|
|
1003
1025
|
}
|
|
1004
1026
|
}
|
|
1005
1027
|
|
|
1006
|
-
async
|
|
1028
|
+
async _refreshWorkspacesCache() {
|
|
1007
1029
|
try {
|
|
1008
|
-
console.error('Listing workspaces via MCP tool')
|
|
1009
|
-
|
|
1010
|
-
// Call the MCP tool endpoint (server provides the list)
|
|
1011
1030
|
const response = await fetch(
|
|
1012
1031
|
`${this.baseUrl}/v1/graphs/${this.primaryGraphId}/mcp/call-tool`,
|
|
1013
1032
|
{
|
|
1014
1033
|
method: 'POST',
|
|
1015
|
-
headers: this.headers,
|
|
1016
|
-
body: JSON.stringify({
|
|
1017
|
-
name: 'list-workspaces',
|
|
1018
|
-
arguments: {},
|
|
1019
|
-
}),
|
|
1034
|
+
headers: { ...this.headers, Accept: 'application/json' },
|
|
1035
|
+
body: JSON.stringify({ name: 'list-workspaces', arguments: {} }),
|
|
1020
1036
|
}
|
|
1021
1037
|
)
|
|
1022
1038
|
|
|
@@ -1027,7 +1043,6 @@ class RoboSystemsMCPClient {
|
|
|
1027
1043
|
|
|
1028
1044
|
const data = await response.json()
|
|
1029
1045
|
|
|
1030
|
-
// Parse the result
|
|
1031
1046
|
let result
|
|
1032
1047
|
if (data.result && data.result.type === 'text' && data.result.text) {
|
|
1033
1048
|
try {
|
|
@@ -1039,18 +1054,7 @@ class RoboSystemsMCPClient {
|
|
|
1039
1054
|
result = data.result || data
|
|
1040
1055
|
}
|
|
1041
1056
|
|
|
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
1057
|
if (result.workspaces) {
|
|
1053
|
-
// Clear and rebuild workspace tracking from server data
|
|
1054
1058
|
this.workspaces.clear()
|
|
1055
1059
|
for (const ws of result.workspaces) {
|
|
1056
1060
|
this.workspaces.set(ws.workspace_id, {
|
|
@@ -1061,39 +1065,20 @@ class RoboSystemsMCPClient {
|
|
|
1061
1065
|
created_at: ws.created_at ? new Date(ws.created_at).getTime() : Date.now(),
|
|
1062
1066
|
})
|
|
1063
1067
|
}
|
|
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
1068
|
}
|
|
1074
1069
|
|
|
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
|
-
}
|
|
1070
|
+
return result
|
|
1094
1071
|
} catch (error) {
|
|
1095
|
-
console.error(`Failed to
|
|
1072
|
+
console.error(`Failed to refresh workspaces cache: ${error.message}`)
|
|
1073
|
+
return null
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1096
1076
|
|
|
1077
|
+
async _handleListWorkspaces() {
|
|
1078
|
+
console.error('Listing workspaces via MCP tool')
|
|
1079
|
+
const result = await this._refreshWorkspacesCache()
|
|
1080
|
+
|
|
1081
|
+
if (!result) {
|
|
1097
1082
|
// Fallback to client-side tracking
|
|
1098
1083
|
const workspaces = Array.from(this.workspaces.entries()).map(([id, meta]) => ({
|
|
1099
1084
|
workspace_id: id,
|
|
@@ -1120,6 +1105,49 @@ class RoboSystemsMCPClient {
|
|
|
1120
1105
|
),
|
|
1121
1106
|
}
|
|
1122
1107
|
}
|
|
1108
|
+
|
|
1109
|
+
if (result.error) {
|
|
1110
|
+
console.error(`Server error listing workspaces: ${result.message}`)
|
|
1111
|
+
return {
|
|
1112
|
+
type: 'text',
|
|
1113
|
+
text: JSON.stringify(result, null, 2),
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
if (!result.workspaces) {
|
|
1118
|
+
return {
|
|
1119
|
+
type: 'text',
|
|
1120
|
+
text: JSON.stringify(result, null, 2),
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// Validate that the current activeGraphId still exists
|
|
1125
|
+
if (!this.workspaces.has(this.activeGraphId)) {
|
|
1126
|
+
console.error(
|
|
1127
|
+
`Active workspace ${this.activeGraphId} no longer exists on server, switching to primary`
|
|
1128
|
+
)
|
|
1129
|
+
this.activeGraphId = this.primaryGraphId
|
|
1130
|
+
this.metrics.workspaceSwitches++
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
const workspaces = result.workspaces.map((ws) => ({
|
|
1134
|
+
...ws,
|
|
1135
|
+
active: ws.workspace_id === this.activeGraphId,
|
|
1136
|
+
}))
|
|
1137
|
+
|
|
1138
|
+
return {
|
|
1139
|
+
type: 'text',
|
|
1140
|
+
text: JSON.stringify(
|
|
1141
|
+
{
|
|
1142
|
+
primary_graph_id: result.primary_graph_id,
|
|
1143
|
+
active_workspace: this.activeGraphId,
|
|
1144
|
+
total_workspaces: workspaces.length,
|
|
1145
|
+
workspaces,
|
|
1146
|
+
},
|
|
1147
|
+
null,
|
|
1148
|
+
2
|
|
1149
|
+
),
|
|
1150
|
+
}
|
|
1123
1151
|
}
|
|
1124
1152
|
|
|
1125
1153
|
cleanup() {
|
|
@@ -1152,16 +1180,43 @@ async function main() {
|
|
|
1152
1180
|
|
|
1153
1181
|
const remoteClient = new RoboSystemsMCPClient(baseUrl, apiKey, graphId)
|
|
1154
1182
|
|
|
1183
|
+
// Prefetch the primary graph's tools + instructions BEFORE constructing the
|
|
1184
|
+
// server. The MCP `instructions` field ships in the initialize handshake and
|
|
1185
|
+
// is immutable afterward, so it must be present at construction time (unlike
|
|
1186
|
+
// tools, which are fetched lazily per ListTools request). This also serves as
|
|
1187
|
+
// the initial connection test.
|
|
1188
|
+
let primaryInstructions
|
|
1189
|
+
try {
|
|
1190
|
+
console.error('Testing API connection...')
|
|
1191
|
+
const tools = await remoteClient.getTools()
|
|
1192
|
+
const toolNames = tools.map((t) => t.name)
|
|
1193
|
+
console.error(`Connected successfully. Available tools: ${toolNames.join(', ')}`)
|
|
1194
|
+
primaryInstructions = remoteClient.instructions || undefined
|
|
1195
|
+
if (primaryInstructions) {
|
|
1196
|
+
console.error(
|
|
1197
|
+
`Loaded per-graph instructions for ${graphId} (${primaryInstructions.length} chars)`
|
|
1198
|
+
)
|
|
1199
|
+
}
|
|
1200
|
+
} catch (error) {
|
|
1201
|
+
console.error(`Initial connection test failed: ${error.message}`)
|
|
1202
|
+
// Continue anyway: ListTools retries on demand; instructions stay unset.
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
const serverOptions = {
|
|
1206
|
+
capabilities: {
|
|
1207
|
+
tools: {},
|
|
1208
|
+
},
|
|
1209
|
+
}
|
|
1210
|
+
if (primaryInstructions) {
|
|
1211
|
+
serverOptions.instructions = primaryInstructions
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1155
1214
|
const server = new Server(
|
|
1156
1215
|
{
|
|
1157
1216
|
name: 'robosystems-mcp',
|
|
1158
1217
|
version: PACKAGE_VERSION,
|
|
1159
1218
|
},
|
|
1160
|
-
|
|
1161
|
-
capabilities: {
|
|
1162
|
-
tools: {},
|
|
1163
|
-
},
|
|
1164
|
-
}
|
|
1219
|
+
serverOptions
|
|
1165
1220
|
)
|
|
1166
1221
|
|
|
1167
1222
|
// List tools handler
|
|
@@ -1207,13 +1262,8 @@ async function main() {
|
|
|
1207
1262
|
}
|
|
1208
1263
|
})
|
|
1209
1264
|
|
|
1210
|
-
//
|
|
1265
|
+
// Start server (connection + tools already verified during prefetch above)
|
|
1211
1266
|
try {
|
|
1212
|
-
console.error('Testing API connection...')
|
|
1213
|
-
const tools = await remoteClient.getTools()
|
|
1214
|
-
const toolNames = tools.map((t) => t.name)
|
|
1215
|
-
console.error(`Connected successfully. Available tools: ${toolNames.join(', ')}`)
|
|
1216
|
-
|
|
1217
1267
|
const transport = new StdioServerTransport()
|
|
1218
1268
|
console.error('Starting MCP stdio transport...')
|
|
1219
1269
|
await server.connect(transport)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robosystems/mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
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",
|
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
"test:watch": "vitest",
|
|
26
26
|
"test:all": "npm run validate && npm run test",
|
|
27
27
|
"feature:create": "./bin/create-feature.sh",
|
|
28
|
-
"release:create": "./bin/create-release.sh"
|
|
29
|
-
"pr:create": "./bin/create-pr.sh"
|
|
28
|
+
"release:create": "./bin/create-release.sh"
|
|
30
29
|
},
|
|
31
30
|
"keywords": [
|
|
32
31
|
"mcp",
|