initialize check
This commit is contained in:
parent
32fd95dc3f
commit
0ad7be85d4
3 changed files with 677 additions and 48 deletions
68
src/checks.ts
Normal file
68
src/checks.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { ConformanceCheck, CheckStatus } from './types.js';
|
||||
|
||||
export function createClientInitializationCheck(
|
||||
initializeRequest: any,
|
||||
expectedSpecVersion: string = '2025-06-18'
|
||||
): ConformanceCheck {
|
||||
const protocolVersionSent = initializeRequest?.protocolVersion;
|
||||
const versionMatch = protocolVersionSent === expectedSpecVersion;
|
||||
|
||||
const errors: string[] = [];
|
||||
if (!protocolVersionSent) errors.push('Protocol version not provided');
|
||||
if (!versionMatch) errors.push(`Version mismatch: expected ${expectedSpecVersion}, got ${protocolVersionSent}`);
|
||||
if (!initializeRequest?.clientInfo?.name) errors.push('Client name missing');
|
||||
if (!initializeRequest?.clientInfo?.version) errors.push('Client version missing');
|
||||
|
||||
const status: CheckStatus = errors.length === 0 ? 'SUCCESS' : 'FAILURE';
|
||||
|
||||
return {
|
||||
id: 'mcp-client-initialization',
|
||||
name: 'MCPClientInitialization',
|
||||
description: 'Validates that MCP client properly initializes with server',
|
||||
status,
|
||||
timestamp: new Date().toISOString(),
|
||||
specReferences: [
|
||||
{ id: 'MCP-Lifecycle', url: 'https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle' }
|
||||
],
|
||||
details: {
|
||||
protocolVersionSent,
|
||||
expectedSpecVersion,
|
||||
versionMatch,
|
||||
clientName: initializeRequest?.clientInfo?.name,
|
||||
clientVersion: initializeRequest?.clientInfo?.version
|
||||
},
|
||||
errorMessage: errors.length > 0 ? errors.join('; ') : undefined,
|
||||
logs: errors.length > 0 ? errors : undefined
|
||||
};
|
||||
}
|
||||
|
||||
export function createServerInfoCheck(
|
||||
serverInfo: { name?: string; version?: string } | null
|
||||
): ConformanceCheck {
|
||||
const hasName = !!serverInfo?.name;
|
||||
const hasVersion = !!serverInfo?.version;
|
||||
const status: CheckStatus = hasName && hasVersion ? 'SUCCESS' : 'FAILURE';
|
||||
|
||||
const errors: string[] = [];
|
||||
if (!hasName) errors.push('Server name missing');
|
||||
if (!hasVersion) errors.push('Server version missing');
|
||||
|
||||
return {
|
||||
id: 'server-info',
|
||||
name: 'ServerInfo',
|
||||
description: 'Validates server implementation includes required name and version',
|
||||
status,
|
||||
timestamp: new Date().toISOString(),
|
||||
specReferences: [
|
||||
{ id: 'MCP-Lifecycle', url: 'https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle' }
|
||||
],
|
||||
details: {
|
||||
serverName: serverInfo?.name,
|
||||
serverVersion: serverInfo?.version,
|
||||
hasName,
|
||||
hasVersion
|
||||
},
|
||||
errorMessage: errors.length > 0 ? errors.join('; ') : undefined,
|
||||
logs: errors.length > 0 ? errors : undefined
|
||||
};
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
const checks = [
|
||||
{
|
||||
id: "check-001",
|
||||
name: "Basic Auth Check",
|
||||
description: "Validates basic authentication flow",
|
||||
status: "SUCCESS",
|
||||
timestamp: new Date().toISOString(),
|
||||
specReferences: [
|
||||
{
|
||||
id: "rfc6750",
|
||||
url: "https://tools.ietf.org/html/rfc6750"
|
||||
}
|
||||
],
|
||||
details: {
|
||||
authType: "Bearer",
|
||||
responseTime: 45
|
||||
},
|
||||
logs: [
|
||||
"Auth endpoint reached",
|
||||
"Token validated successfully"
|
||||
]
|
||||
},
|
||||
{
|
||||
id: "check-002",
|
||||
name: "Token Expiry Check",
|
||||
description: "Validates token expiration handling",
|
||||
status: "FAILURE",
|
||||
timestamp: new Date().toISOString(),
|
||||
errorMessage: "Token expiry not properly enforced",
|
||||
logs: [
|
||||
"Token validation started",
|
||||
"Expiry check failed"
|
||||
]
|
||||
},
|
||||
{
|
||||
id: "check-003",
|
||||
name: "CORS Header Check",
|
||||
description: "Validates CORS headers in response",
|
||||
status: "WARNING",
|
||||
timestamp: new Date().toISOString(),
|
||||
details: {
|
||||
missingHeaders: ["Access-Control-Allow-Credentials"]
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
console.log(JSON.stringify(checks, null, 2));
|
||||
19
src/runner.ts
Normal file
19
src/runner.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { createClientInitializationCheck, createServerInfoCheck } from './checks.ts';
|
||||
|
||||
const initializeRequest = {
|
||||
protocolVersion: '2025-06-18',
|
||||
clientInfo: {
|
||||
name: 'ExampleClient',
|
||||
version: '1.0.0'
|
||||
}
|
||||
};
|
||||
|
||||
const checks = [
|
||||
createClientInitializationCheck(initializeRequest),
|
||||
createServerInfoCheck({
|
||||
name: 'ExampleMCPServer',
|
||||
version: '1.0.0'
|
||||
})
|
||||
];
|
||||
|
||||
console.log(JSON.stringify(checks, null, 2));
|
||||
Loading…
Reference in a new issue