/ src / renderer / store / stdio.ts
stdio.ts
 1  import { defineStore } from 'pinia'
 2  import { ref, toRaw } from 'vue'
 3  
 4  import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js'
 5  
 6  // Other keyof StdioServerParameters are not in use
 7  export type StdioServerKey = 'command' | 'args' | 'env'
 8  
 9  export type CustomStdioServerParameters = Partial<StdioServerParameters>
10  
11  export const useStdioStore = defineStore(
12    'stdioStore',
13    () => {
14      const configValues = ref<Record<string, CustomStdioServerParameters>>({})
15  
16      function updateConfigAttribute<K extends StdioServerKey>(
17        name: string,
18        key: K,
19        value: StdioServerParameters[K]
20      ) {
21        if (!configValues.value[name]) {
22          configValues.value[name] = {}
23        }
24        configValues.value[name][key] = value
25      }
26  
27      const getConfig = (name: string) => {
28        return toRaw(configValues.value[name]) ?? null
29      }
30  
31      function deleteConfig(name: string) {
32        delete configValues.value[name]
33      }
34  
35      return { configValues, getConfig, deleteConfig, updateConfigAttribute }
36    },
37    {
38      persist: true
39    }
40  )