Skip to main content

A Model-Context-Protocol (MCP) for saving files to Nextcloud and getting public share links.

Project description

Nextcloud MCP

This project provides a Model-Context-Protocol (MCP) for saving files to a Nextcloud instance and immediately receiving a publicly available share URL.

Features

  • Save & Share: Upload files to a designated Nextcloud folder and automatically generate a public, read-only share link.
  • File and Folder Management: Create and delete files and folders.
  • Configurable: All Nextcloud connection details are configurable via environment variables.
  • Robust: Built with modern Python libraries (httpx, pydantic) and includes error handling.
  • Asynchronous: Uses asyncio for non-blocking I/O operations.

Quickstart

1. Prerequisites

  • Python 3.8+
  • A Nextcloud account with WebDAV access enabled.

2. Installation

Clone the repository and install the required dependencies:

git clone https://github.com/your-username/nextcloud-mcp.git
cd nextcloud-mcp
pip install -e .

3. Configuration

This project uses environment variables for configuration. Create a .env file in the project root and add the following variables:

NEXTCLOUD_INSTANCE_URL="https://your-nextcloud-instance.com"
NEXTCLOUD_USERNAME="your_username"
NEXTCLOUD_PASSWORD="your_password"
# Optional: Specify a folder to save files in.
# If not set, files will be saved in the root directory.
NEXTCLOUD_USAGE_FOLDER="MyUploads"

You can get a secure app password from your Nextcloud account settings under Security > Devices & sessions.

4. Usage

The save_and_share.py script provides a simple example of how to use the library.

python nextcloud_mcp/save_and_share.py

The script will:

  1. Load the configuration from your .env file.
  2. Create a new text file with a timestamp.
  3. Upload the file to your Nextcloud instance.
  4. Print the public share URL to the console.

How It Works

The core logic is in the Ctx class (nextcloud_mcp/context.py), which handles the two main steps:

  1. File Upload: Uses the WebDAV protocol (PUT request) to upload the file to the specified path.
  2. Share Link Creation: Uses the Nextcloud OCS (Open Collaboration Services) API to create a public share link for the uploaded file.

Project Structure

.
├── nextcloud_mcp/
│   ├── __init__.py
│   ├── config.py       # Configuration loading and validation
│   ├── context.py      # Core Ctx class for Nextcloud interaction
│   ├── exceptions.py   # Custom exception classes
│   └── save_and_share.py # Example usage script
├── tests/              # Unit tests
├── .env.example        # Example environment file
├── pyproject.toml      # Project metadata and dependencies
└── README.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nextcloud_mcp-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nextcloud_mcp-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file nextcloud_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: nextcloud_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for nextcloud_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 47337f50a311213e150b641a5b3c38dcdb042c37c467d21723f277031fa34f11
MD5 d32912159a38d20deb5fe196f3665298
BLAKE2b-256 d9f47c648fe6125764a9acc4d2ec33d41fa9ea06d0246c45faab71bb422fc787

See more details on using hashes here.

File details

Details for the file nextcloud_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nextcloud_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for nextcloud_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae575d795fd46060206f365a3b0519b17b4404a12f0b0bcfd14fa4c30824cbc5
MD5 83366f623ab2859080e3068b424031f0
BLAKE2b-256 cc2ad1b19f87910e016245267bd2b6ca8214ad1fa4e945d1f08d53ccdcac7555

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page