Skip to main content
Glama
ddukbg

GitHub Enterprise MCP Server

get-content

Retrieve file or directory content from GitHub Enterprise repositories by specifying owner, repo, and path parameters.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesUser or organization name
repoYesRepository name
pathYesFile or directory path
refNoBranch or commit hash (default: default branch)

Implementation Reference

  • The primary handler for the 'get-content' MCP tool. Validates inputs using Zod, fetches content from GitHub via RepositoryAPI, formats the response with formatContent, and returns a structured text response.
    server.tool("get-content", {
        owner: z.string().describe("저장소 소유자 (사용자 또는 조직)"),
        repo: z.string().describe("저장소 이름"),
        path: z.string().describe("파일 또는 디렉토리 경로"),
        ref: z.string().optional().describe("브랜치 또는 커밋 해시 (기본값: 기본 브랜치)")
    }, async ({ owner, repo, path, ref }) => {
        try {
            // 매개변수 검증
            if (!owner || typeof owner !== 'string' || owner.trim() === '') {
                return {
                    content: [
                        {
                            type: "text",
                            text: "오류: 저장소 소유자(owner)는 필수 항목입니다."
                        }
                    ],
                    isError: true
                };
            }
            if (!repo || typeof repo !== 'string' || repo.trim() === '') {
                return {
                    content: [
                        {
                            type: "text",
                            text: "오류: 저장소 이름(repo)은 필수 항목입니다."
                        }
                    ],
                    isError: true
                };
            }
            if (!path || typeof path !== 'string') {
                return {
                    content: [
                        {
                            type: "text",
                            text: "오류: 파일 또는 디렉토리 경로(path)는 필수 항목입니다."
                        }
                    ],
                    isError: true
                };
            }
            const content = await context.repository.getContent(owner, repo, path, ref);
            // 내용 형식화
            const formattedContent = formatContent(content);
            // 디렉토리인지 파일인지에 따라 다른 응답 메시지
            const isDirectory = Array.isArray(content);
            const responseText = isDirectory
                ? `디렉토리 '${path}'의 내용 (${formattedContent.length}개 항목):`
                : `파일 '${path}'의 내용:`;
            return {
                content: [
                    {
                        type: "text",
                        text: `저장소 '${owner}/${repo}'의 ${responseText}\n\n${JSON.stringify(formattedContent, null, 2)}`
                    }
                ]
            };
        }
        catch (error) {
            console.error('파일/디렉토리 내용 조회 오류:', error);
            return {
                content: [
                    {
                        type: "text",
                        text: `파일/디렉토리 내용 조회 중 오류가 발생했습니다: ${error.message}`
                    }
                ],
                isError: true
            };
        }
    });
  • Zod input schema for the 'get-content' tool parameters.
    owner: z.string().describe("저장소 소유자 (사용자 또는 조직)"),
    repo: z.string().describe("저장소 이름"),
    path: z.string().describe("파일 또는 디렉토리 경로"),
    ref: z.string().optional().describe("브랜치 또는 커밋 해시 (기본값: 기본 브랜치)")
  • Helper function to format GitHub contents API response, handling both files (decoding base64) and directories.
    function formatContent(content) {
        // 디렉토리인 경우 (배열)
        if (Array.isArray(content)) {
            return content.map(item => ({
                name: item.name,
                path: item.path,
                type: item.type,
                size: item.size,
                url: item.html_url
            }));
        }
        // 파일인 경우 (단일 객체)
        const result = {
            name: content.name,
            path: content.path,
            type: content.type,
            size: content.size,
            url: content.html_url
        };
        // 파일 내용이 있으면 디코딩
        if (content.content && content.encoding === 'base64') {
            try {
                result.content = Buffer.from(content.content, 'base64').toString('utf-8');
            }
            catch (e) {
                result.content = '파일 내용을 디코딩할 수 없습니다.';
            }
        }
        return result;
    }
  • RepositoryAPI method that performs the actual GitHub API call to retrieve file or directory contents.
    async getContent(owner, repo, path, ref) {
        return this.client.get(`repos/${owner}/${repo}/contents/${path}`, {
            params: { ref }
        });
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ddukbg/github-enterprise-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server