yt-dlp-mcp/test-mcp.mjs
kevinwatt 26b2137751 chore: release v0.7.0 - MCP Best Practices & Quality Improvements
Major release with comprehensive MCP best practices implementation:

 Added:
- Tool name prefixes (ytdlp_) for all 8 tools to avoid naming conflicts
- Zod schema validation with runtime input validation
- Tool annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint)
- Response format options (JSON/Markdown) for search tools
- Pagination support with offset parameter
- Character limits (25K standard, 50K for transcripts) with smart truncation
- Actionable error messages with platform-specific guidance

🔧 Improved:
- Comprehensive tool descriptions with usage examples
- Enhanced configuration system with limits
- Better TypeScript type safety
- Professional README with badges and tables

🐛 Fixed:
- JSON parsing issue in metadata truncation
- Maintained valid JSON structure when truncated

🧪 Tested:
-  YouTube platform (Rick Astley video)
-  Bilibili platform (Chinese content)
-  Multi-language support verified
-  All 8 tools tested with real API calls

📖 Documentation:
- Created comprehensive CHANGELOG.md
- Redesigned README.md with professional formatting
- Added migration guide for v0.6.x users

🌍 Platform Support:
- Verified: YouTube, Bilibili
- Theory: 1000+ platforms via yt-dlp
2025-10-19 01:52:22 +08:00

106 lines
2.6 KiB
JavaScript
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* Simple MCP protocol test
* This script tests if the MCP server responds correctly to basic protocol messages
*/
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const serverPath = join(__dirname, 'lib', 'index.mjs');
console.log('🧪 Testing yt-dlp MCP Server\n');
console.log('Starting server from:', serverPath);
const server = spawn('node', [serverPath]);
let testsPassed = 0;
let testsFailed = 0;
let responseBuffer = '';
// Timeout to ensure tests complete
const timeout = setTimeout(() => {
console.log('\n⏱ Test timeout - killing server');
server.kill();
process.exit(testsFailed > 0 ? 1 : 0);
}, 10000);
server.stdout.on('data', (data) => {
responseBuffer += data.toString();
// Try to parse JSON-RPC responses
const lines = responseBuffer.split('\n');
responseBuffer = lines.pop() || ''; // Keep incomplete line in buffer
lines.forEach(line => {
if (line.trim()) {
try {
const response = JSON.parse(line);
console.log('📨 Received:', JSON.stringify(response, null, 2));
if (response.result) {
testsPassed++;
console.log('✅ Test passed\n');
}
} catch (e) {
// Not JSON, might be regular output
console.log('📝 Output:', line);
}
}
});
});
server.stderr.on('data', (data) => {
console.log('🔧 Server log:', data.toString().trim());
});
server.on('close', (code) => {
clearTimeout(timeout);
console.log(`\n📊 Test Results:`);
console.log(` ✅ Passed: ${testsPassed}`);
console.log(` ❌ Failed: ${testsFailed}`);
console.log(` Server exit code: ${code}`);
process.exit(testsFailed > 0 ? 1 : 0);
});
// Wait a bit for server to start
setTimeout(() => {
console.log('\n🔍 Test 1: Initialize');
const initRequest = {
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
}
};
server.stdin.write(JSON.stringify(initRequest) + '\n');
setTimeout(() => {
console.log('\n🔍 Test 2: List Tools');
const listToolsRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/list',
params: {}
};
server.stdin.write(JSON.stringify(listToolsRequest) + '\n');
setTimeout(() => {
console.log('\n✅ Basic protocol tests completed');
server.kill();
}, 2000);
}, 2000);
}, 1000);