115driver

repository·main·Indexed 41 days ago

https://github.com/sheltonzhu/115driver

A Go-based toolkit for interacting with 115.com cloud storage. It includes a high-level driver library for programmatic integration, a feature-rich CLI for file management and offline tasks, and an MCP server for AI agent integration with tools for account, directory, and file operations.

Tokens
11.5K
Snippets
52
Records
65
Agent score
49%

What's inside 115driver

  1. Understand the 115driver project structure

    main

    The project is organized into several key directories depending on how you intend to use it:

    • cmd/115driver/: The CLI entry point. Use this if you want to install the binary via go install.
    • pkg/driver/: The core driver package. This contains the primary logic for the client, login, file management (upload/download), search, sharing, and offline operations. Use this for programmatic integration.
    • pkg/crypto/: Cryptography utilities including ECDH, AES, and RSA.
    • mcp/: An MCP (Model Context Protocol) server implementation using stdin/stdout JSON-RPC 2.0. It provides tools for account, directory, file, search, offline, share, and recycle operations.
    • cli/: The implementation of the command-line interface using Cobra.
  2. Enable Destructive Tools

    main

    By default, tools that mutate the 115 cloud state (e.g., deleting, renaming, moving, or uploading files) are not registered. To enable these capabilities, you must start the server with the --allow-destructive-tools flag.

    Enabled mutations include:

    • Directory creation (mkdir)
    • File rename, move, copy, and delete
    • Cloud uploads
    • Recycle bin mutations
    • Offline task mutations
    ./mcp-server --cookie="UID=..." --allow-destructive-tools
  3. Initialize a 115driver client in Go

    main

    To start using the driver, you must first create credentials and then initialize a client. You can create credentials from a cookie string or manually by providing the UID, CID, SEID, and KID.

    package main
    
    import (
        "github.com/SheltonZhu/115driver/pkg/driver"
        "log"
    )
    
    func main() {
        // Option 1: Import credentials from cookie string
        cr, err := driver.CredentialFromCookie("your_cookie_string")
        if err != nil {
            log.Fatalf("Failed to create credential: %v", err)
        }
    
        // Create client with credentials
        client := driver.Default().ImportCredential(cr)
    
        // Check login status
        if err := client.LoginCheck(); err != nil {
            log.Fatalf("Login failed: %v", err)
        }
    
        log.Println("Successfully logged in!")
    }
    package main
    
    import (
        "github.com/SheltonZhu/115driver/pkg/driver"
        "log"
    )
    
    func main() {
        cr, err := driver.CredentialFromCookie("your_cookie_string")
        if err != nil {
            log.Fatalf("Failed to create credential: %v", err)
        }
    
        client := driver.Default().ImportCredential(cr)
    
        if err := client.LoginCheck(); err != nil {
            log.Fatalf("Login failed: %v", err)
        }
    
        log.Println("Successfully logged in!")
    }
  4. Build and Start the 115driver MCP Server

    main

    To use the 115driver MCP server, you must first build it using Go and then run it with your 115 cloud authentication cookies. The server communicates via stdin/stdout following the Model Context Protocol (MCP).

    Build

    go build -o mcp-server mcp/main.go

    Run with Authentication

    You must provide your 115 cookies using the --cookie flag. The required format is a semicolon-separated string of UID, CID, and SEID.

    ./mcp-server --cookie="UID=your_uid;CID=your_cid;SEID=your_seid"
    go build -o mcp-server mcp/main.go
    ./mcp-server --cookie="UID=your_uid;CID=your_cid;SEID=your_seid"
  5. Configure Local File Access and Timeouts

    main

    The MCP server includes several security and performance configuration flags:

    • Local File Access: By default, local file access is disabled. To allow download_file to write to your machine or upload_from_local to read from it, you must specify a --local-root. Tools are restricted to paths under this directory.
    • Download Timeout: MCP HTTP transfers have a default 2-hour timeout. Use --download-timeout to change this (e.g., 6h) or --download-timeout=0 to disable it.
    • Size Limits:
      • Use --download-max-bytes to set a limit for download_file (default is unlimited).
      • Use --url-upload-max-bytes to set a limit for upload_from_url (default is 2 GiB).
      • Setting either to 0 disables the limit.
    # Example with local root and custom timeout
    ./mcp-server --cookie="UID=..." --local-root="/safe/path" --download-timeout=6h
  6. Authenticate with the 115driver CLI

    main

    The CLI supports interactive QR code login and cookie-based login. Credentials are stored in ~/.115driver/config.toml.

    QR code login (interactive):

    115driver login

    Cookie login:

    115driver login --cookie "UID=xxx;CID=xxx;SEID=xxx;KID=xxx"

    Authentication Priority:

    1. --cookie flag
    2. DRIVER115_COOKIE environment variable
    3. Config file (~/.115driver/config.toml)

    Environment Variables:

    • DRIVER115_CONFIG: Path to config file
    • DRIVER115_PROFILE: Profile name to use
  7. Install and use the 115driver MCP Server

    main

    The Model Context Protocol (MCP) server allows AI applications like Claude Desktop or Cursor to interact with your 115 cloud storage.

    Installation (via go install):

    go install github.com/SheltonZhu/115driver/mcp@latest

    Running the server:

    # Basic usage
    mcp --cookie="UID=xxx;CID=xxx;SEID=xxx;KID=xxx"
    
    # With custom download timeout and transfer limits
    ./115driver-mcp-server --cookie="UID=xxx;CID=xxx;SEID=xxx;KID=xxx" --download-timeout=6h --download-max-bytes=0 --url-upload-max-bytes=10737418240

    Enabling destructive tools: By default, the server is read-only (except for download_file). To allow tools that mutate state (mkdir, delete, rename, move, copy, upload, offline tasks, recycle bin), you must include the --allow-destructive-tools flag.

    Claude Desktop Configuration: Add the following to your claude_desktop_config.json:

    {
      "mcpServers": {
        "115driver": {
          "command": "mcp",
          "args": ["--cookie=UID=xxx;CID=xxx;SEID=xxx;KID=xxx"]
        }
      }
    }
  8. Manage Authentication Profiles and Config Files

    main

    115driver uses a TOML configuration file to manage multiple authentication profiles. By default, the configuration is stored in ~/.115driver/config.toml.

    Configuration Structure

    The configuration file follows this schema:

    default_profile = "main"
    
    [profiles.main]
    cookie = "YOUR_COOKIE_HERE"
    
    [profiles.work]
    cookie = "ANOTHER_COOKIE_HERE"

    Credential Resolution Order

    When the CLI attempts to authenticate, it resolves credentials in the following priority:

    1. Command-line flag: If a cookie is passed directly via a flag.
    2. Environment Variable: The DRIVER115_COOKIE variable.
    3. Config File: The cookie associated with the active profile in the configuration file.

    If no credentials are found, the CLI will suggest running 115driver login to authenticate.

  9. How the empty User-Agent workaround works

    main

    The Pan115Client implements a specific workaround to allow sending HTTP requests with a completely empty User-Agent header. This is required because the underlying resty library automatically injects a default User-Agent if it detects an empty string.

    The mechanism:

    1. Sentinel Injection: When a request is initiated with an empty User-Agent, the client replaces it with a non-empty internal marker (\x00__EMPTY_UA__).
    2. Pre-Request Stripping: Just before the bytes are sent over the wire, a hook strips the sentinel, resulting in no User-Agent header being sent.
    3. Post-Response Alignment: After the response is received, the client cleans up the request headers so that the internal sentinel does not leak into the resp.Request.Header object used by the developer.
  10. Use Custom Configuration Paths

    main
    If you do not want to use the default configuration directory (~/.115driver/config.toml), you can specify a custom path using the DRIVER115_CONFIG environment variable. This allows you to keep credentials in a specific location or use a different file for different environments.