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

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 +362 -4
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -8,6 +8,12 @@ import {
8
8
  } from '@modelcontextprotocol/sdk/types.js';
9
9
  import fetch from 'node-fetch';
10
10
 
11
+ // MCP Signature Authentication (optional - for player data access)
12
+ const WALLET = process.env.WALLET;
13
+ const SIGNATURE = process.env.SIGNATURE;
14
+ const SIGNED_AT = process.env.SIGNED_AT;
15
+ const hasWalletAuth = WALLET && SIGNATURE && SIGNED_AT;
16
+
11
17
  // Hardcoded rewards data for demo
12
18
  const DEMO_WALLET = '0xfbc159e35f56580d5d297af18a8c19f83d66088a';
13
19
 
@@ -100,8 +106,7 @@ const server = new Server(
100
106
 
101
107
  // List available tools
102
108
  server.setRequestHandler(ListToolsRequestSchema, async () => {
103
- return {
104
- tools: [
109
+ const tools = [
105
110
  {
106
111
  name: 'legends_global_stats',
107
112
  description: 'Get overall Legends of Champz game statistics including total legends rolled, CHAMPZ burned, USDC distributed, total battles, and more',
@@ -201,8 +206,52 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
201
206
  required: []
202
207
  },
203
208
  }
204
- ],
205
- };
209
+ ];
210
+
211
+ // Add player data tools if wallet is configured
212
+ if (hasWalletAuth) {
213
+ tools.push({
214
+ name: 'legends_player_data',
215
+ description: 'Get your personal Legends of Champz statistics including CHAMPZ spent on packs, legends owned, thrones, battle stats, claims history, and saved trainers. Requires wallet authentication.',
216
+ inputSchema: {
217
+ type: 'object',
218
+ properties: {},
219
+ required: []
220
+ },
221
+ });
222
+
223
+ tools.push({
224
+ name: 'show_legend',
225
+ description: 'Show details and image for a specific legend you own by ID. Use this when the user asks to see a particular legend (e.g., "show me legend #1010").',
226
+ inputSchema: {
227
+ type: 'object',
228
+ properties: {
229
+ legend_id: {
230
+ type: 'number',
231
+ description: 'The ID of the legend to display'
232
+ }
233
+ },
234
+ required: ['legend_id']
235
+ },
236
+ });
237
+
238
+ tools.push({
239
+ name: 'show_throne',
240
+ description: 'Show details and image for a specific throne you own by ID. Use this when the user asks to see a particular throne.',
241
+ inputSchema: {
242
+ type: 'object',
243
+ properties: {
244
+ throne_id: {
245
+ type: 'number',
246
+ description: 'The ID of the throne to display'
247
+ }
248
+ },
249
+ required: ['throne_id']
250
+ },
251
+ });
252
+ }
253
+
254
+ return { tools };
206
255
  });
207
256
 
208
257
  // Handle tool calls
