Skip to main content
Glama

search_heroes

Find and match hero characters by keyword, enabling quick identification of relevant personas within the MCP server for collaboration and analysis.

Instructions

根据关键词搜索匹配的英雄角色

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes搜索关键词,可以是英雄名称或描述中的词语

Implementation Reference

  • The main execution logic for the search_heroes tool. Fetches all heroes from repository, filters by keyword matching name, description, ID, or tags, formats results or error/no-result messages.
    async ({ keyword }) => { try { const allHeroes = await heroRepo.getAllHeroes(); const matchedHeroes = allHeroes.filter((hero: any) => hero.name.toLowerCase().includes(keyword.toLowerCase()) || (hero.description || '').toLowerCase().includes(keyword.toLowerCase()) || hero.id.toLowerCase().includes(keyword.toLowerCase()) || hero.tags?.some((tag: any) => tag.toLowerCase().includes(keyword.toLowerCase())) ); if (matchedHeroes.length === 0) { return { content: [{ type: 'text', text: `🔍 没有找到包含关键词"${keyword}"的英雄。\n\n💡 建议:\n1. 尝试其他关键词\n2. 使用 list_heroes 查看所有可用英雄` }] }; } const heroList = matchedHeroes.map((hero: any) => `• **${hero.name}** (${hero.source || 'unknown'}): ${hero.description || '无描述'}` ).join('\n'); return { content: [{ type: 'text', text: `🔍 找到 ${matchedHeroes.length} 个匹配"${keyword}"的英雄:\n\n${heroList}\n\n💡 使用 \`summon_hero\` 召唤任意英雄。` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ 搜索英雄时发生错误:${error instanceof Error ? error.message : '未知错误'}` }] }; } }
  • Input schema definition for search_heroes tool, specifying the required 'keyword' string parameter with description.
    { title: '搜索英雄', description: '根据关键词搜索匹配的英雄角色', inputSchema: { keyword: z.string().describe('搜索关键词,可以是英雄名称或描述中的词语') }
  • src/server.ts:201-248 (registration)
    Tool registration call using McpServer.registerTool, specifying name 'search_heroes', schema, and handler function.
    server.registerTool( 'search_heroes', { title: '搜索英雄', description: '根据关键词搜索匹配的英雄角色', inputSchema: { keyword: z.string().describe('搜索关键词,可以是英雄名称或描述中的词语') } }, async ({ keyword }) => { try { const allHeroes = await heroRepo.getAllHeroes(); const matchedHeroes = allHeroes.filter((hero: any) => hero.name.toLowerCase().includes(keyword.toLowerCase()) || (hero.description || '').toLowerCase().includes(keyword.toLowerCase()) || hero.id.toLowerCase().includes(keyword.toLowerCase()) || hero.tags?.some((tag: any) => tag.toLowerCase().includes(keyword.toLowerCase())) ); if (matchedHeroes.length === 0) { return { content: [{ type: 'text', text: `🔍 没有找到包含关键词"${keyword}"的英雄。\n\n💡 建议:\n1. 尝试其他关键词\n2. 使用 list_heroes 查看所有可用英雄` }] }; } const heroList = matchedHeroes.map((hero: any) => `• **${hero.name}** (${hero.source || 'unknown'}): ${hero.description || '无描述'}` ).join('\n'); return { content: [{ type: 'text', text: `🔍 找到 ${matchedHeroes.length} 个匹配"${keyword}"的英雄:\n\n${heroList}\n\n💡 使用 \`summon_hero\` 召唤任意英雄。` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ 搜索英雄时发生错误:${error instanceof Error ? error.message : '未知错误'}` }] }; } } );
  • Supporting searchHeroes method in RemoteHeroRepository class, providing similar keyword-based filtering logic used by other tools like summon_hero.
    async searchHeroes(query: string): Promise<Hero[]> { const allHeroes = await this.getAllHeroes(); const lowerQuery = query.toLowerCase(); return allHeroes.filter((hero: any) => hero.name.toLowerCase().includes(lowerQuery) || (hero.description || '').toLowerCase().includes(lowerQuery) || hero.id.toLowerCase().includes(lowerQuery) || hero.tags?.some((tag: any) => tag.toLowerCase().includes(lowerQuery)) ); }

Other Tools

Related 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/juyitingmcp/juyitingmcp'

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