fix: now deletes only the current version of MCP-remote

This commit is contained in:
stevehuynh 2025-05-14 21:48:05 +10:00
parent 4db39b0d06
commit ea80a7c663
2 changed files with 13 additions and 11 deletions

View file

@ -3,7 +3,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js'
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js' import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js' import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js' import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'
import fs from 'fs' import * as fsSync from 'fs'
import path from 'path' import path from 'path'
import os from 'os' import os from 'os'
import { OAuthClientInformationFull, OAuthClientInformationFullSchema } from '@modelcontextprotocol/sdk/shared/auth.js' import { OAuthClientInformationFull, OAuthClientInformationFullSchema } from '@modelcontextprotocol/sdk/shared/auth.js'
@ -12,7 +12,7 @@ import { getConfigFilePath, readJsonFile } from './mcp-auth-config'
import express from 'express' import express from 'express'
import net from 'net' import net from 'net'
import crypto from 'crypto' import crypto from 'crypto'
import fs from 'fs/promises' import * as fs from 'fs/promises'
// Connection constants // Connection constants
export const REASON_AUTH_NEEDED = 'authentication-needed' export const REASON_AUTH_NEEDED = 'authentication-needed'
@ -37,15 +37,17 @@ export function log(str: string, ...rest: unknown[]) {
*/ */
function clearMcpAuthFiles() { function clearMcpAuthFiles() {
try { try {
const mcpDir = path.join(os.homedir(), '.mcp-auth') const baseConfigDir = process.env.MCP_REMOTE_CONFIG_DIR || path.join(os.homedir(), '.mcp-auth')
log('Short timeout reached, clearing MCP auth files') const versionDir = path.join(baseConfigDir, `mcp-remote-${MCP_REMOTE_VERSION}`)
// Check if the directory exists
if (fs.existsSync(mcpDir)) { log('Short timeout reached, clearing MCP auth files for current version')
// Delete the entire directory and its contents // Check if the version directory exists
fs.rmSync(mcpDir, { recursive: true, force: true }) if (fsSync.existsSync(versionDir)) {
log('MCP auth directory cleared successfully') // Delete only the current version directory and its contents
fsSync.rmSync(versionDir, { recursive: true, force: true })
log(`MCP auth directory for version ${MCP_REMOTE_VERSION} cleared successfully`)
} else { } else {
log('No MCP directory found, nothing to clear') log(`No MCP directory found for version ${MCP_REMOTE_VERSION}, nothing to clear`)
} }
} catch (error) { } catch (error) {
log('Error clearing MCP auth files:', error) log('Error clearing MCP auth files:', error)

View file

@ -136,7 +136,7 @@ to the CA certificate file. If using claude_desktop_config.json, this might look
} }
// Parse command-line arguments and run the proxy // Parse command-line arguments and run the proxy
parseCommandLineArgs(process.argv.slice(2), 3334, 'Usage: npx tsx proxy.ts <https://server-url> [callback-port]') parseCommandLineArgs(process.argv.slice(2), 'Usage: npx tsx proxy.ts <https://server-url> [callback-port]')
.then(({ serverUrl, callbackPort, headers, transportStrategy, shortTimeout }) => { .then(({ serverUrl, callbackPort, headers, transportStrategy, shortTimeout }) => {
return runProxy(serverUrl, callbackPort, headers, transportStrategy, shortTimeout) return runProxy(serverUrl, callbackPort, headers, transportStrategy, shortTimeout)
}) })