@@ -531,6 +580,315 @@ Last updated: ${new Date(stats.cached_at * 1000).toLocaleString()}`;
531
580
  };
532
581
  }
533
582
 
583
+ case 'legends_player_data':
584
+ // Check if wallet authentication is configured
585
+ if (!hasWalletAuth) {
586
+ return {
587
+ content: [
588
+ {
589
+ type: 'text',
590
+ text: `To access your personal Legends of Champz data, you need to connect your wallet.
591
+
592
+ 🔗 Setup Guide: https://legends.champz.world/mcp-setup
593
+
594
+ This one-time setup takes 2 minutes:
595
+ 1. Visit the link above on your desktop
596
+ 2. Connect your Coinbase Wallet
597
+ 3. Sign a message to prove ownership
598
+ 4. Copy the config to Claude Desktop
599
+ 5. Restart Claude Desktop
600
+
601
+ You can still ask about:
602
+ • Global game stats (legends_global_stats)
603
+ • Leaderboards (legends_leaderboard_*)
604
+ • Current cycle information`,
605
+ },
606
+ ],
607
+ };
608
+ }
609
+
610
+ try {
611
+ // Call player-data endpoint with signature authentication
612
+ const url = `https://api.champz.world/game/spore-trainer/player-data?wallet=${encodeURIComponent(WALLET)}&signature=${encodeURIComponent(SIGNATURE)}&timestamp=${encodeURIComponent(SIGNED_AT)}`;
613
+ const response = await fetch(url);
614
+ const data = await response.json();
615
+
616
+ if (!data.success) {
617
+ throw new Error(data.error || 'Failed to fetch player data');
618
+ }
619
+
620
+ // Format player data
621
+ const displayName = data.display_name || data.basename || `${data.wallet.slice(0, 8)}...`;
622
+ const stats = data.statistics;
623
+ const claims = data.claims;
624
+
625
+ let output = `Legends of Champz - Your Statistics\n\n`;
626
+ output += `Player: ${displayName}\n`;
627
+ output += `Wallet: ${data.wallet}\n`;
628
+ if (data.basename) {
629
+ output += `Basename: ${data.basename}\n`;
630
+ }
631
+ output += `Member since: ${new Date(stats.member_since).toLocaleDateString()}\n\n`;
632
+
633
+ output += `📦 Packs & Legends:\n`;
634
+ output += ` • Total packs opened: ${stats.total_packs_opened}\n`;
635
+ output += ` • CHAMPZ spent on packs: ${stats.champz_spent_on_packs.toLocaleString()}\n`;
636
+ output += ` • Legends owned: ${stats.legends_owned}\n`;
637
+ output += ` • Saved trainer slots: ${stats.saved_trainer_slots}\n\n`;
638
+
639
+ output += `⚔️ Battle Statistics:\n`;
640
+ output += ` • Total battles: ${stats.total_battles}\n`;
641
+ output += ` • Wins: ${stats.battles_won} (${(stats.win_rate * 100).toFixed(1)}% win rate)\n`;
642
+ output += ` • Losses: ${stats.battles_lost}\n`;
643
+ output += ` • Current streak: ${stats.current_win_streak}\n`;
644
+ output += ` • Best streak: ${stats.best_win_streak}\n\n`;
645
+
646
+ output += `👑 Thrones & Guardian:\n`;
647
+ output += ` • Thrones owned: ${stats.thrones_owned}\n`;
648
+ output += ` • Times held guardian: ${stats.times_held_guardian}\n`;
649
+ output += ` • CHAMPZ spent on guardian: ${stats.champz_spent_on_guardian.toLocaleString()}\n\n`;
650
+
651
+ output += `💰 Claims History:\n`;
652
+ output += ` • Total USDC claimed: $${claims.total_usdc_claimed}\n`;
653
+ output += ` • Total CHAMPZ claimed: ${claims.total_champz_claimed.toLocaleString()}\n`;
654
+ output += ` • Battle USDC (type 6): ${claims.by_type['6'].count} claims, $${claims.by_type['6'].total_amount}\n`;
655
+ output += ` • Battle CHAMPZ (type 5): ${claims.by_type['5'].count} claims, ${claims.by_type['5'].total_amount.toLocaleString()} tokens\n`;
656
+ output += ` • Guardian USDC (type 19): ${claims.by_type['19'].count} claims, $${claims.by_type['19'].total_amount}\n`;
657
+ output += ` • Guardian CHAMPZ (type 18): ${claims.by_type['18'].count} claims, ${claims.by_type['18'].total_amount.toLocaleString()} tokens\n\n`;
658
+
659
+ // Build content array with text and images
660
+ const content = [
661
+ {
662
+ type: 'text',
663
+ text: output,
664
+ },
665
+ ];
666
+
667
+ // Add throne images (show all thrones)
668
+ if (data.thrones && data.thrones.length > 0) {
669
+ const throneText = `\n🏆 Throne Collection (${data.thrones.length}):\n`;
670
+ let throneList = '';
671
+
672
+ data.thrones.forEach((throne, i) => {
673
+ throneList += `${i + 1}. ${throne.name} (${throne.rarity.toUpperCase()}) - Cycle ${throne.cycle_id}\n`;
674
+
675
+ // Add throne image
676
+ const imageUrl = `https://img.champz.world${throne.image_path}`;
677
+ content.push({
678
+ type: 'image',
679
+ data: imageUrl,
680
+ mimeType: 'image/png',
681
+ });
682
+ });
683
+
684
+ content[0].text += throneText + throneList + '\n';
685
+ }
686
+
687
+ // Show legend summary (don't show all images by default - too many)
688
+ if (data.all_legends && data.all_legends.length > 0) {
689
+ const legendText = `\n🍄 All Legends Owned (${data.all_legends.length}):\n`;
690
+ let legendSummary = '';
691
+
692
+ // Group by rarity
693
+ const byRarity = {
694
+ unique: [],
695
+ legendary: [],
696
+ epic: [],
697
+ rare: [],
698
+ common: []
699
+ };
700
+
701
+ data.all_legends.forEach(legend => {
702
+ byRarity[legend.rarity]?.push(legend);
703
+ });
704
+
705
+ Object.entries(byRarity).forEach(([rarity, legends]) => {
706
+ if (legends.length > 0) {
707
+ legendSummary += ` ${rarity.toUpperCase()}: ${legends.length} legends\n`;
708
+ }
709
+ });
710
+
711
+ legendSummary += `\nTo view a specific legend, ask: "Show me legend #<ID>"\n`;
712
+ legendSummary += `Example: "Show me legend #1010"\n\n`;
713
+
714
+ content[0].text += legendText + legendSummary;
715
+ }
716
+
717
+ // Add saved trainer images (premium collection)
718
+ if (data.saved_trainers && data.saved_trainers.length > 0) {
719
+ const trainerText = `⭐ Saved Trainers (${data.saved_trainers.length}):\n`;
720
+ let trainerList = '';
721
+
722
+ data.saved_trainers.forEach((trainer, i) => {
723
+ trainerList += `${i + 1}. ${trainer.rarity.toUpperCase()} Legend #${trainer.legend_id} - Power: ${trainer.total_power}\n`;
724
+ trainerList += ` ATK: ${trainer.attack} | DEF: ${trainer.defense} | SPD: ${trainer.speed}\n`;
725
+ trainerList += ` Elements: ${trainer.elements.join(', ')}\n\n`;
726
+
727
+ // Add trainer image
728
+ const imageUrl = `https://img.champz.world${trainer.image_path}`;
729
+ content.push({
730
+ type: 'image',
731
+ data: imageUrl,
732
+ mimeType: 'image/png',
733
+ });
734
+ });
735
+
736
+ content[0].text += trainerText + trainerList;
737
+ }
738
+
739
+ return { content };
740
+ } catch (error) {
741
+ return {
742
+ content: [
743
+ {
744
+ type: 'text',
745
+ text: `Error fetching player data: ${error.message}\n\nMake sure your wallet is registered in Legends of Champz. Visit https://legends.champz.world to play!`,
746
+ },
747
+ ],
748
+ };
749
+ }
750
+
751
+ case 'show_legend':
752
+ if (!hasWalletAuth) {
753
+ return {
754
+ content: [{ type: 'text', text: 'Authentication required. Visit https://legends.champz.world/mcp-setup' }],
755
+ };
756
+ }
757
+
758
+ try {
759
+ const legendId = request.params.arguments?.legend_id;
760
+ if (!legendId) {
761
+ throw new Error('legend_id is required');
762
+ }
763
+
764
+ // Fetch player data
765
+ const url = `https://api.champz.world/game/spore-trainer/player-data?wallet=${encodeURIComponent(WALLET)}&signature=${encodeURIComponent(SIGNATURE)}&timestamp=${encodeURIComponent(SIGNED_AT)}`;
766
+ const response = await fetch(url);
767
+ const data = await response.json();
768
+
769
+ if (!data.success) {
770
+ throw new Error('Failed to fetch player data');
771
+ }
772
+
773
+ // Find the legend in all_legends
774
+ const legend = data.all_legends?.find(l => l.legend_id === legendId);
775
+
776
+ if (!legend) {
777
+ return {
778
+ content: [
779
+ {
780
+ type: 'text',
781
+ text: `Legend #${legendId} not found in your collection. You own ${data.all_legends?.length || 0} legends total.`,
782
+ },
783
+ ],
784
+ };
785
+ }
786
+
787
+ // Build output
788
+ let output = `Legend #${legend.legend_id} - ${legend.name}\n\n`;
789
+ output += `Rarity: ${legend.rarity.toUpperCase()}\n`;
790
+ output += `Total Power: ${legend.total_power}\n`;
791
+ output += `ATK: ${legend.attack} | DEF: ${legend.defense} | SPD: ${legend.speed}\n`;
792
+ output += `Elements: ${legend.elements.join(', ')}\n`;
793
+ output += `Rolled: ${new Date(legend.rolled_at).toLocaleDateString()}\n`;
794
+ output += `Saved: ${legend.is_saved ? 'Yes ⭐' : 'No'}\n`;
795
+
796
+ // Return with image
797
+ const imageUrl = `https://img.champz.world${legend.image_path}`;
798
+
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
+ };
812
+ } catch (error) {
813
+ return {
814
+ content: [
815
+ {
816
+ type: 'text',
817
+ text: `Error showing legend: ${error.message}`,
818
+ },
819
+ ],
820
+ };
821
+ }
822
+
823
+ case 'show_throne':
824
+ if (!hasWalletAuth) {
825
+ return {
826
+ content: [{ type: 'text', text: 'Authentication required. Visit https://legends.champz.world/mcp-setup' }],
827
+ };
828
+ }
829
+
830
+ try {
831
+ const throneId = request.params.arguments?.throne_id;
832
+ if (!throneId) {
833
+ throw new Error('throne_id is required');
834
+ }
835
+
836
+ // Fetch player data
837
+ const url = `https://api.champz.world/game/spore-trainer/player-data?wallet=${encodeURIComponent(WALLET)}&signature=${encodeURIComponent(SIGNATURE)}&timestamp=${encodeURIComponent(SIGNED_AT)}`;
838
+ const response = await fetch(url);
839
+ const data = await response.json();
840
+
841
+ if (!data.success) {
842
+ throw new Error('Failed to fetch player data');
843
+ }
844
+
845
+ // Find the throne
846
+ const throne = data.thrones?.find(t => t.throne_id === throneId);
847
+
848
+ if (!throne) {
849
+ return {
850
+ content: [
851
+ {
852
+ type: 'text',
853
+ text: `Throne #${throneId} not found in your collection. You own ${data.thrones?.length || 0} thrones total.`,
854
+ },
855
+ ],
856
+ };
857
+ }
858
+
859
+ // Build output
860
+ let output = `Throne #${throne.throne_id} - ${throne.name}\n\n`;
861
+ output += `Rarity: ${throne.rarity.toUpperCase()}\n`;
862
+ output += `Earned in Cycle: ${throne.cycle_id}\n`;
863
+ output += `Earned: ${new Date(throne.earned_at).toLocaleDateString()}\n`;
864
+
865
+ // Return with image
866
+ const imageUrl = `https://img.champz.world${throne.image_path}`;
867
+
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
+ };
881
+ } catch (error) {
882
+ return {
883
+ content: [
884
+ {
885
+ type: 'text',
886
+ text: `Error showing throne: ${error.message}`,
887
+ },
888
+ ],
889
+ };
890
+ }
891
+
534
892
  default:
535
893
  throw new Error(`Unknown tool: ${name}`);
536
894
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@champz-llc/legends-mcp-server",
3
- "version": "1.2.1",
4
- "description": "MCP server for Legends of Champz - Query game stats and claim rewards through Claude Desktop",
3
+ "version": "1.3.2",
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",
7
7
  "bin": {