Skip to content

Commit 14592ca

Browse files
committed
Cleaning up redundant debug logs
1 parent 47e00b0 commit 14592ca

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

src/lib/coordination.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ export async function isLockValid(lockData: LockfileData): Promise<boolean> {
8383
*/
8484
export async function waitForAuthentication(port: number): Promise<boolean> {
8585
log(`Waiting for authentication from the server on port ${port}...`)
86-
if (DEBUG) debugLog(`Waiting for authentication from server on port ${port}`)
8786

8887
try {
8988
let attempts = 0
9089
while (true) {
9190
attempts++
9291
const url = `http://127.0.0.1:${port}/wait-for-auth`
9392
log(`Querying: ${url}`)
94-
if (DEBUG) debugLog(`Poll attempt ${attempts}: ${url}`)
93+
if (DEBUG) debugLog(`Poll attempt ${attempts}`)
9594

9695
try {
9796
const response = await fetch(url)
@@ -100,16 +99,14 @@ export async function waitForAuthentication(port: number): Promise<boolean> {
10099
if (response.status === 200) {
101100
// Auth completed, but we don't return the code anymore
102101
log(`Authentication completed by other instance`)
103-
if (DEBUG) debugLog(`Authentication completed by other instance`)
104102
return true
105103
} else if (response.status === 202) {
106104
// Continue polling
107105
log(`Authentication still in progress`)
108-
if (DEBUG) debugLog(`Authentication still in progress, will retry in 1s`)
106+
if (DEBUG) debugLog(`Will retry in 1s`)
109107
await new Promise((resolve) => setTimeout(resolve, 1000))
110108
} else {
111109
log(`Unexpected response status: ${response.status}`)
112-
if (DEBUG) debugLog(`Unexpected response status`, { status: response.status })
113110
return false
114111
}
115112
} catch (fetchError) {
@@ -181,17 +178,15 @@ export async function coordinateAuth(
181178

182179
// If there's a valid lockfile, try to use the existing auth process
183180
if (lockData && (await isLockValid(lockData))) {
184-
log(`Another instance is handling authentication on port ${lockData.port}`)
185-
if (DEBUG) debugLog('Another instance is handling authentication', { port: lockData.port, pid: lockData.pid })
181+
log(`Another instance is handling authentication on port ${lockData.port} (pid: ${lockData.pid})`)
186182

187183
try {
188184
// Try to wait for the authentication to complete
189185
if (DEBUG) debugLog('Waiting for authentication from other instance')
190186
const authCompleted = await waitForAuthentication(lockData.port)
191187

192188
if (authCompleted) {
193-
log('Authentication completed by another instance')
194-
if (DEBUG) debugLog('Authentication completed by another instance, will use tokens from disk')
189+
log('Authentication completed by another instance. Using tokens from disk')
195190

196191
// Setup a dummy server - the client will use tokens directly from disk
197192
const dummyServer = express().listen(0) // Listen on any available port
@@ -201,7 +196,6 @@ export async function coordinateAuth(
201196
// This shouldn't actually be called in normal operation, but provide it for API compatibility
202197
const dummyWaitForAuthCode = () => {
203198
log('WARNING: waitForAuthCode called in secondary instance - this is unexpected')
204-
if (DEBUG) debugLog('WARNING: waitForAuthCode called in secondary instance - this is unexpected')
205199
// Return a promise that never resolves - the client should use the tokens from disk instead
206200
return new Promise<string>(() => {})
207201
}
@@ -213,7 +207,6 @@ export async function coordinateAuth(
213207
}
214208
} else {
215209
log('Taking over authentication process...')
216-
if (DEBUG) debugLog('Taking over authentication process')
217210
}
218211
} catch (error) {
219212
log(`Error waiting for authentication: ${error}`)
@@ -226,7 +219,6 @@ export async function coordinateAuth(
226219
} else if (lockData) {
227220
// Invalid lockfile, delete it
228221
log('Found invalid lockfile, deleting it')
229-
if (DEBUG) debugLog('Found invalid lockfile, deleting it')
230222
await deleteLockfile(serverUrlHash)
231223
}
232224

@@ -244,14 +236,12 @@ export async function coordinateAuth(
244236
if (DEBUG) debugLog('OAuth callback server running', { port: actualPort })
245237

246238
log(`Creating lockfile for server ${serverUrlHash} with process ${process.pid} on port ${actualPort}`)
247-
if (DEBUG) debugLog('Creating lockfile', { serverUrlHash, pid: process.pid, port: actualPort })
248239
await createLockfile(serverUrlHash, process.pid, actualPort)
249240

250241
// Make sure lockfile is deleted on process exit
251242
const cleanupHandler = async () => {
252243
try {
253244
log(`Cleaning up lockfile for server ${serverUrlHash}`)
254-
if (DEBUG) debugLog('Cleaning up lockfile')
255245
await deleteLockfile(serverUrlHash)
256246
} catch (error) {
257247
log(`Error cleaning up lockfile: ${error}`)

src/lib/node-oauth-client-provider.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ export class NodeOAuthClientProvider implements OAuthClientProvider {
167167
try {
168168
await open(authorizationUrl.toString())
169169
log('Browser opened automatically.')
170-
if (DEBUG) debugLog('Browser opened automatically')
171170
} catch (error) {
172171
log('Could not open browser automatically. Please copy and paste the URL above into your browser.')
173172
if (DEBUG) debugLog('Failed to open browser', error)

src/lib/utils.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ export function mcpProxy({ transportToClient, transportToServer }: { transportTo
156156

157157
function onClientError(error: Error) {
158158
log('Error from local client:', error)
159-
if (DEBUG) debugLog('Error from local client', { errorMessage: error.message, stack: error.stack })
159+
if (DEBUG) debugLog('Error from local client', { stack: error.stack })
160160
}
161161

162162
function onServerError(error: Error) {
163163
log('Error from remote server:', error)
164-
if (DEBUG) debugLog('Error from remote server', { errorMessage: error.message, stack: error.stack })
164+
if (DEBUG) debugLog('Error from remote server', { stack: error.stack })
165165
}
166166
}
167167

@@ -252,7 +252,6 @@ export async function connectToRemoteServer(
252252
}
253253
}
254254
log(`Connected to remote server using ${transport.constructor.name}`)
255-
if (DEBUG) debugLog(`Connected to remote server successfully`, { transportType: transport.constructor.name })
256255

257256
return transport
258257
} catch (error: any) {
@@ -305,10 +304,8 @@ export async function connectToRemoteServer(
305304

306305
if (skipBrowserAuth) {
307306
log('Authentication required but skipping browser auth - using shared auth')
308-
if (DEBUG) debugLog('Authentication required but skipping browser auth - using shared auth')
309307
} else {
310308
log('Authentication required. Waiting for authorization...')
311-
if (DEBUG) debugLog('Authentication required. Waiting for authorization...')
312309
}
313310

314311
// Wait for the authorization code from the callback
@@ -318,7 +315,6 @@ export async function connectToRemoteServer(
318315

319316
try {
320317
log('Completing authorization...')
321-
if (DEBUG) debugLog('Completing authorization with transport.finishAuth')
322318
await transport.finishAuth(code)
323319
if (DEBUG) debugLog('Authorization completed successfully')
324320

0 commit comments

Comments
 (0)