Reubencf commited on
Commit
707bbb4
·
1 Parent(s): 6c63555

Add verify_session tool to MCP server

Browse files
Files changed (1) hide show
  1. mcp-server.js +46 -0
mcp-server.js CHANGED
@@ -53,6 +53,20 @@ class ReubenOSMCPServer {
53
  },
54
  },
55
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  {
57
  name: 'upload_file',
58
  description: 'Upload a file to session or public folder',
@@ -282,6 +296,8 @@ class ReubenOSMCPServer {
282
  switch (name) {
283
  case 'create_session':
284
  return await this.createSession(args);
 
 
285
  case 'upload_file':
286
  return await this.uploadFile(args);
287
  case 'download_file':
@@ -338,6 +354,36 @@ class ReubenOSMCPServer {
338
  };
339
  }
340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  async uploadFile(args) {
342
  const formData = new FormData();
343
  const buffer = Buffer.from(args.content, args.content.includes('base64,') ? 'base64' : 'utf8');
 
53
  },
54
  },
55
  },
56
+ {
57
+ name: 'verify_session',
58
+ description: 'Verify if a session key is valid and active',
59
+ inputSchema: {
60
+ type: 'object',
61
+ properties: {
62
+ sessionKey: {
63
+ type: 'string',
64
+ description: 'Session key to verify',
65
+ },
66
+ },
67
+ required: ['sessionKey'],
68
+ },
69
+ },
70
  {
71
  name: 'upload_file',
72
  description: 'Upload a file to session or public folder',
 
296
  switch (name) {
297
  case 'create_session':
298
  return await this.createSession(args);
299
+ case 'verify_session':
300
+ return await this.verifySession(args);
301
  case 'upload_file':
302
  return await this.uploadFile(args);
303
  case 'download_file':
 
354
  };
355
  }
356
 
357
+ async verifySession(args) {
358
+ const response = await fetch(`${BASE_URL}/api/sessions/verify`, {
359
+ method: 'POST',
360
+ headers: { 'Content-Type': 'application/json' },
361
+ body: JSON.stringify({ sessionKey: args.sessionKey }),
362
+ });
363
+
364
+ const data = await response.json();
365
+
366
+ if (data.success && data.valid) {
367
+ return {
368
+ content: [
369
+ {
370
+ type: 'text',
371
+ text: `✅ Session is VALID!\n\nSession ID: ${data.session.id}\nCreated: ${new Date(data.session.createdAt).toLocaleString()}\nLast Accessed: ${new Date(data.session.lastAccessed).toLocaleString()}\n\nYou can use this session key for file operations.`,
372
+ },
373
+ ],
374
+ };
375
+ } else {
376
+ return {
377
+ content: [
378
+ {
379
+ type: 'text',
380
+ text: `❌ Session is INVALID or EXPIRED\n\nThe session key you provided is not recognized by the server. This can happen if:\n- The Hugging Face Space restarted\n- The session expired (24 hours old)\n- The session key was mistyped\n\nPlease create a new session using the ReubenOS Session Manager.`,
381
+ },
382
+ ],
383
+ };
384
+ }
385
+ }
386
+
387
  async uploadFile(args) {
388
  const formData = new FormData();
389
  const buffer = Buffer.from(args.content, args.content.includes('base64,') ? 'base64' : 'utf8');