@blocess/mcp 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +96 -2
- package/index.js +55 -0
- package/package.json +36 -3
- package/src/client.js +101 -0
- package/src/commands.js +253 -0
- package/src/server.d.ts +33 -0
- package/src/server.js +129 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 blocess contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @blocess/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[blocess](https://github.com/blocess/blocess) (業務フロー可視化ツール) の図を、AI Agent から読み書きするための MCP server です。
|
|
4
|
+
手元で stdio の server として動き、blocess の HTTP API を呼びます。
|
|
5
|
+
|
|
6
|
+
Agent の編集は、図を開いている画面に数秒で反映されます。
|
|
7
|
+
|
|
8
|
+
## 必要なもの
|
|
9
|
+
|
|
10
|
+
- Node.js 22 以降
|
|
11
|
+
- version 0.2.0 以降の `@blocess/app` で動いている blocess (手元の開発用 server、または deploy 先)
|
|
12
|
+
|
|
13
|
+
## 設定
|
|
14
|
+
|
|
15
|
+
### Claude Code
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
# 手元の開発用 server (pnpm dev) につなぐ
|
|
19
|
+
claude mcp add blocess --env BLOCESS_URL=http://127.0.0.1:5184 -- npx -y @blocess/mcp
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### そのほかの client
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"mcpServers": {
|
|
27
|
+
"blocess": {
|
|
28
|
+
"command": "npx",
|
|
29
|
+
"args": ["-y", "@blocess/mcp"],
|
|
30
|
+
"env": { "BLOCESS_URL": "http://127.0.0.1:5184" }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 環境変数
|
|
37
|
+
|
|
38
|
+
| 名前 | 内容 |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `BLOCESS_URL` | blocess の URL。`--url` でも指定できます |
|
|
41
|
+
| `BLOCESS_ACCESS_CLIENT_ID` | Cloudflare Access の service token の Client ID (deploy 先につなぐとき) |
|
|
42
|
+
| `BLOCESS_ACCESS_CLIENT_SECRET` | Cloudflare Access の service token の Client Secret |
|
|
43
|
+
|
|
44
|
+
## deploy 先につなぐ
|
|
45
|
+
|
|
46
|
+
deploy した blocess は Cloudflare Access の後ろにあるので、service token を使います。
|
|
47
|
+
|
|
48
|
+
1. Cloudflare Zero Trust で service token を作り、Client ID と Client Secret を控えます。
|
|
49
|
+
2. blocess の Access の application に、action が **Service Auth** の policy を足し、その service token を許可します。
|
|
50
|
+
3. 編集もさせる場合は、blocess の Worker の secret `EDITOR_SERVICE_TOKENS` に Client ID を入れます (複数ならカンマ区切り)。
|
|
51
|
+
入れなければ、その service token は読むことだけができます。
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
pnpm wrangler secret put EDITOR_SERVICE_TOKENS
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
4. MCP server に、URL と service token を渡します。
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
claude mcp add blocess \
|
|
61
|
+
--env BLOCESS_URL=https://<deploy 先> \
|
|
62
|
+
--env BLOCESS_ACCESS_CLIENT_ID=<Client ID> \
|
|
63
|
+
--env BLOCESS_ACCESS_CLIENT_SECRET=<Client Secret> \
|
|
64
|
+
-- npx -y @blocess/mcp
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Client Secret は、図を書き換えられる鍵です。repository に commit する設定 file には書かないでください。
|
|
68
|
+
|
|
69
|
+
## tool
|
|
70
|
+
|
|
71
|
+
| tool | 内容 |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `list_diagrams` | 図の一覧と、接続している利用者が編集できるか |
|
|
74
|
+
| `get_diagram` | 図の内容 (入れ子の木)、編集に使う ID、確認したい点 |
|
|
75
|
+
| `create_diagram` | 新しい図を作る |
|
|
76
|
+
| `edit_diagram` | 複数の命令を 1 回で当てる。1 つでも失敗したら、図は変わらない |
|
|
77
|
+
| 命令ごとの tool | `add_block`、`update_block`、`connect`、`group_blocks` など 24 個。命令 1 つを当てる |
|
|
78
|
+
|
|
79
|
+
`edit_diagram` では、何かを作る命令に `as` で名前を付けると、あとの命令の ID の欄に `$名前` と書けます。
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"diagramId": "…",
|
|
84
|
+
"commands": [
|
|
85
|
+
{ "type": "update_block", "blockId": "…", "name": "見積もりを作る", "actor": "営業担当者" },
|
|
86
|
+
{ "type": "add_block", "afterBlockId": "…", "outcomeText": "見積書", "name": "契約する", "as": "contract" },
|
|
87
|
+
{ "type": "add_outcome", "blockId": "$contract", "text": "契約書", "recipient": "取引先" }
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
図の削除と、控えに戻す操作は、tool にしていません。画面から行います。
|
|
93
|
+
|
|
94
|
+
## 画面で編集しているとき
|
|
95
|
+
|
|
96
|
+
画面に未保存の変更が無ければ、Agent の編集はそのまま画面に出ます。
|
|
97
|
+
画面で入力している途中に Agent が編集した場合は、画面の次の保存が競合になり、読み直すかどうかを選ぶ表示が出ます。
|
package/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* blocess の MCP server を stdio で起動する。
|
|
4
|
+
*
|
|
5
|
+
* BLOCESS_URL=http://127.0.0.1:5184 npx @blocess/mcp
|
|
6
|
+
*
|
|
7
|
+
* stdout は MCP の通信に使うので、人に向けた出力はすべて stderr に書く。
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
import { parseArgs } from "node:util";
|
|
11
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
12
|
+
import { createClient, createServer } from "./src/server.js";
|
|
13
|
+
|
|
14
|
+
const USAGE = `使い方: blocess-mcp [--url <blocess の URL>]
|
|
15
|
+
|
|
16
|
+
環境変数:
|
|
17
|
+
BLOCESS_URL blocess の URL (--url の代わり)
|
|
18
|
+
BLOCESS_ACCESS_CLIENT_ID Cloudflare Access の service token の Client ID (deploy 先につなぐとき)
|
|
19
|
+
BLOCESS_ACCESS_CLIENT_SECRET Cloudflare Access の service token の Client Secret
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
function fail(/** @type {string} */ message) {
|
|
23
|
+
process.stderr.write(`${message}\n\n${USAGE}`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let args;
|
|
28
|
+
try {
|
|
29
|
+
args = parseArgs({ options: { url: { type: "string" }, help: { type: "boolean", short: "h" } } }).values;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
32
|
+
}
|
|
33
|
+
if (args?.help) {
|
|
34
|
+
process.stderr.write(USAGE);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const url = args?.url ?? process.env.BLOCESS_URL;
|
|
39
|
+
if (!url) fail("blocess の URL を、--url か BLOCESS_URL で指定してください");
|
|
40
|
+
|
|
41
|
+
let client;
|
|
42
|
+
try {
|
|
43
|
+
client = createClient({
|
|
44
|
+
url: /** @type {string} */ (url),
|
|
45
|
+
clientId: process.env.BLOCESS_ACCESS_CLIENT_ID,
|
|
46
|
+
clientSecret: process.env.BLOCESS_ACCESS_CLIENT_SECRET,
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { version } = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
|
|
53
|
+
const server = createServer(/** @type {import("./src/client.js").Client} */ (client), { version });
|
|
54
|
+
await server.connect(new StdioServerTransport());
|
|
55
|
+
process.stderr.write(`blocess-mcp ${version}: ${client?.origin} に接続する設定で起動しました\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocess/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "blocess の図を AI Agent から読み書きするための MCP server (stdio)",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/blocess/blocess.git",
|
|
9
|
+
"directory": "packages/mcp"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/blocess/blocess#readme",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"bin": {
|
|
17
|
+
"blocess-mcp": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./src/server.d.ts",
|
|
22
|
+
"default": "./src/server.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"index.js",
|
|
27
|
+
"src"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
31
|
+
"zod": "^4.6.7"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=22"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test": "node --test test/"
|
|
38
|
+
}
|
|
6
39
|
}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** blocess の HTTP API の呼び出し。 */
|
|
2
|
+
|
|
3
|
+
export class ApiError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* @param {number} status
|
|
6
|
+
* @param {string} code
|
|
7
|
+
* @param {string} message
|
|
8
|
+
*/
|
|
9
|
+
constructor(status, code, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "ApiError";
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {object} ClientOptions
|
|
19
|
+
* @property {string} url blocess の URL (例: http://127.0.0.1:5184)
|
|
20
|
+
* @property {string} [clientId] Cloudflare Access の service token の Client ID
|
|
21
|
+
* @property {string} [clientSecret] Cloudflare Access の service token の Client Secret
|
|
22
|
+
* @property {typeof fetch} [fetch] test 用の差し替え
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** @param {ClientOptions} options */
|
|
26
|
+
export function createClient(options) {
|
|
27
|
+
const base = new URL(options.url);
|
|
28
|
+
if (base.protocol !== "http:" && base.protocol !== "https:") {
|
|
29
|
+
throw new Error(`BLOCESS_URL は http か https の URL にしてください: ${options.url}`);
|
|
30
|
+
}
|
|
31
|
+
const hasId = Boolean(options.clientId);
|
|
32
|
+
const hasSecret = Boolean(options.clientSecret);
|
|
33
|
+
if (hasId !== hasSecret) {
|
|
34
|
+
throw new Error("service token は、Client ID と Client Secret の両方を指定してください");
|
|
35
|
+
}
|
|
36
|
+
// secret を暗号化されない通信に載せない (手元の server は除く)
|
|
37
|
+
const local = ["localhost", "127.0.0.1", "[::1]"].includes(base.hostname);
|
|
38
|
+
if (hasSecret && base.protocol !== "https:" && !local) {
|
|
39
|
+
throw new Error("service token を使うときは、https の URL を指定してください");
|
|
40
|
+
}
|
|
41
|
+
const doFetch = options.fetch ?? fetch;
|
|
42
|
+
const origin = base.origin;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} method
|
|
46
|
+
* @param {string} path
|
|
47
|
+
* @param {unknown} [body]
|
|
48
|
+
*/
|
|
49
|
+
async function call(method, path, body) {
|
|
50
|
+
/** @type {Record<string, string>} */
|
|
51
|
+
const headers = { Accept: "application/json" };
|
|
52
|
+
if (hasId) {
|
|
53
|
+
headers["CF-Access-Client-Id"] = /** @type {string} */ (options.clientId);
|
|
54
|
+
headers["CF-Access-Client-Secret"] = /** @type {string} */ (options.clientSecret);
|
|
55
|
+
}
|
|
56
|
+
if (body !== undefined) headers["Content-Type"] = "application/json";
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await doFetch(`${origin}${path}`, {
|
|
60
|
+
method,
|
|
61
|
+
headers,
|
|
62
|
+
// Access の login 画面への redirect を追わない (HTML を JSON として読もうとして分かりにくい失敗になるため)
|
|
63
|
+
redirect: "manual",
|
|
64
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new ApiError(0, "unreachable", `${origin} に接続できません: ${error instanceof Error ? error.message : String(error)}`);
|
|
68
|
+
}
|
|
69
|
+
if (response.status >= 300 && response.status < 400) {
|
|
70
|
+
throw new ApiError(
|
|
71
|
+
response.status,
|
|
72
|
+
"unauthorized",
|
|
73
|
+
"Cloudflare Access の login 画面に転送されました。service token の指定と、Access の policy (Service Auth) を確かめてください",
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const data = await response.json().catch(() => null);
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
throw new ApiError(response.status, data?.error ?? "unknown", data?.message ?? `失敗しました (${response.status})`);
|
|
79
|
+
}
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @param {string} id */
|
|
84
|
+
const path = (id) => `/api/diagrams/${encodeURIComponent(id)}`;
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
origin,
|
|
88
|
+
/** 図を画面で開く URL @param {string} id */
|
|
89
|
+
viewUrl: (id) => `${origin}/#/d/${encodeURIComponent(id)}`,
|
|
90
|
+
me: () => call("GET", "/api/me"),
|
|
91
|
+
list: () => call("GET", "/api/diagrams"),
|
|
92
|
+
/** @param {string} name */
|
|
93
|
+
create: (name) => call("POST", "/api/diagrams", { name }),
|
|
94
|
+
/** @param {string} id */
|
|
95
|
+
outline: (id) => call("GET", `${path(id)}/outline`),
|
|
96
|
+
/** @param {string} id @param {unknown[]} commands */
|
|
97
|
+
commands: (id, commands) => call("POST", `${path(id)}/commands`, { commands }),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @typedef {ReturnType<typeof createClient>} Client */
|
package/src/commands.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 編集の命令の一覧。@blocess/core の applyCommands が受け付ける形と同じ。
|
|
3
|
+
* 命令 1 つが MCP の tool 1 つになり、edit_diagram はこれらをまとめて送る。
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
const id = (/** @type {string} */ what) => z.string().min(1).describe(what);
|
|
8
|
+
const blockId = id("ブロックの ID");
|
|
9
|
+
const duration = z
|
|
10
|
+
.object({ value: z.number().min(0), unit: z.enum(["minute", "hour", "day", "week", "month"]) })
|
|
11
|
+
.nullable()
|
|
12
|
+
.optional();
|
|
13
|
+
|
|
14
|
+
/** ブロックの中身。add_block と update_block で共通。 */
|
|
15
|
+
const blockFields = {
|
|
16
|
+
name: z.string().optional().describe("ブロックの名前 (短い見出し)"),
|
|
17
|
+
what: z.string().optional().describe("何を: 行う作業の内容"),
|
|
18
|
+
actor: z
|
|
19
|
+
.string()
|
|
20
|
+
.optional()
|
|
21
|
+
.describe("誰が: 登場人物の名前。未登録の名前なら社内の登場人物として登録する。空文字で未設定に戻す。個人名ではなく役割で書く"),
|
|
22
|
+
actorId: z.string().nullable().optional().describe("誰が: 登場人物の ID (actor の代わり)。null で未設定に戻す"),
|
|
23
|
+
duration: duration.describe("所要時間 (作業そのものにかかる時間)。null で未入力に戻す"),
|
|
24
|
+
waitTime: duration.describe("待ち時間 (着手までに待つ時間)。null で未入力に戻す"),
|
|
25
|
+
cost: z.number().min(0).nullable().optional().describe("費用 (円)。null で未入力に戻す"),
|
|
26
|
+
issue: z.string().optional().describe("課題メモ"),
|
|
27
|
+
note: z.string().optional().describe("補足"),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const actorKind = z.enum(["internal", "external", "system"]).describe("internal: 社内 / external: 社外 / system: システム");
|
|
31
|
+
const actorIcon = z
|
|
32
|
+
.union([
|
|
33
|
+
z.object({ type: z.literal("emoji"), value: z.string() }),
|
|
34
|
+
z.object({ type: z.literal("symbol"), name: z.string().describe("Material Symbols のアイコン名 (例: support_agent)") }),
|
|
35
|
+
])
|
|
36
|
+
.nullable()
|
|
37
|
+
.optional()
|
|
38
|
+
.describe("アイコン。null で自動の模様に戻す");
|
|
39
|
+
|
|
40
|
+
const recipient = {
|
|
41
|
+
recipient: z.string().optional().describe("渡し先の登場人物の名前。未登録なら登録する。空文字で渡し先なしに戻す"),
|
|
42
|
+
recipientActorId: z.string().nullable().optional().describe("渡し先の登場人物の ID (recipient の代わり)。null で渡し先なしに戻す"),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {object} CommandSpec
|
|
47
|
+
* @property {string} type
|
|
48
|
+
* @property {string} title
|
|
49
|
+
* @property {string} description
|
|
50
|
+
* @property {Record<string, import("zod").ZodType>} shape
|
|
51
|
+
* @property {string} [creates] 作るものの ID が入る結果の欄 (as で名前を付けられる)
|
|
52
|
+
* @property {boolean} [destructive]
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/** @type {CommandSpec[]} */
|
|
56
|
+
export const COMMANDS = [
|
|
57
|
+
{
|
|
58
|
+
type: "rename_diagram",
|
|
59
|
+
title: "図の名前を変える",
|
|
60
|
+
description: "図の名前を変える。",
|
|
61
|
+
shape: { name: z.string() },
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "add_actor",
|
|
65
|
+
title: "登場人物を足す",
|
|
66
|
+
description: "登場人物 (役割) を登録する。ブロックの actor に名前を書くだけでも登録されるので、社外・システムの登場人物や、アイコンを付けたいときに使う。",
|
|
67
|
+
shape: { name: z.string().min(1), kind: actorKind.optional(), icon: actorIcon },
|
|
68
|
+
creates: "actorId",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: "update_actor",
|
|
72
|
+
title: "登場人物を変える",
|
|
73
|
+
description: "登場人物の名前・種別・アイコンを変える。",
|
|
74
|
+
shape: { actorId: id("登場人物の ID"), name: z.string().min(1).optional(), kind: actorKind.optional(), icon: actorIcon },
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: "remove_actor",
|
|
78
|
+
title: "登場人物を消す",
|
|
79
|
+
description: "登場人物を消す。その人が担当していたブロックと、渡し先にしていた成果は未設定になる。",
|
|
80
|
+
shape: { actorId: id("登場人物の ID") },
|
|
81
|
+
destructive: true,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: "move_actor",
|
|
85
|
+
title: "登場人物を並び替える",
|
|
86
|
+
description: "登場人物の並び順 (レーン表示の行の順) を変える。",
|
|
87
|
+
shape: { actorId: id("登場人物の ID"), toIndex: z.number().int().min(0).describe("移動先の位置 (0 が先頭)") },
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: "add_block",
|
|
91
|
+
title: "次のブロックを足す",
|
|
92
|
+
description:
|
|
93
|
+
"ある成果のあとに行うブロックを足す。新しいブロックの「いつ」は、その成果になる。" +
|
|
94
|
+
"fromOutcomeId (既存の成果) か afterBlockId (ブロック。成果を 1 行新しく作ってつなぐ) のどちらか一方を指定する。" +
|
|
95
|
+
"名前・誰が・何をも同時に書ける。",
|
|
96
|
+
shape: {
|
|
97
|
+
fromOutcomeId: z.string().optional().describe("つなぐ元の成果の ID"),
|
|
98
|
+
afterBlockId: z.string().optional().describe("つなぐ元のブロックの ID。このブロックに成果を 1 行足してからつなぐ"),
|
|
99
|
+
outcomeText: z.string().optional().describe("afterBlockId で新しく作る成果の文 (例: 見積書を送る)"),
|
|
100
|
+
placeAfterBlockId: z
|
|
101
|
+
.string()
|
|
102
|
+
.optional()
|
|
103
|
+
.describe("新しいブロックを置く位置 (このブロックの直後、同じ階層)。省くと、つなぐ元のブロックの直後。親ブロックの外に続きを作るときは、親の ID を渡す"),
|
|
104
|
+
...blockFields,
|
|
105
|
+
},
|
|
106
|
+
creates: "blockId",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: "update_block",
|
|
110
|
+
title: "ブロックを変える",
|
|
111
|
+
description: "ブロックの名前・誰が・何を・時間・費用・メモを変える。書いた欄だけが変わる。子を持つ親ブロックで変えられるのは name だけ。",
|
|
112
|
+
shape: { blockId, ...blockFields },
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: "remove_block",
|
|
116
|
+
title: "ブロックを消す",
|
|
117
|
+
description: "ブロックを子孫ごと消す。消えた成果を待っていた「いつ」は未設定として残る。図の最後の 1 ブロックは消せない。",
|
|
118
|
+
shape: { blockId },
|
|
119
|
+
destructive: true,
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: "decompose_block",
|
|
123
|
+
title: "ブロックを分解する",
|
|
124
|
+
description: "末端のブロックを親にし、いまの内容を最初の子に移す。続けて add_block で子を足すと、1 つの業務を手順に分けられる。",
|
|
125
|
+
shape: { blockId },
|
|
126
|
+
creates: "childBlockId",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: "group_blocks",
|
|
130
|
+
title: "ブロックをまとめる",
|
|
131
|
+
description: "同じ階層のブロックを、新しい親ブロックで包む。",
|
|
132
|
+
shape: { blockIds: z.array(z.string()).min(1).describe("まとめるブロックの ID (同じ階層のもの)"), name: z.string().optional().describe("親ブロックの名前") },
|
|
133
|
+
creates: "parentBlockId",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: "ungroup_block",
|
|
137
|
+
title: "まとめを解く",
|
|
138
|
+
description: "親ブロックだけを消し、子を 1 段上に出す。",
|
|
139
|
+
shape: { blockId: id("親ブロックの ID") },
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
type: "add_trigger",
|
|
143
|
+
title: "「いつ」を足す",
|
|
144
|
+
description:
|
|
145
|
+
"ブロックが始まるきっかけを足す。schedule は定期・時刻 (例: 月に一度)、external は外部の出来事 (例: 問い合わせが来たら)。" +
|
|
146
|
+
"ほかのブロックの成果をきっかけにするときは、これではなく connect か add_block を使う。",
|
|
147
|
+
shape: { blockId, kind: z.enum(["schedule", "external"]), text: z.string().optional() },
|
|
148
|
+
creates: "triggerId",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
type: "update_trigger",
|
|
152
|
+
title: "「いつ」を変える",
|
|
153
|
+
description: "「いつ」の文や種類を変える。成果を待つ「いつ」には、condition (例: 追加から6ヶ月後) を付けられる。",
|
|
154
|
+
shape: {
|
|
155
|
+
blockId,
|
|
156
|
+
triggerId: id("「いつ」の ID"),
|
|
157
|
+
kind: z.enum(["schedule", "external"]).optional(),
|
|
158
|
+
text: z.string().optional(),
|
|
159
|
+
condition: z.string().optional().describe("成果を待つ「いつ」に付ける条件や時間差"),
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: "remove_trigger",
|
|
164
|
+
title: "「いつ」を消す",
|
|
165
|
+
description: "「いつ」を消す。成果を待つ「いつ」を消すと、そのつながりも消える。",
|
|
166
|
+
shape: { blockId, triggerId: id("「いつ」の ID") },
|
|
167
|
+
destructive: true,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
type: "add_outcome",
|
|
171
|
+
title: "成果を足す",
|
|
172
|
+
description: "ブロックの成果 (作業の結果として出るもの) を足す。成果は、次のブロックの「いつ」になる。",
|
|
173
|
+
shape: { blockId, text: z.string().optional(), ...recipient },
|
|
174
|
+
creates: "outcomeId",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
type: "update_outcome",
|
|
178
|
+
title: "成果を変える",
|
|
179
|
+
description: "成果の文や渡し先を変える。",
|
|
180
|
+
shape: { outcomeId: id("成果の ID"), text: z.string().optional(), ...recipient },
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
type: "remove_outcome",
|
|
184
|
+
title: "成果を消す",
|
|
185
|
+
description: "成果を消す。この成果を待っていた「いつ」は未設定として残る。",
|
|
186
|
+
shape: { outcomeId: id("成果の ID") },
|
|
187
|
+
destructive: true,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
type: "connect",
|
|
191
|
+
title: "成果をブロックにつなぐ",
|
|
192
|
+
description: "既存の成果を、既存のブロックの「いつ」にする (差し戻しや合流に使う)。",
|
|
193
|
+
shape: { outcomeId: id("成果の ID"), targetBlockId: id("成果を待つ側のブロックの ID") },
|
|
194
|
+
creates: "triggerId",
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
type: "disconnect",
|
|
198
|
+
title: "つながりを外す",
|
|
199
|
+
description: "成果とブロックのつながりを外す。",
|
|
200
|
+
shape: { blockId: id("成果を待っている側のブロックの ID"), triggerId: id("「いつ」の ID"), outcomeId: id("成果の ID") },
|
|
201
|
+
destructive: true,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
type: "bundle_triggers",
|
|
205
|
+
title: "「いつ」を束ねる",
|
|
206
|
+
description: "成果を待つ「いつ」を 2 つ以上束ねて「すべてそろったら」にする (束ねなければ「どれか 1 つが起きたら」)。",
|
|
207
|
+
shape: { blockId, triggerIds: z.array(z.string()).min(2) },
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
type: "unbundle_trigger",
|
|
211
|
+
title: "束ねを解く",
|
|
212
|
+
description: "束ねた「いつ」を、成果ごとの「いつ」に戻す。",
|
|
213
|
+
shape: { blockId, triggerId: id("束ねた「いつ」の ID") },
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
type: "add_resource",
|
|
217
|
+
title: "資料を足す",
|
|
218
|
+
description: "ブロックに、参照する資料 (名前と URL) を足す。",
|
|
219
|
+
shape: { blockId, name: z.string(), url: z.string().optional() },
|
|
220
|
+
creates: "resourceId",
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
type: "update_resource",
|
|
224
|
+
title: "資料を変える",
|
|
225
|
+
description: "資料の名前や URL を変える。",
|
|
226
|
+
shape: { blockId, resourceId: id("資料の ID"), name: z.string().optional(), url: z.string().optional() },
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
type: "remove_resource",
|
|
230
|
+
title: "資料を消す",
|
|
231
|
+
description: "資料を消す。",
|
|
232
|
+
shape: { blockId, resourceId: id("資料の ID") },
|
|
233
|
+
destructive: true,
|
|
234
|
+
},
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
/** edit_diagram に渡す命令 1 つの形 */
|
|
238
|
+
export const commandSchema = z.discriminatedUnion(
|
|
239
|
+
"type",
|
|
240
|
+
/** @type {[import("zod").ZodObject, ...import("zod").ZodObject[]]} */ (
|
|
241
|
+
COMMANDS.map((command) =>
|
|
242
|
+
z
|
|
243
|
+
.object({
|
|
244
|
+
type: z.literal(command.type),
|
|
245
|
+
...command.shape,
|
|
246
|
+
...(command.creates
|
|
247
|
+
? { as: z.string().regex(/^[A-Za-z_][A-Za-z0-9_-]*$/).optional().describe(`作った ${command.creates} に付ける名前。あとの命令の ID の欄に "$名前" と書くと使える`) }
|
|
248
|
+
: {}),
|
|
249
|
+
})
|
|
250
|
+
.describe(command.description),
|
|
251
|
+
)
|
|
252
|
+
),
|
|
253
|
+
);
|
package/src/server.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
|
|
3
|
+
export interface ClientOptions {
|
|
4
|
+
/** blocess の URL (例: http://127.0.0.1:5184) */
|
|
5
|
+
url: string;
|
|
6
|
+
/** Cloudflare Access の service token の Client ID */
|
|
7
|
+
clientId?: string | undefined;
|
|
8
|
+
/** Cloudflare Access の service token の Client Secret */
|
|
9
|
+
clientSecret?: string | undefined;
|
|
10
|
+
/** test 用の差し替え */
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** blocess の HTTP API の呼び出し */
|
|
15
|
+
export interface Client {
|
|
16
|
+
origin: string;
|
|
17
|
+
viewUrl(id: string): string;
|
|
18
|
+
me(): Promise<{ email: string; canEdit: boolean }>;
|
|
19
|
+
list(): Promise<{ id: string; name: string; version: number; updatedAt: string }[]>;
|
|
20
|
+
create(name: string): Promise<{ diagram: { id: string; name: string; rootIds: string[] }; version: number }>;
|
|
21
|
+
outline(id: string): Promise<{ outline: Record<string, unknown>; version: number }>;
|
|
22
|
+
commands(id: string, commands: unknown[]): Promise<{ version: number; updatedAt: string; results: Record<string, string>[] }>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class ApiError extends Error {
|
|
26
|
+
readonly status: number;
|
|
27
|
+
readonly code: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createClient(options: ClientOptions): Client;
|
|
31
|
+
|
|
32
|
+
/** blocess の図を読み書きする MCP server を作る。transport につなぐのは呼ぶ側で行う。 */
|
|
33
|
+
export function createServer(client: Client, options?: { version?: string }): McpServer;
|
package/src/server.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** blocess の図を読み書きする MCP server。tool は、渡された client 経由で blocess の HTTP API を呼ぶ。 */
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { ApiError } from "./client.js";
|
|
5
|
+
import { COMMANDS, commandSchema } from "./commands.js";
|
|
6
|
+
|
|
7
|
+
export { createClient, ApiError } from "./client.js";
|
|
8
|
+
|
|
9
|
+
const INSTRUCTIONS = `blocess は、業務フローを「ブロック」のつながりとして描くツールです。
|
|
10
|
+
|
|
11
|
+
- ブロックは 1 つの作業で、「いつ (triggers)・誰が (actor)・何を (what)・成果 (outcomes)」を持ちます。
|
|
12
|
+
- あるブロックの成果が、次のブロックの「いつ」になります。このつながりが図の矢印です。
|
|
13
|
+
- ブロックは入れ子にできます。子を持つ親ブロックは名前だけを持ち、中身は子が持ちます (大きな業務を手順に分ける)。
|
|
14
|
+
- 登場人物 (actor) は個人名ではなく、役割 (例: 経理チーム、取引先) で書きます。
|
|
15
|
+
|
|
16
|
+
使い方:
|
|
17
|
+
1. list_diagrams で図を探すか、create_diagram で作ります。新しい図には、空のブロックが 1 つあります。
|
|
18
|
+
2. get_diagram で図を読みます。編集に使う ID はすべてここに出ます。findings は、入力の抜けやボトルネックの候補です。
|
|
19
|
+
3. 編集は、まとまった変更なら edit_diagram (複数の命令を 1 回で、全部成功か全部失敗)、1 つだけなら命令ごとの tool を使います。
|
|
20
|
+
edit_diagram では、作る命令に "as": "名前" を付けると、あとの命令の ID の欄に "$名前" と書けます。
|
|
21
|
+
4. 編集は、図を開いている画面に数秒で反映されます。`;
|
|
22
|
+
|
|
23
|
+
/** @param {unknown} value */
|
|
24
|
+
const text = (value) => ({ content: [{ type: /** @type {const} */ ("text"), text: typeof value === "string" ? value : JSON.stringify(value, null, 2) }] });
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* API の失敗を、Agent が読める tool の失敗として返す。
|
|
28
|
+
* @template {unknown[]} A
|
|
29
|
+
* @param {(...args: A) => Promise<unknown>} run
|
|
30
|
+
*/
|
|
31
|
+
const guarded =
|
|
32
|
+
(run) =>
|
|
33
|
+
/** @param {A} args */
|
|
34
|
+
async (...args) => {
|
|
35
|
+
try {
|
|
36
|
+
return text(await run(...args));
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (!(error instanceof ApiError)) throw error;
|
|
39
|
+
return { ...text(`失敗しました (${error.code}): ${error.message}`), isError: true };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const diagramId = z.string().min(1).describe("図の ID (list_diagrams か create_diagram で分かる)");
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {import("./client.js").Client} client
|
|
47
|
+
* @param {{ version?: string }} [options]
|
|
48
|
+
*/
|
|
49
|
+
export function createServer(client, options = {}) {
|
|
50
|
+
const server = new McpServer({ name: "blocess", version: options.version ?? "0.0.0" }, { instructions: INSTRUCTIONS });
|
|
51
|
+
|
|
52
|
+
server.registerTool(
|
|
53
|
+
"list_diagrams",
|
|
54
|
+
{
|
|
55
|
+
title: "図の一覧",
|
|
56
|
+
description: "保存されている図の一覧 (ID、名前、更新日時) を返す。接続している利用者が編集できるかも返す。",
|
|
57
|
+
inputSchema: {},
|
|
58
|
+
annotations: { readOnlyHint: true },
|
|
59
|
+
},
|
|
60
|
+
guarded(async () => {
|
|
61
|
+
const [me, diagrams] = await Promise.all([client.me(), client.list()]);
|
|
62
|
+
return {
|
|
63
|
+
server: client.origin,
|
|
64
|
+
canEdit: me.canEdit,
|
|
65
|
+
diagrams: diagrams.map((/** @type {{ id: string }} */ diagram) => ({ ...diagram, url: client.viewUrl(diagram.id) })),
|
|
66
|
+
};
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
server.registerTool(
|
|
71
|
+
"get_diagram",
|
|
72
|
+
{
|
|
73
|
+
title: "図を読む",
|
|
74
|
+
description:
|
|
75
|
+
"図の内容を返す。blocks は入れ子の木で、未入力の欄は省かれる。triggers の waitsFor は、待っている成果とその持ち主のブロック。" +
|
|
76
|
+
"findings は、入力の抜け (担当者なし、行き止まりの成果など) とボトルネックの候補。",
|
|
77
|
+
inputSchema: { diagramId },
|
|
78
|
+
annotations: { readOnlyHint: true },
|
|
79
|
+
},
|
|
80
|
+
guarded(async ({ diagramId: id }) => {
|
|
81
|
+
const { outline, version } = await client.outline(id);
|
|
82
|
+
return { ...outline, version, url: client.viewUrl(id) };
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
server.registerTool(
|
|
87
|
+
"create_diagram",
|
|
88
|
+
{
|
|
89
|
+
title: "図を作る",
|
|
90
|
+
description: "新しい図を作る。空のブロックが 1 つある状態で始まるので、まずそのブロックを update_block で埋める。",
|
|
91
|
+
inputSchema: { name: z.string().describe("図の名前") },
|
|
92
|
+
},
|
|
93
|
+
guarded(async ({ name }) => {
|
|
94
|
+
const { diagram, version } = await client.create(name);
|
|
95
|
+
return { id: diagram.id, name: diagram.name, firstBlockId: diagram.rootIds[0], version, url: client.viewUrl(diagram.id) };
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
server.registerTool(
|
|
100
|
+
"edit_diagram",
|
|
101
|
+
{
|
|
102
|
+
title: "図をまとめて編集する",
|
|
103
|
+
description:
|
|
104
|
+
"編集の命令を上から順に当てる。1 つでも失敗したら全体が失敗し、図は変わらない。" +
|
|
105
|
+
'作る命令に "as": "名前" を付けると、あとの命令の ID の欄に "$名前" と書いて、作った ID を使える。' +
|
|
106
|
+
"結果の results は、命令と同じ順で、作ったものの ID が入る。",
|
|
107
|
+
inputSchema: { diagramId, commands: z.array(commandSchema).min(1).max(200) },
|
|
108
|
+
},
|
|
109
|
+
guarded(({ diagramId: id, commands }) => client.commands(id, commands)),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
for (const command of COMMANDS) {
|
|
113
|
+
server.registerTool(
|
|
114
|
+
command.type,
|
|
115
|
+
{
|
|
116
|
+
title: command.title,
|
|
117
|
+
description: command.description,
|
|
118
|
+
inputSchema: { diagramId, ...command.shape },
|
|
119
|
+
...(command.destructive ? { annotations: { destructiveHint: true } } : {}),
|
|
120
|
+
},
|
|
121
|
+
guarded(async ({ diagramId: id, ...fields }) => {
|
|
122
|
+
const { version, results } = await client.commands(/** @type {string} */ (id), [{ type: command.type, ...fields }]);
|
|
123
|
+
return { version, ...results[0] };
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return server;
|
|
129
|
+
}
|