@townco/cli 0.1.23 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,111 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- // ============================================================================
5
- // Constants
6
- // ============================================================================
7
- const TOWN_CONFIG_DIR = join(homedir(), ".config", "town");
8
- const MCPS_FILE = join(TOWN_CONFIG_DIR, "mcps.json");
9
- // ============================================================================
10
- // Helper Functions
11
- // ============================================================================
12
- /**
13
- * Ensure the config directory exists
14
- */
15
- function ensureConfigDir() {
16
- if (!existsSync(TOWN_CONFIG_DIR)) {
17
- mkdirSync(TOWN_CONFIG_DIR, { recursive: true });
18
- }
19
- }
20
- /**
21
- * Load all MCP configs from the JSON file
22
- */
23
- function loadStore() {
24
- ensureConfigDir();
25
- if (!existsSync(MCPS_FILE)) {
26
- return {};
27
- }
28
- try {
29
- const content = readFileSync(MCPS_FILE, "utf-8");
30
- return JSON.parse(content);
31
- }
32
- catch (error) {
33
- throw new Error(`Failed to load MCP configs: ${error instanceof Error ? error.message : String(error)}`);
34
- }
35
- }
36
- /**
37
- * Save all MCP configs to the JSON file
38
- */
39
- function saveStore(store) {
40
- ensureConfigDir();
41
- try {
42
- const content = JSON.stringify(store, null, 2);
43
- writeFileSync(MCPS_FILE, content, "utf-8");
44
- }
45
- catch (error) {
46
- throw new Error(`Failed to save MCP configs: ${error instanceof Error ? error.message : String(error)}`);
47
- }
48
- }
49
- // ============================================================================
50
- // Public API
51
- // ============================================================================
52
- /**
53
- * Save an MCP config to the store
54
- */
55
- export function saveMCPConfig(config) {
56
- const store = loadStore();
57
- store[config.name] = config;
58
- saveStore(store);
59
- }
60
- /**
61
- * Load an MCP config by name
62
- */
63
- export function loadMCPConfig(name) {
64
- const store = loadStore();
65
- return store[name] || null;
66
- }
67
- /**
68
- * Delete an MCP config by name
69
- */
70
- export function deleteMCPConfig(name) {
71
- const store = loadStore();
72
- if (store[name]) {
73
- delete store[name];
74
- saveStore(store);
75
- return true;
76
- }
77
- return false;
78
- }
79
- /**
80
- * List all MCP configs
81
- */
82
- export function listMCPConfigs() {
83
- const store = loadStore();
84
- return Object.values(store).sort((a, b) => a.name.localeCompare(b.name));
85
- }
86
- /**
87
- * Check if an MCP config exists
88
- */
89
- export function mcpConfigExists(name) {
90
- const store = loadStore();
91
- return name in store;
92
- }
93
- /**
94
- * Get a summary of an MCP config for display
95
- */
96
- export function getMCPSummary(config) {
97
- if (config.transport === "http") {
98
- const parts = [`HTTP: ${config.url}`];
99
- if (config.headers && Object.keys(config.headers).length > 0) {
100
- parts.push(`(${Object.keys(config.headers).length} header${Object.keys(config.headers).length === 1 ? "" : "s"})`);
101
- }
102
- return parts.join(" ");
103
- }
104
- else {
105
- const parts = [`Stdio: ${config.command}`];
106
- if (config.args && config.args.length > 0) {
107
- parts.push(`[${config.args.join(" ")}]`);
108
- }
109
- return parts.join(" ");
110
- }
111
- }