Parcourir la source

fix: remove get_contents and get_raw_content tools to prevent context overflow #19

Large files retrieved through get_contents and get_raw_content tools were
filling up the context unnecessarily. These tools have been removed to
prevent this issue.

Removed:
- get_contents tool and schema
- get_raw_content tool and schema
- getContents() and getRawContent() methods from GogsClient
- Updated README.md and CLAUDE.md documentation

The get_tree tool remains available for accessing repository structure
without retrieving full file contents.

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

Co-Authored-By: Claude <noreply@anthropic.com>
claude il y a 8 mois
Parent
commit
c900ac17e5
4 fichiers modifiés avec 1 ajouts et 152 suppressions
  1. 1 1
      CLAUDE.md
  2. 0 14
      README.md
  3. 0 31
      src/gogs-client.ts
  4. 0 106
      src/server.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, 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
+- **Content Access**: 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
 - **Milestone Management**: list_milestones, get_milestone, create_milestone, update_milestone, delete_milestone

+ 0 - 14
README.md

@@ -386,20 +386,6 @@ Delete a repository (requires admin access).
 
 ### Content Tools
 
-#### `get_contents`
-Get file or directory contents from a repository.
-- `owner` (string, required): Repository owner username
-- `repo` (string, required): Repository name
-- `path` (string, required): File or directory path
-- `ref` (string, optional): Branch, tag, or commit SHA (default: default branch)
-
-#### `get_raw_content`
-Get raw file content from a repository.
-- `owner` (string, required): Repository owner username
-- `repo` (string, required): Repository name
-- `ref` (string, required): Branch, tag, or commit SHA
-- `path` (string, required): File path
-
 #### `list_branches`
 List all branches in a repository.
 - `owner` (string, required): Repository owner username

+ 0 - 31
src/gogs-client.ts

@@ -143,37 +143,6 @@ export class GogsClient {
     await this.client.delete(`/repos/${owner}/${repo}`);
   }
 
-  /**
-   * Get file or directory contents
-   */
-  async getContents(
-    owner: string,
-    repo: string,
-    path: string,
-    ref?: string
-  ): Promise<GogsFileContent | GogsFileContent[]> {
-    const response = await this.client.get<GogsFileContent | GogsFileContent[]>(
-      `/repos/${owner}/${repo}/contents/${path}`,
-      {
-        params: ref ? { ref } : undefined,
-      }
-    );
-    return response.data;
-  }
-
-  /**
-   * Get raw file content
-   */
-  async getRawContent(owner: string, repo: string, ref: string, path: string): Promise<string> {
-    const response = await this.client.get<string>(
-      `/repos/${owner}/${repo}/raw/${ref}/${path}`,
-      {
-        responseType: 'text',
-      }
-    );
-    return response.data;
-  }
-
   /**
    * List branches in a repository
    */

+ 0 - 106
src/server.ts

@@ -54,20 +54,6 @@ const DeleteRepoSchema = z.object({
   repo: z.string().describe('Repository name'),
 });
 
-const GetContentsSchema = z.object({
-  owner: z.string().describe('Repository owner username'),
-  repo: z.string().describe('Repository name'),
-  path: z.string().describe('File or directory path'),
-  ref: z.string().optional().describe('Branch, tag, or commit SHA (default: default branch)'),
-});
-
-const GetRawContentSchema = z.object({
-  owner: z.string().describe('Repository owner username'),
-  repo: z.string().describe('Repository name'),
-  ref: z.string().describe('Branch, tag, or commit SHA'),
-  path: z.string().describe('File path'),
-});
-
 const ListBranchesSchema = z.object({
   owner: z.string().describe('Repository owner username'),
   repo: z.string().describe('Repository name'),
@@ -706,58 +692,6 @@ export function createMcpServer(gogsClient: GogsClient): Server {
             required: ['owner', 'repo'],
           },
         },
-        {
-          name: 'get_contents',
-          description: 'Get file or directory contents from a Gogs repository',
-          inputSchema: {
-            type: 'object',
-            properties: {
-              owner: {
-                type: 'string',
-                description: 'Repository owner username',
-              },
-              repo: {
-                type: 'string',
-                description: 'Repository name',
-              },
-              path: {
-                type: 'string',
-                description: 'File or directory path',
-              },
-              ref: {
-                type: 'string',
-                description: 'Branch, tag, or commit SHA (default: default branch)',
-              },
-            },
-            required: ['owner', 'repo', 'path'],
-          },
-        },
-        {
-          name: 'get_raw_content',
-          description: 'Get raw file content from a Gogs repository',
-          inputSchema: {
-            type: 'object',
-            properties: {
-              owner: {
-                type: 'string',
-                description: 'Repository owner username',
-              },
-              repo: {
-                type: 'string',
-                description: 'Repository name',
-              },
-              ref: {
-                type: 'string',
-                description: 'Branch, tag, or commit SHA',
-              },
-              path: {
-                type: 'string',
-                description: 'File path',
-              },
-            },
-            required: ['owner', 'repo', 'ref', 'path'],
-          },
-        },
         {
           name: 'list_branches',
           description: 'List all branches in a Gogs repository',
@@ -2627,46 +2561,6 @@ export function createMcpServer(gogsClient: GogsClient): Server {
           };
         }
 
-        case 'get_contents': {
-          const { owner, repo, path, ref } = GetContentsSchema.parse(args);
-          const contents = await gogsClient.getContents(owner, repo, path, ref);
-
-          // If it's a file with base64 content, decode it
-          if (!Array.isArray(contents) && contents.type === 'file' && contents.content) {
-            const decodedContent = Buffer.from(contents.content, 'base64').toString('utf-8');
-            return {
-              content: [
-                {
-                  type: 'text',
-                  text: `File: ${contents.path}\nSize: ${contents.size} bytes\nSHA: ${contents.sha}\n\nContent:\n${decodedContent}`,
-                },
-              ],
-            };
-          }
-
-          return {
-            content: [
-              {
-                type: 'text',
-                text: JSON.stringify(contents, null, 2),
-              },
-            ],
-          };
-        }
-
-        case 'get_raw_content': {
-          const { owner, repo, ref, path } = GetRawContentSchema.parse(args);
-          const content = await gogsClient.getRawContent(owner, repo, ref, path);
-          return {
-            content: [
-              {
-                type: 'text',
-                text: content,
-              },
-            ],
-          };
-        }
-
         case 'list_branches': {
           const { owner, repo } = ListBranchesSchema.parse(args);
           const branches = await gogsClient.listBranches(owner, repo);