소스 검색

feat: add Git Trees support #14

Implement get_tree tool to provide low-level access to repository structure at specific commits or tree SHAs.

Changes:
- Add GogsTree and GogsTreeEntry TypeScript types to src/types.ts
- Implement getTree method in src/gogs-client.ts
- Add get_tree tool with Zod schema to src/server.ts
- Update README.md with get_tree tool documentation
- Update CLAUDE.md to include get_tree in Content Access tools

The get_tree tool enables advanced operations like:
- Directory browsing at specific commits
- Analyzing file hierarchies
- Building custom repository explorers
- Accessing tree entry types (blob, tree, commit)
- Accessing tree entry modes (file permissions)

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

Co-Authored-By: Claude <noreply@anthropic.com>
claude 9 달 전
부모
커밋
28f1a458be
5개의 변경된 파일73개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      CLAUDE.md
  2. 7 0
      README.md
  3. 9 0
      src/gogs-client.ts
  4. 41 0
      src/server.ts
  5. 15 0
      src/types.ts

+ 1 - 1
CLAUDE.md

@@ -30,7 +30,7 @@ This is a Model Context Protocol (MCP) server that provides AI assistants (like
 The server exposes tools in these categories:
 - **User Management**: get_current_user, get_user, search_users
 - **Repository Management**: list_user_repositories, search_repositories, get_repository, create_repository, delete_repository
-- **Content Access**: get_contents, get_raw_content, list_branches, get_commits
+- **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
 - **Label Management**: list_labels, get_label, create_label, update_label, delete_label, list_issue_labels, add_issue_labels, remove_issue_label, replace_issue_labels, remove_all_issue_labels
 - **Organization Management**: list_user_organizations, create_organization, list_public_organizations, get_organization, update_organization, add_organization_member

+ 7 - 0
README.md

@@ -23,6 +23,7 @@ This MCP server provides tools to:
   - Get raw file content
   - List repository branches
   - Get commit history
+  - Get git trees (low-level repository structure access)
 
 - **Issue Management**
   - List issues in a repository
@@ -364,6 +365,12 @@ Get commit history from a repository.
 - `sha` (string, optional): Branch name or commit SHA
 - `page` (number, optional): Page number (default: 1)
 
+#### `get_tree`
+Get a git tree by SHA - provides low-level access to repository structure at a specific commit or tree SHA. Returns tree entries including files (blobs), directories (trees), and submodules (commits) with their modes and permissions.
+- `owner` (string, required): Repository owner username
+- `repo` (string, required): Repository name
+- `sha` (string, required): Git tree SHA or commit SHA
+
 ### Issue Management Tools
 
 #### `list_issues`

+ 9 - 0
src/gogs-client.ts

@@ -17,6 +17,7 @@ import type {
   GogsLabel,
   GogsOrganization,
   GogsTeam,
+  GogsTree,
 } from './types.js';
 
 export class GogsClient {
@@ -182,6 +183,14 @@ export class GogsClient {
     return response.data;
   }
 
+  /**
+   * Get a git tree by SHA
+   */
+  async getTree(owner: string, repo: string, sha: string): Promise<GogsTree> {
+    const response = await this.client.get<GogsTree>(`/repos/${owner}/${repo}/git/trees/${sha}`);
+    return response.data;
+  }
+
   /**
    * List issues in a repository
    */

+ 41 - 0
src/server.ts

@@ -80,6 +80,12 @@ const GetCommitsSchema = z.object({
   page: z.number().optional().describe('Page number (default: 1)'),
 });
 
+const GetTreeSchema = z.object({
+  owner: z.string().describe('Repository owner username'),
+  repo: z.string().describe('Repository name'),
+  sha: z.string().describe('Git tree SHA or commit SHA'),
+});
+
 const ListIssuesSchema = z.object({
   owner: z.string().describe('Repository owner username'),
   repo: z.string().describe('Repository name'),
@@ -527,6 +533,28 @@ export function createMcpServer(gogsClient: GogsClient): Server {
             required: ['owner', 'repo'],
           },
         },
+        {
+          name: 'get_tree',
+          description: 'Get a git tree by SHA - provides low-level access to repository structure at a specific commit or tree SHA',
+          inputSchema: {
+            type: 'object',
+            properties: {
+              owner: {
+                type: 'string',
+                description: 'Repository owner username',
+              },
+              repo: {
+                type: 'string',
+                description: 'Repository name',
+              },
+              sha: {
+                type: 'string',
+                description: 'Git tree SHA or commit SHA',
+              },
+            },
+            required: ['owner', 'repo', 'sha'],
+          },
+        },
         {
           name: 'list_issues',
           description: 'List issues in a repository',
@@ -1386,6 +1414,19 @@ export function createMcpServer(gogsClient: GogsClient): Server {
           };
         }
 
+        case 'get_tree': {
+          const { owner, repo, sha } = GetTreeSchema.parse(args);
+          const tree = await gogsClient.getTree(owner, repo, sha);
+          return {
+            content: [
+              {
+                type: 'text',
+                text: JSON.stringify(tree, null, 2),
+              },
+            ],
+          };
+        }
+
         case 'list_issues': {
           const { owner, repo, state, labels, page, per_page } = ListIssuesSchema.parse(args);
           const issues = await gogsClient.listIssues(owner, repo, { state, labels, page, per_page });

+ 15 - 0
src/types.ts

@@ -143,3 +143,18 @@ export interface GogsTeam {
   description: string;
   permission: 'owner' | 'read' | 'write';
 }
+
+export interface GogsTreeEntry {
+  path: string;
+  mode: string;
+  type: 'blob' | 'tree' | 'commit';
+  size: number;
+  sha: string;
+  url: string;
+}
+
+export interface GogsTree {
+  sha: string;
+  url: string;
+  tree: GogsTreeEntry[];
+}