setup-clients.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/usr/bin/env node
  2. /**
  3. * Auto-setup script for Cognio MCP Server
  4. * Automatically generates configuration for all supported AI clients
  5. */
  6. import fs from 'fs';
  7. import path from 'path';
  8. import os from 'os';
  9. const homeDir = os.homedir();
  10. const workspaceDir = process.cwd();
  11. // Find workspace root (go up if we're in mcp-server)
  12. const workspaceRoot = workspaceDir.endsWith('mcp-server')
  13. ? path.dirname(workspaceDir)
  14. : workspaceDir;
  15. // Configuration templates
  16. const configs = {
  17. // Claude Desktop (Mac/Windows)
  18. claudeDesktop: {
  19. mac: path.join(homeDir, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json'),
  20. windows: path.join(homeDir, 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json'),
  21. linux: path.join(homeDir, '.config', 'Claude', 'claude_desktop_config.json'),
  22. content: {
  23. "mcpServers": {
  24. "cognio": {
  25. "command": "node",
  26. "args": [path.join(workspaceRoot, "mcp-server", "index.js")],
  27. "env": {
  28. "COGNIO_API_URL": "http://localhost:8080"
  29. }
  30. }
  31. }
  32. }
  33. },
  34. // Cursor settings
  35. cursor: {
  36. path: path.join(homeDir, '.cursor', 'mcp_settings.json'),
  37. content: {
  38. "mcpServers": {
  39. "cognio": {
  40. "command": "node",
  41. "args": [path.join(workspaceRoot, "mcp-server", "index.js")],
  42. "env": {
  43. "COGNIO_API_URL": "http://localhost:8080"
  44. }
  45. }
  46. }
  47. }
  48. },
  49. // Continue.dev config
  50. continue: {
  51. path: path.join(homeDir, '.continue', 'config.json'),
  52. content: {
  53. "mcpServers": [
  54. {
  55. "name": "cognio",
  56. "command": "node",
  57. "args": [path.join(workspaceRoot, "mcp-server", "index.js")],
  58. "env": {
  59. "COGNIO_API_URL": "http://localhost:8080"
  60. }
  61. }
  62. ],
  63. "systemMessage": "You have access to Cognio semantic memory. Search past work when relevant, save useful solutions for later."
  64. }
  65. },
  66. // Cline settings
  67. cline: {
  68. path: path.join(homeDir, '.cline', 'mcp.json'),
  69. content: {
  70. "mcpServers": {
  71. "cognio": {
  72. "command": "node",
  73. "args": [path.join(workspaceRoot, "mcp-server", "index.js")],
  74. "env": {
  75. "COGNIO_API_URL": "http://localhost:8080"
  76. }
  77. }
  78. }
  79. }
  80. },
  81. // Windsurf settings
  82. windsurf: {
  83. path: path.join(homeDir, '.windsurf', 'mcp_config.json'),
  84. content: {
  85. "mcpServers": {
  86. "cognio": {
  87. "command": "node",
  88. "args": [path.join(workspaceRoot, "mcp-server", "index.js")],
  89. "env": {
  90. "COGNIO_API_URL": "http://localhost:8080"
  91. }
  92. }
  93. }
  94. }
  95. },
  96. // Kiro settings
  97. kiro: {
  98. path: path.join(homeDir, '.kiro', 'settings', 'mcp.json'),
  99. content: {
  100. "mcpServers": {
  101. "cognio": {
  102. "command": "node",
  103. "args": [path.join(workspaceRoot, "mcp-server", "index.js")],
  104. "env": {
  105. "COGNIO_API_URL": "http://localhost:8080"
  106. }
  107. }
  108. }
  109. }
  110. },
  111. // Claude Code (CLI) settings
  112. claudeCode: {
  113. path: path.join(homeDir, '.claude.json'),
  114. content: {
  115. "mcpServers": {
  116. "cognio": {
  117. "type": "stdio",
  118. "command": "node",
  119. "args": [path.join(workspaceRoot, "mcp-server", "index.js")],
  120. "env": {
  121. "COGNIO_API_URL": "http://localhost:8080"
  122. }
  123. }
  124. }
  125. }
  126. },
  127. // Gemini CLI settings
  128. geminiCLI: {
  129. path: path.join(homeDir, 'gemini', 'settings.json'),
  130. content: {
  131. "mcpServers": {
  132. "cognio": {
  133. "command": "node",
  134. "args": [path.join(workspaceRoot, "mcp-server", "index.js")],
  135. "env": {
  136. "COGNIO_API_URL": "http://localhost:8080"
  137. }
  138. }
  139. }
  140. }
  141. }
  142. };
  143. // Instructions for each platform
  144. const instructions = {
  145. claude: `CLAUDE DESKTOP: Ready to use`,
  146. cursor: `CURSOR: Ready to use`,
  147. continue: `CONTINUE.DEV: Ready to use`,
  148. cline: `CLINE: Ready to use`,
  149. windsurf: `WINDSURF: Ready to use`,
  150. kiro: `KIRO: Ready to use`,
  151. claudeCode: `CLAUDE CODE: Ready to use`,
  152. geminiCLI: `GEMINI CLI: Ready to use`
  153. };
  154. function ensureDirectoryExists(filePath) {
  155. const dir = path.dirname(filePath);
  156. if (!fs.existsSync(dir)) {
  157. fs.mkdirSync(dir, { recursive: true });
  158. }
  159. }
  160. function mergeConfig(existingConfig, newConfig) {
  161. if (!existingConfig) return newConfig;
  162. // Deep merge for objects
  163. const merged = { ...existingConfig };
  164. for (const [key, value] of Object.entries(newConfig)) {
  165. if (typeof value === 'object' && !Array.isArray(value) && merged[key]) {
  166. merged[key] = mergeConfig(merged[key], value);
  167. } else {
  168. merged[key] = value;
  169. }
  170. }
  171. return merged;
  172. }
  173. function setupConfig(name, config) {
  174. try {
  175. let configPath = config.path;
  176. // Handle platform-specific paths (Claude Desktop)
  177. if (name === 'claudeDesktop') {
  178. const platform = os.platform();
  179. if (platform === 'darwin') configPath = config.mac;
  180. else if (platform === 'win32') configPath = config.windows;
  181. else configPath = config.linux;
  182. }
  183. ensureDirectoryExists(configPath);
  184. let existingConfig = {};
  185. if (fs.existsSync(configPath)) {
  186. const content = fs.readFileSync(configPath, 'utf8');
  187. existingConfig = JSON.parse(content);
  188. }
  189. const mergedConfig = mergeConfig(existingConfig, config.content);
  190. fs.writeFileSync(configPath, JSON.stringify(mergedConfig, null, 2));
  191. console.log(`[OK] ${name}: ${configPath}`);
  192. return true;
  193. } catch (error) {
  194. console.log(`[WARN] ${name}: ${error.message}`);
  195. return false;
  196. }
  197. }
  198. function main() {
  199. console.log('\n=== Cognio MCP Auto-Setup ===\n');
  200. console.log('Configuring clients for automatic Cognio integration...\n');
  201. const results = {
  202. claudeDesktop: setupConfig('claudeDesktop', configs.claudeDesktop),
  203. cursor: setupConfig('cursor', configs.cursor),
  204. continue: setupConfig('continue', configs.continue),
  205. cline: setupConfig('cline', configs.cline),
  206. windsurf: setupConfig('windsurf', configs.windsurf),
  207. kiro: setupConfig('kiro', configs.kiro),
  208. claudeCode: setupConfig('claudeCode', configs.claudeCode),
  209. geminiCLI: setupConfig('geminiCLI', configs.geminiCLI)
  210. };
  211. console.log('\n[SUMMARY]\n');
  212. console.log('✓ cognio.md auto-generated (AI context for all tools)\n');
  213. Object.entries(results).forEach(([name, success]) => {
  214. if (success) console.log(`✓ ${name}`);
  215. });
  216. console.log('\n[NEXT STEPS]');
  217. console.log('1. Start Cognio: python -m uvicorn src.main:app --port 8080');
  218. console.log('2. Restart your AI client');
  219. console.log('3. cognio.md provides context to all AI tools\n');
  220. }
  221. main();