CLAUDE.mdā¢6.3 kB
# Forgejo MCP Server
A Model Context Protocol (MCP) server that enables MCP clients to interact with Gitea/Forgejo repositories.
## Project Overview
This project provides MCP integration for managing Forgejo/Gitea repositories through MCP-compatible clients such as Claude Desktop, Continue, and other LLM applications.
### Supported Operations
- Issues (create, edit, comment, close)
- Labels (list, create, edit, delete)
- Milestones (list, create, edit, delete)
- Releases (list, create, edit, delete, manage assets)
- Pull requests (list, view)
- Repository search and listing
- Wiki pages (create, edit, delete)
- Forgejo Actions tasks (view)
### Transport Modes
- **stdio**: Standard input/output (best for local integration)
- **sse**: Server-Sent Events over HTTP (best for web apps) - *planned*
- **http**: HTTP POST requests (best for simple integrations) - *planned*
## Architecture
### Core Components
- **cmd/**: CLI application using Cobra framework
- `root.go`: Main command with global configuration
- `stdio.go`: Stdio transport mode implementation
- **types/**: Data structures and response types
- `api.go`: MCP response types wrapping Forgejo SDK types
- **main.go**: Application entry point
### Key Dependencies
- **MCP SDK**: `github.com/modelcontextprotocol/go-sdk`
* There are 3 important sub packages: `mcp`, `jsonschema` and `jsonrpc`
- **Forgejo SDK**: `codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2`
- **CLI Framework**: `github.com/spf13/cobra`
- **Configuration**: `github.com/spf13/viper`
If you need to get documentation of these packages, `go doc` should be the best bet.
### Implementation Strategy
- **š¢ SDK-based (71%)**: Use official Forgejo SDK where available
- **š” Custom HTTP (29%)**: Implement custom requests for unsupported features (Wiki, Actions, Issue dependencies)
## Configuration
### CLI Arguments
```bash
forgejo-mcp stdio --server https://git.example.com --token your_token
```
### Environment Variables
- `FORGEJOMCP_SERVER`: Forgejo server URL
- `FORGEJOMCP_TOKEN`: Access token
### Config File
Default location: `~/.forgejo-mcp.yaml`
Priority: CLI args > Environment variables > Config file
## Development
### Language and Style
- **Code/Comments**: English (open source project)
- **Documentation**: English (unless `.tw.md` suffix for Traditional Chinese)
### Key Files
- `proposal.tw.md`: Project requirements (Traditional Chinese)
- `features.tw.md`: Feature specifications (Traditional Chinese)
- `design.tw.md`: Architecture documentation (Traditional Chinese)
- `swagger.v1.json`: API documentation
### Response Format
- **Error responses**: Plain text
- **Success responses**: Markdown format in MCP TextContent.Text field
- **Structured data**: Dual format (markdown + JSON) for MCP compatibility
### Architecture Decisions
- Use **endpoint-based markdown formatting** rather than type-based to avoid LLM confusion
- Each data type implements `ToMarkdown()` method for reusability
- Endpoint handlers add context-specific headers and descriptions
- **Tool responses**: Use single TextContent with markdown formatting (follows MCP best practices)
- **Tool organization**: Mixed modular architecture with sub-packages for logical grouping
### Tool Architecture
The project uses a **mixed modular architecture** for organizing MCP tools:
#### Structure
```
tools/
āāā module.go # ToolImpl interface definition
āāā registry.go # Unified tool registration
āāā helpers.go # Shared utility functions
āāā issue/ # Issue-related operations
ā āāā crud.go # create/edit/delete issue
ā āāā list.go # list_issues
ā āāā comment.go # issue comments
ā āāā label.go # issue label operations
ā āāā attach.go # issue attachments
ā āāā dep.go # issue dependencies
āāā label/ # Label management
ā āāā crud.go # all label operations
āāā milestone/ # Milestone management
ā āāā crud.go # all milestone operations
āāā release/ # Release management
ā āāā crud.go # create/edit/delete release
ā āāā attach.go # release attachments
āāā pullreq/ # Pull Request operations
ā āāā list.go # list pull requests
ā āāā view.go # get pull request details
āāā action/ # Forgejo Actions (CI/CD)
ā āāā list.go # list_action_tasks
āāā wiki/ # Wiki pages
ā āāā crud.go # create/edit/delete wiki pages
ā āāā list.go # list wiki pages
āāā repo/ # Repository operations
āāā list.go # repository listing and search
```
#### Design Principles
- **Logical grouping**: Related tools grouped in sub-packages
- **Single responsibility**: Each file handles closely related operations
- **Interface-driven**: All tools implement the `ToolImpl` interface
- **Extensibility**: Easy to add new tools and categories
- **Testability**: Each module can be independently tested
## Development Workflow
1. Test-Driven Development (TDD)
2. Red-Green-Refactor cycle
3. Human review at each step
4. Git commit after each milestone
## Useful Commands
### Go Commands
```bash
# Build the project for release
go build -o forgejo-mcp
# Check compilation error
go build ./...
# Run tests
go test ./...
# Format code
goimports -w .
# Get dependencies
go mod tidy
```
### Swagger
```
# Find definition of specified api endpoint
# .paths["/path/to/endpoint"].http_method
jq '.paths["/repos/{owner}/{repo}/labels/{id}"].patch' swagger.v1.json
# Get summary string of specified api endpoint
# .paths["/path/to/endpoint"].http_method.summary
#
# Change "summary" to "parameters" or "responses" to get params/responses
jq '.paths["/repos/{owner}/{repo}/labels/{id}"].patch.summary' swagger.v1.json
# Get referenced type definition
#
# for "$refs": "#/abc/def"
jq '.abc.def' swagger.v1.json
```
## Additional tools
- `my-git-server`: Tools to access remote git server. The repository is `ronmi/forgejo-mcp`.
- `gopls`: Go language server to query for difinitions, references, and more.