bitwrench 2.0.22 → 2.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +1 -1
- package/README.md +4 -3
- package/bin/bwmcp.js +3 -0
- package/dist/bitwrench-bccl.cjs.js +1 -1
- package/dist/bitwrench-bccl.cjs.min.js +1 -1
- package/dist/bitwrench-bccl.cjs.min.js.gz +0 -0
- package/dist/bitwrench-bccl.esm.js +1 -1
- package/dist/bitwrench-bccl.esm.min.js +1 -1
- package/dist/bitwrench-bccl.esm.min.js.gz +0 -0
- package/dist/bitwrench-bccl.umd.js +1 -1
- package/dist/bitwrench-bccl.umd.min.js +1 -1
- package/dist/bitwrench-bccl.umd.min.js.gz +0 -0
- package/dist/bitwrench-code-edit.cjs.js +1 -1
- package/dist/bitwrench-code-edit.cjs.min.js +1 -1
- package/dist/bitwrench-code-edit.es5.js +1 -1
- package/dist/bitwrench-code-edit.es5.min.js +1 -1
- package/dist/bitwrench-code-edit.esm.js +1 -1
- package/dist/bitwrench-code-edit.esm.min.js +1 -1
- package/dist/bitwrench-code-edit.umd.js +1 -1
- package/dist/bitwrench-code-edit.umd.min.js +1 -1
- package/dist/bitwrench-code-edit.umd.min.js.gz +0 -0
- package/dist/bitwrench-debug.js +1 -1
- package/dist/bitwrench-debug.min.js +1 -1
- package/dist/bitwrench-lean.cjs.js +3 -3
- package/dist/bitwrench-lean.cjs.min.js +2 -2
- package/dist/bitwrench-lean.cjs.min.js.gz +0 -0
- package/dist/bitwrench-lean.es5.js +3 -3
- package/dist/bitwrench-lean.es5.min.js +2 -2
- package/dist/bitwrench-lean.es5.min.js.gz +0 -0
- package/dist/bitwrench-lean.esm.js +3 -3
- package/dist/bitwrench-lean.esm.min.js +2 -2
- package/dist/bitwrench-lean.esm.min.js.gz +0 -0
- package/dist/bitwrench-lean.umd.js +3 -3
- package/dist/bitwrench-lean.umd.min.js +2 -2
- package/dist/bitwrench-lean.umd.min.js.gz +0 -0
- package/dist/bitwrench-util-css.cjs.js +1 -1
- package/dist/bitwrench-util-css.cjs.min.js +1 -1
- package/dist/bitwrench-util-css.es5.js +1 -1
- package/dist/bitwrench-util-css.es5.min.js +1 -1
- package/dist/bitwrench-util-css.esm.js +1 -1
- package/dist/bitwrench-util-css.esm.min.js +1 -1
- package/dist/bitwrench-util-css.umd.js +1 -1
- package/dist/bitwrench-util-css.umd.min.js +1 -1
- package/dist/bitwrench-util-css.umd.min.js.gz +0 -0
- package/dist/bitwrench.cjs.js +3 -3
- package/dist/bitwrench.cjs.min.js +2 -2
- package/dist/bitwrench.cjs.min.js.gz +0 -0
- package/dist/bitwrench.css +1 -1
- package/dist/bitwrench.es5.js +3 -3
- package/dist/bitwrench.es5.min.js +2 -2
- package/dist/bitwrench.es5.min.js.gz +0 -0
- package/dist/bitwrench.esm.js +3 -3
- package/dist/bitwrench.esm.min.js +2 -2
- package/dist/bitwrench.esm.min.js.gz +0 -0
- package/dist/bitwrench.umd.js +3 -3
- package/dist/bitwrench.umd.min.js +2 -2
- package/dist/bitwrench.umd.min.js.gz +0 -0
- package/dist/builds.json +65 -65
- package/dist/bwserve.cjs.js +2 -2
- package/dist/bwserve.esm.js +2 -2
- package/dist/sri.json +45 -45
- package/docs/README.md +76 -0
- package/docs/app-patterns.md +264 -0
- package/docs/bitwrench-mcp.md +426 -0
- package/docs/bitwrench_api.md +2232 -0
- package/docs/bw-attach.md +399 -0
- package/docs/bwserve.md +841 -0
- package/docs/cli.md +307 -0
- package/docs/component-cheatsheet.md +144 -0
- package/docs/component-library.md +1099 -0
- package/docs/framework-translation-table.md +33 -0
- package/docs/llm-bitwrench-guide.md +672 -0
- package/docs/routing.md +562 -0
- package/docs/state-management.md +767 -0
- package/docs/taco-format.md +373 -0
- package/docs/theming.md +309 -0
- package/docs/thinking-in-bitwrench.md +1457 -0
- package/docs/tutorial-bwserve.md +297 -0
- package/docs/tutorial-embedded.md +314 -0
- package/docs/tutorial-website.md +255 -0
- package/package.json +11 -3
- package/readme.html +5 -4
- package/src/mcp/knowledge.js +231 -0
- package/src/mcp/live.js +226 -0
- package/src/mcp/server.js +216 -0
- package/src/mcp/tools.js +369 -0
- package/src/mcp/transport.js +55 -0
- package/src/version.js +3 -3
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
# bwmcp -- MCP Server for Bitwrench
|
|
2
|
+
|
|
3
|
+
bwmcp is an MCP (Model Context Protocol) server that lets AI agents build
|
|
4
|
+
and control live browser UI through bitwrench. An agent connects via MCP,
|
|
5
|
+
calls tools to compose TACO components, and the result renders live in a
|
|
6
|
+
browser window. The agent can screenshot, inspect, and iterate.
|
|
7
|
+
|
|
8
|
+
## Quick Start
|
|
9
|
+
|
|
10
|
+
### 1. Configure in Claude Code
|
|
11
|
+
|
|
12
|
+
Add to your Claude Code MCP settings (`~/.claude/settings.json` or project `.mcp.json`):
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"mcpServers": {
|
|
17
|
+
"bitwrench": {
|
|
18
|
+
"command": "node",
|
|
19
|
+
"args": ["/path/to/bitwrench/bin/bwmcp.js"]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or if bitwrench is installed globally (`npm install -g bitwrench`):
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"mcpServers": {
|
|
30
|
+
"bitwrench": {
|
|
31
|
+
"command": "bwmcp"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 2. Configure in Cursor / VS Code
|
|
38
|
+
|
|
39
|
+
In your project's `.cursor/mcp.json` or VS Code MCP settings:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"bitwrench": {
|
|
45
|
+
"command": "node",
|
|
46
|
+
"args": ["/path/to/bitwrench/bin/bwmcp.js", "--open"]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. Use It
|
|
53
|
+
|
|
54
|
+
Ask the AI agent:
|
|
55
|
+
|
|
56
|
+
> "Build me a dashboard with stat cards showing revenue, users, and orders."
|
|
57
|
+
|
|
58
|
+
The agent will:
|
|
59
|
+
1. Call `bitwrench_start_here` to learn the workflow
|
|
60
|
+
2. Call `make_stat_card` three times with appropriate props
|
|
61
|
+
3. Compose the cards into a grid layout
|
|
62
|
+
4. Call `build_page` with a theme to produce a standalone HTML file
|
|
63
|
+
|
|
64
|
+
With `--open` or live rendering, the agent can also push UI to a browser
|
|
65
|
+
and iterate visually using screenshots.
|
|
66
|
+
|
|
67
|
+
## CLI Options
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
bwmcp [options]
|
|
71
|
+
|
|
72
|
+
Options:
|
|
73
|
+
--port <n> bwserve port for live browser rendering (default: 7910)
|
|
74
|
+
--theme <name> Default theme preset (ocean, forest, sunset, etc.)
|
|
75
|
+
--open Open browser automatically on start
|
|
76
|
+
--no-browser Skip starting bwserve (testing/offline mode)
|
|
77
|
+
--help, -h Show help
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## How It Works
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
AI Agent (Claude, Cursor, etc.)
|
|
84
|
+
|
|
|
85
|
+
| JSON-RPC 2.0 over stdio
|
|
86
|
+
|
|
|
87
|
+
bwmcp ──────────────────────────────────────
|
|
88
|
+
| |
|
|
89
|
+
| MCP Protocol Handler |
|
|
90
|
+
| tools/list -> 21 tools |
|
|
91
|
+
| tools/call -> execute tool |
|
|
92
|
+
| |
|
|
93
|
+
| Knowledge Tools (5) |
|
|
94
|
+
| Read docs from disk, serve to LLM |
|
|
95
|
+
| |
|
|
96
|
+
| Component Tools (10) |
|
|
97
|
+
| Call bw.makeCard(), etc. |
|
|
98
|
+
| Return TACO JSON |
|
|
99
|
+
| |
|
|
100
|
+
| Utility Tools (3) |
|
|
101
|
+
| render_taco, build_page, make_styles |
|
|
102
|
+
| |
|
|
103
|
+
| Live Tools (3) |
|
|
104
|
+
| Push to browser via bwserve SSE |
|
|
105
|
+
| |
|
|
106
|
+
| bwserve instance (port 7910) |
|
|
107
|
+
| HTTP server + SSE streaming |
|
|
108
|
+
────|────────────────────────────────────────
|
|
109
|
+
|
|
|
110
|
+
| HTTP / SSE
|
|
111
|
+
|
|
|
112
|
+
Browser Window
|
|
113
|
+
Renders TACO, captures screenshots
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## The Core Loop
|
|
117
|
+
|
|
118
|
+
The primary value of bwmcp is the iterative render-screenshot-adjust loop:
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
Agent bwmcp Browser
|
|
122
|
+
| | |
|
|
123
|
+
|-- bitwrench_start_here ----->| |
|
|
124
|
+
|<-- orientation text ---------| |
|
|
125
|
+
| | |
|
|
126
|
+
|-- make_stat_card {...} ----->| |
|
|
127
|
+
|<-- TACO JSON ----------------| |
|
|
128
|
+
| | |
|
|
129
|
+
|-- render_live {taco} ------->|-- SSE: replace #app -------->|
|
|
130
|
+
|<-- {rendered, clientCount} --| |-- UI visible
|
|
131
|
+
| | |
|
|
132
|
+
|-- screenshot {} ------------>|-- screenshot request -------->|
|
|
133
|
+
|<-- PNG image data -----------|<-- html2canvas capture ------|
|
|
134
|
+
| | |
|
|
135
|
+
| (agent evaluates image, | |
|
|
136
|
+
| decides to adjust) | |
|
|
137
|
+
| | |
|
|
138
|
+
|-- render_live {patch} ------>|-- SSE: patch ---------------->|
|
|
139
|
+
|<-- {rendered} ---------------| |-- UI updated
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
## Tool Reference
|
|
144
|
+
|
|
145
|
+
### Knowledge Tools
|
|
146
|
+
|
|
147
|
+
These return documentation text. They teach the LLM how to use bitwrench.
|
|
148
|
+
|
|
149
|
+
| Tool | Description | When to Call |
|
|
150
|
+
|------|-------------|--------------|
|
|
151
|
+
| `bitwrench_start_here` | 30-line orientation: TACO, workflow, key rules | Always first |
|
|
152
|
+
| `bitwrench_guide` | Full developer guide (629 lines). Optional `section` filter. | Before building UI |
|
|
153
|
+
| `bitwrench_components` | Props reference for all 50+ make*() components. Optional `component` filter. | When configuring components |
|
|
154
|
+
| `bitwrench_server_guide` | bwserve tutorial for server-driven UI | Only for live/streaming UI |
|
|
155
|
+
| `bitwrench_themes` | Theme presets, palettes, color utilities | When choosing/customizing themes |
|
|
156
|
+
|
|
157
|
+
**Section filter** for `bitwrench_guide`:
|
|
158
|
+
```
|
|
159
|
+
taco, levels, events, css, components, bwserve, routing, api-reference, rules
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Component filter** for `bitwrench_components`:
|
|
163
|
+
```
|
|
164
|
+
makeCard, makeButton, makeTable, makeTabs, makeAccordion, makeAlert,
|
|
165
|
+
makeNav, makeHero, makeStatCard, makeFormGroup, ... (47+ total)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Component Tools
|
|
169
|
+
|
|
170
|
+
Each returns a TACO object (JSON) that can be composed or rendered.
|
|
171
|
+
|
|
172
|
+
| Tool | Props | Description |
|
|
173
|
+
|------|-------|-------------|
|
|
174
|
+
| `make_card` | title, subtitle, content, footer, image, variant, ... | Card with optional header image |
|
|
175
|
+
| `make_button` | text, variant, size, disabled, type | Button with color variant |
|
|
176
|
+
| `make_table` | data, columns, striped, hover, sortable | Data table with sorting |
|
|
177
|
+
| `make_tabs` | tabs: [{label, content}], activeIndex | Tabbed interface |
|
|
178
|
+
| `make_accordion` | items: [{title, content}], multiOpen | Collapsible sections |
|
|
179
|
+
| `make_alert` | content, variant, dismissible | Alert/notification box |
|
|
180
|
+
| `make_nav` | items: [{text, href, active}], pills, vertical | Navigation links |
|
|
181
|
+
| `make_hero` | title, subtitle, content, variant, size, actions | Full-width hero section |
|
|
182
|
+
| `make_stat_card` | label, value, change, prefix, suffix, icon, variant | KPI stat card |
|
|
183
|
+
| `make_form_group` | label, input, help, id, required, validation | Label + input wrapper |
|
|
184
|
+
|
|
185
|
+
**Variants:** primary, secondary, success, danger, warning, info
|
|
186
|
+
|
|
187
|
+
### Utility Tools
|
|
188
|
+
|
|
189
|
+
| Tool | Input | Output |
|
|
190
|
+
|------|-------|--------|
|
|
191
|
+
| `render_taco` | `{taco, indent}` | HTML string |
|
|
192
|
+
| `build_page` | `{title, content, theme, runtime}` | Complete standalone HTML page |
|
|
193
|
+
| `make_styles` | `{primary, secondary, background, surface}` | CSS text |
|
|
194
|
+
|
|
195
|
+
### Live Rendering Tools
|
|
196
|
+
|
|
197
|
+
These require a browser connected to the bwserve instance.
|
|
198
|
+
|
|
199
|
+
| Tool | Input | Output |
|
|
200
|
+
|------|-------|--------|
|
|
201
|
+
| `render_live` | `{target, taco, action}` | Push TACO to browser. Actions: replace, append, patch, remove |
|
|
202
|
+
| `screenshot` | `{selector}` | Base64 PNG image of browser viewport |
|
|
203
|
+
| `query_dom` | `{code}` | Execute JS in browser, return result |
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
## Guide for LLM Agents
|
|
207
|
+
|
|
208
|
+
This section is written for you, the AI agent. When you connect to bwmcp
|
|
209
|
+
via MCP, follow this workflow.
|
|
210
|
+
|
|
211
|
+
### Step 1: Orient Yourself
|
|
212
|
+
|
|
213
|
+
Call `bitwrench_start_here`. It returns a 30-line cheat sheet covering:
|
|
214
|
+
- What bitwrench is (zero-dep JS UI library)
|
|
215
|
+
- The TACO format: `{t: 'div', a: {class: 'x'}, c: 'content'}`
|
|
216
|
+
- Your 5-step workflow
|
|
217
|
+
- Key rules (compose TACOs, use grid, pick a theme)
|
|
218
|
+
- Which other knowledge tools to call
|
|
219
|
+
|
|
220
|
+
This costs about 200 tokens. Always call it first.
|
|
221
|
+
|
|
222
|
+
### Step 2: Learn (Optional but Recommended)
|
|
223
|
+
|
|
224
|
+
If you have not used bitwrench before, call `bitwrench_guide`. This is the
|
|
225
|
+
full tutorial (about 4000 tokens). It covers TACO nesting, the three-level
|
|
226
|
+
component model, events, CSS/theming, all component categories, debugging,
|
|
227
|
+
bwserve, routing, and API reference tables.
|
|
228
|
+
|
|
229
|
+
If you only need info on specific topics, use the section filter:
|
|
230
|
+
```
|
|
231
|
+
bitwrench_guide({section: 'css'}) // just CSS and theming
|
|
232
|
+
bitwrench_guide({section: 'components'}) // component categories
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Step 3: Look Up Component Props
|
|
236
|
+
|
|
237
|
+
When you need exact props for a component, call:
|
|
238
|
+
```
|
|
239
|
+
bitwrench_components({component: 'makeStatCard'})
|
|
240
|
+
```
|
|
241
|
+
This returns the detailed signature, props, variants, and examples for
|
|
242
|
+
that specific component. Much cheaper than loading the full catalog.
|
|
243
|
+
|
|
244
|
+
### Step 4: Build Components
|
|
245
|
+
|
|
246
|
+
Call the make_* tools to create TACO objects:
|
|
247
|
+
```
|
|
248
|
+
make_stat_card({label: 'Revenue', value: '$12,345', variant: 'primary'})
|
|
249
|
+
make_stat_card({label: 'Users', value: '1,234', variant: 'success'})
|
|
250
|
+
make_table({data: [...], columns: [{key:'name', label:'Name'}, ...]})
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Each returns a TACO object in `structuredContent`. Save these for composition.
|
|
254
|
+
|
|
255
|
+
### Step 5: Compose Layout
|
|
256
|
+
|
|
257
|
+
Nest the TACOs into a grid layout. The bitwrench grid uses three classes:
|
|
258
|
+
```
|
|
259
|
+
bw_container > bw_row > bw_col
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Build a layout TACO by nesting:
|
|
263
|
+
```json
|
|
264
|
+
{
|
|
265
|
+
"t": "div", "a": {"class": "bw_container"}, "c": [
|
|
266
|
+
{"t": "h1", "c": "Dashboard"},
|
|
267
|
+
{"t": "div", "a": {"class": "bw_row"}, "c": [
|
|
268
|
+
{"t": "div", "a": {"class": "bw_col"}, "c": [<stat1 taco>]},
|
|
269
|
+
{"t": "div", "a": {"class": "bw_col"}, "c": [<stat2 taco>]},
|
|
270
|
+
{"t": "div", "a": {"class": "bw_col"}, "c": [<stat3 taco>]}
|
|
271
|
+
]},
|
|
272
|
+
<table taco>
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Step 6: Generate Output
|
|
278
|
+
|
|
279
|
+
**For a standalone HTML file** (the typical case):
|
|
280
|
+
```
|
|
281
|
+
build_page({
|
|
282
|
+
title: 'My Dashboard',
|
|
283
|
+
theme: 'ocean',
|
|
284
|
+
content: <your composed layout TACO>
|
|
285
|
+
})
|
|
286
|
+
```
|
|
287
|
+
Returns a complete `.html` file with bitwrench inlined. Works offline.
|
|
288
|
+
Save it to disk with your file-writing tool.
|
|
289
|
+
|
|
290
|
+
**For live browser rendering:**
|
|
291
|
+
```
|
|
292
|
+
render_live({target: '#app', taco: <your layout TACO>})
|
|
293
|
+
```
|
|
294
|
+
The UI appears immediately in the browser at http://localhost:7910.
|
|
295
|
+
|
|
296
|
+
### Step 7: Iterate (Live Mode)
|
|
297
|
+
|
|
298
|
+
If using live rendering:
|
|
299
|
+
```
|
|
300
|
+
screenshot({}) // see what the browser shows
|
|
301
|
+
screenshot({selector: '.bw_stat_card:first-child'}) // zoom in on one element
|
|
302
|
+
query_dom({code: 'document.querySelectorAll(".bw_card").length'}) // count cards
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Evaluate the screenshot, decide what to change, and call `render_live` again.
|
|
306
|
+
|
|
307
|
+
### Key Rules
|
|
308
|
+
|
|
309
|
+
1. Every make*() tool returns a TACO object, NOT HTML
|
|
310
|
+
2. Compose by nesting TACOs in the `c` field: `{t:'div', c: [taco1, taco2]}`
|
|
311
|
+
3. Grid layout: `bw_container > bw_row > bw_col`
|
|
312
|
+
4. Always use a theme with `build_page` (ocean, forest, sunset, midnight, etc.)
|
|
313
|
+
5. Call `render_taco` to preview a single TACO as HTML
|
|
314
|
+
6. Call `build_page` as the final step to get a standalone file
|
|
315
|
+
7. The `structuredContent` field in tool results contains the TACO as a parsed object -- use it directly when composing
|
|
316
|
+
8. Do NOT generate raw HTML strings -- always work with TACO objects
|
|
317
|
+
|
|
318
|
+
### Common Mistakes
|
|
319
|
+
|
|
320
|
+
- **Stacking everything vertically.** Use the grid (bw_container/bw_row/bw_col).
|
|
321
|
+
- **Calling build_page per component.** Build all components first, compose into one layout, then call build_page once.
|
|
322
|
+
- **Ignoring themes.** `build_page` with no theme produces unstyled output. Always pass a theme name.
|
|
323
|
+
- **Generating HTML strings.** The tools return TACO objects. Compose TACOs, not HTML. Call render_taco or build_page only at the end.
|
|
324
|
+
- **Not calling start_here first.** Without orientation, you will misuse the tools.
|
|
325
|
+
|
|
326
|
+
### Token Budget
|
|
327
|
+
|
|
328
|
+
| Knowledge Tool | Tokens | When Needed |
|
|
329
|
+
|---------------|--------|-------------|
|
|
330
|
+
| bitwrench_start_here | ~200 | Always (first call) |
|
|
331
|
+
| bitwrench_guide | ~4,000 | Usually (first session) |
|
|
332
|
+
| bitwrench_guide (section) | ~300-600 | When refreshing one topic |
|
|
333
|
+
| bitwrench_components | ~6,500 | When configuring components |
|
|
334
|
+
| bitwrench_components (one) | ~100-300 | When looking up one component |
|
|
335
|
+
| bitwrench_server_guide | ~1,800 | Only for server-driven UI |
|
|
336
|
+
| bitwrench_themes | ~1,900 | Only when theming matters |
|
|
337
|
+
|
|
338
|
+
Minimal session: start_here (200) + a few make_* calls = under 1K tokens of context.
|
|
339
|
+
Typical session: start_here (200) + guide (4K) + components (6.5K) = about 11K tokens.
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
## Programmatic Usage (Node.js)
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
import { createMcpServer } from 'bitwrench/mcp';
|
|
346
|
+
|
|
347
|
+
var server = createMcpServer({
|
|
348
|
+
port: 7910,
|
|
349
|
+
theme: 'ocean',
|
|
350
|
+
open: true
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
server.listen();
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## Programmatic Usage (Python)
|
|
357
|
+
|
|
358
|
+
Two example projects demonstrate Python integration:
|
|
359
|
+
|
|
360
|
+
- **`examples/mcp-agent/`** -- Scripted agent that builds a dashboard and
|
|
361
|
+
saves a standalone HTML file. Demonstrates the full tool workflow
|
|
362
|
+
(orient, build, compose, export, screenshot, inspect).
|
|
363
|
+
|
|
364
|
+
- **`examples/mcp-agent-live/`** -- Connects a local LLM (ollama, lmstudio,
|
|
365
|
+
openrouter, or openai) to bwmcp. You type a prompt, the LLM decides what
|
|
366
|
+
to build, and you watch components appear one by one in the browser with a
|
|
367
|
+
live progress bar. Run `python3 live_builder.py --no-llm` for a demo
|
|
368
|
+
without any LLM.
|
|
369
|
+
|
|
370
|
+
The pattern works with any language -- bwmcp speaks JSON-RPC
|
|
371
|
+
2.0 over stdin/stdout.
|
|
372
|
+
|
|
373
|
+
```python
|
|
374
|
+
import subprocess, json
|
|
375
|
+
|
|
376
|
+
proc = subprocess.Popen(
|
|
377
|
+
['node', '/path/to/bin/bwmcp.js', '--no-browser'],
|
|
378
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
379
|
+
text=True
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
def call_tool(name, args={}):
|
|
383
|
+
msg = {"jsonrpc": "2.0", "id": 1, "method": "tools/call",
|
|
384
|
+
"params": {"name": name, "arguments": args}}
|
|
385
|
+
proc.stdin.write(json.dumps(msg) + "\n")
|
|
386
|
+
proc.stdin.flush()
|
|
387
|
+
return json.loads(proc.stdout.readline())
|
|
388
|
+
|
|
389
|
+
# Orient
|
|
390
|
+
orientation = call_tool("bitwrench_start_here")
|
|
391
|
+
print(orientation["result"]["content"][0]["text"][:200])
|
|
392
|
+
|
|
393
|
+
# Build a card
|
|
394
|
+
card = call_tool("make_card", {"title": "Hello", "content": "World"})
|
|
395
|
+
taco = card["result"]["structuredContent"]
|
|
396
|
+
|
|
397
|
+
# Build a full page
|
|
398
|
+
page = call_tool("build_page", {
|
|
399
|
+
"title": "My Page", "theme": "ocean", "content": taco
|
|
400
|
+
})
|
|
401
|
+
html = page["result"]["content"][0]["text"]
|
|
402
|
+
|
|
403
|
+
with open("output.html", "w") as f:
|
|
404
|
+
f.write(html)
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
## Architecture Notes
|
|
409
|
+
|
|
410
|
+
- bwmcp runs as a single Node.js process
|
|
411
|
+
- MCP protocol is JSON-RPC 2.0 over stdio (newline-delimited)
|
|
412
|
+
- bwserve runs as an embedded HTTP+SSE server on port 7910
|
|
413
|
+
- Knowledge tools read docs from disk at call time (always fresh)
|
|
414
|
+
- Component tools call `bw.makeCard()` etc. from source directly (not dist)
|
|
415
|
+
- No runtime dependencies beyond Node.js stdlib
|
|
416
|
+
- No build step needed -- bwmcp runs from source
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
## Related Documentation
|
|
420
|
+
|
|
421
|
+
- [LLM Guide](llm-bitwrench-guide.md) -- The full developer guide served by `bitwrench_guide`
|
|
422
|
+
- [Component Library](component-library.md) -- Full props reference served by `bitwrench_components`
|
|
423
|
+
- [Theming](theming.md) -- Theme configuration served by `bitwrench_themes`
|
|
424
|
+
- [bwserve Tutorial](tutorial-bwserve.md) -- Server-driven UI served by `bitwrench_server_guide`
|
|
425
|
+
- [bwserve Protocol](bwserve.md) -- Wire protocol details (SSE message types)
|
|
426
|
+
- [MCP Server Design](../dev/bitwrench-mcp-server-design.md) -- Internal design document
|