release: v1.26.1-moko.06.06.01 #520
@@ -0,0 +1,129 @@
|
||||
<!-- Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
DEFGROUP: gitea-api-mcp.Documentation
|
||||
REPO: https://git.mokoconsulting.tech/MokoConsulting/gitea-api-mcp
|
||||
-->
|
||||
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
- **Renamed** package from `@mokoconsulting/gitea-api-mcp` to `@mokoconsulting/mokogitea-api-mcp` to distinguish Moko's forked Gitea MCP from upstream
|
||||
- **Renamed** McpServer name and bin entry to `mokogitea-api-mcp`
|
||||
|
||||
|
||||
## [0.0] - 2026-05-07
|
||||
|
||||
### Added
|
||||
|
||||
#### User / Auth (3 tools)
|
||||
- `gitea_me` -- Get the authenticated user info
|
||||
- `gitea_user_orgs` -- List organizations the authenticated user belongs to
|
||||
- `gitea_user_repos` -- List repositories owned by the authenticated user
|
||||
|
||||
#### Repositories (8 tools)
|
||||
- `gitea_repo_get` -- Get repository details
|
||||
- `gitea_repo_create` -- Create a new repository
|
||||
- `gitea_repo_delete` -- Delete a repository
|
||||
- `gitea_repo_edit` -- Edit repository settings
|
||||
- `gitea_repo_fork` -- Fork a repository
|
||||
- `gitea_repo_search` -- Search repositories
|
||||
- `gitea_org_repos` -- List repositories in an organization
|
||||
- `gitea_list_connections` -- List configured Gitea connections
|
||||
|
||||
#### File Contents (5 tools)
|
||||
- `gitea_file_get` -- Get file contents from a repository
|
||||
- `gitea_dir_get` -- Get directory contents (file listing) from a repository
|
||||
- `gitea_file_create_or_update` -- Create or update a file in a repository
|
||||
- `gitea_file_delete` -- Delete a file from a repository
|
||||
- `gitea_tree_get` -- Get the git tree for a repository (recursive file listing)
|
||||
|
||||
#### Branches (4 tools)
|
||||
- `gitea_branches_list` -- List branches in a repository
|
||||
- `gitea_branch_get` -- Get a specific branch
|
||||
- `gitea_branch_create` -- Create a new branch
|
||||
- `gitea_branch_delete` -- Delete a branch
|
||||
|
||||
#### Commits (2 tools)
|
||||
- `gitea_commits_list` -- List commits in a repository
|
||||
- `gitea_commit_get` -- Get a specific commit
|
||||
|
||||
#### Issues (7 tools)
|
||||
- `gitea_issues_list` -- List issues in a repository
|
||||
- `gitea_issue_get` -- Get a single issue by number
|
||||
- `gitea_issue_create` -- Create a new issue
|
||||
- `gitea_issue_update` -- Update an issue
|
||||
- `gitea_issue_comments_list` -- List comments on an issue
|
||||
- `gitea_issue_comment_create` -- Add a comment to an issue
|
||||
- `gitea_issue_search` -- Search issues across all repositories
|
||||
|
||||
#### Labels (2 tools)
|
||||
- `gitea_labels_list` -- List labels in a repository
|
||||
- `gitea_label_create` -- Create a label
|
||||
|
||||
#### Milestones (2 tools)
|
||||
- `gitea_milestones_list` -- List milestones in a repository
|
||||
- `gitea_milestone_create` -- Create a milestone
|
||||
|
||||
#### Pull Requests (6 tools)
|
||||
- `gitea_pulls_list` -- List pull requests
|
||||
- `gitea_pull_get` -- Get a single pull request
|
||||
- `gitea_pull_create` -- Create a pull request
|
||||
- `gitea_pull_merge` -- Merge a pull request
|
||||
- `gitea_pull_files` -- List files changed in a pull request
|
||||
- `gitea_pull_review_create` -- Create a pull request review
|
||||
|
||||
#### Releases (5 tools)
|
||||
- `gitea_releases_list` -- List releases
|
||||
- `gitea_release_get` -- Get a single release by ID
|
||||
- `gitea_release_latest` -- Get the latest release
|
||||
- `gitea_release_create` -- Create a new release
|
||||
- `gitea_release_delete` -- Delete a release
|
||||
|
||||
#### Tags (3 tools)
|
||||
- `gitea_tags_list` -- List tags
|
||||
- `gitea_tag_create` -- Create a tag
|
||||
- `gitea_tag_delete` -- Delete a tag
|
||||
|
||||
#### Actions (2 tools)
|
||||
- `gitea_actions_runs_list` -- List workflow runs for a repository
|
||||
- `gitea_actions_run_get` -- Get a specific workflow run
|
||||
|
||||
#### Organizations (3 tools)
|
||||
- `gitea_org_get` -- Get organization details
|
||||
- `gitea_org_teams_list` -- List teams in an organization
|
||||
- `gitea_org_members_list` -- List members of an organization
|
||||
|
||||
#### Users (2 tools)
|
||||
- `gitea_user_get` -- Get a user profile
|
||||
- `gitea_users_search` -- Search users
|
||||
|
||||
#### Webhooks (2 tools)
|
||||
- `gitea_webhooks_list` -- List webhooks for a repository
|
||||
- `gitea_webhook_create` -- Create a webhook
|
||||
|
||||
#### Wiki (2 tools)
|
||||
- `gitea_wiki_pages_list` -- List wiki pages
|
||||
- `gitea_wiki_page_get` -- Get a wiki page
|
||||
|
||||
#### Notifications (2 tools)
|
||||
- `gitea_notifications_list` -- List notifications for the authenticated user
|
||||
- `gitea_notifications_read` -- Mark all notifications as read
|
||||
|
||||
#### Generic (2 tools)
|
||||
- `gitea_api_request` -- Make a raw API request to any Gitea v1 endpoint
|
||||
- `gitea_list_connections` -- List configured Gitea connections
|
||||
|
||||
### Infrastructure
|
||||
- Multi-connection config support via `~/.gitea-api-mcp.json`
|
||||
- Token-based authentication (Gitea native `Authorization: token` header)
|
||||
- Built on `node:https` / `node:http` (zero HTTP dependencies)
|
||||
- MCP SDK v1.12.x with stdio transport
|
||||
|
||||
[0.0.1]: https://git.mokoconsulting.tech/MokoConsulting/gitea-api-mcp/releases/tag/v0.0.1
|
||||
@@ -0,0 +1,286 @@
|
||||
<!-- Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
DEFGROUP: gitea-api-mcp.Documentation
|
||||
REPO: https://git.mokoconsulting.tech/MokoConsulting/gitea-api-mcp
|
||||
-->
|
||||
|
||||
# gitea-api-mcp
|
||||
|
||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||
[](https://modelcontextprotocol.io)
|
||||
[](https://nodejs.org)
|
||||
[](https://www.typescriptlang.org)
|
||||
|
||||
> MCP server for Gitea REST API v1 operations -- 61 tools for complete Gitea instance management from Claude Code and other MCP clients.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Background](#background)
|
||||
- [Install](#install)
|
||||
- [Configuration](#configuration)
|
||||
- [Usage](#usage)
|
||||
- [Tools](#tools)
|
||||
- [Contributing](#contributing)
|
||||
- [License](#license)
|
||||
- [Revision History](#revision-history)
|
||||
|
||||
## Background
|
||||
|
||||
`gitea-api-mcp` is a Model Context Protocol (MCP) server that exposes 61 tools for interacting with the Gitea REST API v1. It supports multiple named connections, allowing you to manage several Gitea instances from a single server. Authentication uses Gitea's native `Authorization: token` header format.
|
||||
|
||||
## Install
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Node.js >= 20.0.0
|
||||
- A Gitea instance with API access
|
||||
- A Gitea access token (Settings > Applications > Generate Token)
|
||||
|
||||
### Build from Source
|
||||
|
||||
```bash
|
||||
git clone https://git.mokoconsulting.tech/MokoConsulting/gitea-api-mcp.git
|
||||
cd gitea-api-mcp
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Create `~/.gitea-api-mcp.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"defaultConnection": "moko",
|
||||
"connections": {
|
||||
"moko": {
|
||||
"baseUrl": "https://git.mokoconsulting.tech",
|
||||
"token": "your-gitea-access-token",
|
||||
"insecure": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Config Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `baseUrl` | string | Yes | Base URL of your Gitea instance |
|
||||
| `token` | string | Yes | Gitea API access token |
|
||||
| `insecure` | boolean | No | Skip TLS verification (self-signed certs) |
|
||||
|
||||
Override the config path with the `GITEA_API_MCP_CONFIG` environment variable.
|
||||
|
||||
### Multi-Connection Example
|
||||
|
||||
```json
|
||||
{
|
||||
"defaultConnection": "moko",
|
||||
"connections": {
|
||||
"moko": {
|
||||
"baseUrl": "https://git.mokoconsulting.tech",
|
||||
"token": "token-for-moko-gitea"
|
||||
},
|
||||
"github-mirror": {
|
||||
"baseUrl": "https://gitea.example.com",
|
||||
"token": "token-for-mirror"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Claude Code Registration
|
||||
|
||||
Add to your Claude Code MCP config (`~/.claude/claude_desktop_config.json` or project-level `.mcp.json`):
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"gitea-moko": {
|
||||
"command": "node",
|
||||
"args": ["/path/to/gitea-api-mcp/dist/index.js"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Multi-Connection Usage in Claude Code
|
||||
|
||||
When using multiple connections, pass the `connection` parameter to any tool:
|
||||
|
||||
```
|
||||
Use gitea_repo_get with connection "github-mirror" to get owner/repo details.
|
||||
```
|
||||
|
||||
If `connection` is omitted, the `defaultConnection` is used.
|
||||
|
||||
## Tools
|
||||
|
||||
### User / Auth (3 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_me` | Get the authenticated user info |
|
||||
| `gitea_user_orgs` | List organizations the authenticated user belongs to |
|
||||
| `gitea_user_repos` | List repositories owned by the authenticated user |
|
||||
|
||||
### Repositories (8 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_repo_get` | Get repository details |
|
||||
| `gitea_repo_create` | Create a new repository |
|
||||
| `gitea_repo_delete` | Delete a repository |
|
||||
| `gitea_repo_edit` | Edit repository settings |
|
||||
| `gitea_repo_fork` | Fork a repository |
|
||||
| `gitea_repo_search` | Search repositories |
|
||||
| `gitea_org_repos` | List repositories in an organization |
|
||||
| `gitea_list_connections` | List configured Gitea connections |
|
||||
|
||||
### File Contents (5 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_file_get` | Get file contents from a repository |
|
||||
| `gitea_dir_get` | Get directory contents (file listing) from a repository |
|
||||
| `gitea_file_create_or_update` | Create or update a file in a repository |
|
||||
| `gitea_file_delete` | Delete a file from a repository |
|
||||
| `gitea_tree_get` | Get the git tree for a repository (recursive file listing) |
|
||||
|
||||
### Branches (4 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_branches_list` | List branches in a repository |
|
||||
| `gitea_branch_get` | Get a specific branch |
|
||||
| `gitea_branch_create` | Create a new branch |
|
||||
| `gitea_branch_delete` | Delete a branch |
|
||||
|
||||
### Commits (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_commits_list` | List commits in a repository |
|
||||
| `gitea_commit_get` | Get a specific commit |
|
||||
|
||||
### Issues (7 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_issues_list` | List issues in a repository |
|
||||
| `gitea_issue_get` | Get a single issue by number |
|
||||
| `gitea_issue_create` | Create a new issue |
|
||||
| `gitea_issue_update` | Update an issue |
|
||||
| `gitea_issue_comments_list` | List comments on an issue |
|
||||
| `gitea_issue_comment_create` | Add a comment to an issue |
|
||||
| `gitea_issue_search` | Search issues across all repositories |
|
||||
|
||||
### Labels (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_labels_list` | List labels in a repository |
|
||||
| `gitea_label_create` | Create a label |
|
||||
|
||||
### Milestones (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_milestones_list` | List milestones in a repository |
|
||||
| `gitea_milestone_create` | Create a milestone |
|
||||
|
||||
### Pull Requests (6 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_pulls_list` | List pull requests |
|
||||
| `gitea_pull_get` | Get a single pull request |
|
||||
| `gitea_pull_create` | Create a pull request |
|
||||
| `gitea_pull_merge` | Merge a pull request |
|
||||
| `gitea_pull_files` | List files changed in a pull request |
|
||||
| `gitea_pull_review_create` | Create a pull request review |
|
||||
|
||||
### Releases (5 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_releases_list` | List releases |
|
||||
| `gitea_release_get` | Get a single release by ID |
|
||||
| `gitea_release_latest` | Get the latest release |
|
||||
| `gitea_release_create` | Create a new release |
|
||||
| `gitea_release_delete` | Delete a release |
|
||||
|
||||
### Tags (3 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_tags_list` | List tags |
|
||||
| `gitea_tag_create` | Create a tag |
|
||||
| `gitea_tag_delete` | Delete a tag |
|
||||
|
||||
### Actions (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_actions_runs_list` | List workflow runs for a repository |
|
||||
| `gitea_actions_run_get` | Get a specific workflow run |
|
||||
|
||||
### Organizations (3 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_org_get` | Get organization details |
|
||||
| `gitea_org_teams_list` | List teams in an organization |
|
||||
| `gitea_org_members_list` | List members of an organization |
|
||||
|
||||
### Users (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_user_get` | Get a user profile |
|
||||
| `gitea_users_search` | Search users |
|
||||
|
||||
### Webhooks (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_webhooks_list` | List webhooks for a repository |
|
||||
| `gitea_webhook_create` | Create a webhook |
|
||||
|
||||
### Wiki (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_wiki_pages_list` | List wiki pages |
|
||||
| `gitea_wiki_page_get` | Get a wiki page |
|
||||
|
||||
### Notifications (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_notifications_list` | List notifications for the authenticated user |
|
||||
| `gitea_notifications_read` | Mark all notifications as read |
|
||||
|
||||
### Generic (2 tools)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `gitea_api_request` | Make a raw API request to any Gitea v1 endpoint |
|
||||
| `gitea_list_connections` | List configured Gitea connections |
|
||||
|
||||
## Contributing
|
||||
|
||||
See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines.
|
||||
|
||||
## License
|
||||
|
||||
[GPL-3.0-or-later](https://www.gnu.org/licenses/gpl-3.0.html) -- Copyright (C) 2026 Moko Consulting
|
||||
|
||||
## Revision History
|
||||
|
||||
| Version | Date | Description |
|
||||
|---------|------|-------------|
|
||||
| 0.0.1 | 2026-05-07 | Initial release with 61 tools |
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"defaultConnection": "moko",
|
||||
"connections": {
|
||||
"moko": {
|
||||
"baseUrl": "https://git.mokoconsulting.tech",
|
||||
"token": "your-gitea-access-token"
|
||||
},
|
||||
"github-mirror": {
|
||||
"baseUrl": "https://gitea.example.com",
|
||||
"token": "your-other-token"
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+1198
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@mokoconsulting/mcp-mokogitea-api",
|
||||
"version": "1.0.0",
|
||||
"description": "MCP server for Gitea REST API v1 operations",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
"mokogitea-api-mcp": "dist/index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsc --watch",
|
||||
"start": "node dist/index.js",
|
||||
"setup": "node scripts/setup.mjs",
|
||||
"clean": "rm -rf dist/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/sdk": "^1.12.1",
|
||||
"zod": "^3.24.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.15.3",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"license": "GPL-3.0-or-later",
|
||||
"author": "Moko Consulting <hello@mokoconsulting.tech>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.mokoconsulting.tech/MokoConsulting/gitea-api-mcp.git"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# mcp_mokogitea_api PowerShell Profile
|
||||
# Source this with: . ./profile.ps1
|
||||
|
||||
$env:MCP_ROOT = $PSScriptRoot
|
||||
$env:TEMP = 'A:\temp'
|
||||
$env:TMP = 'A:\temp'
|
||||
|
||||
function mcp { Set-Location $PSScriptRoot }
|
||||
function mcp-src { Set-Location (Join-Path $PSScriptRoot 'src') }
|
||||
function mcp-build { Set-Location $PSScriptRoot; npm run build }
|
||||
function mcp-dev { Set-Location $PSScriptRoot; npm run dev }
|
||||
|
||||
Write-Host "mcp_mokogitea_api profile loaded" -ForegroundColor Cyan
|
||||
Write-Host " Commands: mcp-build, mcp-dev" -ForegroundColor DarkGray
|
||||
Write-Host " Navigate: mcp, mcp-src" -ForegroundColor DarkGray
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* BRIEF: Interactive setup — prompts for Gitea connection details
|
||||
*/
|
||||
import { createInterface } from 'node:readline/promises';
|
||||
import { readFile, writeFile } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
import { homedir } from 'node:os';
|
||||
|
||||
const CONFIG_PATH = resolve(homedir(), '.gitea-api-mcp.json');
|
||||
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
||||
|
||||
async function prompt(q, d) { const a = await rl.question(`${q}${d ? ` [${d}]` : ''}: `); return a.trim() || d || ''; }
|
||||
async function promptRequired(q) { let a = ''; while (!a) { a = (await rl.question(`${q}: `)).trim(); if (!a) console.log(' Required.'); } return a; }
|
||||
|
||||
async function main() {
|
||||
console.log('\n=== gitea-api-mcp Setup ===\n');
|
||||
let existing = null;
|
||||
try { existing = JSON.parse(await readFile(CONFIG_PATH, 'utf-8')); console.log(`Existing: ${Object.keys(existing.connections).join(', ')}\n`); } catch {}
|
||||
|
||||
const name = await prompt('Connection name', 'moko');
|
||||
const baseUrl = await promptRequired('Gitea URL (e.g. https://git.mokoconsulting.tech)');
|
||||
const token = await promptRequired('Access token (Settings > Applications > Generate Token)');
|
||||
const insecure = (await prompt('Skip TLS verification? (y/N)', 'N')).toLowerCase() === 'y';
|
||||
|
||||
const conn = { baseUrl: baseUrl.replace(/\/+$/, ''), token };
|
||||
if (insecure) conn.insecure = true;
|
||||
|
||||
const config = existing ?? { defaultConnection: name, connections: {} };
|
||||
config.connections[name] = conn;
|
||||
if (!existing) config.defaultConnection = name;
|
||||
else if ((await prompt(`Set "${name}" as default? (y/N)`, 'N')).toLowerCase() === 'y') config.defaultConnection = name;
|
||||
|
||||
await writeFile(CONFIG_PATH, JSON.stringify(config, null, '\t') + '\n', 'utf-8');
|
||||
console.log(`\nConfig written to ${CONFIG_PATH}\n`);
|
||||
rl.close();
|
||||
}
|
||||
|
||||
main().catch(e => { console.error(e.message); rl.close(); process.exit(1); });
|
||||
@@ -0,0 +1,120 @@
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* This file is part of a Moko Consulting project.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: gitea-api-mcp.Client
|
||||
* INGROUP: gitea-api-mcp
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/gitea-api-mcp
|
||||
* PATH: /src/client.ts
|
||||
* VERSION: 01.00.00
|
||||
* BRIEF: HTTP client for Gitea REST API v1
|
||||
*/
|
||||
|
||||
import * as https from 'node:https';
|
||||
import * as http from 'node:http';
|
||||
import type { GiteaConnection, ApiResponse } from './types.js';
|
||||
|
||||
const API_PREFIX = '/api/v1';
|
||||
const TIMEOUT_MS = 30_000;
|
||||
|
||||
export class GiteaClient {
|
||||
private readonly base_url: string;
|
||||
private readonly headers: Record<string, string>;
|
||||
private readonly insecure: boolean;
|
||||
|
||||
constructor(conn: GiteaConnection) {
|
||||
this.base_url = conn.baseUrl.replace(/\/+$/, '') + API_PREFIX;
|
||||
this.headers = {
|
||||
'Authorization': `token ${conn.token}`,
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
};
|
||||
this.insecure = conn.insecure ?? false;
|
||||
}
|
||||
|
||||
async get(endpoint: string, params?: Record<string, string>): Promise<ApiResponse> {
|
||||
return this.request(this.buildUrl(endpoint, params), 'GET');
|
||||
}
|
||||
|
||||
async post(endpoint: string, body?: unknown): Promise<ApiResponse> {
|
||||
return this.request(this.buildUrl(endpoint), 'POST', body);
|
||||
}
|
||||
|
||||
async patch(endpoint: string, body: unknown): Promise<ApiResponse> {
|
||||
return this.request(this.buildUrl(endpoint), 'PATCH', body);
|
||||
}
|
||||
|
||||
async put(endpoint: string, body: unknown): Promise<ApiResponse> {
|
||||
return this.request(this.buildUrl(endpoint), 'PUT', body);
|
||||
}
|
||||
|
||||
async delete(endpoint: string): Promise<ApiResponse> {
|
||||
return this.request(this.buildUrl(endpoint), 'DELETE');
|
||||
}
|
||||
|
||||
private buildUrl(endpoint: string, params?: Record<string, string>): string {
|
||||
const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
||||
const url = new URL(`${this.base_url}${path}`);
|
||||
if (params) {
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
url.searchParams.set(key, value);
|
||||
}
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
private request(url: string, method: string, body?: unknown): Promise<ApiResponse> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const parsed = new URL(url);
|
||||
const is_https = parsed.protocol === 'https:';
|
||||
const transport = is_https ? https : http;
|
||||
|
||||
const options: https.RequestOptions = {
|
||||
hostname: parsed.hostname,
|
||||
port: parsed.port || (is_https ? 443 : 80),
|
||||
path: parsed.pathname + parsed.search,
|
||||
method,
|
||||
headers: { ...this.headers },
|
||||
timeout: TIMEOUT_MS,
|
||||
};
|
||||
|
||||
if (this.insecure && is_https) {
|
||||
options.rejectUnauthorized = false;
|
||||
}
|
||||
|
||||
const payload = body !== undefined ? JSON.stringify(body) : undefined;
|
||||
if (payload) {
|
||||
(options.headers as Record<string, string>)['Content-Length'] = Buffer.byteLength(payload).toString();
|
||||
}
|
||||
|
||||
const req = transport.request(options, (res) => {
|
||||
const chunks: Buffer[] = [];
|
||||
res.on('data', (chunk: Buffer) => chunks.push(chunk));
|
||||
res.on('end', () => {
|
||||
const raw = Buffer.concat(chunks).toString('utf-8');
|
||||
let data: unknown;
|
||||
try {
|
||||
data = JSON.parse(raw);
|
||||
} catch {
|
||||
data = raw;
|
||||
}
|
||||
resolve({ status: res.statusCode ?? 0, data });
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (err) => reject(err));
|
||||
req.on('timeout', () => {
|
||||
req.destroy();
|
||||
reject(new Error('Request timed out'));
|
||||
});
|
||||
|
||||
if (payload) {
|
||||
req.write(payload);
|
||||
}
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* This file is part of a Moko Consulting project.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: gitea-api-mcp.Config
|
||||
* INGROUP: gitea-api-mcp
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/gitea-api-mcp
|
||||
* PATH: /src/config.ts
|
||||
* VERSION: 01.00.00
|
||||
* BRIEF: Configuration loader for Gitea API MCP connections
|
||||
*/
|
||||
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
import { homedir } from 'node:os';
|
||||
import type { GiteaConfig, GiteaConnection } from './types.js';
|
||||
|
||||
const CONFIG_FILENAME = '.mcp_mokogitea.json';
|
||||
|
||||
export async function loadConfig(): Promise<GiteaConfig> {
|
||||
const config_path = process.env.GITEA_API_MCP_CONFIG
|
||||
? resolve(process.env.GITEA_API_MCP_CONFIG)
|
||||
: resolve(homedir(), CONFIG_FILENAME);
|
||||
|
||||
try {
|
||||
const raw = await readFile(config_path, 'utf-8');
|
||||
const parsed = JSON.parse(raw) as Partial<GiteaConfig>;
|
||||
|
||||
if (!parsed.connections || Object.keys(parsed.connections).length === 0) {
|
||||
throw new Error('No connections defined in config');
|
||||
}
|
||||
|
||||
return {
|
||||
connections: parsed.connections,
|
||||
defaultConnection: parsed.defaultConnection ?? Object.keys(parsed.connections)[0],
|
||||
};
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
throw new Error(
|
||||
`Failed to load config from ${config_path}: ${message}\n` +
|
||||
`Create ${config_path} — see config.example.json for format.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function getConnection(config: GiteaConfig, name?: string): GiteaConnection {
|
||||
const key = name ?? config.defaultConnection;
|
||||
const conn = config.connections[key];
|
||||
if (!conn) {
|
||||
throw new Error(
|
||||
`Connection "${key}" not found. Available: ${Object.keys(config.connections).join(', ')}`,
|
||||
);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* This file is part of a Moko Consulting project.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: gitea-api-mcp.Types
|
||||
* INGROUP: gitea-api-mcp
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/gitea-api-mcp
|
||||
* PATH: /src/types.ts
|
||||
* VERSION: 01.00.00
|
||||
* BRIEF: TypeScript type definitions for Gitea API MCP server
|
||||
*/
|
||||
|
||||
export interface GiteaConnection {
|
||||
baseUrl: string;
|
||||
token: string;
|
||||
/** Skip TLS certificate verification (self-signed certs) */
|
||||
insecure?: boolean;
|
||||
}
|
||||
|
||||
export interface GitHubBackupConfig {
|
||||
token: string;
|
||||
org: string;
|
||||
}
|
||||
|
||||
export interface GiteaConfig {
|
||||
connections: Record<string, GiteaConnection>;
|
||||
defaultConnection: string;
|
||||
github?: GitHubBackupConfig;
|
||||
}
|
||||
|
||||
export interface ApiResponse {
|
||||
status: number;
|
||||
data: unknown;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "Node16",
|
||||
"moduleResolution": "Node16",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user