@@ -6,13 +6,16 @@ import { Logger } from "./logger.util.js";
66
77/**
88 * Configuration loader that handles multiple sources with priority:
9- * 1. Direct ENV pass (process.env)
10- * 2. .env file in project root
11- * 3. Global config file at $HOME/.mcp/configs.json
9+ * 1. MCP initialization config (from clientInfo)
10+ * 2. Direct ENV pass (process.env)
11+ * 3. .env file in project root
12+ * 4. Global config file at $HOME/.mcp/configs.json
1213 */
1314class ConfigLoader {
1415 private packageName : string ;
1516 private configLoaded = false ;
17+ private mcpInitConfig : Record < string , unknown > = { } ;
18+ private httpQueryConfig : Record < string , unknown > = { } ;
1619
1720 /**
1821 * Create a new ConfigLoader instance
@@ -22,6 +25,39 @@ class ConfigLoader {
2225 this . packageName = packageName ;
2326 }
2427
28+ /**
29+ * Set configuration from HTTP query parameters (highest priority for Smithery)
30+ * @param config Configuration object from HTTP query parameters
31+ */
32+ setHttpQueryConfig ( config : Record < string , unknown > ) : void {
33+ const methodLogger = Logger . forContext (
34+ "utils/config.util.ts" ,
35+ "setHttpQueryConfig" ,
36+ ) ;
37+
38+ this . httpQueryConfig = { ...config } ;
39+ methodLogger . debug ( "HTTP query parameter configuration set" , {
40+ keysCount : Object . keys ( config ) . length ,
41+ keys : Object . keys ( config ) ,
42+ } ) ;
43+ }
44+
45+ /**
46+ * Set configuration from MCP initialization (second highest priority)
47+ * @param config Configuration object from MCP clientInfo
48+ */
49+ setMcpInitConfig ( config : Record < string , unknown > ) : void {
50+ const methodLogger = Logger . forContext (
51+ "utils/config.util.ts" ,
52+ "setMcpInitConfig" ,
53+ ) ;
54+
55+ this . mcpInitConfig = { ...config } ;
56+ methodLogger . debug ( "MCP initialization configuration set" , {
57+ keysCount : Object . keys ( config ) . length ,
58+ } ) ;
59+ }
60+
2561 /**
2662 * Load configuration from all sources with proper priority
2763 */
@@ -35,15 +71,12 @@ class ConfigLoader {
3571
3672 methodLogger . debug ( "Loading configuration..." ) ;
3773
38- // Priority 3 : Load from global config file
74+ // Priority 5 : Load from global config file
3975 this . loadFromGlobalConfig ( ) ;
4076
41- // Priority 2 : Load from .env file
77+ // Priority 4 : Load from .env file
4278 this . loadFromEnvFile ( ) ;
4379
44- // Priority 1: Direct ENV pass is already in process.env
45- // No need to do anything as it already has highest priority
46-
4780 this . configLoaded = true ;
4881 methodLogger . debug ( "Configuration loaded successfully" ) ;
4982 }
@@ -91,12 +124,11 @@ class ConfigLoader {
91124 const config = JSON . parse ( configContent ) ;
92125
93126 // Determine the potential keys for the current package
94- const shortKey = "boilerplate" ; // Project-specific short key
95- const fullPackageName = this . packageName ; // e.g., '@aashari/boilerplate-mcp-server'
127+ const fullPackageName = this . packageName ; // e.g., 'lokalise-mcp'
96128 const unscopedPackageName =
97- fullPackageName . split ( "/" ) [ 1 ] || fullPackageName ; // e.g., 'boilerplate -mcp-server '
129+ fullPackageName . split ( "/" ) [ 1 ] || fullPackageName ; // e.g., 'lokalise -mcp'
98130
99- const potentialKeys = [ shortKey , fullPackageName , unscopedPackageName ] ;
131+ const potentialKeys = [ fullPackageName , unscopedPackageName ] ;
100132 let foundConfigSection : {
101133 environments ?: Record < string , unknown > ;
102134 } | null = null ;
@@ -145,6 +177,17 @@ class ConfigLoader {
145177 * @returns The configuration value or the default value
146178 */
147179 get ( key : string , defaultValue ?: string ) : string | undefined {
180+ // Priority 1: HTTP query parameters (highest priority for Smithery)
181+ if ( this . httpQueryConfig [ key ] !== undefined ) {
182+ return String ( this . httpQueryConfig [ key ] ) ;
183+ }
184+
185+ // Priority 2: MCP initialization config
186+ if ( this . mcpInitConfig [ key ] !== undefined ) {
187+ return String ( this . mcpInitConfig [ key ] ) ;
188+ }
189+
190+ // Priority 3: Environment variables
148191 return process . env [ key ] || defaultValue ;
149192 }
150193
@@ -196,4 +239,4 @@ class ConfigLoader {
196239}
197240
198241// Create and export a singleton instance with the package name from package.json
199- export const config = new ConfigLoader ( "@aashari/boilerplate -mcp-server " ) ;
242+ export const config = new ConfigLoader ( "lokalise -mcp" ) ;
0 commit comments