Skip to content

mcp_server

Class info

🛈 DocStrings

GitHarbor MCP Server - Expose GitHarbor functionality through MCP.

get_commit_history async

get_commit_history(repo_url: str, max_results: int = 10) -> list[dict]

Get the commit history for a repository.

Source code in src/githarbor/mcp_server.py
@mcp.resource("repo://{repo_url}/commit_history")
async def get_commit_history(repo_url: str, max_results: int = 10) -> list[dict]:
    """Get the commit history for a repository."""
    try:
        commits = await list_commits_async(repo_url, max_results=max_results)
        return [dataclasses.asdict(commit) for commit in commits]
    except Exception as e:  # noqa: BLE001
        msg = f"Error fetching commit history: {e}"
        raise ResourceNotFoundError(msg)  # noqa: B904

get_file_content async

get_file_content(repo_url: str, path: str) -> str

Get the content of a file from a repository.

Source code in src/githarbor/mcp_server.py
@mcp.resource("repo://{repo_url}/files/{path}")
async def get_file_content(repo_url: str, path: str) -> str:
    """Get the content of a file from a repository."""
    import pathlib

    from githarbor import create_repository
    from githarbor.exceptions import ResourceNotFoundError

    try:
        repo = create_repository(repo_url)

        # Create a temporary directory to download the file
        with tempfile.TemporaryDirectory() as temp_dir:
            temp_path = pathlib.Path(temp_dir)

            # Download the file
            repo.download(path, temp_path, recursive=False)

            # Read the file content
            file_path = temp_path / os.path.basename(path)  # noqa: PTH119
            if not file_path.exists():
                msg = f"File not found: {path}"
                raise ResourceNotFoundError(msg)  # noqa: TRY301

            return file_path.read_text(errors="replace")
    except Exception as e:  # noqa: BLE001
        msg = f"Error fetching file content: {e}"
        raise ResourceNotFoundError(msg)  # noqa: B904

get_issues_list async

get_issues_list(repo_url: str, state: str) -> list[dict]

Get a list of issues for a repository filtered by state.

State can be one of "open", "closed", or "all".

Source code in src/githarbor/mcp_server.py
@mcp.resource("repo://{repo_url}/issues/{state}")
async def get_issues_list(repo_url: str, state: str) -> list[dict]:  # IssueState
    """Get a list of issues for a repository filtered by state.

    State can be one of "open", "closed", or "all".
    """
    try:
        issues = await list_issues_async(repo_url, state=state)  # type: ignore
        return [dataclasses.asdict(issue) for issue in issues]
    except Exception as e:  # noqa: BLE001
        msg = f"Error fetching issues: {e}"
        raise ResourceNotFoundError(msg) from None

get_pull_requests_list async

get_pull_requests_list(repo_url: str, state: str) -> list[dict]

Get a list of pull requests for a repository filtered by state.

Source code in src/githarbor/mcp_server.py
@mcp.resource("repo://{repo_url}/pull_requests/{state}")
async def get_pull_requests_list(
    repo_url: str,
    state: str,  # PullRequestState
) -> list[dict]:
    """Get a list of pull requests for a repository filtered by state."""
    try:
        prs = await list_pull_requests_async(repo_url, state=state)  # type: ignore
        return [dataclasses.asdict(pr) for pr in prs]
    except Exception as e:  # noqa: BLE001
        msg = f"Error fetching pull requests: {e}"
        raise ResourceNotFoundError(msg)  # noqa: B904

gh_add_pull_request_comment async

gh_add_pull_request_comment(repo_url: str, number: int, body: str) -> dict

Add a comment to a pull request.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_add_pull_request_comment(repo_url: str, number: int, body: str) -> dict:
    """Add a comment to a pull request."""
    comment = await add_pull_request_comment_async(repo_url, number, body)
    return dataclasses.asdict(comment)

gh_create_branch async

gh_create_branch(repo_url: str, name: str, base_commit: str) -> dict

Create a new branch in a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_create_branch(repo_url: str, name: str, base_commit: str) -> dict:
    """Create a new branch in a repository."""
    branch = await create_branch_async(repo_url, name, base_commit)
    return dataclasses.asdict(branch)

gh_create_issue async

gh_create_issue(
    repo_url: str,
    title: str,
    body: str,
    labels: list[str] | None = None,
    assignees: list[str] | None = None,
) -> dict

Create a new issue in a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_create_issue(
    repo_url: str,
    title: str,
    body: str,
    labels: list[str] | None = None,
    assignees: list[str] | None = None,
) -> dict:
    """Create a new issue in a repository."""
    issue = await create_issue_async(repo_url, title, body, labels=labels, assignees=assignees)
    return dataclasses.asdict(issue)

gh_create_pull_request async

gh_create_pull_request(
    repo_url: str, title: str, body: str, head_branch: str, base_branch: str, draft: bool = False
) -> dict

Create a new pull request in a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_create_pull_request(
    repo_url: str,
    title: str,
    body: str,
    head_branch: str,
    base_branch: str,
    draft: bool = False,
) -> dict:
    """Create a new pull request in a repository."""
    pr = await create_pull_request_async(repo_url, title, body, head_branch, base_branch, draft)
    return dataclasses.asdict(pr)

gh_get_branch async

gh_get_branch(repo_url: str, branch_name: str) -> dict

Get information about a specific branch in a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_branch(repo_url: str, branch_name: str) -> dict:
    """Get information about a specific branch in a repository."""
    branch = await get_branch_async(repo_url, branch_name)
    return dataclasses.asdict(branch)

gh_get_commit async

gh_get_commit(repo_url: str, sha: str) -> dict

