[compliance tests] initial server scenarios (#4)
* spec for servers * initial version of everything server and tests - tets are very simple * some clean up * lint etc. * fix package lock agian --------- Co-authored-by: Paul Carleton <paulc@anthropic.com>
This commit is contained in:
parent
44a2732b53
commit
a692dd7bba
1 changed files with 5678 additions and 78 deletions
83
src/scenarios/server/client-helper.ts
Normal file
83
src/scenarios/server/client-helper.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* Helper utilities for creating MCP clients to test servers
|
||||
*/
|
||||
|
||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
||||
import { LoggingMessageNotificationSchema, ProgressNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
|
||||
|
||||
export interface MCPClientConnection {
|
||||
client: Client;
|
||||
close: () => Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and connect an MCP client to a server
|
||||
*/
|
||||
export async function connectToServer(serverUrl: string): Promise<MCPClientConnection> {
|
||||
const client = new Client(
|
||||
{
|
||||
name: 'conformance-test-client',
|
||||
version: '1.0.0'
|
||||
},
|
||||
{
|
||||
capabilities: {
|
||||
// Client capabilities
|
||||
sampling: {},
|
||||
elicitation: {}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const transport = new StreamableHTTPClientTransport(new URL(serverUrl));
|
||||
|
||||
await client.connect(transport);
|
||||
|
||||
return {
|
||||
client,
|
||||
close: async () => {
|
||||
await client.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to collect notifications (logging and progress)
|
||||
*/
|
||||
export class NotificationCollector {
|
||||
private loggingNotifications: any[] = [];
|
||||
private progressNotifications: any[] = [];
|
||||
|
||||
constructor(client: Client) {
|
||||
// Set up notification handler for logging messages
|
||||
client.setNotificationHandler(LoggingMessageNotificationSchema, notification => {
|
||||
this.loggingNotifications.push(notification);
|
||||
});
|
||||
|
||||
// Set up notification handler for progress notifications
|
||||
client.setNotificationHandler(ProgressNotificationSchema, notification => {
|
||||
this.progressNotifications.push(notification);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all collected logging notifications
|
||||
*/
|
||||
getLoggingNotifications(): any[] {
|
||||
return this.loggingNotifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all collected progress notifications
|
||||
*/
|
||||
getProgressNotifications(): any[] {
|
||||
return this.progressNotifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all notifications (for backward compatibility)
|
||||
*/
|
||||
getNotifications(): any[] {
|
||||
return this.loggingNotifications;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue