Home / Projects / Forgejo MCP Server

Forgejo MCP Server Integration

Bringing Model Context Protocol to the open-source DevOps world - enabling AI agents to manage Git repositories through standardized protocol messages

June 2025
3 months
DevOps + AI
MCP Forgejo FastAPI Python Docker
MCP Server Dashboard

Overview

This project extends the Model Context Protocol (MCP) architecture by integrating it directly with Forgejo, the open-source and self-hosted Git service (a community-driven fork of Gitea).

While the MCP ecosystem is rapidly expanding across AI and automation platforms, Forgejo had no official MCP support - neither from the Forgejo team nor the broader open-source community. To fill this gap, I built a Forgejo MCP Server that allows AI agents and automation systems to communicate directly with Forgejo repositories and services through standardized protocol messages.

The result is a context-aware integration layer where AI agents can perform repository operations, manage files, interact with wikis, and publish releases - all through a single MCP-compatible interface.

🎯 Project Goals

  • Enable AI-assisted DevOps workflows through Forgejo
  • Provide real-time context sharing between AI models and Git repositories
  • Build a reliable, protocol-driven API that supports multiple agents
  • Maintain full data privacy and open-source compatibility

Core Components

1. Protocol Layer

Implements the official @modelcontextprotocol/sdk, providing a fully compliant MCP interface. Supports both stdio and streamable-http modes for flexible client communication.

Protocol Features

  • FastAPI-based MCP endpoint handler
  • WebSocket channel for real-time message streaming
  • JSON-RPC-based message format (request, response, notifications)
  • Automatic protocol version negotiation
  • Error recovery and reconnection support

2. Forgejo Adapter Layer

The Forgejo adapter translates MCP actions into Forgejo API calls while preserving context. It acts as a two-way bridge between AI agents and Forgejo's REST endpoints.

Repository Actions

  • forgejo.repo.list
  • forgejo.repo.get
  • forgejo.file.read
  • forgejo.file.write

Wiki & Docs

  • forgejo.wiki.get
  • forgejo.wiki.update
  • forgejo.release.list
  • forgejo.release.create

Package Management

  • forgejo.package.list
  • forgejo.package.publish
  • Version control
  • Asset management

These actions expose Forgejo's capabilities in a structured, language-model-friendly way - enabling AI agents (like LangChain or custom assistants) to perform repository management tasks using natural language.

DevOps Infrastructure

Self-hosted DevOps infrastructure with AI capabilities

Security Model

The Forgejo MCP Server supports two authentication patterns, depending on your deployment context:

Single-User Mode

  • One Forgejo token configured server-side
  • All AI agents share the same identity
  • Ideal for personal or team projects
  • Simplified token management

Multi-User Mode

  • Clients provide their own tokens
  • Per-user permission enforcement
  • Audit trails per agent/user
  • Enterprise-grade access control

This flexibility allows teams to start simple and scale their authentication as needs evolve, without changing the MCP protocol integration.

System Architecture

The system follows a three-layer approach with clear separation of concerns:

┌──────────────────────────────────────────────────────────────┐
│                       MCP Protocol Layer                     │
│   (FastAPI + MCP SDK, stdio/streamable-http modes)          │
└────────────────────────┬─────────────────────────────────────┘
                         │
                         ▼
┌──────────────────────────────────────────────────────────────┐
│                    Forgejo Adapter Layer                     │
│  Actions: repo.list, file.write, wiki.update, release.*     │
└────────────────────────┬─────────────────────────────────────┘
                         │
                         ▼
┌──────────────────────────────────────────────────────────────┐
│                    Forgejo REST API                          │
│         (Self-hosted Git server with package registry)       │
└──────────────────────────────────────────────────────────────┘

Each layer is independently testable and can be scaled or replaced as requirements evolve.

Example Workflow

Here's how an AI agent might use the MCP server to create a new release after a successful CI pipeline:

  1. Agent invokes: forgejo.release.create
  2. MCP server: Validates parameters (repo, tag, notes, assets)
  3. Forgejo adapter: Calls Forgejo API to publish release
  4. Response: MCP-formatted result with release URL and metadata

This workflow demonstrates the power of protocol-driven automation - the AI agent never touches the Forgejo API directly, yet performs complex repository operations.

Key Insights

  • Protocol Over REST: By abstracting Forgejo's API behind MCP, we unlock compatibility with any MCP-compliant client (Claude Desktop, custom agents, LangChain tools) without client-side Forgejo knowledge.
  • Security Simplicity: Supporting both single-user and multi-user modes keeps the system flexible. Most self-hosted users start with single-user mode, then migrate to multi-user when scaling teams.
  • Open Source Value: Forgejo being a community fork of Gitea means this project serves users who prioritize self-hosting, privacy, and avoiding vendor lock-in.

Technical Stack

The project leverages modern Python technologies and best practices:

Backend

  • FastAPI framework
  • MCP SDK (@modelcontextprotocol/sdk)
  • Python 3.11+
  • Pydantic for validation

Forgejo Integration

  • Forgejo REST API client
  • Git operations wrapper
  • Wiki management
  • Package registry access

DevOps

  • Docker Compose
  • MCP Inspector for testing
  • Self-hosted deployment
  • stdio/HTTP protocol modes

Future Enhancements

The roadmap includes several high-impact features to expand AI-assisted DevOps capabilities:

  • Commit Diff Summarization: Automatically generate human-readable summaries of code changes for release notes and changelogs
  • Webhook Support: Enable AI agents to react to Forgejo events (push, PR, issue) in real-time via webhook notifications
  • Multi-Agent Co-Review: Coordinate multiple AI agents to perform collaborative code reviews with different specializations (security, performance, style)
  • Dashboard UI: Web interface to visualize MCP activity, monitor API usage, and manage authentication tokens
  • Extended Package Operations: Support for container registry and Helm chart management through MCP actions

Interested in this project?

I'd love to discuss the technical details and share more insights about building AI automation systems.

Get In Touch