Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/config-writer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,61 @@ describe('writeConfig', () => {
expect(mcp).toHaveLength(3)
expect(mcp.map((e: { serverName: string }) => e.serverName)).toEqual(['server_a', 'server_b', 'server_c'])
})

it('normalizes hyphens to underscores in serverName', () => {
writeConfig({
serverName: 'glean-default',
serverUrl: 'https://example.com/mcp/default',
autoUpdate: false,
binaryUrlPrefix: 'https://example.com/binaries',
outputDir,
})

const mcp = JSON.parse(readFileSync(join(outputDir, 'mcp-config.json'), 'utf-8'))
expect(mcp).toHaveLength(1)
expect(mcp[0].serverName).toBe('glean_default')
})

it('deduplicates hyphenated serverName against existing underscored entry', () => {
writeConfig({
serverName: 'glean_default',
serverUrl: 'https://example.com/mcp/default',
autoUpdate: false,
binaryUrlPrefix: 'https://example.com/binaries',
outputDir,
})

writeConfig({
serverName: 'glean-default',
serverUrl: 'https://other.example.com/mcp/default',
autoUpdate: false,
binaryUrlPrefix: 'https://example.com/binaries',
outputDir,
})

const mcp = JSON.parse(readFileSync(join(outputDir, 'mcp-config.json'), 'utf-8'))
expect(mcp).toHaveLength(1)
expect(mcp[0].serverName).toBe('glean_default')
})

it('skips new entry when existing hyphenated entry normalizes to same name', () => {
const mcpPath = join(outputDir, 'mcp-config.json')
writeFileSync(
mcpPath,
JSON.stringify([{ serverName: 'glean-default', url: 'https://example.com/mcp/default' }]) + '\n',
)

writeConfig({
serverName: 'glean_default',
serverUrl: 'https://other.example.com/mcp/default',
autoUpdate: false,
binaryUrlPrefix: 'https://example.com/binaries',
outputDir,
})

// The existing entry is recognized as a duplicate after normalization,
// so no new entry is appended
const mcp = JSON.parse(readFileSync(mcpPath, 'utf-8'))
expect(mcp).toHaveLength(1)
})
})
2 changes: 1 addition & 1 deletion src/config-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function writeConfig(options: WriteConfigOptions): void {
const outputDir = options.outputDir ?? getDefaultConfigDir()
mkdirSync(outputDir, { recursive: true })

const newEntry = { serverName: options.serverName, url: options.serverUrl }
const newEntry = { serverName: options.serverName.replace(/-/g, '_'), url: options.serverUrl }
McpConfigSchema.parse([newEntry])

const mdmData: Record<string, unknown> = {
Expand Down
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { getDefaultMcpConfigPath, getDefaultMdmConfigPath } from './platform.js'
const SEMVER_PATTERN = /^v?\d+\.\d+\.\d+$/

const McpServerEntrySchema = z.object({
serverName: z.string().min(1),
serverName: z
.string()
.min(1)
.transform((name) => name.replace(/-/g, '_')),
url: z.string().min(1),
})

Expand Down