@champz-llc/legends-mcp-server 1.3.2 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +71 -42
  2. package/package.json +1 -2
package/index.js CHANGED
@@ -8,6 +8,21 @@ import {
8
8
  } from '@modelcontextprotocol/sdk/types.js';
9
9
  import fetch from 'node-fetch';
10
10
 
11
+ // Helper function to fetch image and convert to base64
12
+ async function fetchImageAsBase64(imageUrl) {
13
+ try {
14
+ const response = await fetch(imageUrl);
15
+ if (!response.ok) {
16
+ throw new Error(`Failed to fetch image: ${response.status}`);
17
+ }
18
+ const buffer = await response.buffer();
19
+ return buffer.toString('base64');
20
+ } catch (error) {
21
+ console.error(`Error fetching image ${imageUrl}:`, error.message);
22
+ return null;
23
+ }
24
+ }
25
+
11
26
  // MCP Signature Authentication (optional - for player data access)
12
27
  const WALLET = process.env.WALLET;
13
28
  const SIGNATURE = process.env.SIGNATURE;
@@ -669,17 +684,20 @@ You can still ask about:
669
684
  const throneText = `\nšŸ† Throne Collection (${data.thrones.length}):\n`;
670
685
  let throneList = '';
671
686
 
672
- data.thrones.forEach((throne, i) => {
687
+ for (const [i, throne] of data.thrones.entries()) {
673
688
  throneList += `${i + 1}. ${throne.name} (${throne.rarity.toUpperCase()}) - Cycle ${throne.cycle_id}\n`;
674
689
 
675
690
  // Add throne image
676
691
  const imageUrl = `https://img.champz.world${throne.image_path}`;
677
- content.push({
678
- type: 'image',
679
- data: imageUrl,
680
- mimeType: 'image/png',
681
- });
682
- });
692
+ const base64Data = await fetchImageAsBase64(imageUrl);
693
+ if (base64Data) {
694
+ content.push({
695
+ type: 'image',
696
+ data: base64Data,
697
+ mimeType: 'image/png',
698
+ });
699
+ }
700
+ }
683
701
 
684
702
  content[0].text += throneText + throneList + '\n';
685
703
  }
@@ -719,19 +737,22 @@ You can still ask about:
719
737
  const trainerText = `⭐ Saved Trainers (${data.saved_trainers.length}):\n`;
720
738
  let trainerList = '';
721
739
 
722
- data.saved_trainers.forEach((trainer, i) => {
740
+ for (const [i, trainer] of data.saved_trainers.entries()) {
723
741
  trainerList += `${i + 1}. ${trainer.rarity.toUpperCase()} Legend #${trainer.legend_id} - Power: ${trainer.total_power}\n`;
724
742
  trainerList += ` ATK: ${trainer.attack} | DEF: ${trainer.defense} | SPD: ${trainer.speed}\n`;
725
743
  trainerList += ` Elements: ${trainer.elements.join(', ')}\n\n`;
726
744
 
727
745
  // Add trainer image
728
746
  const imageUrl = `https://img.champz.world${trainer.image_path}`;
729
- content.push({
730
- type: 'image',
731
- data: imageUrl,
732
- mimeType: 'image/png',
733
- });
734
- });
747
+ const base64Data = await fetchImageAsBase64(imageUrl);
748
+ if (base64Data) {
749
+ content.push({
750
+ type: 'image',
751
+ data: base64Data,
752
+ mimeType: 'image/png',
753
+ });
754
+ }
755
+ }
735
756
 
736
757
  content[0].text += trainerText + trainerList;
737
758
  }
@@ -793,22 +814,26 @@ You can still ask about:
793
814
  output += `Rolled: ${new Date(legend.rolled_at).toLocaleDateString()}\n`;
794
815
  output += `Saved: ${legend.is_saved ? 'Yes ⭐' : 'No'}\n`;
795
816
 
796
- // Return with image
817
+ // Fetch and convert image to base64
797
818
  const imageUrl = `https://img.champz.world${legend.image_path}`;
819
+ const base64Data = await fetchImageAsBase64(imageUrl);
798
820
 
799
- return {
800
- content: [
801
- {
802
- type: 'text',
803
- text: output,
804
- },
805
- {
806
- type: 'image',
807
- data: imageUrl,
808
- mimeType: 'image/png',
809
- },
810
- ],
811
- };
821
+ const content = [
822
+ {
823
+ type: 'text',
824
+ text: output,
825
+ },
826
+ ];
827
+
828
+ if (base64Data) {
829
+ content.push({
830
+ type: 'image',
831
+ data: base64Data,
832
+ mimeType: 'image/png',
833
+ });
834
+ }
835
+
836
+ return { content };
812
837
  } catch (error) {
813
838
  return {
814
839
  content: [
@@ -862,22 +887,26 @@ You can still ask about:
862
887
  output += `Earned in Cycle: ${throne.cycle_id}\n`;
863
888
  output += `Earned: ${new Date(throne.earned_at).toLocaleDateString()}\n`;
864
889
 
865
- // Return with image
890
+ // Fetch and convert image to base64
866
891
  const imageUrl = `https://img.champz.world${throne.image_path}`;
892
+ const base64Data = await fetchImageAsBase64(imageUrl);
867
893
 
868
- return {
869
- content: [
870
- {
871
- type: 'text',
872
- text: output,
873
- },
874
- {
875
- type: 'image',
876
- data: imageUrl,
877
- mimeType: 'image/png',
878
- },
879
- ],
880
- };
894
+ const content = [
895
+ {
896
+ type: 'text',
897
+ text: output,
898
+ },
899
+ ];
900
+
901
+ if (base64Data) {
902
+ content.push({
903
+ type: 'image',
904
+ data: base64Data,
905
+ mimeType: 'image/png',
906
+ });
907
+ }
908
+
909
+ return { content };
881
910
  } catch (error) {
882
911
  return {
883
912
  content: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@champz-llc/legends-mcp-server",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "MCP server for Legends of Champz - Query game stats, access personal data with signature auth, and claim rewards through Claude Desktop",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -33,7 +33,6 @@
33
33
  "node": ">=18.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "@champz-llc/legends-mcp-server": "^1.1.0",
37
36
  "@modelcontextprotocol/sdk": "^1.0.0",
38
37
  "node-fetch": "^3.3.2"
39
38
  }