From c16f82ea38cb358cc54819576065a3a3fbdd57ec Mon Sep 17 00:00:00 2001 From: Steve White Date: Mon, 6 Jan 2025 16:34:57 -0600 Subject: [PATCH] Make Gitea URL configurable and update documentation --- .env.example | 3 ++ README.md | 100 +++++++++++++++++++++++++-------------------------- src/index.ts | 6 +++- 3 files changed, 58 insertions(+), 51 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7888cd0 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +# Gitea Configuration +GITEA_API_URL=https://gitea.r8z.us/api/v1 +GITEA_TOKEN=your_token_here diff --git a/README.md b/README.md index d566dfd..f997720 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,70 @@ -# gitea-server MCP Server +# Gitea MCP Server -"An MCP server providing access to gitea.r8z.us" +An MCP server that provides tools for interacting with the Gitea API. -This is a TypeScript-based MCP server that implements a simple notes system. It demonstrates core MCP concepts by providing: +## Setup -- Resources representing text notes with URIs and metadata -- Tools for creating new notes -- Prompts for generating summaries of notes +1. Clone the repository +2. Install dependencies: + ```bash + npm install + ``` +3. Copy the example environment file: + ```bash + cp .env.example .env + ``` +4. Configure your environment variables in `.env`: + - `GITEA_API_URL`: Your Gitea API URL (e.g., https://gitea.example.com/api/v1) + - `GITEA_TOKEN`: Your Gitea API token -## Features +## Building -### Resources -- List and access notes via `note://` URIs -- Each note has a title, content and metadata -- Plain text mime type for simple content access - -### Tools -- `create_note` - Create new text notes - - Takes title and content as required parameters - - Stores note in server state - -### Prompts -- `summarize_notes` - Generate a summary of all stored notes - - Includes all note contents as embedded resources - - Returns structured prompt for LLM summarization - -## Development - -Install dependencies: -```bash -npm install -``` - -Build the server: ```bash npm run build ``` -For development with auto-rebuild: -```bash -npm run watch -``` +## Available Tools -## Installation +- `list_repositories`: List repositories for the authenticated user +- `get_repository`: Get details about a specific repository +- `list_issues`: List issues in a repository +- `create_issue`: Create a new issue in a repository +- `list_pull_requests`: List pull requests in a repository +- `create_repository`: Create a new repository +- `get_contents`: Get contents of a file or directory in a repository +- `add_file_to_repo`: Add a new file to a repository +- `create_branch`: Create a new branch in a repository -To use with Claude Desktop, add the server config: +## Tool Usage Examples -On MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json` -On Windows: `%APPDATA%/Claude/claude_desktop_config.json` +### Adding a File to a Repository -```json +```typescript { - "mcpServers": { - "gitea-server": { - "command": "/path/to/gitea-server/build/index.js" - } - } + "owner": "username", + "repo": "repository-name", + "path": "path/to/file.txt", + "content": "File content here", // or use file_text + "message": "Commit message", + "branch": "main" // optional } ``` -### Debugging +### Creating a Repository -Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector), which is available as a package script: - -```bash -npm run inspector +```typescript +{ + "name": "repository-name", + "description": "Repository description", + "private": false, + "autoInit": true +} ``` -The Inspector will provide a URL to access debugging tools in your browser. +## Error Handling + +The server will throw appropriate errors if: +- Required environment variables are missing +- API requests fail +- Invalid parameters are provided +- Tool names are incorrect diff --git a/src/index.ts b/src/index.ts index 9bf377a..671f7f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,10 +53,14 @@ interface PullRequestArgs extends RepoArgs { } const GITEA_TOKEN = process.env.GITEA_TOKEN; +const GITEA_API_URL = process.env.GITEA_API_URL; + if (!GITEA_TOKEN) { throw new Error('GITEA_TOKEN environment variable is required'); } -const GITEA_API_URL = 'https://gitea.r8z.us/api/v1'; +if (!GITEA_API_URL) { + throw new Error('GITEA_API_URL environment variable is required'); +} class GiteaServer { private server: Server;