agentic-mermaid 0.1.2 → 0.2.0
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/AGENT_NATIVE.md +671 -0
- package/CHANGELOG.md +19 -0
- package/Instructions_for_agents.md +89 -0
- package/README.md +8 -8
- package/assets/hero.png +0 -0
- package/dist/agent-core.d.ts +2 -2
- package/dist/agent-core.js +2 -2
- package/dist/agent.d.ts +2 -2
- package/dist/agent.js +4 -4
- package/dist/agentic-mermaid-mcp.js +5 -5
- package/dist/am.js +8 -15
- package/dist/{chunk-QKDLMOJJ.js → chunk-2P5FKUQC.js} +7 -9
- package/dist/{chunk-WN3YDOBG.js → chunk-2S3VSS6I.js} +4 -4
- package/dist/{chunk-CDPKJ2BQ.js → chunk-2SILJDW2.js} +2 -2
- package/dist/{chunk-ZYMMKQ3I.js → chunk-BJYMBT4I.js} +299 -973
- package/dist/{chunk-WI35L7IR.js → chunk-FDM43XU7.js} +2 -2
- package/dist/{chunk-4QECACIA.js → chunk-MYPDVZCO.js} +19 -19
- package/dist/{index-D54dqSdC.d.ts → index-DWPa2MJs.d.ts} +7 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp-cli-5J47WEY3.js +17 -0
- package/docs/README.md +34 -34
- package/docs/agent-api-cookbook.md +317 -0
- package/docs/agent-mutation-policy.md +104 -0
- package/docs/agent-workflow-examples.md +46 -0
- package/docs/api.md +418 -0
- package/docs/ascii.md +113 -0
- package/docs/code-mode-impact.md +214 -0
- package/docs/comparison.md +106 -0
- package/docs/computational-aesthetics-prototype-plan.md +252 -0
- package/docs/config.md +121 -0
- package/docs/custom-fonts.md +265 -0
- package/docs/custom-style-cookbook.md +275 -0
- package/docs/diagram-families.md +218 -0
- package/docs/features.md +154 -0
- package/docs/fork-differences.md +133 -0
- package/docs/getting-started.md +182 -0
- package/docs/issue-derived-test-cases.md +163 -0
- package/docs/mcp-code-mode-rationale.md +108 -0
- package/docs/mcp-http-transport.md +230 -0
- package/docs/mermaid-layout-complaints.md +851 -0
- package/docs/mutation-testing.md +285 -0
- package/docs/quality.md +224 -0
- package/docs/react.md +97 -0
- package/docs/style-authoring.md +336 -0
- package/docs/svg-semantic-contract.md +49 -0
- package/docs/testing-strategy.md +443 -0
- package/docs/theming.md +149 -0
- package/package.json +21 -6
- package/server.json +2 -2
- package/skills/agentic-mermaid-live-editor/SKILL.md +1 -1
- package/dist/mcp-cli-SBQSTJFC.js +0 -17
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# MCP HTTP/SSE transport quickstart
|
|
2
|
+
|
|
3
|
+
`agentic-mermaid-mcp` defaults to stdio for local MCP clients. Use HTTP/SSE only when a client needs a reachable endpoint or when PNG artifacts should be fetched by file/URL instead of returned as large base64 strings.
|
|
4
|
+
|
|
5
|
+
> Looking for a zero-setup endpoint? A **hosted** MCP already runs at `https://agentic-mermaid.dev/mcp` (`claude mcp add --transport http agentic-mermaid https://agentic-mermaid.dev/mcp`). It is a different implementation — stateless Streamable HTTP, Cloudflare-backed, tools `execute`/`describe_sdk`/`render_svg`/`render_ascii`/`render_png`/`verify`/`describe`/`mutate`/`build`, inputs capped at 64KB, and no file/URL PNG artifacts (base64 only). See the [as-built record](./project/archive/hosted-mcp-cloudflare-plan.md). Run the local server below when you need file/URL artifacts, larger inputs, offline use, or your own auth.
|
|
6
|
+
>
|
|
7
|
+
> **Privacy and caching:** every hosted call (`execute`, `render_*`, `verify`, `describe`, `mutate`, `build`) sends your diagram source or code to the agentic-mermaid.dev server. Successful deterministic pure-tool results may be reused by a private server-side Workers Cache for up to 24 hours; `execute`, `mutate`, and `build` bypass it. The JSON-RPC HTTP response itself is always `cache-control: no-store`; `x-agentic-mermaid-compute-cache` reports `hit`, `miss`, `mixed`, `bypass`, or `disabled`. For diagrams that must not leave your machine, use the library, the CLI, or the local stdio/HTTP server on this page — the pipeline is fully local and needs no network.
|
|
8
|
+
|
|
9
|
+
## Which endpoint returns plain JSON?
|
|
10
|
+
|
|
11
|
+
Two transports, two framings — pick by what your client expects:
|
|
12
|
+
|
|
13
|
+
| You are… | Use | Response framing |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| An MCP client (Claude Code, MCP SDKs) | hosted `/mcp`, or local `/sse` + `/message` | Handled by the client. |
|
|
16
|
+
| A script POSTing JSON-RPC yourself | hosted `POST /mcp`, or local `POST /rpc` | Plain `application/json` — `json.loads` the body directly. |
|
|
17
|
+
|
|
18
|
+
The local `/sse` + `/message` pair is the MCP SSE session transport: `POST /message` returns only `202 {"ok":true}`, and the actual JSON-RPC response arrives on the open `/sse` stream framed as SSE events (`event: message` / `data: {...}` lines). If you find yourself stripping `data:` prefixes before parsing, switch to `POST /rpc` (local) or `POST /mcp` (hosted) — both reply with an unframed JSON body.
|
|
19
|
+
|
|
20
|
+
## Start the server
|
|
21
|
+
|
|
22
|
+
Loopback/local development:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
npx -y agentic-mermaid-mcp --transport http --host 127.0.0.1 --port 3000 \
|
|
26
|
+
--artifact-dir .agentic-mermaid-artifacts
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Remote binding requires a bearer token:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npx -y agentic-mermaid-mcp --transport http --host 0.0.0.0 --port 3000 \
|
|
33
|
+
--artifact-dir .agentic-mermaid-artifacts \
|
|
34
|
+
--auth-token "$AGENTIC_MERMAID_MCP_TOKEN"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
HTTP endpoints:
|
|
38
|
+
|
|
39
|
+
| Endpoint | Purpose |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `GET /health` | Readiness probe, returns `{ "ok": true }`. |
|
|
42
|
+
| `GET /sse` | MCP SSE session endpoint. First event contains the `/message?sessionId=...` URL. |
|
|
43
|
+
| `POST /message?sessionId=...` | JSON-RPC requests for an SSE session. Requests get `202 {"ok":true}` while the JSON-RPC response is emitted on the SSE stream; notifications get an empty `202` and no stream frame. |
|
|
44
|
+
| `POST /rpc` | Direct JSON-RPC endpoint for tests/scripts/simple integrations. Replies with plain `application/json` (no SSE framing). |
|
|
45
|
+
| `GET /artifacts/<name>` | Fetch managed artifacts returned by `render_png` `output: "url"`. |
|
|
46
|
+
|
|
47
|
+
`/rpc` and `/message` require `content-type: application/json`; browser-simple `text/plain` form posts are rejected. Non-loopback hosts require `Authorization: Bearer <token>` on `/rpc`, `/sse`, `/message`, and `/artifacts/*`, and the same Origin check covers those routes. SSE sessions are capped (32 by default); an exhausted server returns `503` instead of retaining another session.
|
|
48
|
+
|
|
49
|
+
## Direct JSON-RPC examples: `render_png`
|
|
50
|
+
|
|
51
|
+
### Base64 output (default)
|
|
52
|
+
|
|
53
|
+
Request:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"jsonrpc": "2.0",
|
|
58
|
+
"id": 1,
|
|
59
|
+
"method": "tools/call",
|
|
60
|
+
"params": {
|
|
61
|
+
"name": "render_png",
|
|
62
|
+
"arguments": {
|
|
63
|
+
"source": "flowchart TD\n A --> B",
|
|
64
|
+
"fontDirs": ["./fonts"],
|
|
65
|
+
"loadSystemFonts": false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`curl`:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
curl -sS http://127.0.0.1:3000/rpc \
|
|
75
|
+
-H 'content-type: application/json' \
|
|
76
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"render_png","arguments":{"source":"flowchart TD\n A --> B"}}}'
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Response shape:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"jsonrpc": "2.0",
|
|
84
|
+
"id": 1,
|
|
85
|
+
"result": {
|
|
86
|
+
"content": [
|
|
87
|
+
{
|
|
88
|
+
"type": "text",
|
|
89
|
+
"text": "{\"ok\":true,\"png_base64\":\"iVBORw0KGgo...\",\"warnings\":[]}"
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"isError": false
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`warnings` always appears. `PNG_FONT_COVERAGE` names missing CJK/emoji coverage and points to `fontDirs`/`loadSystemFonts`; source configuration diagnostics use the same deterministic warning envelope.
|
|
98
|
+
|
|
99
|
+
### File output
|
|
100
|
+
|
|
101
|
+
Request:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"jsonrpc": "2.0",
|
|
106
|
+
"id": 2,
|
|
107
|
+
"method": "tools/call",
|
|
108
|
+
"params": {
|
|
109
|
+
"name": "render_png",
|
|
110
|
+
"arguments": {
|
|
111
|
+
"source": "flowchart TD\n A --> B",
|
|
112
|
+
"output": "file"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Response shape (`content[0].text` is JSON):
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"ok": true,
|
|
123
|
+
"artifact": {
|
|
124
|
+
"path": "/absolute/path/.agentic-mermaid-artifacts/<name>.png",
|
|
125
|
+
"mimeType": "image/png",
|
|
126
|
+
"bytes": 12345,
|
|
127
|
+
"sha256": "64 lowercase hex characters"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Use `output: "file"` when the MCP host and consumer share a filesystem or when a local orchestrator will move the artifact elsewhere.
|
|
133
|
+
|
|
134
|
+
### URL output
|
|
135
|
+
|
|
136
|
+
Request:
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"jsonrpc": "2.0",
|
|
141
|
+
"id": 3,
|
|
142
|
+
"method": "tools/call",
|
|
143
|
+
"params": {
|
|
144
|
+
"name": "render_png",
|
|
145
|
+
"arguments": {
|
|
146
|
+
"source": "flowchart TD\n A --> B",
|
|
147
|
+
"output": "url"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Response shape (`content[0].text` is JSON):
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"ok": true,
|
|
158
|
+
"artifact": {
|
|
159
|
+
"url": "http://127.0.0.1:3000/artifacts/<name>.png",
|
|
160
|
+
"mimeType": "image/png",
|
|
161
|
+
"bytes": 12345,
|
|
162
|
+
"sha256": "64 lowercase hex characters"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Fetch the artifact:
|
|
168
|
+
|
|
169
|
+
```sh
|
|
170
|
+
curl -L -o diagram.png 'http://127.0.0.1:3000/artifacts/<name>.png'
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
If the server is behind a reverse proxy, set `--public-url https://example.com/artifacts` so returned URLs are externally reachable. The URL must be absolute HTTP(S); its origin (here `https://example.com`) is also accepted by the `/rpc`, `/sse`, `/message`, and `/artifacts/*` browser-origin guard. Other browser origins remain forbidden.
|
|
174
|
+
|
|
175
|
+
## Sample SSE flow
|
|
176
|
+
|
|
177
|
+
Open the SSE stream and capture the first event:
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
curl -N http://127.0.0.1:3000/sse
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The server immediately sends an endpoint event:
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
event: endpoint
|
|
187
|
+
data: http://127.0.0.1:3000/message?sessionId=<session-id>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Post JSON-RPC to that message URL:
|
|
191
|
+
|
|
192
|
+
```sh
|
|
193
|
+
curl -sS 'http://127.0.0.1:3000/message?sessionId=<session-id>' \
|
|
194
|
+
-H 'content-type: application/json' \
|
|
195
|
+
-d '{"jsonrpc":"2.0","id":4,"method":"ping"}'
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The response is delivered on the open SSE stream:
|
|
199
|
+
|
|
200
|
+
```text
|
|
201
|
+
event: message
|
|
202
|
+
data: {"jsonrpc":"2.0","id":4,"result":{}}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Options
|
|
206
|
+
|
|
207
|
+
| Option | Default | Purpose |
|
|
208
|
+
|---|---:|---|
|
|
209
|
+
| `--transport stdio\|http` | `stdio` | Select stdio or HTTP transport. |
|
|
210
|
+
| `--host <host>` | `127.0.0.1` | HTTP bind host. Non-loopback hosts require `--auth-token`. |
|
|
211
|
+
| `--port <port>` | `3000` | HTTP bind port. Use `0` for an ephemeral test port. |
|
|
212
|
+
| `--artifact-dir <dir>` | OS temp dir | Directory for managed file/URL artifacts. Files use generated safe names. |
|
|
213
|
+
| `--public-url <url>` | `http://<host>:<port>/artifacts` | Absolute HTTP(S) prefix returned by `output: "url"`; its origin is accepted by the HTTP/SSE browser-origin guard. |
|
|
214
|
+
| `--auth-token <token>` | unset | Bearer token required for every non-health HTTP route when binding non-loopback. Optional on loopback. |
|
|
215
|
+
| `--max-artifact-bytes <n>` | `20971520` | Maximum bytes for a single managed artifact. |
|
|
216
|
+
| `--max-artifact-total-bytes <n>` | `209715200` | Aggregate byte budget for unexpired managed artifacts. |
|
|
217
|
+
| `--max-artifacts <n>` | `1000` | Maximum number of unexpired managed artifacts. |
|
|
218
|
+
| `--artifact-ttl-ms <n>` | `3600000` | How long managed artifacts remain fetchable. |
|
|
219
|
+
| `--max-rpc-body-bytes <n>` | `1048576` | Maximum HTTP JSON-RPC request body size. |
|
|
220
|
+
| `--max-sandbox-timeout-ms <n>` | `30000` | Maximum `execute` timeout accepted over any transport. |
|
|
221
|
+
|
|
222
|
+
## Security defaults
|
|
223
|
+
|
|
224
|
+
- HTTP binds to loopback by default.
|
|
225
|
+
- Non-loopback binding requires `--auth-token`.
|
|
226
|
+
- `/rpc` and `/message` reject non-JSON content types; every non-health route rejects browser origins other than the internal server or configured public origin.
|
|
227
|
+
- Request bodies and artifact sizes are bounded.
|
|
228
|
+
- URL/file artifacts use a persisted, integrity-checked manifest; aggregate quotas and TTL survive clean restarts, and cache headers never outlive the stored expiry.
|
|
229
|
+
- Exactly one live store owns an artifact directory. A second server fails before reading or writing state, preventing stale-manifest quota bypass. After an unclean stop, remove `.agentic-mermaid-artifacts-v1.lock` only after confirming no server still uses that directory.
|
|
230
|
+
- `execute(code)` still runs in local `node:vm`, not an OS/container security boundary. Do not expose HTTP/SSE to hostile users without an outer isolation layer.
|