@@ -2,7 +2,7 @@ import { type FastifyInstance } from 'fastify';
22import { requireAuthenticationAny , requireOAuthScope } from '../../middleware/oauthMiddleware' ;
33import { getDb } from '../../db' ;
44import { eq , and , inArray } from 'drizzle-orm' ;
5- import { mcpServers , mcpServerInstallations , mcpUserConfigurations , teamMemberships } from '../../db/schema.sqlite' ;
5+ import { mcpServers , mcpServerInstallations , mcpUserConfigurations , teamMemberships , devices } from '../../db/schema.sqlite' ;
66
77// Response schemas
88const GATEWAY_MCP_SERVER_SCHEMA = {
@@ -63,7 +63,7 @@ const ERROR_RESPONSE_SCHEMA = {
6363
6464// TypeScript interfaces
6565interface QueryParams {
66- device_id ?: string ;
66+ hardware_id ?: string ;
6767}
6868
6969interface GatewayMcpServer {
@@ -104,9 +104,9 @@ export default async function gatewayMeMcpConfigurationsRoute(server: FastifyIns
104104 querystring : {
105105 type : 'object' ,
106106 properties : {
107- device_id : {
107+ hardware_id : {
108108 type : 'string' ,
109- description : 'Device ID to get device-specific user configurations'
109+ description : 'Hardware ID to get device-specific user configurations'
110110 }
111111 } ,
112112 additionalProperties : false
@@ -118,7 +118,7 @@ export default async function gatewayMeMcpConfigurationsRoute(server: FastifyIns
118118 } ,
119119 400 : {
120120 ...ERROR_RESPONSE_SCHEMA ,
121- description : 'Bad Request - Invalid device_id or missing parameters'
121+ description : 'Bad Request - Invalid hardware_id or missing parameters'
122122 } ,
123123 401 : {
124124 ...ERROR_RESPONSE_SCHEMA ,
@@ -137,13 +137,13 @@ export default async function gatewayMeMcpConfigurationsRoute(server: FastifyIns
137137 } , async ( request , reply ) => {
138138 const userId = request . user ! . id ;
139139 const query = request . query as QueryParams ;
140- const deviceId = query . device_id ;
140+ const hardwareId = query . hardware_id ;
141141 const authType = request . tokenPayload ? 'oauth2' : 'cookie' ;
142142
143143 request . log . debug ( {
144144 operation : 'gateway_mcp_configurations' ,
145145 userId,
146- deviceId ,
146+ hardwareId ,
147147 authType,
148148 clientId : request . tokenPayload ?. clientId ,
149149 scope : request . tokenPayload ?. scope ,
@@ -153,13 +153,44 @@ export default async function gatewayMeMcpConfigurationsRoute(server: FastifyIns
153153 request . log . info ( {
154154 operation : 'get_gateway_mcp_configurations' ,
155155 userId,
156- deviceId ,
156+ hardwareId ,
157157 authType
158158 } , 'Getting merged MCP configurations for gateway' ) ;
159159
160160 try {
161161 const db = getDb ( ) ;
162162
163+ // Find device by hardware_id if provided
164+ let deviceId : string | null = null ;
165+ if ( hardwareId ) {
166+ const deviceResults = await db
167+ . select ( { id : devices . id } )
168+ . from ( devices )
169+ . where (
170+ and (
171+ eq ( devices . user_id , userId ) ,
172+ eq ( devices . hardware_id , hardwareId )
173+ )
174+ )
175+ . limit ( 1 ) ;
176+
177+ if ( deviceResults . length > 0 ) {
178+ deviceId = deviceResults [ 0 ] . id ;
179+ request . log . debug ( {
180+ operation : 'get_gateway_mcp_configurations' ,
181+ userId,
182+ hardwareId,
183+ deviceId
184+ } , 'Found device by hardware_id' ) ;
185+ } else {
186+ request . log . warn ( {
187+ operation : 'get_gateway_mcp_configurations' ,
188+ userId,
189+ hardwareId
190+ } , 'No device found for hardware_id' ) ;
191+ }
192+ }
193+
163194 // Get user's teams
164195 const userTeams = await db
165196 . select ( { teamId : teamMemberships . team_id } )
@@ -347,6 +378,7 @@ export default async function gatewayMeMcpConfigurationsRoute(server: FastifyIns
347378 configStatus = 'invalid' ;
348379 request . log . warn ( {
349380 serverId : server . id ,
381+ hardwareId,
350382 deviceId
351383 } , 'User configuration required but not found' ) ;
352384 }
@@ -382,6 +414,7 @@ export default async function gatewayMeMcpConfigurationsRoute(server: FastifyIns
382414 request . log . info ( {
383415 operation : 'get_gateway_mcp_configurations' ,
384416 userId,
417+ hardwareId,
385418 deviceId,
386419 authType,
387420 serversCount : servers . length ,
@@ -403,7 +436,7 @@ export default async function gatewayMeMcpConfigurationsRoute(server: FastifyIns
403436 operation : 'get_gateway_mcp_configurations' ,
404437 error,
405438 userId,
406- deviceId
439+ hardwareId
407440 } , 'Failed to retrieve gateway MCP configurations' ) ;
408441
409442 const errorMessage = error instanceof Error ? error . message : 'Unknown error occurred' ;
0 commit comments