Skip to main content
Glama
Cicatriiz

Civitai MCP Server

search_models_by_tag

Find AI models on Civitai using specific tags. Filter results by sorting options such as highest rated, most downloaded, or newest, and control the number of models returned.

Instructions

Search for models by a specific tag

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of models to return (default: 20)
sortNoSort order for results
tagYesTag name to search for

Implementation Reference

  • The primary MCP tool handler for 'search_models_by_tag'. It invokes the CivitaiClient, formats the API response into a readable list of models, and returns it as MCP text content.
    private async searchModelsByTag(args: any) {
      const response = await this.client.searchModelsByTag(args.tag, args);
      const formatted = this.formatModelsResponse(response);
      
      return {
        content: [
          {
            type: 'text',
            text: `# Models tagged "${args.tag}"\\n\\n${formatted.models.map((model: any) => 
              `**${model.name}** (${model.type})\\n` +
              `Creator: ${model.creator}\\n` +
              `Downloads: ${model.stats.downloads.toLocaleString()} | Rating: ${model.stats.rating.toFixed(1)}\\n` +
              `${model.description}\\n\\n`
            ).join('---\\n')}`,
          },
        ],
      };
    }
  • JSON schema defining the input parameters for the 'search_models_by_tag' tool, including required 'tag' and optional 'limit' and 'sort'.
    inputSchema: {
      type: 'object',
      properties: {
        tag: { type: 'string', description: 'Tag name to search for' },
        limit: { type: 'number', description: 'Number of models to return (default: 20)', minimum: 1, maximum: 100 },
        sort: { 
          type: 'string', 
          enum: ['Highest Rated', 'Most Downloaded', 'Newest'],
          description: 'Sort order for results'
        },
      },
      required: ['tag'],
  • src/index.ts:258-274 (registration)
    Tool registration in the getTools() method, defining name, description, and input schema for 'search_models_by_tag' returned in ListTools response.
    {
      name: 'search_models_by_tag',
      description: 'Search for models by a specific tag',
      inputSchema: {
        type: 'object',
        properties: {
          tag: { type: 'string', description: 'Tag name to search for' },
          limit: { type: 'number', description: 'Number of models to return (default: 20)', minimum: 1, maximum: 100 },
          sort: { 
            type: 'string', 
            enum: ['Highest Rated', 'Most Downloaded', 'Newest'],
            description: 'Sort order for results'
          },
        },
        required: ['tag'],
      },
    },
  • src/index.ts:69-70 (registration)
    Dispatch registration in the CallToolRequest handler switch statement, routing calls to the searchModelsByTag handler.
    case 'search_models_by_tag':
      return await this.searchModelsByTag(args);
  • Helper function used by the handler to format raw API model responses into a simplified structure for display.
    private formatModelsResponse(response: any) {
      const models = response.items.map((model: any) => {
        const latestVersion = model.modelVersions[0];
        return {
          id: model.id,
          name: model.name,
          type: model.type,
          creator: model.creator.username,
          description: model.description.substring(0, 200) + (model.description.length > 200 ? '...' : ''),
          tags: model.tags.slice(0, 5), // Limit tags for readability
          nsfw: model.nsfw,
          stats: {
            downloads: model.stats?.downloadCount || 0,
            rating: model.stats?.rating || 0,
            favorites: model.stats?.favoriteCount || 0,
          },
          latestVersion: latestVersion ? {
            id: latestVersion.id,
            name: latestVersion.name,
            createdAt: latestVersion.createdAt,
            trainedWords: latestVersion.trainedWords,
          } : null,
        };
      });
    
      return {
        models,
        pagination: {
          currentPage: response.metadata.currentPage || 1,
          totalPages: response.metadata.totalPages || 1,
          totalItems: response.metadata.totalItems || models.length,
          hasNextPage: response.metadata.nextPage ? true : false,
        },
      };
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

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/Cicatriiz/civitai-mcp-server'

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