Skip to main content
Glama
sweetwisdom

MCP Project Query Server

by sweetwisdom

get_random_wallpaper

Retrieve random Bing wallpapers with customizable resolution and region settings to refresh desktop backgrounds or find visual inspiration.

Instructions

从Bing壁纸获取随机壁纸,返回壁纸的URL、标题和描述信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resolutionNo壁纸分辨率,可选值:1920x1080, 3840x2160, 1366x768等,默认为1920x1080
marketNo地区市场,如zh-CN(中国), en-US(美国)等,默认为zh-CN

Implementation Reference

  • Registers the 'get_random_wallpaper' MCP tool, including input schema with optional resolution and market parameters using Zod, description, and a thin handler delegating to WallpaperController.
    server.tool(
        'get_random_wallpaper',
        '从Bing壁纸获取随机壁纸,返回壁纸的URL、标题和描述信息',
        {
            resolution: z.string().optional().describe('壁纸分辨率,可选值:1920x1080, 3840x2160, 1366x768等,默认为1920x1080'),
            market: z.string().optional().describe('地区市场,如zh-CN(中国), en-US(美国)等,默认为zh-CN'),
        },
        async ({ resolution = AppConfig.DEFAULT_WALLPAPER_RESOLUTION, market = AppConfig.DEFAULT_MARKET }) => {
            return await wallpaperController.getRandomWallpaper(resolution, market);
        }
    );
  • Controller handler that invokes the wallpaper service, stringifies the result as JSON, and formats it into MCP-compatible response structure with error handling.
    async getRandomWallpaper(resolution: string = '1920x1080', market: string = 'zh-CN'): Promise<{ content: Array<{ type: 'text'; text: string }> }> {
      try {
        const wallpaperInfo = await this.wallpaperService.getRandomWallpaper(resolution, market);
        
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(wallpaperInfo, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `获取壁纸时出错: ${error instanceof Error ? error.message : '未知错误'}`,
            },
          ],
        };
      }
    }
  • Core tool logic: constructs Bing wallpaper API URL, performs HTTPS request, parses JSON response, extracts image details, and returns structured WallpaperInfo.
    async getRandomWallpaper(resolution: string = '1920x1080', market: string = 'zh-CN'): Promise<WallpaperInfo> {
      const apiUrl = `https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=${market}&uhd=1&uhdwidth=${resolution.split('x')[0]}&uhdheight=${resolution.split('x')[1]}`;
      
      const wallpaperData = await this.makeHttpRequest(apiUrl);
      
      if (!wallpaperData.images || wallpaperData.images.length === 0) {
        throw new Error('未找到可用的壁纸');
      }
    
      const wallpaper = wallpaperData.images[0];
      const baseUrl = 'https://www.bing.com';
      const imageUrl = baseUrl + wallpaper.url;
      
      return {
        title: wallpaper.title,
        description: wallpaper.copyright,
        imageUrl: imageUrl,
        resolution: resolution,
        date: wallpaper.startdate,
        market: market,
        fullUrl: imageUrl
      };
    }
  • Zod input schema for the tool parameters: optional resolution and market strings.
    {
        resolution: z.string().optional().describe('壁纸分辨率,可选值:1920x1080, 3840x2160, 1366x768等,默认为1920x1080'),
        market: z.string().optional().describe('地区市场,如zh-CN(中国), en-US(美国)等,默认为zh-CN'),
    },
  • Private helper method to perform HTTPS GET request to Bing API, accumulate response data, parse JSON, with error handling.
    private makeHttpRequest(url: string): Promise<any> {
      return new Promise((resolve, reject) => {
        https.get(url, (res) => {
          let data = '';
          res.on('data', (chunk) => {
            data += chunk;
          });
          res.on('end', () => {
            try {
              const jsonData = JSON.parse(data);
              resolve(jsonData);
            } catch (error) {
              reject(new Error('解析壁纸数据失败'));
            }
          });
        }).on('error', (error) => {
          reject(new Error(`获取壁纸失败: ${error.message}`));
        });
      });
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sweetwisdom/mcp-demo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server