@@ -2,12 +2,18 @@ package workingset
22
33import (
44 "encoding/json"
5+ "os"
6+ "path/filepath"
57
68 "github.com/docker/mcp-gateway/pkg/config"
79)
810
911type Config struct {
10- WorkingSets map [string ]WorkingSet `json:"workingSets"`
12+ WorkingSets map [string ]WorkingSetMetadata `json:"workingSets"`
13+ }
14+
15+ type WorkingSetMetadata struct {
16+ DisplayName string `json:"displayName"`
1117}
1218
1319type WorkingSet struct {
@@ -17,7 +23,7 @@ type WorkingSet struct {
1723}
1824
1925func ReadConfig () (* Config , error ) {
20- buf , err := config .ReadWorkingSets ()
26+ buf , err := config .ReadWorkingSetConfig ()
2127 if err != nil {
2228 return nil , err
2329 }
@@ -30,21 +36,73 @@ func ReadConfig() (*Config, error) {
3036 }
3137
3238 if result .WorkingSets == nil {
33- result .WorkingSets = map [string ]WorkingSet {}
39+ result .WorkingSets = map [string ]WorkingSetMetadata {}
3440 }
3541
3642 return & result , nil
3743}
3844
3945func WriteConfig (cfg * Config ) error {
4046 if cfg .WorkingSets == nil {
41- cfg .WorkingSets = map [string ]WorkingSet {}
47+ cfg .WorkingSets = map [string ]WorkingSetMetadata {}
4248 }
4349
4450 data , err := json .MarshalIndent (cfg , "" , " " )
4551 if err != nil {
4652 return err
4753 }
4854
49- return config .WriteWorkingSets (data )
55+ return config .WriteWorkingSetConfig (data )
56+ }
57+
58+ func ReadWorkingSetFile (name string ) (* WorkingSet , error ) {
59+ buf , err := config .ReadWorkingSetFile (name )
60+ if err != nil {
61+ return nil , err
62+ }
63+
64+ if len (buf ) == 0 {
65+ return nil , os .ErrNotExist
66+ }
67+
68+ var ws WorkingSet
69+ if err := json .Unmarshal (buf , & ws ); err != nil {
70+ return nil , err
71+ }
72+
73+ return & ws , nil
74+ }
75+
76+ func WriteWorkingSetFile (name string , ws * WorkingSet ) error {
77+ data , err := json .MarshalIndent (ws , "" , " " )
78+ if err != nil {
79+ return err
80+ }
81+
82+ return config .WriteWorkingSetFile (name , data )
83+ }
84+
85+ func ListWorkingSets () (map [string ]WorkingSet , error ) {
86+ cfg , err := ReadConfig ()
87+ if err != nil {
88+ return nil , err
89+ }
90+
91+ workingSets := make (map [string ]WorkingSet )
92+ for name := range cfg .WorkingSets {
93+ ws , err := ReadWorkingSetFile (name )
94+ if err != nil {
95+ if os .IsNotExist (err ) {
96+ continue // Skip missing files
97+ }
98+ return nil , err
99+ }
100+ workingSets [name ] = * ws
101+ }
102+
103+ return workingSets , nil
104+ }
105+
106+ func WorkingSetFilePath (name string ) (string , error ) {
107+ return config .FilePath (filepath .Join ("working-sets" , name + ".json" ))
50108}
0 commit comments