|
1 | | -# runware-image |
| 1 | +# runware-mcp |
2 | 2 |
|
3 | 3 | [](https://github.com/GeekLord/) |
4 | 4 | [](https://github.com/GeekLord/OpenClaw_Runware_API) |
5 | | -[](https://www.python.org/) |
| 5 | +[](https://www.python.org/) |
6 | 6 |
|
| 7 | +**Multi-modal Runware.ai skill** — image, video, audio, text, and 3D generation via the official `runware-sdk` Python library, plus MCP-style tooling. |
7 | 8 |
|
8 | | -Runware Image Skill - a small CLI skill to generate images on-demand via the Runware.ai Image Inference API. |
9 | | - |
10 | | -This repository contains an OpenClaw-style skill that provides a Python CLI script to submit text-to-image tasks to Runware, save generated images locally, and includes tests, examples, and CI configuration to make the skill production-ready for publishing to ClawHub (or GitHub first). |
| 9 | +This repository contains an OpenClaw-compatible skill that connects to [Runware.ai's MCP server](https://runware.ai/mcp) and exposes a clean Python CLI for generating media, browsing models, checking pricing, and managing your account. |
11 | 10 |
|
12 | 11 | ## Features |
13 | 12 |
|
14 | | -- Submit text-to-image tasks to Runware's task API (imageInference). |
15 | | -- Default synchronous generation (returns base64 image data) with support for async/webhook workflows. |
16 | | -- Safe-by-default prompt validation to reduce the risk of generating images of minors. |
17 | | -- Default output directory: `~/runware_images` (created automatically). The script remembers the last used output directory. |
18 | | -- Minimal dependencies. Tests can be configured to run in CI with secrets for integration or skipped when no RUNWARE_API_KEY is present. |
| 13 | +- **Multi-modal** — Generate images, videos, audio, text, and 3D models |
| 14 | +- **Official SDK** — Uses `runware-sdk` (async, typed, JSON-Schema validated) |
| 15 | +- **MCP integration** — MCP-style tools (`run`, `list-models`, `model-pricing`, `model-details`, `account`) |
| 16 | +- **Hosted MCP server** — Can connect directly to `https://mcp.runware.ai` (OAuth 2.1, no local install needed) |
| 17 | +- **Sync + async** — Sync delivery for fast tasks, async polling for long-running ones |
| 18 | +- **Safe-by-default** — Lightweight prompt filtering |
| 19 | +- **Configurable** — Default model, size, format via `skill-config.json` |
| 20 | +- **Tested** — Pytest unit tests + optional integration tests |
19 | 21 |
|
20 | | -## Contents |
| 22 | +## Quick Start |
21 | 23 |
|
22 | | -- `SKILL.md` - Skill metadata and usage guidance (required by OpenClaw skills). |
23 | | -- `skill-config.json` - Default settings (no secrets). Contains `default_size`, `default_format`, and `default_output_dir`. |
24 | | -- `scripts/generate_image.py` - Primary CLI script (Python 3.8+). |
25 | | -- `requirements.txt` - Minimal dependencies. |
26 | | -- `tests/test_generate_image.py` - Pytest unit test that mocks Runware responses. |
27 | | -- `examples/` - Example CLI commands. |
28 | | -- `.github/workflows/ci.yml` - GitHub Actions CI workflow to run tests. |
29 | | -- `LICENSE`, `CONTRIBUTING.md` - Project metadata. |
| 24 | +```bash |
| 25 | +# Install dependencies |
| 26 | +pip install -r requirements.txt |
30 | 27 |
|
31 | | -## System Architecture |
| 28 | +# Set your API key |
| 29 | +echo "RUNWARE_API_KEY=your_key_here" > .env |
32 | 30 |
|
33 | | -```mermaid |
34 | | -graph TD |
35 | | - User[User / Terminal] -->|Run| Script[scripts/generate_image.py] |
36 | | - Script -->|Load| Env[.env] |
37 | | - Script -->|Load| Config[skill-config.json] |
38 | | - Script -->|POST /run| Runware[Runware.ai API] |
39 | | - Runware -->|JSON Response| Script |
40 | | - Script -->|Decode & Save| Image[Output Image] |
41 | | -``` |
| 31 | +# Generate an image |
| 32 | +python scripts/generate.py --prompt "A serene mountain landscape" --mode image --outfile landscape.png |
42 | 33 |
|
43 | | -## Quick Start (GitHub) |
| 34 | +# Generate a video |
| 35 | +python scripts/generate.py --prompt "Waves crashing on a beach" --mode video --duration 8 --outfile waves.mp4 |
44 | 36 |
|
45 | | -1. Clone the repository: |
| 37 | +# Browse models via MCP-style CLI |
| 38 | +python scripts/runware_mcp.py list-models --category image --search "flux" |
46 | 39 |
|
47 | | -```bash |
48 | | -git clone <repo-url> |
49 | | -cd runware-image |
| 40 | +# Check account balance |
| 41 | +python scripts/runware_mcp.py account |
50 | 42 | ``` |
51 | 43 |
|
52 | | -2. Create a Python virtual environment and install deps: |
| 44 | +## MCP Server Connection |
53 | 45 |
|
54 | | -```bash |
55 | | -python -m venv .venv |
56 | | -source .venv/bin/activate # or .\.venv\Scripts\activate on Windows |
57 | | -pip install -r requirements.txt |
| 46 | +### 1. Hosted (easiest — no install) |
| 47 | + |
| 48 | +Any MCP-compatible client can connect to Runware's hosted server: |
| 49 | + |
| 50 | +```json |
| 51 | +{ |
| 52 | + "mcpServers": { |
| 53 | + "runware": { "url": "https://mcp.runware.ai" } |
| 54 | + } |
| 55 | +} |
58 | 56 | ``` |
59 | 57 |
|
60 | | -3. Set your Runware API key. |
61 | | - - Create a `.env` file in the root of the skill: `RUNWARE_API_KEY=your_key` |
62 | | - - OR set it in the environment: `$env:RUNWARE_API_KEY = "<YOUR_KEY>"` |
| 58 | +Authentication is handled via OAuth 2.1 — your API key stays server-side, encrypted in the OAuth session. |
63 | 59 |
|
64 | | -4. Generate an image (sync): |
| 60 | +### 2. Local (self-hosted) |
65 | 61 |
|
66 | | -```bash |
67 | | -python scripts/generate_image.py --prompt "A photorealistic portrait of an adult (age 28)" --sync --outfile "portrait.png" |
| 62 | +```json |
| 63 | +{ |
| 64 | + "mcpServers": { |
| 65 | + "runware": { |
| 66 | + "command": "npx", |
| 67 | + "args": ["-y", "@runware/mcp"], |
| 68 | + "env": { "RUNWARE_API_KEY": "your-api-key" } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### 3. Python (this skill) |
| 75 | + |
| 76 | +```json |
| 77 | +{ |
| 78 | + "mcpServers": { |
| 79 | + "runware-python": { |
| 80 | + "command": "python", |
| 81 | + "args": ["scripts/runware_mcp.py"] |
| 82 | + } |
| 83 | + } |
| 84 | +} |
68 | 85 | ``` |
69 | 86 |
|
70 | | -By default, images are saved under `~/runware_images/` unless you provide an absolute path or a relative filename. The script also remembers the last directory used. |
| 87 | +## Files |
| 88 | + |
| 89 | +| File | Purpose | |
| 90 | +|------|---------| |
| 91 | +| `scripts/generate.py` | Main multi-modal generator | |
| 92 | +| `scripts/runware_mcp.py` | MCP-style CLI tool interface | |
| 93 | +| `skill-config.json` | Default settings (no secrets) | |
| 94 | +| `SKILL.md` | OpenClaw skill metadata & usage | |
| 95 | +| `tests/test_generate.py` | Pytest tests | |
| 96 | +| `examples/` | Example commands | |
71 | 97 |
|
72 | 98 | ## Configuration |
73 | 99 |
|
74 | | -`skill-config.json` contains defaults used by the CLI. Fields: |
| 100 | +`skill-config.json` fields: |
75 | 101 |
|
76 | | -- `default_size` - default image size (e.g., "1024x1024"). |
77 | | -- `default_format` - output format (png/jpg/webp). |
78 | | -- `default_output_dir` - default output directory (for example, `~/runware_images` on Unix-like systems). |
79 | | -- `last_output_dir` - automatically updated by the script to remember the last save location. |
| 102 | +- `default_size` — default image size (e.g. `"1024x1024"`) |
| 103 | +- `default_format` — output format (`png`/`jpg`/`webp`/`mp4`/`wav`/`glb`) |
| 104 | +- `default_output_dir` — default output directory |
| 105 | +- `last_output_dir` — auto-updated by the script |
80 | 106 |
|
81 | | -Do NOT store API keys in this file. Use the `RUNWARE_API_KEY` environment variable or a secret manager. |
| 107 | +## CLI Reference |
82 | 108 |
|
83 | | -## Safety |
| 109 | +### `scripts/generate.py` |
84 | 110 |
|
85 | | -- The script implements a simple prompt filter to block prompts that reference minors (e.g., "teen", ages under 21). This is a lightweight safeguard but does not replace human judgment or platform policies. |
86 | | -- Users are responsible for ensuring they have legal rights to generate and host requested imagery and for following Runware's terms of service. |
| 111 | +| Flag | Description | |
| 112 | +|------|-------------| |
| 113 | +| `--prompt` | Text prompt | |
| 114 | +| `--mode` | `image`, `video`, `audio`, `text`, or `3d` | |
| 115 | +| `--model` | Runware model ID (e.g. `runware:400@1`) | |
| 116 | +| `--size` | Dimensions (e.g. `1024x1024`) | |
| 117 | +| `--sync` / `--no-sync` | Sync vs async delivery | |
| 118 | +| `--duration` | Video duration (seconds) | |
| 119 | +| `--num-results` | Number of outputs | |
| 120 | +| `--extra KEY VALUE` | Extra payload parameters | |
| 121 | +| `--outfile` | Output filename | |
87 | 122 |
|
88 | | -## Testing & CI |
| 123 | +### `scripts/runware_mcp.py` |
89 | 124 |
|
90 | | -- Tests are in `tests/` and use pytest. The included test stubs/mocks `requests.post` so CI does not require real API keys. |
91 | | -- GitHub Actions workflow `.github/workflows/ci.yml` runs the tests on push and pull requests. |
| 125 | +| Command | Description | |
| 126 | +|---------|-------------| |
| 127 | +| `run --prompt "..."` | Run inference task | |
| 128 | +| `list-models` | Browse model catalog | |
| 129 | +| `model-pricing --model X` | Get model pricing | |
| 130 | +| `model-details --model X` | Get model metadata | |
| 131 | +| `account` | Show account info & balance | |
92 | 132 |
|
93 | | -Run tests locally: |
| 133 | +## Testing |
94 | 134 |
|
95 | 135 | ```bash |
96 | 136 | pytest -q |
97 | 137 | ``` |
98 | 138 |
|
99 | | -## Examples |
| 139 | +Integration tests require `RUNWARE_API_KEY` set in the environment. |
100 | 140 |
|
101 | | -See `examples/README.md` for example prompts and usage patterns (sync vs async). |
102 | | - |
103 | | -## Packaging & Publishing |
| 141 | +## Safety |
104 | 142 |
|
105 | | -Before publishing to ClawHub: |
| 143 | +- Prompt filter blocks requests referencing minors |
| 144 | +- Users must follow [Runware's terms of service](https://runware.ai/terms) |
| 145 | +- API key stays client-side or in OAuth session — never committed |
106 | 146 |
|
107 | | -1. Ensure `skill-config.json` contains no secrets. |
108 | | -2. Run tests and fix any issues. |
109 | | -3. Optionally package the skill using the project packaging script (if available) or create a .zip that follows the skill layout. |
| 147 | +## Architecture |
110 | 148 |
|
111 | | -I can assist with creating the .skill package and publishing to ClawHub when you’re ready. |
| 149 | +```mermaid |
| 150 | +graph TD |
| 151 | + User[User / Terminal] -->|Prompt| Gen[scripts/generate.py] |
| 152 | + User -->|Tool call| MCP[scripts/runware_mcp.py] |
| 153 | + Gen -->|async with Runware| SDK[runware-sdk] |
| 154 | + MCP -->|async with Runware| SDK |
| 155 | + SDK -->|run()| API[Runware.ai API] |
| 156 | + API -->|Results| SDK |
| 157 | + SDK -->|Decoded output| Gen |
| 158 | + SDK -->|Decoded output| MCP |
| 159 | + Gen -->|Save| Output[Local file] |
| 160 | + MCP -->|Print| Output2[JSON stdout] |
| 161 | +
|
| 162 | + MCP_Client[MCP Client e.g. Claude Desktop] |
| 163 | + MCP_Client -->|stdio / HTTP| MCP_Server["npx @runware/mcp"] |
| 164 | + MCP_Server --> API |
| 165 | +``` |
112 | 166 |
|
113 | | -## Contributing |
| 167 | +## Migration from v1.x |
114 | 168 |
|
115 | | -See `CONTRIBUTING.md` for contribution guidelines. Keep changes small, include tests, and run CI locally. |
| 169 | +| Old | New | |
| 170 | +|-----|-----| |
| 171 | +| `scripts/generate_image.py` | `scripts/generate.py` | |
| 172 | +| `requests.post` to `/v1/tasks` | `runware-sdk` `client.run()` | |
| 173 | +| Manual UUIDs & response parsing | SDK handles schema, validation, delivery | |
| 174 | +| Image-only | Image + video + audio + text + 3D | |
| 175 | +| Python 3.8+ | Python 3.11+ | |
116 | 176 |
|
117 | 177 | ## Author |
118 | 178 |
|
119 | | -- **Shobhit Kumar Prabhaar** - [GitHub Profile](https://github.com/GeekLord/) |
| 179 | +**Shobhit Kumar Prabhakar** — [@GeekLord](https://github.com/GeekLord/) |
120 | 180 |
|
121 | 181 | ## License |
122 | 182 |
|
123 | | -This project is licensed under the MIT License - see LICENSE. |
| 183 | +MIT — see LICENSE. |
124 | 184 |
|
125 | | -## Contact / Support |
| 185 | +## Links |
126 | 186 |
|
127 | | -Open an issue or a pull request on the repository. For Runware API specifics, consult: https://runware.ai/docs/getting-started/introduction |
| 187 | +- [Runware MCP Server](https://runware.ai/mcp) |
| 188 | +- [Runware MCP Docs](https://runware.ai/docs/platform/mcp) |
| 189 | +- [Runware Python SDK](https://runware.ai/docs/platform/python) |
| 190 | +- [Official @runware/mcp GitHub](https://github.com/runware/mcp) |
0 commit comments