import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { spawn } from "child_process";
async function testNotificationServer() {
console.log("Starting MCP Notifications Server test...\n");
// Start the server process
const serverProcess = spawn("node", ["build/index.js"], {
env: process.env,
});
// Create transport connected to the server
const transport = new StdioClientTransport({
command: "node",
args: ["build/index.js"],
});
// Create client
const client = new Client(
{
name: "test-client",
version: "1.0.0",
},
{
capabilities: {},
}
);
try {
// Connect to server
await client.connect(transport);
console.log("✓ Connected to server\n");
// List available tools
const tools = await client.listTools();
console.log("Available tools:");
tools.tools.forEach((tool) => {
console.log(` - ${tool.name}: ${tool.description}`);
});
console.log();
// Test 1: Basic notification
console.log("Test 1: Basic notification (title + content)");
const result1 = await client.callTool({
name: "show_notification",
arguments: {
title: "Test Notification",
content: "This is a test from MCP server!",
},
});
console.log("Result:", result1.content[0].text);
console.log();
// Wait a bit before next notification
await new Promise((resolve) => setTimeout(resolve, 1000));
// Test 2: Notification with sound
console.log("Test 2: Notification with sound");
const result2 = await client.callTool({
name: "show_notification",
arguments: {
title: "Sound Test",
content: "This notification should play the Ping sound",
sound: "Ping",
},
});
console.log("Result:", result2.content[0].text);
console.log();
console.log("✓ All tests passed!");
} catch (error) {
console.error("Error during testing:", error);
} finally {
await client.close();
serverProcess.kill();
process.exit(0);
}
}
testNotificationServer();