@blokjs/trigger-mcp 0.6.19 → 0.6.21

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.
Files changed (2) hide show
  1. package/README.md +131 -0
  2. package/package.json +4 -4
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # @blokjs/trigger-mcp
2
+
3
+ Model Context Protocol (MCP) trigger for [Blok](https://github.com/well-prado/blok)
4
+ workflows. Expose a workflow as an MCP **tool** or **resource** so AI
5
+ clients — Claude Code, Cursor, Claude Desktop, or your own agent — can
6
+ discover and call it. Serves both transports (Streamable-HTTP + legacy
7
+ SSE) on the shared Hono HTTP port.
8
+
9
+ > **Full reference:** [Blok docs → Triggers → MCP](https://github.com/well-prado/blok/blob/main/docs/d/triggers/mcp.mdx)
10
+
11
+ ## What it does
12
+
13
+ - Scans the workflow registry for workflows with a `trigger.mcp` block and
14
+ exposes each one to MCP clients.
15
+ - Generates each tool's JSON `inputSchema` from the workflow's Zod `input`
16
+ (via `zod-to-json-schema`).
17
+ - Runs `tools/call` / `resources/read` through the normal Blok runner — so
18
+ retries, idempotency, middleware, cancellation, and Studio tracing all
19
+ apply.
20
+ - Mounts on the HTTP trigger's Hono app (same port, same process). No
21
+ separate listener.
22
+
23
+ ## Authoring a tool
24
+
25
+ A `trigger.mcp` workflow is a normal v2 workflow. The `input` schema is the
26
+ tool contract; the final step's output is the tool result.
27
+
28
+ ```ts
29
+ import { workflow } from "@blokjs/helper";
30
+ import { z } from "zod";
31
+
32
+ export default workflow({
33
+ name: "mcp-greeter",
34
+ version: "1.0.0",
35
+ input: z.object({
36
+ name: z.string().min(1).describe("Name of the person to greet"),
37
+ excited: z.boolean().default(false),
38
+ }),
39
+ trigger: {
40
+ mcp: {
41
+ path: "/mcp",
42
+ serverName: "blok-examples",
43
+ tool: { name: "greet", description: "Greet a person by name." },
44
+ },
45
+ },
46
+ steps: [
47
+ {
48
+ id: "greet",
49
+ use: "@blokjs/expr",
50
+ inputs: {
51
+ expression:
52
+ '({ greeting: "Hello, " + (ctx.request.body.name || "there") + (ctx.request.body.excited ? "!" : ".") })',
53
+ },
54
+ },
55
+ ],
56
+ });
57
+ ```
58
+
59
+ Scaffold a project with this exact example:
60
+
61
+ ```bash
62
+ npx blokctl@latest create project --triggers http,mcp --examples
63
+ ```
64
+
65
+ ## Transports & routes
66
+
67
+ Both default on; override per workflow with `transports: [...]`.
68
+
69
+ | Transport | Route(s) | State |
70
+ | --- | --- | --- |
71
+ | Streamable-HTTP | `ALL <path>` (e.g. `POST /mcp`) | Stateless |
72
+ | SSE (legacy) | `GET <path>/sse` + `POST <path>/messages?sessionId=…` | Stateful |
73
+
74
+ On start the trigger logs each mounted server and route:
75
+
76
+ ```
77
+ [blok][mcp] server "blok-examples" at /mcp — 1 tool(s), 0 resource(s), transports=[sse,streamable-http]
78
+ [blok][mcp] GET /mcp/sse POST /mcp/messages (sse)
79
+ [blok][mcp] ALL /mcp (streamable-http)
80
+ ```
81
+
82
+ ## Connecting a client
83
+
84
+ Give the client the URL `http://localhost:4000/mcp` (Streamable-HTTP) or
85
+ `http://localhost:4000/mcp/sse` (SSE).
86
+
87
+ ```bash
88
+ # Claude Code
89
+ claude mcp add --transport http blok http://localhost:4000/mcp
90
+
91
+ # Interactive debugging
92
+ npx @modelcontextprotocol/inspector # → connect to http://localhost:4000/mcp
93
+ ```
94
+
95
+ ```json
96
+ // Cursor — .cursor/mcp.json
97
+ { "mcpServers": { "blok": { "url": "http://localhost:4000/mcp" } } }
98
+ ```
99
+
100
+ Raw JSON-RPC (send `Accept: application/json, text/event-stream`):
101
+
102
+ ```bash
103
+ curl -sS http://localhost:4000/mcp \
104
+ -H 'Content-Type: application/json' \
105
+ -H 'Accept: application/json, text/event-stream' \
106
+ -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"greet","arguments":{"name":"Ada","excited":true}}}'
107
+ ```
108
+
109
+ ## Config reference
110
+
111
+ | Field | Type | Default | Notes |
112
+ | --- | --- | --- | --- |
113
+ | `path` | `string` | `"/mcp"` | Base path; workflows sharing a path aggregate into one server. |
114
+ | `serverName` | `string` | `"blok-mcp"` | Advertised to clients — set something project-specific. |
115
+ | `serverVersion` | `string` | `"1.0.0"` | Advertised server version. |
116
+ | `transports` | `("sse" \| "streamable-http")[]` | both | At least one required. |
117
+ | `tool` | `{ name?, description? }` | — | Tool mode (default). `name` defaults to the workflow name. |
118
+ | `resource` | `{ uri, name?, description?, mimeType? }` | — | Resource mode. `uri` required; `mimeType` defaults to `application/json`. |
119
+ | `middleware` | `string[]` | — | Trigger-level middleware chain. |
120
+
121
+ ## Identity is not authorization
122
+
123
+ An `x-user-context` header (base64 `{ userId, email }`) or `?user_context=`
124
+ query param is parsed and exposed at `ctx._mcp.userContext`. This is
125
+ **credential injection only** — the trigger does not verify it or scope
126
+ access. Enforce authorization yourself via trigger middleware or an auth
127
+ proxy in front of the endpoint.
128
+
129
+ ## License
130
+
131
+ Part of the Blok framework. See the repository root for license details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blokjs/trigger-mcp",
3
- "version": "0.6.19",
3
+ "version": "0.6.21",
4
4
  "files": ["dist"],
5
5
  "description": "Model Context Protocol (MCP) trigger for Blok workflows — expose workflows as MCP tools over SSE + Streamable-HTTP on the shared Hono port.",
6
6
  "type": "module",
@@ -15,9 +15,9 @@
15
15
  "author": "Deskree Technologies Inc.",
16
16
  "license": "Apache-2.0",
17
17
  "dependencies": {
18
- "@blokjs/helper": "^0.6.19",
19
- "@blokjs/runner": "^0.6.19",
20
- "@blokjs/shared": "^0.6.19",
18
+ "@blokjs/helper": "^0.6.21",
19
+ "@blokjs/runner": "^0.6.21",
20
+ "@blokjs/shared": "^0.6.21",
21
21
  "@modelcontextprotocol/sdk": "^1.29.0",
22
22
  "@opentelemetry/api": "^1.9.0",
23
23
  "hono": "^4.11.7",