blockflow-mcp 0.0.0-stage → 1.0.1

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/resources.mjs ADDED
@@ -0,0 +1,67 @@
1
+ // The documents an LLM needs to write workflows, served as MCP resources. A published package carries
2
+ // copies in ./resources (made by `npm pack` through the prepack script); in the repo they are read from
3
+ // docs/guide and llms.txt, so they are never stale while developing.
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ export const PACKAGE_DIR = path.dirname(fileURLToPath(import.meta.url));
9
+ const REPO_DIR = path.resolve(PACKAGE_DIR, '../..');
10
+
11
+ /** uri, MCP name, file name in ./resources, path in the repo. */
12
+ export const RESOURCES = [
13
+ {
14
+ uri: 'blockflow://guide',
15
+ name: 'guide',
16
+ title: 'BlockFlow usage guide',
17
+ description: 'How to write BlockFlow workflows: rules for AI tools, the script format, locators, waiting, error codes and the Repair table for import issues. Read first.',
18
+ mimeType: 'text/markdown',
19
+ file: 'README.md',
20
+ repo: 'docs/guide/README.md',
21
+ },
22
+ {
23
+ uri: 'blockflow://blocks',
24
+ name: 'blocks',
25
+ title: 'Block reference',
26
+ description: 'Every block type with its config keys, defaults and outputs (generated from the code). Block keys and settings in a script must come from here.',
27
+ mimeType: 'text/markdown',
28
+ file: 'blocks.md',
29
+ repo: 'docs/guide/blocks.md',
30
+ },
31
+ {
32
+ uri: 'blockflow://script-schema',
33
+ name: 'script-schema',
34
+ title: 'Script JSON Schema',
35
+ description: 'JSON Schema of the script format (blockflow-script, version 1). Unknown keys are errors.',
36
+ mimeType: 'application/schema+json',
37
+ file: 'script.schema.json',
38
+ repo: 'docs/guide/script.schema.json',
39
+ },
40
+ {
41
+ uri: 'blockflow://llms.txt',
42
+ name: 'llms.txt',
43
+ title: 'llms.txt',
44
+ description: 'Short index of BlockFlow for language models: what to read in which order.',
45
+ mimeType: 'text/plain',
46
+ file: 'llms.txt',
47
+ repo: 'llms.txt',
48
+ },
49
+ ];
50
+
51
+ /** Where a resource is read from: the packaged copy first, then the repo. */
52
+ export function resourcePath(resource, dirs = { packageDir: PACKAGE_DIR, repoDir: REPO_DIR }) {
53
+ const packaged = path.join(dirs.packageDir, 'resources', resource.file);
54
+ if (existsSync(packaged)) return packaged;
55
+ const inRepo = path.join(dirs.repoDir, resource.repo);
56
+ if (existsSync(inRepo)) return inRepo;
57
+ throw new Error(`${resource.title} not found (looked in ${packaged} and ${inRepo}).`);
58
+ }
59
+
60
+ export function readResource(resource, dirs) {
61
+ return readFileSync(resourcePath(resource, dirs), 'utf8');
62
+ }
63
+
64
+ /** Used by the prepack script: copies every resource from the repo into ./resources. */
65
+ export function copyResources(dirs = { packageDir: PACKAGE_DIR, repoDir: REPO_DIR }) {
66
+ return RESOURCES.map((resource) => ({ from: path.join(dirs.repoDir, resource.repo), to: path.join(dirs.packageDir, 'resources', resource.file) }));
67
+ }
@@ -0,0 +1,20 @@
1
+ // `node scripts/pack.mjs copy` (prepack): copy the guide, block reference, script schema and llms.txt
2
+ // into ./resources so the published package is self-contained. `clean` (postpack) removes the copies
3
+ // again, so a development checkout always reads the live files from the repo.
4
+ import { copyFileSync, mkdirSync, rmSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { PACKAGE_DIR, copyResources } from '../resources.mjs';
7
+
8
+ const mode = process.argv[2];
9
+ if (mode === 'copy') {
10
+ for (const { from, to } of copyResources()) {
11
+ mkdirSync(path.dirname(to), { recursive: true });
12
+ copyFileSync(from, to);
13
+ console.error(`copied ${path.relative(PACKAGE_DIR, to)}`);
14
+ }
15
+ } else if (mode === 'clean') {
16
+ rmSync(path.join(PACKAGE_DIR, 'resources'), { recursive: true, force: true });
17
+ } else {
18
+ console.error('usage: node scripts/pack.mjs copy|clean');
19
+ process.exit(2);
20
+ }
package/server.mjs ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ // blockflow-mcp: the BlockFlow MCP server over stdio. MCP clients start it with `npx blockflow-mcp`.
3
+ // It connects to the BlockFlow bridge (local socket, BLOCKFLOW_SOCKET / BLOCKFLOW_TOKEN_FILE override the
4
+ // default paths) on the first tool call, not at startup, so it starts even while the browser is closed.
5
+ // stdout is the MCP channel: log to stderr only.
6
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
7
+ import { createBlockflowServer, VERSION } from './index.mjs';
8
+
9
+ if (process.argv.includes('--version')) {
10
+ console.log(VERSION);
11
+ process.exit(0);
12
+ }
13
+
14
+ const app = createBlockflowServer();
15
+ const transport = new StdioServerTransport();
16
+
17
+ let closing = false;
18
+ async function shutdown() {
19
+ if (closing) return;
20
+ closing = true;
21
+ await app.close().catch(() => {});
22
+ process.exit(0);
23
+ }
24
+ process.stdin.on('end', shutdown);
25
+ process.on('SIGINT', shutdown);
26
+ process.on('SIGTERM', shutdown);
27
+ process.on('unhandledRejection', (error) => console.error('blockflow-mcp: unhandled rejection:', error));
28
+
29
+ await app.server.connect(transport);
30
+ console.error(`blockflow-mcp ${VERSION} ready (stdio)`);