JC321 commited on
Commit
9929ae9
Β·
verified Β·
1 Parent(s): e14b845

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +143 -0
app.py CHANGED
@@ -55,6 +55,9 @@ HTML_CONTENT = """
55
  https://jc321-easyreportsmcpserver.hf.space/sse
56
  </div>
57
  <p><span class="badge badge-info">Protocol: MCP 2024-11-05</span> <span class="badge badge-info">Transport: SSE</span></p>
 
 
 
58
 
59
  <h2>πŸ› οΈ Available Tools (7)</h2>
60
 
@@ -223,5 +226,145 @@ HTML_CONTENT = """
223
  async def root():
224
  return HTML_CONTENT
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  if __name__ == "__main__":
227
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
55
  https://jc321-easyreportsmcpserver.hf.space/sse
56
  </div>
57
  <p><span class="badge badge-info">Protocol: MCP 2024-11-05</span> <span class="badge badge-info">Transport: SSE</span></p>
58
+ <p style="text-align: center; margin: 20px 0;">
59
+ <a href="/test" style="display: inline-block; padding: 12px 24px; background: #2563eb; color: white; text-decoration: none; border-radius: 6px; font-weight: bold;">πŸ§ͺ Test MCP Server Live</a>
60
+ </p>
61
 
62
  <h2>πŸ› οΈ Available Tools (7)</h2>
63
 
 
226
  async def root():
227
  return HTML_CONTENT
228
 
229
+ @app.get("/test", response_class=HTMLResponse)
230
+ async def test_page():
231
+ return """
232
+ <!DOCTYPE html>
233
+ <html>
234
+ <head>
235
+ <title>MCP Server Test</title>
236
+ <style>
237
+ body { font-family: monospace; padding: 20px; max-width: 1000px; margin: 0 auto; }
238
+ button { padding: 10px 20px; margin: 5px; cursor: pointer; background: #2563eb; color: white; border: none; border-radius: 5px; }
239
+ button:hover { background: #1e40af; }
240
+ .result { background: #1e293b; color: #e2e8f0; padding: 15px; margin: 10px 0; border-radius: 5px; white-space: pre-wrap; word-wrap: break-word; }
241
+ .status { padding: 10px; margin: 10px 0; border-radius: 5px; }
242
+ .success { background: #dcfce7; color: #166534; }
243
+ .error { background: #fee2e2; color: #991b1b; }
244
+ </style>
245
+ </head>
246
+ <body>
247
+ <h1>πŸ§ͺ MCP Server Live Test</h1>
248
+ <p>Test the MCP server at: <code>https://jc321-easyreportsmcpserver.hf.space/sse</code></p>
249
+
250
+ <div>
251
+ <button onclick="testToolsList()">πŸ“‹ Test: List Tools</button>
252
+ <button onclick="testSearchCompany()">πŸ” Test: Search Tesla</button>
253
+ <button onclick="testFinancialMetrics()">πŸ“Š Test: Get Financial Metrics</button>
254
+ </div>
255
+
256
+ <div id="status"></div>
257
+ <div id="result"></div>
258
+
259
+ <script>
260
+ const endpoint = 'https://jc321-easyreportsmcpserver.hf.space/sse';
261
+
262
+ function showStatus(msg, isError) {
263
+ document.getElementById('status').innerHTML =
264
+ `<div class="status ${isError ? 'error' : 'success'}">${msg}</div>`;
265
+ }
266
+
267
+ function showResult(data) {
268
+ document.getElementById('result').innerHTML =
269
+ `<div class="result">${JSON.stringify(data, null, 2)}</div>`;
270
+ }
271
+
272
+ async function testToolsList() {
273
+ showStatus('⏳ Sending request to list tools...');
274
+ try {
275
+ const response = await fetch(endpoint, {
276
+ method: 'POST',
277
+ headers: { 'Content-Type': 'application/json' },
278
+ body: JSON.stringify({
279
+ jsonrpc: '2.0',
280
+ method: 'tools/list',
281
+ id: 1
282
+ })
283
+ });
284
+
285
+ const text = await response.text();
286
+ showStatus('βœ… Response received!', false);
287
+
288
+ // Try to parse as JSON or show raw text
289
+ try {
290
+ const json = JSON.parse(text);
291
+ showResult(json);
292
+ } catch {
293
+ showResult({ raw_response: text });
294
+ }
295
+ } catch (error) {
296
+ showStatus('❌ Error: ' + error.message, true);
297
+ showResult({ error: error.toString() });
298
+ }
299
+ }
300
+
301
+ async function testSearchCompany() {
302
+ showStatus('⏳ Searching for Tesla...');
303
+ try {
304
+ const response = await fetch(endpoint, {
305
+ method: 'POST',
306
+ headers: { 'Content-Type': 'application/json' },
307
+ body: JSON.stringify({
308
+ jsonrpc: '2.0',
309
+ method: 'tools/call',
310
+ params: {
311
+ name: 'search_company',
312
+ arguments: { company_name: 'Tesla' }
313
+ },
314
+ id: 2
315
+ })
316
+ });
317
+
318
+ const text = await response.text();
319
+ showStatus('βœ… Response received!', false);
320
+
321
+ try {
322
+ const json = JSON.parse(text);
323
+ showResult(json);
324
+ } catch {
325
+ showResult({ raw_response: text });
326
+ }
327
+ } catch (error) {
328
+ showStatus('❌ Error: ' + error.message, true);
329
+ showResult({ error: error.toString() });
330
+ }
331
+ }
332
+
333
+ async function testFinancialMetrics() {
334
+ showStatus('⏳ Getting Tesla financial metrics (3 years)...');
335
+ try {
336
+ const response = await fetch(endpoint, {
337
+ method: 'POST',
338
+ headers: { 'Content-Type': 'application/json' },
339
+ body: JSON.stringify({
340
+ jsonrpc: '2.0',
341
+ method: 'tools/call',
342
+ params: {
343
+ name: 'extract_financial_metrics',
344
+ arguments: { cik: '0001318605', years: 3 }
345
+ },
346
+ id: 3
347
+ })
348
+ });
349
+
350
+ const text = await response.text();
351
+ showStatus('βœ… Response received!', false);
352
+
353
+ try {
354
+ const json = JSON.parse(text);
355
+ showResult(json);
356
+ } catch {
357
+ showResult({ raw_response: text });
358
+ }
359
+ } catch (error) {
360
+ showStatus('❌ Error: ' + error.message, true);
361
+ showResult({ error: error.toString() });
362
+ }
363
+ }
364
+ </script>
365
+ </body>
366
+ </html>
367
+ """
368
+
369
  if __name__ == "__main__":
370
  uvicorn.run(app, host="0.0.0.0", port=7860)