@@ -13,6 +13,8 @@ export interface CodexSettings {
1313 personality ?: string ;
1414 modelReasoningEffort ?: string ;
1515 trustLevel ?: string ;
16+ // Names of every `[mcp_servers.<name>]` section declared in the user's config.toml
17+ mcpServerNames : string [ ] ;
1618}
1719
1820/**
@@ -24,32 +26,29 @@ export interface CodexSettings {
2426 */
2527export class CodexSettingsManager {
2628 private cwd : string ;
27- private settings : CodexSettings = { } ;
28- private initialized = false ;
29+ private settings : CodexSettings = { mcpServerNames : [ ] } ;
2930
3031 constructor ( cwd : string ) {
3132 this . cwd = cwd ;
33+ this . loadSettings ( ) ;
3234 }
3335
3436 async initialize ( ) : Promise < void > {
35- if ( this . initialized ) {
36- return ;
37- }
38- await this . loadSettings ( ) ;
39- this . initialized = true ;
37+ // No-op: settings are loaded in the constructor. Kept async to
38+ // satisfy the BaseSettingsManager interface.
4039 }
4140
4241 private getConfigPath ( ) : string {
4342 return path . join ( os . homedir ( ) , ".codex" , "config.toml" ) ;
4443 }
4544
46- private async loadSettings ( ) : Promise < void > {
45+ private loadSettings ( ) : void {
4746 const configPath = this . getConfigPath ( ) ;
4847 try {
49- const content = await fs . promises . readFile ( configPath , "utf-8" ) ;
48+ const content = fs . readFileSync ( configPath , "utf-8" ) ;
5049 this . settings = parseCodexToml ( content , this . cwd ) ;
5150 } catch {
52- this . settings = { } ;
51+ this . settings = { mcpServerNames : [ ] } ;
5352 }
5453 }
5554
@@ -62,17 +61,13 @@ export class CodexSettingsManager {
6261 }
6362
6463 async setCwd ( cwd : string ) : Promise < void > {
65- if ( this . cwd === cwd ) {
66- return ;
67- }
68- this . dispose ( ) ;
64+ if ( this . cwd === cwd ) return ;
6965 this . cwd = cwd ;
70- this . initialized = false ;
71- await this . initialize ( ) ;
66+ this . loadSettings ( ) ;
7267 }
7368
7469 dispose ( ) : void {
75- this . initialized = false ;
70+ // No-op: no resources to release. Kept to satisfy the BaseSettingsManager interface.
7671 }
7772}
7873
@@ -82,7 +77,8 @@ export class CodexSettingsManager {
8277 * Does NOT handle full TOML spec — only what codex config uses.
8378 */
8479function parseCodexToml ( content : string , cwd : string ) : CodexSettings {
85- const settings : CodexSettings = { } ;
80+ const settings : CodexSettings = { mcpServerNames : [ ] } ;
81+ const mcpServerNames = new Set < string > ( ) ;
8682 let currentSection = "" ;
8783
8884 for ( const line of content . split ( "\n" ) ) {
@@ -93,6 +89,9 @@ function parseCodexToml(content: string, cwd: string): CodexSettings {
9389 const sectionMatch = trimmed . match ( / ^ \[ ( .+ ) \] $ / ) ;
9490 if ( sectionMatch ) {
9591 currentSection = sectionMatch [ 1 ] ?? "" ;
92+ if ( currentSection . startsWith ( "mcp_servers." ) ) {
93+ mcpServerNames . add ( currentSection . slice ( "mcp_servers." . length ) ) ;
94+ }
9695 continue ;
9796 }
9897
@@ -123,5 +122,6 @@ function parseCodexToml(content: string, cwd: string): CodexSettings {
123122 }
124123 }
125124
125+ settings . mcpServerNames = Array . from ( mcpServerNames ) ;
126126 return settings ;
127127}
0 commit comments