Skip to content

Commit

Permalink
fix: use 'env' instead of 'envVars' in Claude desktop config
Browse files Browse the repository at this point in the history
- Updates MCPServer interface to use 'env' key
- Adds unit tests to verify config structure

Fixes #48

Co-Authored-By: Michael Latman <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and michaellatman committed Dec 12, 2024
1 parent 07b9365 commit 2f0a711
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
1 change: 0 additions & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const config = {
},
testMatch: ['**/__tests__/**/*.test.ts'],
testPathIgnorePatterns: ['/node_modules/', '/loaders/'],
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
};

export default config;
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"build": "tsc && chmod +x dist/index.js",
"start": "node dist/index.js",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.mjs",
"test:list": "node --loader ts-node/esm src/index.ts list",
"test:install": "node --loader ts-node/esm src/index.ts install",
"test:installed": "node --loader ts-node/esm src/index.ts installed",
Expand Down Expand Up @@ -41,7 +42,7 @@
"@types/inquirer": "^8.2.4",
"@types/inquirer-autocomplete-prompt": "^3.0.3",
"@types/jest": "^29.5.14",
"@types/node": "^14.0.0",
"@types/node": "^14.18.63",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.1"
Expand Down
42 changes: 42 additions & 0 deletions src/utils/__tests__/config-manager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { jest, describe, it, expect, beforeEach } from '@jest/globals';
import { ConfigManager } from '../config-manager';
import { Package } from '../../types/package';
import fs from 'fs';
import path from 'path';

jest.mock('fs');
jest.mock('path');

describe('ConfigManager', () => {
beforeEach(() => {
jest.clearAllMocks();
});

describe('installPackage', () => {
it('should create config with "env" key for environment variables', async () => {
const mockPackage: Package = {
name: 'test-package',
description: 'Test package for config manager',
runtime: 'node',
vendor: 'test-vendor',
sourceUrl: 'https://github.com/test/test-package',
homepage: 'https://test-package.com',
license: 'MIT'
};

const mockEnvVars = {
TEST_KEY: 'test-value'
};

const writeFileSpy = jest.spyOn(fs, 'writeFileSync');

await ConfigManager.installPackage(mockPackage, mockEnvVars);

expect(writeFileSpy).toHaveBeenCalled();
const writtenConfig = JSON.parse(writeFileSpy.mock.calls[0][1] as string);
expect(writtenConfig.mcpServers['test-package'].env).toBeDefined();
expect(writtenConfig.mcpServers['test-package'].envVars).toBeUndefined();
expect(writtenConfig.mcpServers['test-package'].env).toEqual(mockEnvVars);
});
});
});
10 changes: 5 additions & 5 deletions src/utils/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface MCPServer {
runtime: 'node' | 'python';
command?: string;
args?: string[];
envVars?: Record<string, string>;
env?: Record<string, string>; // Changed from envVars to env
}

export interface MCPConfig {
Expand Down Expand Up @@ -106,10 +106,10 @@ export class ConfigManager {
static async installPackage(pkg: Package, envVars?: Record<string, string>): Promise<void> {
const config = this.readConfig();
const serverName = pkg.name.replace(/\//g, '-');

const serverConfig: MCPServer = {
runtime: pkg.runtime,
envVars
env: envVars // Changed from envVars to env
};

// Add command and args based on runtime
Expand All @@ -128,12 +128,12 @@ export class ConfigManager {
static async uninstallPackage(packageName: string): Promise<void> {
const config = this.readConfig();
const serverName = packageName.replace(/\//g, '-');

if (!config.mcpServers || !config.mcpServers[serverName]) {
console.log(`Package ${packageName} is not installed.`);
return;
}

delete config.mcpServers[serverName];
this.writeConfig(config);
}
Expand Down

0 comments on commit 2f0a711

Please sign in to comment.