get_user
Retrieve Mantis user details by inputting a username, facilitating quick access to user information within the Mantis Bug Tracker system.
Instructions
根據用戶名稱查詢 Mantis 用戶
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | 用戶名稱 |
Implementation Reference
- src/server.ts:173-184 (registration)Registers the "get_user" MCP tool on the McpServer, including name, description, input schema (username), and handler function."get_user", "根據用戶名稱查詢 Mantis 用戶", { username: z.string().describe("用戶名稱") }, async (params) => { return withMantisConfigured("get_user", async () => { const user = await mantisApi.getUserByUsername(params.username); return JSON.stringify(user, null, 2); }); } );
- src/server.ts:178-183 (handler)The handler function that executes the tool logic: checks Mantis config, fetches user by username via mantisApi, and returns JSON string.async (params) => { return withMantisConfigured("get_user", async () => { const user = await mantisApi.getUserByUsername(params.username); return JSON.stringify(user, null, 2); }); }
- src/server.ts:175-177 (schema)Input schema validation using Zod, requiring a 'username' string parameter.{ username: z.string().describe("用戶名稱") },
- src/services/mantisApi.ts:91-118 (helper)Helper function implementing the core API call to Mantis to get user by username, with caching and error handling.async getUserByUsername(username: string): Promise<User> { const cacheKey = `user_${username}`; const cached = this.cache.get(cacheKey); if (cached && Date.now() - cached.timestamp < 300000) { return cached.data; } try { const response = await this.api.get(`/users/username/${encodeURIComponent(username)}`); const user = response.data; this.cache.set(cacheKey, { data: user, timestamp: Date.now() }); return user; } catch (error) { if (error instanceof MantisApiError) { throw error; } if (error instanceof Error) { throw new MantisApiError(`獲取用戶資訊失敗: ${error.message}`); } throw new MantisApiError('獲取用戶資訊失敗'); } }