Skip to main content
Glama
SLdragon

MCP User Profile Management Server

by SLdragon

search_users

Find user profiles by entering search terms to locate specific individuals in the user management system.

Instructions

Search through user profiles using a simple text query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'search_users' tool. It handles input query (with elicitation fallback), searches users in storage by name/email/role, and returns matching users or error messages.
      async (inputs, context) => {
        try {
          let searchQuery = inputs.query;
    
          if (!searchQuery) {
            const elicitationResult = await elicitationHelper.elicitWithProgress(
              "Please enter your search query to find users",
              {
                type: "object",
                properties: {
                  query: {
                    type: "string",
                    title: "Search Query",
                    description: "Enter keywords to search for users by name, email, or role"
                  }
                },
                required: ["query"]
              },
              inputs
            );
    
            if (elicitationResult.action === "accept" && elicitationResult.content?.query) {
              searchQuery = elicitationResult.content.query;
            } else if (elicitationResult.action === "decline") {
              return utils.createErrorResponse("User declined to provide search query. Search cancelled.");
            } else {
              return utils.createErrorResponse("User cancelled the search process.");
            }
          }
    
          const { storage } = await import('../storage.js');
          const query = searchQuery.toLowerCase();
          
          const matchingUsers = storage.users.filter(user => {
            return (
              user.name?.toLowerCase().includes(query) ||
              user.email?.toLowerCase().includes(query) ||
              user.role?.toLowerCase().includes(query)
            );
          });
    
          if (matchingUsers.length === 0) {
            return utils.createSuccessResponse(`No users found matching query: "${searchQuery}"`);
          }
    
          return utils.createSuccessResponse(
            `Found ${matchingUsers.length} user(s) matching "${searchQuery}":\n${JSON.stringify(matchingUsers, null, 2)}`
          );
        } catch (error) {
          return utils.createErrorResponse(`Error searching users: ${error.message}`);
        }
      }
    );
  • The primary input schema for the 'search_users' tool, defining a required 'query' string parameter.
    {
      type: "object",
      properties: {
        query: {
          type: "string",
          description: "Search query to find users by name, email, or role"
        }
      }
    },
  • The searchUsersTool function that registers the 'search_users' MCP tool on the server, including name, description, schema, and handler.
    export function searchUsersTool(server, elicitationHelper) {
      return server.tool(
        "search_users",
        "Search through user profiles using a simple text query",
        {
          type: "object",
          properties: {
            query: {
              type: "string",
              description: "Search query to find users by name, email, or role"
            }
          }
        },
        async (inputs, context) => {
          try {
            let searchQuery = inputs.query;
    
            if (!searchQuery) {
              const elicitationResult = await elicitationHelper.elicitWithProgress(
                "Please enter your search query to find users",
                {
                  type: "object",
                  properties: {
                    query: {
                      type: "string",
                      title: "Search Query",
                      description: "Enter keywords to search for users by name, email, or role"
                    }
                  },
                  required: ["query"]
                },
                inputs
              );
    
              if (elicitationResult.action === "accept" && elicitationResult.content?.query) {
                searchQuery = elicitationResult.content.query;
              } else if (elicitationResult.action === "decline") {
                return utils.createErrorResponse("User declined to provide search query. Search cancelled.");
              } else {
                return utils.createErrorResponse("User cancelled the search process.");
              }
            }
    
            const { storage } = await import('../storage.js');
            const query = searchQuery.toLowerCase();
            
            const matchingUsers = storage.users.filter(user => {
              return (
                user.name?.toLowerCase().includes(query) ||
                user.email?.toLowerCase().includes(query) ||
                user.role?.toLowerCase().includes(query)
              );
            });
    
            if (matchingUsers.length === 0) {
              return utils.createSuccessResponse(`No users found matching query: "${searchQuery}"`);
            }
    
            return utils.createSuccessResponse(
              `Found ${matchingUsers.length} user(s) matching "${searchQuery}":\n${JSON.stringify(matchingUsers, null, 2)}`
            );
          } catch (error) {
            return utils.createErrorResponse(`Error searching users: ${error.message}`);
          }
        }
      );
    }
  • index.js:18-18 (registration)
    Invocation of searchUsersTool to register the 'search_users' tool during server setup.
    searchUsersTool(server, elicitationHelper);
  • index.js:5-5 (helper)
    Import of the searchUsersTool registration helper from userTools.js.
    import { createUserTool, listUsersTool, searchUsersTool } from './tools/userTools.js';

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/SLdragon/mcp-elicitation-server'

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