Versioning storage based on mcp-auth version number to let us iterate on storage format
This commit is contained in:
parent
a97fd9e5c6
commit
1382827ebd
3 changed files with 28 additions and 35 deletions
|
@ -18,7 +18,7 @@ import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
||||||
import { ListResourcesResultSchema, ListToolsResultSchema } from '@modelcontextprotocol/sdk/types.js'
|
import { ListResourcesResultSchema, ListToolsResultSchema } from '@modelcontextprotocol/sdk/types.js'
|
||||||
import { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js'
|
import { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js'
|
||||||
import { NodeOAuthClientProvider } from './lib/node-oauth-client-provider'
|
import { NodeOAuthClientProvider } from './lib/node-oauth-client-provider'
|
||||||
import { parseCommandLineArgs, setupOAuthCallbackServer, setupSignalHandlers } from './lib/utils'
|
import { parseCommandLineArgs, setupOAuthCallbackServer, setupSignalHandlers, MCP_REMOTE_VERSION } from './lib/utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function to run the client
|
* Main function to run the client
|
||||||
|
@ -39,7 +39,7 @@ async function runClient(serverUrl: string, callbackPort: number, clean: boolean
|
||||||
const client = new Client(
|
const client = new Client(
|
||||||
{
|
{
|
||||||
name: 'mcp-remote',
|
name: 'mcp-remote',
|
||||||
version: require('../package.json').version,
|
version: MCP_REMOTE_VERSION,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
capabilities: {},
|
capabilities: {},
|
||||||
|
|
|
@ -2,6 +2,7 @@ import crypto from 'crypto'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
|
import { MCP_REMOTE_VERSION } from './utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MCP Remote Authentication Configuration
|
* MCP Remote Authentication Configuration
|
||||||
|
@ -26,11 +27,7 @@ import fs from 'fs/promises'
|
||||||
/**
|
/**
|
||||||
* Known configuration file names that might need to be cleaned
|
* Known configuration file names that might need to be cleaned
|
||||||
*/
|
*/
|
||||||
export const knownConfigFiles = [
|
export const knownConfigFiles = ['client_info.json', 'tokens.json', 'code_verifier.txt']
|
||||||
'client_info.json',
|
|
||||||
'tokens.json',
|
|
||||||
'code_verifier.txt',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all known configuration files for a specific server
|
* Deletes all known configuration files for a specific server
|
||||||
|
@ -48,7 +45,9 @@ export async function cleanServerConfig(serverUrlHash: string): Promise<void> {
|
||||||
* @returns The path to the configuration directory
|
* @returns The path to the configuration directory
|
||||||
*/
|
*/
|
||||||
export function getConfigDir(): string {
|
export function getConfigDir(): string {
|
||||||
return process.env.MCP_REMOTE_CONFIG_DIR || path.join(os.homedir(), '.mcp-auth')
|
const baseConfigDir = process.env.MCP_REMOTE_CONFIG_DIR || path.join(os.homedir(), '.mcp-auth')
|
||||||
|
// Add a version subdirectory so we don't need to worry about backwards/forwards compatibility yet
|
||||||
|
return path.join(baseConfigDir, `mcp-remote-${MCP_REMOTE_VERSION}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,7 +112,7 @@ export async function readJsonFile<T>(
|
||||||
serverUrlHash: string,
|
serverUrlHash: string,
|
||||||
filename: string,
|
filename: string,
|
||||||
schema: any,
|
schema: any,
|
||||||
clean: boolean = false
|
clean: boolean = false,
|
||||||
): Promise<T | undefined> {
|
): Promise<T | undefined> {
|
||||||
try {
|
try {
|
||||||
await ensureConfigDir()
|
await ensureConfigDir()
|
||||||
|
@ -141,11 +140,7 @@ export async function readJsonFile<T>(
|
||||||
* @param filename The name of the file to write
|
* @param filename The name of the file to write
|
||||||
* @param data The data to write
|
* @param data The data to write
|
||||||
*/
|
*/
|
||||||
export async function writeJsonFile(
|
export async function writeJsonFile(serverUrlHash: string, filename: string, data: any): Promise<void> {
|
||||||
serverUrlHash: string,
|
|
||||||
filename: string,
|
|
||||||
data: any
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
await ensureConfigDir()
|
await ensureConfigDir()
|
||||||
const filePath = getConfigFilePath(serverUrlHash, filename)
|
const filePath = getConfigFilePath(serverUrlHash, filename)
|
||||||
|
@ -168,7 +163,7 @@ export async function readTextFile(
|
||||||
serverUrlHash: string,
|
serverUrlHash: string,
|
||||||
filename: string,
|
filename: string,
|
||||||
errorMessage?: string,
|
errorMessage?: string,
|
||||||
clean: boolean = false
|
clean: boolean = false,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
try {
|
try {
|
||||||
await ensureConfigDir()
|
await ensureConfigDir()
|
||||||
|
@ -192,11 +187,7 @@ export async function readTextFile(
|
||||||
* @param filename The name of the file to write
|
* @param filename The name of the file to write
|
||||||
* @param text The text to write
|
* @param text The text to write
|
||||||
*/
|
*/
|
||||||
export async function writeTextFile(
|
export async function writeTextFile(serverUrlHash: string, filename: string, text: string): Promise<void> {
|
||||||
serverUrlHash: string,
|
|
||||||
filename: string,
|
|
||||||
text: string
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
await ensureConfigDir()
|
await ensureConfigDir()
|
||||||
const filePath = getConfigFilePath(serverUrlHash, filename)
|
const filePath = getConfigFilePath(serverUrlHash, filename)
|
||||||
|
|
|
@ -243,3 +243,5 @@ export function setupSignalHandlers(cleanup: () => Promise<void>) {
|
||||||
// Keep the process alive
|
// Keep the process alive
|
||||||
process.stdin.resume()
|
process.stdin.resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const MCP_REMOTE_VERSION = require('../../package.json').version
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue