Reuben_OS / test-mcp-endpoint.js
Reubencf's picture
fix: File preview for secure data and open .dart files in Flutter IDE with content
c52a01c
raw
history blame
5.29 kB
// Test script for MCP handler API
// Run with: node test-mcp-endpoint.js
const BASE_URL = 'https://mcp-1st-birthday-reuben-os.hf.space';
const API_URL = `${BASE_URL}/api/mcp-handler`;
async function testMCPEndpoint() {
console.log('πŸ§ͺ Testing MCP Handler API on Hugging Face...\n');
// Test 1: GET without passkey (should fail with error)
console.log('Test 1: GET without passkey');
try {
const response = await fetch(API_URL);
const data = await response.json();
console.log('βœ… Response:', JSON.stringify(data, null, 2));
console.log('Expected error message: βœ“\n');
} catch (error) {
console.log('❌ Error:', error.message, '\n');
}
// Test 2: POST - Save a test file to public folder
console.log('Test 2: POST - Save public file');
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'save_file',
fileName: 'test.txt',
content: 'Hello from MCP test!',
isPublic: true,
}),
});
const data = await response.json();
console.log('βœ… Response:', JSON.stringify(data, null, 2));
if (data.success) {
console.log('βœ“ File saved successfully to public folder!\n');
} else {
console.log('βœ— Save failed:', data.error, '\n');
}
} catch (error) {
console.log('❌ Error:', error.message, '\n');
}
// Test 3: GET - List public files
console.log('Test 3: GET - List public files');
try {
const url = new URL(API_URL);
url.searchParams.set('isPublic', 'true');
const response = await fetch(url);
const data = await response.json();
console.log('βœ… Response:', JSON.stringify(data, null, 2));
if (data.success) {
console.log(`βœ“ Found ${data.count} public file(s)\n`);
}
} catch (error) {
console.log('❌ Error:', error.message, '\n');
}
// Test 4: POST - Save with passkey
console.log('Test 4: POST - Save with passkey');
const testPasskey = 'test-passkey-123';
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
passkey: testPasskey,
action: 'save_file',
fileName: 'secure_test.dart',
content: `// Flutter test file\nvoid main() {\n print('Hello from secure storage!');\n}`,
isPublic: false,
}),
});
const data = await response.json();
console.log('βœ… Response:', JSON.stringify(data, null, 2));
if (data.success) {
console.log('βœ“ File saved successfully to secure storage!\n');
}
} catch (error) {
console.log('❌ Error:', error.message, '\n');
}
// Test 5: GET - List files with passkey
console.log('Test 5: GET - List files with passkey');
try {
const url = new URL(API_URL);
url.searchParams.set('passkey', testPasskey);
const response = await fetch(url);
const data = await response.json();
console.log('βœ… Response:', JSON.stringify(data, null, 2));
if (data.success) {
console.log(`βœ“ Found ${data.count} file(s) for passkey: ${testPasskey}\n`);
}
} catch (error) {
console.log('❌ Error:', error.message, '\n');
}
// Test 6: Deploy a test quiz
console.log('Test 6: POST - Deploy quiz');
try {
const quizData = {
title: 'Test Quiz',
description: 'A test quiz from MCP',
questions: [
{
id: 'q1',
question: 'What is 2+2?',
type: 'multiple-choice',
options: ['3', '4', '5', '6'],
correctAnswer: 1,
points: 1,
},
],
};
const response = await fetch(API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
passkey: testPasskey,
action: 'deploy_quiz',
fileName: 'quiz.json',
content: JSON.stringify(quizData, null, 2),
isPublic: false,
}),
});
const data = await response.json();
console.log('βœ… Response:', JSON.stringify(data, null, 2));
if (data.success) {
console.log('βœ“ Quiz deployed successfully!\n');
}
} catch (error) {
console.log('❌ Error:', error.message, '\n');
}
console.log('πŸŽ‰ All tests completed!\n');
console.log('Summary:');
console.log('- MCP Handler API is accessible');
console.log('- Public file uploads work');
console.log('- Passkey-protected uploads work');
console.log('- File listing works');
console.log('- Quiz deployment works');
console.log('\nβœ… Claude Desktop can now upload files to ReubenOS!');
}
// Run tests
testMCPEndpoint().catch(console.error);