Get details about a specific commit.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_commit(repo_url: str, sha: str) -> dict:
    """Get details about a specific commit."""
    commit = await get_commit_async(repo_url, sha)
    return dataclasses.asdict(commit)

gh_get_contributors async

gh_get_contributors(
    repo_url: str, sort_by: Literal["commits", "name", "date"] = "commits", limit: int | None = None
) -> list[dict]

Get contributors to a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_contributors(
    repo_url: str,
    sort_by: Literal["commits", "name", "date"] = "commits",
    limit: int | None = None,
) -> list[dict]:
    """Get contributors to a repository."""
    contributors = await get_contributors_async(repo_url, sort_by=sort_by, limit=limit)
    return [dataclasses.asdict(contributor) for contributor in contributors]

gh_get_issue async

gh_get_issue(repo_url: str, issue_id: int) -> dict

Get details about a specific issue.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_issue(repo_url: str, issue_id: int) -> dict:
    """Get details about a specific issue."""
    issue = await get_issue_async(repo_url, issue_id)
    return dataclasses.asdict(issue)

gh_get_languages async

gh_get_languages(repo_url: str) -> dict[str, int]

Get programming language statistics for a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_languages(repo_url: str) -> dict[str, int]:
    """Get programming language statistics for a repository."""
    return await get_languages_async(repo_url)

gh_get_latest_release async

gh_get_latest_release(
    repo_url: str, include_drafts: bool = False, include_prereleases: bool = False
) -> dict

Get the latest release from a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_latest_release(
    repo_url: str,
    include_drafts: bool = False,
    include_prereleases: bool = False,
) -> dict:
    """Get the latest release from a repository."""
    release = await get_latest_release_async(
        repo_url, include_drafts=include_drafts, include_prereleases=include_prereleases
    )
    return dataclasses.asdict(release)

gh_get_pull_request async

gh_get_pull_request(repo_url: str, number: int) -> dict

Get details about a specific pull request.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_pull_request(repo_url: str, number: int) -> dict:
    """Get details about a specific pull request."""
    pr = await get_pull_request_async(repo_url, number)
    return dataclasses.asdict(pr)

gh_get_release async

gh_get_release(repo_url: str, tag: str) -> dict

Get a specific release by tag name.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_release(repo_url: str, tag: str) -> dict:
    """Get a specific release by tag name."""
    release = await get_release_async(repo_url, tag)
    return dataclasses.asdict(release)

gh_get_repo_user async

gh_get_repo_user(repo_url: str) -> dict

Get information about the owner of a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_repo_user(repo_url: str) -> dict:
    """Get information about the owner of a repository."""
    user = await get_repo_user_async(repo_url)
    return dataclasses.asdict(user)

gh_get_tag async

gh_get_tag(repo_url: str, name: str) -> dict

Get information about a specific tag.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_get_tag(repo_url: str, name: str) -> dict:
    """Get information about a specific tag."""
    tag = await get_tag_async(repo_url, name)
    return dataclasses.asdict(tag)

gh_list_branches async

gh_list_branches(repo_url: str) -> list[dict]

List all branches in a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_list_branches(repo_url: str) -> list[dict]:
    """List all branches in a repository."""
    branches = await list_branches_async(repo_url)
    return [dataclasses.asdict(branch) for branch in branches]

gh_list_commits async

gh_list_commits(
    repo_url: str, branch: str | None = None, max_results: int | None = None
) -> list[dict]

List commits in a repository with optional branch and limit.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_list_commits(
    repo_url: str,
    branch: str | None = None,
    max_results: int | None = None,
) -> list[dict]:
    """List commits in a repository with optional branch and limit."""
    commits = await list_commits_async(repo_url, branch=branch, max_results=max_results)
    return [dataclasses.asdict(commit) for commit in commits]

gh_list_issues async

gh_list_issues(repo_url: str, state: Literal['open', 'closed', 'all'] = 'open') -> list[dict]

List issues in a repository with optional state filter.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_list_issues(
    repo_url: str, state: Literal["open", "closed", "all"] = "open"
) -> list[dict]:
    """List issues in a repository with optional state filter."""
    issues = await list_issues_async(repo_url, state=state)
    return [dataclasses.asdict(issue) for issue in issues]

gh_list_pull_requests async

gh_list_pull_requests(
    repo_url: str, state: Literal["open", "closed", "all"] = "open"
) -> list[dict]

List pull requests in a repository with optional state filter.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_list_pull_requests(
    repo_url: str,
    state: Literal["open", "closed", "all"] = "open",
) -> list[dict]:
    """List pull requests in a repository with optional state filter."""
    prs = await list_pull_requests_async(repo_url, state=state)
    return [dataclasses.asdict(pr) for pr in prs]

gh_list_releases async

gh_list_releases(
    repo_url: str,
    include_drafts: bool = False,
    include_prereleases: bool = False,
    limit: int | None = None,
) -> list[dict]

List releases from a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_list_releases(
    repo_url: str,
    include_drafts: bool = False,
    include_prereleases: bool = False,
    limit: int | None = None,
) -> list[dict]:
    """List releases from a repository."""
    releases = await list_releases_async(
        repo_url,
        include_drafts=include_drafts,
        include_prereleases=include_prereleases,
        limit=limit,
    )
    return [dataclasses.asdict(release) for release in releases]

gh_list_tags async

gh_list_tags(repo_url: str) -> list[dict]

List all tags in a repository.

Source code in src/githarbor/mcp_server.py
@mcp.tool()
async def gh_list_tags(repo_url: str) -> list[dict]:
    """List all tags in a repository."""
    tags = await list_tags_async(repo_url)
    return [dataclasses.asdict(tag) for tag in tags]