search_users
Search and filter users by keyword or role on the MCP Test Server to manage user data efficiently for testing and analysis purposes.
Instructions
搜索用户
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 搜索关键词 | |
| role | No | 按角色筛选 |
Implementation Reference
- src/index.ts:124-142 (handler)The asynchronous handler function for the 'search_users' tool. It filters the testData.users array based on the query string matching name or email, optionally filters by role, logs the search, and returns a formatted text response with results.}, async (args) => { const { query, role } = args; let results = testData.users.filter(user => user.name.includes(query) || user.email.includes(query) ); if (role) { results = results.filter(user => user.role === role); } testData.logs.push(`搜索用户: "${query}" ${role ? `(角色: ${role})` : ""}`); return { content: [{ type: "text", text: `🔍 搜索结果 (${results.length}个):\n${JSON.stringify(results, null, 2)}` }] }; });
- src/index.ts:122-123 (schema)Zod input schema for 'search_users' tool: required 'query' (string), optional 'role' (enum: 'admin' or 'user').query: z.string().describe("搜索关键词"), role: z.enum(["admin", "user"]).optional().describe("按角色筛选")
- src/index.ts:121-142 (registration)Registration of the 'search_users' tool using McpServer.tool(), specifying name, description (Chinese: '搜索用户'), input schema, and inline handler function.server.tool("search_users", "搜索用户", { query: z.string().describe("搜索关键词"), role: z.enum(["admin", "user"]).optional().describe("按角色筛选") }, async (args) => { const { query, role } = args; let results = testData.users.filter(user => user.name.includes(query) || user.email.includes(query) ); if (role) { results = results.filter(user => user.role === role); } testData.logs.push(`搜索用户: "${query}" ${role ? `(角色: ${role})` : ""}`); return { content: [{ type: "text", text: `🔍 搜索结果 (${results.length}个):\n${JSON.stringify(results, null, 2)}` }] }; });