ソースを参照

feat: add user email management support #13

Implemented three new MCP tools for managing user email addresses:
- list_user_emails: List all email addresses for authenticated user
- add_user_emails: Add new email address(es) to user account
- delete_user_emails: Remove email address(es) from user account

Changes:
- Added GogsEmail type to types.ts with email, verified, and primary fields
- Implemented listUserEmails, addUserEmails, and deleteUserEmails methods in GogsClient
- Added Zod schemas and tool definitions in server.ts
- Updated README.md with new tools documentation
- Updated CLAUDE.md MCP Tool Categories with email management tools

API endpoints implemented:
- GET /user/emails
- POST /user/emails
- DELETE /user/emails

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
claude 9 ヶ月 前
コミット
63dcd5341d
5 ファイル変更134 行追加1 行削除
  1. 1 1
      CLAUDE.md
  2. 11 0
      README.md
  3. 24 0
      src/gogs-client.ts
  4. 92 0
      src/server.ts
  5. 6 0
      src/types.ts

+ 1 - 1
CLAUDE.md

@@ -28,7 +28,7 @@ This is a Model Context Protocol (MCP) server that provides AI assistants (like
 ### MCP Tool Categories
 
 The server exposes tools in these categories:
-- **User Management**: get_current_user, get_user, search_users
+- **User Management**: get_current_user, get_user, search_users, list_user_emails, add_user_emails, delete_user_emails
 - **Repository Management**: list_user_repositories, search_repositories, get_repository, create_repository, delete_repository
 - **Content Access**: get_contents, get_raw_content, list_branches, get_commits, get_tree
 - **Issue Tracking**: list_issues, get_issue, create_issue, update_issue, list_issue_comments, create_issue_comment, update_issue_comment

+ 11 - 0
README.md

@@ -314,6 +314,17 @@ Search for users by username.
 - `query` (string, required): Search query
 - `limit` (number, optional): Maximum results (default: 10)
 
+#### `list_user_emails`
+List email addresses for the authenticated user. Returns all email addresses associated with your account, including their verification status and whether they are set as primary.
+
+#### `add_user_emails`
+Add new email address(es) to the authenticated user's account.
+- `emails` (array of strings, required): Array of email addresses to add
+
+#### `delete_user_emails`
+Delete email address(es) from the authenticated user's account.
+- `emails` (array of strings, required): Array of email addresses to delete
+
 ### Repository Tools
 
 #### `list_user_repositories`

+ 24 - 0
src/gogs-client.ts

@@ -21,6 +21,7 @@ import type {
   GogsTree,
   GogsRelease,
   GogsCollaborator,
+  GogsEmail,
 } from './types.js';
 
 export class GogsClient {
@@ -670,4 +671,27 @@ export class GogsClient {
   async removeCollaborator(owner: string, repo: string, username: string): Promise<void> {
     await this.client.delete(`/repos/${owner}/${repo}/collaborators/${username}`);
   }
+
+  /**
+   * List email addresses for the authenticated user
+   */
+  async listUserEmails(): Promise<GogsEmail[]> {
+    const response = await this.client.get<GogsEmail[]>('/user/emails');
+    return response.data;
+  }
+
+  /**
+   * Add email address(es) to the authenticated user's account
+   */
+  async addUserEmails(emails: string[]): Promise<GogsEmail[]> {
+    const response = await this.client.post<GogsEmail[]>('/user/emails', { emails });
+    return response.data;
+  }
+
+  /**
+   * Delete email address(es) from the authenticated user's account
+   */
+  async deleteUserEmails(emails: string[]): Promise<void> {
+    await this.client.delete('/user/emails', { data: { emails } });
+  }
 }

+ 92 - 0
src/server.ts

@@ -327,6 +327,14 @@ const RemoveCollaboratorSchema = z.object({
   username: z.string().describe('Username to remove as collaborator'),
 });
 
+const AddUserEmailsSchema = z.object({
+  emails: z.array(z.string()).describe('Array of email addresses to add'),
+});
+
+const DeleteUserEmailsSchema = z.object({
+  emails: z.array(z.string()).describe('Array of email addresses to delete'),
+});
+
 /**
  * Create and configure an MCP server with all tools and handlers
  */
@@ -1535,6 +1543,48 @@ export function createMcpServer(gogsClient: GogsClient): Server {
             required: ['owner', 'repo', 'username'],
           },
         },
+        {
+          name: 'list_user_emails',
+          description: 'List email addresses for the authenticated user',
+          inputSchema: {
+            type: 'object',
+            properties: {},
+          },
+        },
+        {
+          name: 'add_user_emails',
+          description: 'Add email address(es) to the authenticated user account',
+          inputSchema: {
+            type: 'object',
+            properties: {
+              emails: {
+                type: 'array',
+                items: {
+                  type: 'string',
+                },
+                description: 'Array of email addresses to add',
+              },
+            },
+            required: ['emails'],
+          },
+        },
+        {
+          name: 'delete_user_emails',
+          description: 'Delete email address(es) from the authenticated user account',
+          inputSchema: {
+            type: 'object',
+            properties: {
+              emails: {
+                type: 'array',
+                items: {
+                  type: 'string',
+                },
+                description: 'Array of email addresses to delete',
+              },
+            },
+            required: ['emails'],
+          },
+        },
       ],
     };
   });
@@ -2266,6 +2316,48 @@ export function createMcpServer(gogsClient: GogsClient): Server {
           };
         }
 
+        case 'list_user_emails': {
+          const emails = await gogsClient.listUserEmails();
+          return {
+            content: [
+              {
+                type: 'text',
+                text: JSON.stringify(emails, null, 2),
+              },
+            ],
+          };
+        }
+
+        case 'add_user_emails': {
+          const { emails } = AddUserEmailsSchema.parse(args);
+          const addedEmails = await gogsClient.addUserEmails(emails);
+          return {
+            content: [
+              {
+                type: 'text',
+                text: JSON.stringify(addedEmails, null, 2),
+              },
+            ],
+          };
+        }
+
+        case 'delete_user_emails': {
+          const { emails } = DeleteUserEmailsSchema.parse(args);
+          await gogsClient.deleteUserEmails(emails);
+          return {
+            content: [
+              {
+                type: 'text',
+                text: JSON.stringify({
+                  success: true,
+                  message: `Successfully deleted ${emails.length} email address(es)`,
+                  emails
+                }, null, 2),
+              },
+            ],
+          };
+        }
+
         default:
           throw new Error(`Unknown tool: ${name}`);
       }

+ 6 - 0
src/types.ts

@@ -196,3 +196,9 @@ export interface GogsCollaborator {
     pull: boolean;
   };
 }
+
+export interface GogsEmail {
+  email: string;
+  verified: boolean;
+  primary: boolean;
+}