@champz-llc/legends-mcp-server 1.3.6 → 1.3.8

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 +22 -6
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -7,8 +7,9 @@ import {
7
7
  ListToolsRequestSchema,
8
8
  } from '@modelcontextprotocol/sdk/types.js';
9
9
  import fetch from 'node-fetch';
10
+ import sharp from 'sharp';
10
11
 
11
- // Helper function to fetch image and convert to base64
12
+ // Helper function to fetch image, resize, and convert to base64
12
13
  async function fetchImageAsBase64(imageUrl) {
13
14
  try {
14
15
  console.error(`[MCP] Fetching image: ${imageUrl}`);
@@ -21,12 +22,25 @@ async function fetchImageAsBase64(imageUrl) {
21
22
  const contentType = response.headers.get('content-type');
22
23
  console.error(`[MCP] Image content-type: ${contentType}`);
23
24
 
24
- const buffer = await response.buffer();
25
- const base64 = buffer.toString('base64');
26
- console.error(`[MCP] Image converted to base64, size: ${base64.length} chars`);
25
+ // Fetch image as buffer
26
+ const arrayBuffer = await response.arrayBuffer();
27
+ const originalBuffer = Buffer.from(arrayBuffer);
28
+ console.error(`[MCP] Original image size: ${Math.round(originalBuffer.length / 1024)}KB`);
29
+
30
+ // Resize image to max 300x300 (maintains aspect ratio) and compress
31
+ const resizedBuffer = await sharp(originalBuffer)
32
+ .resize(300, 300, {
33
+ fit: 'inside',
34
+ withoutEnlargement: true
35
+ })
36
+ .png({ quality: 85, compressionLevel: 9 })
37
+ .toBuffer();
38
+
39
+ const base64 = resizedBuffer.toString('base64');
40
+ console.error(`[MCP] Resized image size: ${Math.round(resizedBuffer.length / 1024)}KB, base64: ${Math.round(base64.length / 1024)}KB`);
27
41
  return base64;
28
42
  } catch (error) {
29
- console.error(`[MCP] Error fetching image ${imageUrl}:`, error.message);
43
+ console.error(`[MCP] Error processing image ${imageUrl}:`, error.message);
30
44
  return null;
31
45
  }
32
46
  }
@@ -815,8 +829,10 @@ You can still ask about:
815
829
  output += `Rolled: ${new Date(legend.rolled_at).toLocaleDateString()}\n`;
816
830
  output += `Saved: ${legend.is_saved ? 'Yes ⭐' : 'No'}\n`;
817
831
 
818
- // Fetch and convert image to base64
832
+ // Fetch image
819
833
  const imageUrl = `https://img.champz.world${legend.image_path}`;
834
+
835
+ // Fetch and convert image to base64
820
836
  const base64Data = await fetchImageAsBase64(imageUrl);
821
837
 
822
838
  const content = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@champz-llc/legends-mcp-server",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
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",
@@ -34,6 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@modelcontextprotocol/sdk": "^1.0.0",
37
- "node-fetch": "^3.3.2"
37
+ "node-fetch": "^3.3.2",
38
+ "sharp": "^0.34.5"
38
39
  }
39
40
  }