Skip to content

Commit 6f2399b

Browse files
committed
remove client info on conflict
1 parent e5cdf08 commit 6f2399b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/lib/utils.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export const REASON_TRANSPORT_FALLBACK = 'falling-back-to-alternate-transport'
1212
// Transport strategy types
1313
export type TransportStrategy = 'sse-only' | 'http-only' | 'sse-first' | 'http-first'
1414
import { OAuthCallbackServerOptions } from './types'
15-
import { readJsonFile } from './mcp-auth-config'
15+
import { getConfigFilePath, readJsonFile } from './mcp-auth-config'
1616
import express from 'express'
1717
import net from 'net'
1818
import crypto from 'crypto'
19+
import fs from 'fs/promises'
1920

2021
// Package version from package.json
2122
export const MCP_REMOTE_VERSION = require('../../package.json').version
@@ -459,14 +460,23 @@ export async function parseCommandLineArgs(args: string[], defaultPort: number,
459460

460461
// Use the specified port, or the existing client port or fallback to find an available one
461462
const [existingClientPort, availablePort] = await Promise.all([findExistingClientPort(serverUrl), findAvailablePort(defaultPort)])
462-
const callbackPort = specifiedPort || existingClientPort || availablePort
463+
let callbackPort: number
463464

464465
if (specifiedPort) {
465-
log(`Using specified callback port: ${callbackPort}`)
466+
if (existingClientPort && specifiedPort !== existingClientPort) {
467+
log(
468+
`Warning! Specified callback port of ${specifiedPort}, which conflicts with existing client registration port ${existingClientPort}. Deleting existing client data to force reregistration.`,
469+
)
470+
await fs.rm(getConfigFilePath(getServerUrlHash(serverUrl), 'client_info.json'))
471+
}
472+
log(`Using specified callback port: ${specifiedPort}`)
473+
callbackPort = specifiedPort
466474
} else if (existingClientPort) {
467475
log(`Using existing client port: ${existingClientPort}`)
476+
callbackPort = existingClientPort
468477
} else {
469-
log(`Using automatically selected callback port: ${callbackPort}`)
478+
log(`Using automatically selected callback port: ${availablePort}`)
479+
callbackPort = availablePort
470480
}
471481

472482
if (Object.keys(headers).length > 0) {

0 commit comments

Comments
 (0)