Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/auth/sdkOAuthClientProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ vi.mock('@src/constants.js', () => ({
TTL_MS: 30 * 24 * 60 * 60 * 1000, // 30 days
DEFAULT_SCOPES: [],
},
SESSION: {
SUBDIR: 'client',
},
},
},
getGlobalConfigDir: vi.fn(() => '/mock/config/dir'),
Expand Down Expand Up @@ -127,7 +130,7 @@ describe('SDKOAuthClientProvider', () => {
it('should initialize with custom session storage path', () => {
provider = new SDKOAuthClientProvider('test-server', mockConfig, '/custom/path');

expect(FileStorageService).toHaveBeenCalledWith('/custom/path');
expect(FileStorageService).toHaveBeenCalledWith('/custom/path', 'client');
});

it('should load persisted data on initialization', () => {
Expand Down
8 changes: 3 additions & 5 deletions src/auth/sdkOAuthClientProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { randomUUID } from 'node:crypto';
import path from 'path';

import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
import type {
Expand All @@ -8,7 +7,7 @@ import type {
OAuthTokens,
} from '@modelcontextprotocol/sdk/shared/auth.js';

import { AUTH_CONFIG, getGlobalConfigDir } from '@src/constants.js';
import { AUTH_CONFIG } from '@src/constants.js';
import logger from '@src/logger/logger.js';

import { ClientSessionData } from './sessionTypes.js';
Expand Down Expand Up @@ -47,9 +46,8 @@ export class SDKOAuthClientProvider implements OAuthClientProvider {
this.serverName = serverName;
this.config = config;

// Create FileStorageService and ClientSessionRepository
const storagePath = sessionStoragePath || path.join(getGlobalConfigDir(), 'clientSessions');
const fileStorage = new FileStorageService(storagePath);
// Create FileStorageService and ClientSessionRepository with 'client' subdirectory
const fileStorage = new FileStorageService(sessionStoragePath, AUTH_CONFIG.CLIENT.SESSION.SUBDIR);
this.sessionRepository = new ClientSessionRepository(fileStorage);

// Set up client metadata for registration with better defaults
Expand Down
12 changes: 12 additions & 0 deletions src/auth/sessionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ export interface AuthRequestData extends ExpirableData {
resource?: string;
scopes?: string[];
}

// Streamable HTTP session data for session restoration
export interface StreamableSessionData extends ExpirableData {
tags?: string[];
tagExpression?: string; // JSON stringified TagExpression
tagQuery?: string; // JSON stringified TagQuery
tagFilterMode?: 'simple-or' | 'advanced' | 'preset' | 'none';
presetName?: string;
enablePagination?: boolean;
customTemplate?: string;
lastAccessedAt: number;
}
2 changes: 1 addition & 1 deletion src/auth/storage/authCodeRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe('AuthCodeRepository', () => {

// Check that file was created with correct prefix
const expectedFileName = AUTH_CONFIG.SERVER.AUTH_CODE.FILE_PREFIX + code + '.json';
const filePath = path.join(tempDir, expectedFileName);
const filePath = path.join(storage.getStorageDir(), expectedFileName);

expect(fs.existsSync(filePath)).toBe(true);
});
Expand Down
2 changes: 1 addition & 1 deletion src/auth/storage/authRequestRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe('AuthRequestRepository', () => {

// Check that file was created with correct prefix
const expectedFileName = AUTH_CONFIG.SERVER.AUTH_REQUEST.FILE_PREFIX + authRequestId + '.json';
const filePath = path.join(tempDir, expectedFileName);
const filePath = path.join(storage.getStorageDir(), expectedFileName);

expect(fs.existsSync(filePath)).toBe(true);
});
Expand Down
2 changes: 1 addition & 1 deletion src/auth/storage/clientDataRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ describe('ClientDataRepository', () => {

// Check that file was created with correct prefix
const expectedFileName = AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX + clientId + '.json';
const filePath = path.join(tempDir, expectedFileName);
const filePath = path.join(storage.getStorageDir(), expectedFileName);

expect(fs.existsSync(filePath)).toBe(true);
});
Expand Down
2 changes: 1 addition & 1 deletion src/auth/storage/clientSessionRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ describe('ClientSessionRepository', () => {
// Check that file was created with correct prefix
const sessionId = `${AUTH_CONFIG.CLIENT.SESSION.ID_PREFIX}${serverName}`;
const expectedFileName = AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX + sessionId + '.json';
const filePath = path.join(tempDir, expectedFileName);
const filePath = path.join(storage.getStorageDir(), expectedFileName);

expect(fs.existsSync(filePath)).toBe(true);
});
Expand Down
Loading