diff --git a/.claude/bootstrap-version b/.claude/bootstrap-version new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/.claude/bootstrap-version @@ -0,0 +1 @@ +2 diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..2660e12 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,25 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "f=$(cat | python3 -c 'import json,sys; print(json.load(sys.stdin).get(\"tool_input\",{}).get(\"file_path\",\"\"))'); case \"$f\" in *.py) python3 -m py_compile \"$f\" ;; esac" + } + ] + } + ], + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "python3 -m py_compile server.py" + } + ] + } + ] + } +} diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a994a63 --- /dev/null +++ b/.env.example @@ -0,0 +1,8 @@ +# Nextcloud connection (required) +NEXTCLOUD_HOST= +NEXTCLOUD_USERNAME= +NEXTCLOUD_PASSWORD= + +# Server bind address (optional, defaults shown) +BIND_HOST=127.0.0.1 +BIND_PORT=8082 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..19c359c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: + pull_request: + branches: [development] + push: + branches: [development, main] + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + + - name: Install dependencies + run: pip install -r requirements.txt + + # No linter or test suite configured yet; this is a compile-time sanity check. + - name: Compile check + run: python -m py_compile server.py diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..72cd4f3 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,68 @@ +name: Version + +on: + push: + branches: [development, main] + +permissions: + contents: write + +jobs: + bump: + if: ${{ github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, '[skip ci]') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Bump version + id: bump + run: | + set -euo pipefail + current=$(cat VERSION) + IFS='.' read -r major minor patch <<< "$current" + + if [ "${{ github.ref_name }}" = "development" ]; then + patch=$((patch + 1)) + else + # main: a MINOR bump only when every commit in this push came from + # development (i.e. an approved development -> main PR merge); + # anything else pushed straight to main is treated as a hotfix. + parents=$(git log -1 --pretty=%P HEAD | wc -w) + if [ "${{ github.event_name }}" = "push" ] && [ "$parents" -gt 1 ] && \ + git log -1 --pretty=%s HEAD | grep -qiE "merge pull request|from .*/development"; then + minor=$((minor + 1)) + patch=0 + else + patch=$((patch + 1)) + fi + fi + + new_version="$major.$minor.$patch" + echo "$new_version" > VERSION + echo "version=$new_version" >> "$GITHUB_OUTPUT" + + - name: Commit and tag + run: | + git add VERSION + git commit -m "chore(release): v${{ steps.bump.outputs.version }} [skip ci]" + git push origin HEAD:${{ github.ref_name }} + + - name: Merge main back into development + if: ${{ github.ref_name == 'main' }} + run: | + if git ls-remote --exit-code --heads origin development > /dev/null; then + git fetch origin development + git checkout development + git merge --no-edit origin/main + git push origin development + else + echo "No development branch yet; skipping merge-back." + fi diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..876107d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__pycache__/ +*.pyc +.env +.venv/ +venv/ diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..21781d7 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,41 @@ +# CLAUDE.md + +## Overview +MCP server exposing a Nextcloud instance (files, calendars, address books, +Talk) as tools for an MCP-compatible AI agent. Single file: `server.py`. + +## Commands +- Install: `pip install -r requirements.txt` +- Run: `python server.py` (reads `NEXTCLOUD_HOST`, `NEXTCLOUD_USERNAME`, + `NEXTCLOUD_PASSWORD` from the environment; see `.env.example`) +- Test: none yet. +- Lint: none yet. +- Build: none (no packaging step; Nixpacks runs `python server.py` directly, + see `nixpacks.toml`). +- Sanity check: `python -m py_compile server.py` + +## Architecture +See [`docs/architecture.md`](docs/architecture.md). + +## Conventions +- One `@mcp.tool()` function per Nextcloud operation; docstring = tool + description shown to the agent. +- Parsing/formatting helpers are private (`_`-prefixed) and live near the + tools that use them. + +## Workflow quirks +- No `development` branch yet; branch from `main`, PR into `main` directly + until `development` is created. +- No automated tests or linter are configured yet (no pytest/ruff/flake8 in + `requirements.txt`). CI only runs `python -m py_compile server.py` as a + sanity check. + +## Deployment +See [`docs/deployment.md`](docs/deployment.md). Currently deployed via +Nixpacks, not the org's standard LXC/VPS + systemd setup. + +## Gotchas +- `NEXTCLOUD_HOST`, `NEXTCLOUD_USERNAME`, `NEXTCLOUD_PASSWORD` are required + env vars; the process raises `KeyError` on import if any is missing. +- Recurring calendar events are expanded server-side (`c:expand`) in + `list_events`, so each occurrence is a separate item, unlike `get_event`. diff --git a/LESSONS.md b/LESSONS.md new file mode 100644 index 0000000..90cf821 --- /dev/null +++ b/LESSONS.md @@ -0,0 +1,3 @@ +# Lessons + +Recurring mistakes and how to avoid them. Add an entry whenever one repeats. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8aaa9dc --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# ZenvairoCloud-MCP + +MCP server that exposes a Nextcloud instance (files, calendars, address books, +and Talk) as tools for an MCP-compatible AI agent. + +## Quick start + +```bash +pip install -r requirements.txt +cp .env.example .env # fill in NEXTCLOUD_HOST, NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD +python server.py +``` + +See [`docs/architecture.md`](docs/architecture.md) for how it works and +[`docs/deployment.md`](docs/deployment.md) for running it in production. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..1a2f8f3 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,29 @@ +# Architecture + +`server.py` is a single-file MCP server (streamable-http transport, via the +`mcp` package's `MCPServer`) that proxies calls to a Nextcloud instance. + +## Layers + +- **Files**: WebDAV (`PROPFIND`, `GET`, `PUT`, `DELETE`, `MKCOL`, `MOVE`) under + `/remote.php/dav/files/{user}/`, plus the unified search OCS endpoint and + the file-sharing OCS API. +- **Calendars**: CalDAV under `/remote.php/dav/calendars/{user}/`. Events and + tasks (VTODO) are built/parsed with `vobject`. `list_events` uses a + server-side `calendar-query` with `c:expand` so recurring events come back + as individual occurrences. +- **Address books**: CardDAV under `/remote.php/dav/addressbooks/users/{user}/`, + contacts as vCards via `vobject`. +- **Talk**: Nextcloud Talk's OCS Spreed API (`/ocs/v2.php/apps/spreed/api/`) + for listing conversations and reading/sending chat messages. + +All Nextcloud calls use HTTP Basic auth (`NEXTCLOUD_USERNAME` / +`NEXTCLOUD_PASSWORD`) through a short-lived `httpx.Client` per request +(`_client()`). + +## Adding a tool + +Add a function decorated with `@mcp.tool()`; its docstring becomes the tool +description shown to the agent. Keep request/response shaping (XML/vCard/ +iCalendar parsing) in a private helper near the existing `_parse_*` / +`_summarize_*` functions so tools stay thin. diff --git a/docs/deployment.md b/docs/deployment.md new file mode 100644 index 0000000..3848da2 --- /dev/null +++ b/docs/deployment.md @@ -0,0 +1,16 @@ +# Deployment + +The repo currently ships a `nixpacks.toml` (`python server.py`), i.e. it is +built/run through Nixpacks rather than this org's standard LXC/VPS + systemd +setup. + +This does not yet follow the `web-deploy` standard. Missing pieces, if the +deployment target is ever moved to an LXC/VPS: + +- A systemd unit file to run `server.py` as a service. +- An idempotent `scripts/update.sh` (pull, install deps, restart). +- An authenticated HTTP endpoint that triggers the update script (token auth, + single-flight, status, rate limiting). + +Until then, deploy via whatever platform consumes `nixpacks.toml` and set the +environment variables listed in `.env.example`.