apply linting

This commit is contained in:
Paul Carleton 2025-10-30 13:09:16 +00:00
commit f32b01c57d
No known key found for this signature in database
2 changed files with 510 additions and 527 deletions

View file

@ -1,18 +1,16 @@
import { Scenario } from '../types.js';
import { InitializeScenario } from './initialize.js';
export const scenarios = new Map<string, Scenario>([
['initialize', new InitializeScenario()],
]);
export const scenarios = new Map<string, Scenario>([['initialize', new InitializeScenario()]]);
export function registerScenario(name: string, scenario: Scenario): void {
scenarios.set(name, scenario);
scenarios.set(name, scenario);
}
export function getScenario(name: string): Scenario | undefined {
return scenarios.get(name);
return scenarios.get(name);
}
export function listScenarios(): string[] {
return Array.from(scenarios.keys());
return Array.from(scenarios.keys());
}

View file

@ -3,130 +3,134 @@ import { Scenario, ScenarioUrls, ConformanceCheck } from '../types.js';
import { createClientInitializationCheck, createServerInfoCheck } from '../checks.js';
export class InitializeScenario implements Scenario {
name = 'initialize';
description = 'Tests MCP client initialization handshake';
name = 'initialize';
description = 'Tests MCP client initialization handshake';
private server: http.Server | null = null;
private checks: ConformanceCheck[] = [];
private port: number = 0;
private server: http.Server | null = null;
private checks: ConformanceCheck[] = [];
private port: number = 0;
async start(): Promise<ScenarioUrls> {
return new Promise((resolve, reject) => {
this.server = http.createServer((req, res) => {
this.handleRequest(req, res);
});
async start(): Promise<ScenarioUrls> {
return new Promise((resolve, reject) => {
this.server = http.createServer((req, res) => {
this.handleRequest(req, res);
});
this.server.on('error', reject);
this.server.on('error', reject);
this.server.listen(0, () => {
const address = this.server!.address();
if (address && typeof address === 'object') {
this.port = address.port;
resolve({
serverUrl: `http://localhost:${this.port}`
});
} else {
reject(new Error('Failed to get server address'));
}
});
});
}
async stop(): Promise<void> {
return new Promise((resolve, reject) => {
if (this.server) {
this.server.close((err) => {
if (err) {
reject(err);
} else {
this.server = null;
resolve();
}
this.server.listen(0, () => {
const address = this.server!.address();
if (address && typeof address === 'object') {
this.port = address.port;
resolve({
serverUrl: `http://localhost:${this.port}`
});
} else {
reject(new Error('Failed to get server address'));
}
});
});
} else {
resolve();
}
});
}
}
getChecks(): ConformanceCheck[] {
return this.checks;
}
async stop(): Promise<void> {
return new Promise((resolve, reject) => {
if (this.server) {
this.server.close(err => {
if (err) {
reject(err);
} else {
this.server = null;
resolve();
}
});
} else {
resolve();
}
});
}
private handleRequest(req: http.IncomingMessage, res: http.ServerResponse): void {
let body = '';
getChecks(): ConformanceCheck[] {
return this.checks;
}
req.on('data', (chunk) => {
body += chunk.toString();
});
private handleRequest(req: http.IncomingMessage, res: http.ServerResponse): void {
let body = '';
req.on('end', () => {
try {
const request = JSON.parse(body);
req.on('data', chunk => {
body += chunk.toString();
});
if (request.method === 'initialize') {
this.handleInitialize(request, res);
} else if (request.method === 'tools/list') {
this.handleToolsList(request, res);
} else {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
req.on('end', () => {
try {
const request = JSON.parse(body);
if (request.method === 'initialize') {
this.handleInitialize(request, res);
} else if (request.method === 'tools/list') {
this.handleToolsList(request, res);
} else {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(
JSON.stringify({
jsonrpc: '2.0',
id: request.id,
result: {}
})
);
}
} catch (error) {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(
JSON.stringify({
jsonrpc: '2.0',
error: {
code: -32700,
message: `Parse error ${error}`
}
})
);
}
});
}
private handleInitialize(request: any, res: http.ServerResponse): void {
const initializeRequest = request.params;
const check = createClientInitializationCheck(initializeRequest);
this.checks.push(check);
const serverInfo = {
name: 'test-server',
version: '1.0.0'
};
const serverInfoCheck = createServerInfoCheck(serverInfo);
this.checks.push(serverInfoCheck);
const response = {
jsonrpc: '2.0',
id: request.id,
result: {}
}));
}
} catch (error) {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
jsonrpc: '2.0',
error: {
code: -32700,
message: 'Parse error'
}
}));
}
});
}
result: {
protocolVersion: '2025-06-18',
serverInfo,
capabilities: {}
}
};
private handleInitialize(request: any, res: http.ServerResponse): void {
const initializeRequest = request.params;
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(response));
}
const check = createClientInitializationCheck(initializeRequest);
this.checks.push(check);
private handleToolsList(request: any, res: http.ServerResponse): void {
const response = {
jsonrpc: '2.0',
id: request.id,
result: {
tools: []
}
};
const serverInfo = {
name: 'test-server',
version: '1.0.0'
};
const serverInfoCheck = createServerInfoCheck(serverInfo);
this.checks.push(serverInfoCheck);
const response = {
jsonrpc: '2.0',
id: request.id,
result: {
protocolVersion: '2025-06-18',
serverInfo,
capabilities: {}
}
};
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(response));
}
private handleToolsList(request: any, res: http.ServerResponse): void {
const response = {
jsonrpc: '2.0',
id: request.id,
result: {
tools: []
}
};
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(response));
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(response));
}
}