获取当前用户
gitea_user_currentRetrieve details about the currently authenticated user in Gitea, including profile information and account status.
Instructions
Get information about the currently authenticated user
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "gitea_user_current"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:546-586 (registration)Registers the 'gitea_user_current' MCP tool. Includes the tool schema (title and description, no input parameters), and the inline handler function that calls GiteaClient.getCurrentUser() and returns formatted user information or error.
mcpServer.registerTool( 'gitea_user_current', { title: '获取当前用户', description: 'Get information about the currently authenticated user', }, async (_args: any, _extra: any) => { try { const user = await ctx.client.getCurrentUser(); return { content: [ { type: 'text' as const, text: JSON.stringify( { id: user.id, login: user.login, full_name: user.full_name, email: user.email, avatar_url: user.avatar_url, }, null, 2 ), }, ], }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: 'text' as const, text: `Error: ${errorMessage}`, }, ], isError: true, }; } } ); - src/gitea-client.ts:222-233 (helper)Implementation of GiteaClient.getCurrentUser() method, which performs a GET request to the Gitea API endpoint '/api/v1/user' to retrieve the current authenticated user's information.
/** * 获取当前认证用户信息 */ async getCurrentUser(): Promise<{ id: number; login: string; full_name: string; email: string; avatar_url: string; }> { return this.get('/user'); }