feat: initial Gitea MCP server with 30 tools

Covers repos, commits, branches, tags, releases, PRs, issues, comments,
labels, milestones, notifications, orgs, and CI status. Stdio transport,
token auth, same architecture as OpenProject MCP server.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-25 15:56:28 +08:00
commit 06480d5503
10 changed files with 2463 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env node
/**
* Gitea MCP Server
*
* Connects Claude to Gitea via the v1 REST API.
*
* Environment variables:
* GITEA_URL — Base URL of your Gitea instance (e.g. https://gitea.example.com)
* GITEA_TOKEN — API token (generated under Settings > Applications > Access Tokens)
*/
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { GiteaClient } from "./client.js";
import { toolDefs } from "./tools.js";
import { createHandlers } from "./handlers.js";
function getEnvOrThrow(name: string): string {
const value = process.env[name];
if (!value) {
console.error(`Missing required environment variable: ${name}`);
process.exit(1);
}
return value;
}
const client = new GiteaClient({
baseUrl: getEnvOrThrow("GITEA_URL"),
token: getEnvOrThrow("GITEA_TOKEN"),
});
const handlers = createHandlers(client);
const server = new McpServer({
name: "gitea",
version: "0.1.0",
});
// Register each tool from toolDefs with its corresponding handler.
for (const [name, def] of Object.entries(toolDefs)) {
const handler = handlers[name as keyof typeof handlers];
if (!handler) {
console.error(`No handler for tool: ${name}`);
continue;
}
server.tool(
name,
def.description,
def.inputSchema,
async (args: any) => {
try {
const result = await (handler as Function)(args);
return { content: [{ type: "text" as const, text: String(result) }] };
} catch (err: any) {
return {
content: [{ type: "text" as const, text: `Error: ${err.message}` }],
isError: true,
};
}
},
);
}
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("Gitea MCP server running on stdio");
}
main().catch((err) => {
console.error("Fatal error:", err);
process.exit(1);
});