File size: 5,291 Bytes
c52a01c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// 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);