@@ -12,9 +12,7 @@ import {
1212import { Instance } from "../../project/instance"
1313import { Global } from "../../global"
1414import { Log } from "../../util/log"
15- // altimate_change start — shared datamate transport helpers (IDE scan, sync, constants)
1615import { DATAMATE_KEY , readDatamateTransportFromIde } from "../datamate-transport"
17- // altimate_change end
1816
1917const log = Log . create ( { service : "datamate" } )
2018
@@ -31,12 +29,10 @@ export function slugify(name: string): string {
3129 . replace ( / ^ - | - $ / g, "" )
3230}
3331
34- // altimate_change start — readDatamateTransportFromIde (imported from altimate/datamate-transport.ts)
3532// Scans .vscode/mcp.json, .cursor/mcp.json, .github/copilot/mcp.json in projectRootDir
3633// so this works in Cursor, Copilot, and other IDEs that write their own MCP config file.
3734// Returns the exact command from the IDE config so altimate-code reuses the same process
3835// the extension already manages rather than spawning a second one.
39- // altimate_change end
4036
4137export const DatamateManagerTool = Tool . define ( "datamate_manager" , {
4238 description :
@@ -169,10 +165,7 @@ async function handleListIntegrations() {
169165 }
170166}
171167
172- // altimate_change start — server name used by IDEs (VS Code, Cursor, etc) in their MCP config
173168// DATAMATE_KEY is imported from altimate/datamate-transport.ts (shared constant).
174- const EXTENSION_DATAMATE_SERVER = DATAMATE_KEY
175- // altimate_change end
176169
177170async function handleAdd ( args : { datamate_id ?: string ; name ?: string ; scope ?: "project" | "global" } ) {
178171 if ( ! args . datamate_id ) {
@@ -184,31 +177,28 @@ async function handleAdd(args: { datamate_id?: string; name?: string; scope?: "p
184177 }
185178 try {
186179 const datamate = await AltimateApi . getDatamate ( args . datamate_id )
187- // altimate_change start — scan all IDE config locations (VS Code, Cursor, Copilot, etc.)
188180 // readDatamateTransportFromIde returns the exact command from the IDE config so we
189181 // reuse the same process the extension already manages, not a second one.
190182 const transport = await readDatamateTransportFromIde ( projectRoot ( ) )
191183
192184 if ( transport !== null ) {
193185 log . info ( "handleAdd: IDE transport detected, entering single-gateway mode" , {
194- serverName : EXTENSION_DATAMATE_SERVER ,
186+ serverName : DATAMATE_KEY ,
195187 transportType : transport . type ,
196188 } )
197189 } else {
198190 log . info ( "handleAdd: no IDE transport found, using standalone cloud config" )
199191 }
200- // altimate_change end
201192
202- // altimate_change start — single-gateway mode when IDE extension is present
203193 // If an IDE MCP config has a "datamate" entry (written by VS Code, Cursor, etc.),
204- // always use EXTENSION_DATAMATE_SERVER ("datamate") as the server name regardless
194+ // always use DATAMATE_KEY ("datamate") as the server name regardless
205195 // of which specific datamate the user selected. This prevents duplicate tool sets
206196 // — the extension's gateway already serves all datamate tools through a single
207197 // MCP connection.
208198 // In standalone/CLI mode (no IDE datamate entry), fall back to per-datamate naming
209199 // with cloud URL.
210200 const serverName = transport !== null
211- ? EXTENSION_DATAMATE_SERVER
201+ ? DATAMATE_KEY
212202 : ( args . name ?? `datamate-${ slugify ( datamate . name ) } ` )
213203
214204 const creds = transport ? undefined : await AltimateApi . getCredentials ( )
@@ -227,54 +217,54 @@ async function handleAdd(args: { datamate_id?: string; name?: string; scope?: "p
227217 const configPath = await resolveConfigPath ( isGlobal ? Global . Path . config : projectRoot ( ) , isGlobal )
228218
229219 if ( transport !== null ) {
230- // IDE/extension mode: check if EXTENSION_DATAMATE_SERVER is already wired up
220+ // IDE/extension mode: check if DATAMATE_KEY is already wired up
231221 const existingNames = await listMcpInConfig ( configPath )
232222 const staleEntries = existingNames . filter (
233- ( n ) => n !== EXTENSION_DATAMATE_SERVER && n . startsWith ( "datamate-" ) ,
223+ ( n ) => n !== DATAMATE_KEY && n . startsWith ( "datamate-" ) ,
234224 )
235225 if ( staleEntries . length > 0 ) {
236226 log . info ( "handleAdd: stale per-datamate entries detected alongside extension gateway" , {
237227 staleEntries,
238228 } )
239229 }
240230
241- if ( existingNames . includes ( EXTENSION_DATAMATE_SERVER ) ) {
231+ if ( existingNames . includes ( DATAMATE_KEY ) ) {
242232 // Already in config — just ensure it is connected in this session
243233 const allStatus = await MCP . status ( )
244- if ( allStatus [ EXTENSION_DATAMATE_SERVER ] ?. status === "connected" ) {
234+ if ( allStatus [ DATAMATE_KEY ] ?. status === "connected" ) {
245235 log . info ( "handleAdd: already connected, skipping add" , {
246- serverName : EXTENSION_DATAMATE_SERVER ,
236+ serverName : DATAMATE_KEY ,
247237 } )
248238 const mcpTools = await MCP . tools ( )
249239 const toolCount = Object . keys ( mcpTools ) . filter ( ( k ) =>
250- k . startsWith ( EXTENSION_DATAMATE_SERVER + "_" ) ,
240+ k . startsWith ( DATAMATE_KEY + "_" ) ,
251241 ) . length
252242 const staleNote =
253243 staleEntries . length > 0
254244 ? `\n\nNote: stale per-datamate entries found in config: ${ staleEntries . join ( ", " ) } — use operation 'remove' to clean them up.`
255245 : ""
256246 return {
257- title : `Datamate '${ datamate . name } ': already connected via '${ EXTENSION_DATAMATE_SERVER } '` ,
258- metadata : { serverName : EXTENSION_DATAMATE_SERVER , datamateId : args . datamate_id , toolCount } ,
259- output : `Datamate tools are already available via the '${ EXTENSION_DATAMATE_SERVER } ' MCP server (${ toolCount } tools active).${ staleNote } ` ,
247+ title : `Datamate '${ datamate . name } ': already connected via '${ DATAMATE_KEY } '` ,
248+ metadata : { serverName : DATAMATE_KEY , datamateId : args . datamate_id , toolCount } ,
249+ output : `Datamate tools are already available via the '${ DATAMATE_KEY } ' MCP server (${ toolCount } tools active).${ staleNote } ` ,
260250 }
261251 }
262252 // In config but not connected — reconnect via MCP.connect() so persistMcpEnabled
263253 // is called and the enabled:true state survives the next session restart.
264254 // Bug-fix: was previously MCP.add() which skips persistMcpEnabled, so a session
265255 // that had the server disabled would not re-enable it on the next restart.
266256 log . info ( "handleAdd: reconnecting existing datamate entry" , {
267- serverName : EXTENSION_DATAMATE_SERVER ,
257+ serverName : DATAMATE_KEY ,
268258 } )
269- await MCP . connect ( EXTENSION_DATAMATE_SERVER )
259+ await MCP . connect ( DATAMATE_KEY )
270260 } else {
271261 // Not in config yet — write to disk then connect
272262 log . info ( "handleAdd: adding new datamate entry" , {
273- serverName : EXTENSION_DATAMATE_SERVER ,
263+ serverName : DATAMATE_KEY ,
274264 type : mcpConfig . type ,
275265 } )
276- await addMcpToConfig ( EXTENSION_DATAMATE_SERVER , { ...mcpConfig , enabled : true } , configPath )
277- await MCP . add ( EXTENSION_DATAMATE_SERVER , mcpConfig )
266+ await addMcpToConfig ( DATAMATE_KEY , { ...mcpConfig , enabled : true } , configPath )
267+ await MCP . add ( DATAMATE_KEY , mcpConfig )
278268 }
279269 } else {
280270 // Standalone/CLI mode — original behaviour: per-datamate name + cloud URL
@@ -285,7 +275,6 @@ async function handleAdd(args: { datamate_id?: string; name?: string; scope?: "p
285275 await addMcpToConfig ( serverName , { ...mcpConfig , enabled : true } , configPath )
286276 await MCP . add ( serverName , mcpConfig )
287277 }
288- // altimate_change end
289278
290279 // Check connection status
291280 const allStatus = await MCP . status ( )
0 commit comments