@hasna/workflows 0.1.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 +202 -0
- package/README.md +55 -0
- package/dist/agent-tools.js +40 -0
- package/dist/cli/index.js +186 -0
- package/dist/handlers.js +40 -0
- package/dist/index.js +232 -0
- package/dist/mcp/index.js +270 -0
- package/dist/serve/index.js +232 -0
- package/dist/service.js +156 -0
- package/dist/types.js +1 -0
- package/hasna.contract.json +94 -0
- package/package.json +83 -0
- package/types/agent-tools.d.ts +23 -0
- package/types/cli/index.d.ts +2 -0
- package/types/handlers.d.ts +7 -0
- package/types/index.d.ts +10 -0
- package/types/mcp/index.d.ts +2 -0
- package/types/serve/index.d.ts +2 -0
- package/types/serve/server.d.ts +10 -0
- package/types/service.d.ts +14 -0
- package/types/types.d.ts +34 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/service.ts
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
// package.json
|
|
5
|
+
var package_default = {
|
|
6
|
+
name: "@hasna/workflows",
|
|
7
|
+
version: "0.1.0",
|
|
8
|
+
description: "Universal graph workflow app \u2014 scaffold with version/health/readiness on all four surfaces; graph language, store, session WAL, daemon, and lane adapters are roadmap",
|
|
9
|
+
type: "module",
|
|
10
|
+
main: "./dist/index.js",
|
|
11
|
+
types: "./types/index.d.ts",
|
|
12
|
+
bin: {
|
|
13
|
+
workflows: "dist/cli/index.js",
|
|
14
|
+
"workflows-mcp": "dist/mcp/index.js",
|
|
15
|
+
"workflows-serve": "dist/serve/index.js"
|
|
16
|
+
},
|
|
17
|
+
exports: {
|
|
18
|
+
".": {
|
|
19
|
+
types: "./types/index.d.ts",
|
|
20
|
+
import: "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./sdk": {
|
|
23
|
+
types: "./types/index.d.ts",
|
|
24
|
+
import: "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./cli": {
|
|
27
|
+
types: "./types/cli/index.d.ts",
|
|
28
|
+
import: "./dist/cli/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
files: [
|
|
32
|
+
"dist",
|
|
33
|
+
"types",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE",
|
|
36
|
+
"hasna.contract.json"
|
|
37
|
+
],
|
|
38
|
+
scripts: {
|
|
39
|
+
build: "bun run build:runtime && bun run build:types",
|
|
40
|
+
"build:runtime": "rm -rf dist && bun build src/cli/index.ts --outdir dist/cli --target bun --packages external && bun build src/mcp/index.ts --outdir dist/mcp --target bun --packages external && bun build src/serve/index.ts --outdir dist/serve --target bun --packages external && bun build src/index.ts src/service.ts src/handlers.ts src/agent-tools.ts src/types.ts --root src --outdir dist --target bun --packages external",
|
|
41
|
+
"build:types": "rm -rf types && tsc -p tsconfig.build.json --emitDeclarationOnly --outDir types",
|
|
42
|
+
"artifact-scan": "bun scripts/contracts-cli.mjs artifact-scan dist",
|
|
43
|
+
"contract:check": "bun scripts/contracts-cli.mjs repo-conformance .",
|
|
44
|
+
typecheck: "tsc --noEmit",
|
|
45
|
+
test: "bun test",
|
|
46
|
+
"test:pg": 'WORKFLOWS_TEST_DATABASE_URL="${WORKFLOWS_TEST_DATABASE_URL:?point it at a throwaway Postgres; the live-PG gate must not pass without one}" WORKFLOWS_REQUIRE_POSTGRES=1 bun test src/db/pg-live.test.ts',
|
|
47
|
+
prepack: "bun run build && bun run artifact-scan",
|
|
48
|
+
prepublishOnly: "bun run test && bun run build"
|
|
49
|
+
},
|
|
50
|
+
keywords: [
|
|
51
|
+
"workflows",
|
|
52
|
+
"graph",
|
|
53
|
+
"automation",
|
|
54
|
+
"cli",
|
|
55
|
+
"typescript",
|
|
56
|
+
"bun",
|
|
57
|
+
"hasna"
|
|
58
|
+
],
|
|
59
|
+
publishConfig: {
|
|
60
|
+
registry: "https://registry.npmjs.org",
|
|
61
|
+
access: "public"
|
|
62
|
+
},
|
|
63
|
+
repository: {
|
|
64
|
+
type: "git",
|
|
65
|
+
url: "git+https://github.com/hasna/apps.git"
|
|
66
|
+
},
|
|
67
|
+
homepage: "https://github.com/hasna/apps/tree/main/apps/workflows",
|
|
68
|
+
bugs: {
|
|
69
|
+
url: "https://github.com/hasna/apps/issues"
|
|
70
|
+
},
|
|
71
|
+
engines: {
|
|
72
|
+
bun: ">=1.0.0",
|
|
73
|
+
node: ">=20.0.0"
|
|
74
|
+
},
|
|
75
|
+
author: "Hasna",
|
|
76
|
+
license: "Apache-2.0",
|
|
77
|
+
dependencies: {
|
|
78
|
+
commander: "^13.1.0"
|
|
79
|
+
},
|
|
80
|
+
devDependencies: {
|
|
81
|
+
"@hasna/contracts": "0.14.0",
|
|
82
|
+
"@types/bun": "latest",
|
|
83
|
+
"@types/pg": "^8.15.6",
|
|
84
|
+
pg: "^8.16.3",
|
|
85
|
+
typescript: "^5.7.3"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/service.ts
|
|
90
|
+
var DEFAULT_PORT = 8790;
|
|
91
|
+
var DEFAULT_HOST = "127.0.0.1";
|
|
92
|
+
function packageVersion() {
|
|
93
|
+
return package_default.version;
|
|
94
|
+
}
|
|
95
|
+
function envString(names) {
|
|
96
|
+
for (const name of names) {
|
|
97
|
+
const value = process.env[name];
|
|
98
|
+
if (value !== undefined && value !== "")
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
function envInt(names, fallback) {
|
|
104
|
+
const value = envString(names);
|
|
105
|
+
if (value === undefined)
|
|
106
|
+
return fallback;
|
|
107
|
+
const parsed = Number(value);
|
|
108
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
109
|
+
}
|
|
110
|
+
function resolveWorkflowsConfig(overrides = {}) {
|
|
111
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? ".";
|
|
112
|
+
return {
|
|
113
|
+
port: overrides.port ?? envInt(["HASNA_WORKFLOWS_PORT", "WORKFLOWS_PORT"], DEFAULT_PORT),
|
|
114
|
+
host: overrides.host ?? envString(["HASNA_WORKFLOWS_HOST", "WORKFLOWS_HOST"]) ?? DEFAULT_HOST,
|
|
115
|
+
dataDir: overrides.dataDir ?? envString(["HASNA_WORKFLOWS_DATA_DIR", "WORKFLOWS_DATA_DIR"]) ?? join(home, ".hasna", "workflows"),
|
|
116
|
+
apiUrl: overrides.apiUrl ?? envString(["WORKFLOWS_API_URL"]),
|
|
117
|
+
apiKey: overrides.apiKey ?? envString(["WORKFLOWS_API_KEY"])
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class WorkflowsService {
|
|
122
|
+
name = "workflows";
|
|
123
|
+
version;
|
|
124
|
+
config;
|
|
125
|
+
startedAt = Date.now();
|
|
126
|
+
constructor(config = {}) {
|
|
127
|
+
this.config = resolveWorkflowsConfig(config);
|
|
128
|
+
this.version = packageVersion();
|
|
129
|
+
}
|
|
130
|
+
health() {
|
|
131
|
+
return {
|
|
132
|
+
ok: true,
|
|
133
|
+
service: this.name,
|
|
134
|
+
version: this.version,
|
|
135
|
+
pid: process.pid,
|
|
136
|
+
uptimeMs: Date.now() - this.startedAt
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
ready() {
|
|
140
|
+
return {
|
|
141
|
+
ok: true,
|
|
142
|
+
service: this.name,
|
|
143
|
+
version: this.version,
|
|
144
|
+
checks: { version: "ok" }
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function createWorkflowsService(config = {}) {
|
|
149
|
+
return new WorkflowsService(config);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/handlers.ts
|
|
153
|
+
function jsonResponse(body, status = 200) {
|
|
154
|
+
return new Response(JSON.stringify(body), {
|
|
155
|
+
status,
|
|
156
|
+
headers: { "content-type": "application/json" }
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function openApiDoc(service) {
|
|
160
|
+
return {
|
|
161
|
+
openapi: "3.0.3",
|
|
162
|
+
info: { title: "workflows", version: service.version },
|
|
163
|
+
paths: {
|
|
164
|
+
"/health": { get: { summary: "Service health", responses: { "200": { description: "ok" } } } },
|
|
165
|
+
"/ready": { get: { summary: "Service readiness", responses: { "200": { description: "ok" } } } },
|
|
166
|
+
"/version": { get: { summary: "Service version", responses: { "200": { description: "ok" } } } }
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function createRequestHandler(service) {
|
|
171
|
+
return (req) => {
|
|
172
|
+
const url = new URL(req.url);
|
|
173
|
+
switch (url.pathname) {
|
|
174
|
+
case "/health":
|
|
175
|
+
return jsonResponse(service.health());
|
|
176
|
+
case "/ready":
|
|
177
|
+
return jsonResponse(service.ready());
|
|
178
|
+
case "/version":
|
|
179
|
+
return jsonResponse({ service: service.name, version: service.version });
|
|
180
|
+
case "/openapi.json":
|
|
181
|
+
return jsonResponse(openApiDoc(service));
|
|
182
|
+
default:
|
|
183
|
+
return jsonResponse({ error: "not_found", path: url.pathname }, 404);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/agent-tools.ts
|
|
189
|
+
function textResult(payload) {
|
|
190
|
+
return { content: [{ type: "text", text: JSON.stringify(payload) }], isError: false };
|
|
191
|
+
}
|
|
192
|
+
function workflowsTools(_service) {
|
|
193
|
+
return [
|
|
194
|
+
{
|
|
195
|
+
name: "workflows_version",
|
|
196
|
+
description: "Report the installed @hasna/workflows version.",
|
|
197
|
+
inputSchema: { type: "object", properties: {} }
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: "workflows_health",
|
|
201
|
+
description: "Report the workflows service health (service, version, pid, uptime).",
|
|
202
|
+
inputSchema: { type: "object", properties: {} }
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "workflows_ready",
|
|
206
|
+
description: "Report the workflows service readiness (version check).",
|
|
207
|
+
inputSchema: { type: "object", properties: {} }
|
|
208
|
+
}
|
|
209
|
+
];
|
|
210
|
+
}
|
|
211
|
+
function callWorkflowTool(service, name, _args) {
|
|
212
|
+
switch (name) {
|
|
213
|
+
case "workflows_version":
|
|
214
|
+
return textResult({ service: service.name, version: service.version });
|
|
215
|
+
case "workflows_health":
|
|
216
|
+
return textResult(service.health());
|
|
217
|
+
case "workflows_ready":
|
|
218
|
+
return textResult(service.ready());
|
|
219
|
+
default:
|
|
220
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
workflowsTools,
|
|
225
|
+
resolveWorkflowsConfig,
|
|
226
|
+
packageVersion,
|
|
227
|
+
jsonResponse,
|
|
228
|
+
createWorkflowsService,
|
|
229
|
+
createRequestHandler,
|
|
230
|
+
callWorkflowTool,
|
|
231
|
+
WorkflowsService
|
|
232
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// src/mcp/index.ts
|
|
5
|
+
import { createInterface } from "readline";
|
|
6
|
+
|
|
7
|
+
// src/agent-tools.ts
|
|
8
|
+
function textResult(payload) {
|
|
9
|
+
return { content: [{ type: "text", text: JSON.stringify(payload) }], isError: false };
|
|
10
|
+
}
|
|
11
|
+
function workflowsTools(_service) {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
name: "workflows_version",
|
|
15
|
+
description: "Report the installed @hasna/workflows version.",
|
|
16
|
+
inputSchema: { type: "object", properties: {} }
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "workflows_health",
|
|
20
|
+
description: "Report the workflows service health (service, version, pid, uptime).",
|
|
21
|
+
inputSchema: { type: "object", properties: {} }
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "workflows_ready",
|
|
25
|
+
description: "Report the workflows service readiness (version check).",
|
|
26
|
+
inputSchema: { type: "object", properties: {} }
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
function callWorkflowTool(service, name, _args) {
|
|
31
|
+
switch (name) {
|
|
32
|
+
case "workflows_version":
|
|
33
|
+
return textResult({ service: service.name, version: service.version });
|
|
34
|
+
case "workflows_health":
|
|
35
|
+
return textResult(service.health());
|
|
36
|
+
case "workflows_ready":
|
|
37
|
+
return textResult(service.ready());
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/service.ts
|
|
44
|
+
import { join } from "path";
|
|
45
|
+
// package.json
|
|
46
|
+
var package_default = {
|
|
47
|
+
name: "@hasna/workflows",
|
|
48
|
+
version: "0.1.0",
|
|
49
|
+
description: "Universal graph workflow app \u2014 scaffold with version/health/readiness on all four surfaces; graph language, store, session WAL, daemon, and lane adapters are roadmap",
|
|
50
|
+
type: "module",
|
|
51
|
+
main: "./dist/index.js",
|
|
52
|
+
types: "./types/index.d.ts",
|
|
53
|
+
bin: {
|
|
54
|
+
workflows: "dist/cli/index.js",
|
|
55
|
+
"workflows-mcp": "dist/mcp/index.js",
|
|
56
|
+
"workflows-serve": "dist/serve/index.js"
|
|
57
|
+
},
|
|
58
|
+
exports: {
|
|
59
|
+
".": {
|
|
60
|
+
types: "./types/index.d.ts",
|
|
61
|
+
import: "./dist/index.js"
|
|
62
|
+
},
|
|
63
|
+
"./sdk": {
|
|
64
|
+
types: "./types/index.d.ts",
|
|
65
|
+
import: "./dist/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./cli": {
|
|
68
|
+
types: "./types/cli/index.d.ts",
|
|
69
|
+
import: "./dist/cli/index.js"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
files: [
|
|
73
|
+
"dist",
|
|
74
|
+
"types",
|
|
75
|
+
"README.md",
|
|
76
|
+
"LICENSE",
|
|
77
|
+
"hasna.contract.json"
|
|
78
|
+
],
|
|
79
|
+
scripts: {
|
|
80
|
+
build: "bun run build:runtime && bun run build:types",
|
|
81
|
+
"build:runtime": "rm -rf dist && bun build src/cli/index.ts --outdir dist/cli --target bun --packages external && bun build src/mcp/index.ts --outdir dist/mcp --target bun --packages external && bun build src/serve/index.ts --outdir dist/serve --target bun --packages external && bun build src/index.ts src/service.ts src/handlers.ts src/agent-tools.ts src/types.ts --root src --outdir dist --target bun --packages external",
|
|
82
|
+
"build:types": "rm -rf types && tsc -p tsconfig.build.json --emitDeclarationOnly --outDir types",
|
|
83
|
+
"artifact-scan": "bun scripts/contracts-cli.mjs artifact-scan dist",
|
|
84
|
+
"contract:check": "bun scripts/contracts-cli.mjs repo-conformance .",
|
|
85
|
+
typecheck: "tsc --noEmit",
|
|
86
|
+
test: "bun test",
|
|
87
|
+
"test:pg": 'WORKFLOWS_TEST_DATABASE_URL="${WORKFLOWS_TEST_DATABASE_URL:?point it at a throwaway Postgres; the live-PG gate must not pass without one}" WORKFLOWS_REQUIRE_POSTGRES=1 bun test src/db/pg-live.test.ts',
|
|
88
|
+
prepack: "bun run build && bun run artifact-scan",
|
|
89
|
+
prepublishOnly: "bun run test && bun run build"
|
|
90
|
+
},
|
|
91
|
+
keywords: [
|
|
92
|
+
"workflows",
|
|
93
|
+
"graph",
|
|
94
|
+
"automation",
|
|
95
|
+
"cli",
|
|
96
|
+
"typescript",
|
|
97
|
+
"bun",
|
|
98
|
+
"hasna"
|
|
99
|
+
],
|
|
100
|
+
publishConfig: {
|
|
101
|
+
registry: "https://registry.npmjs.org",
|
|
102
|
+
access: "public"
|
|
103
|
+
},
|
|
104
|
+
repository: {
|
|
105
|
+
type: "git",
|
|
106
|
+
url: "git+https://github.com/hasna/apps.git"
|
|
107
|
+
},
|
|
108
|
+
homepage: "https://github.com/hasna/apps/tree/main/apps/workflows",
|
|
109
|
+
bugs: {
|
|
110
|
+
url: "https://github.com/hasna/apps/issues"
|
|
111
|
+
},
|
|
112
|
+
engines: {
|
|
113
|
+
bun: ">=1.0.0",
|
|
114
|
+
node: ">=20.0.0"
|
|
115
|
+
},
|
|
116
|
+
author: "Hasna",
|
|
117
|
+
license: "Apache-2.0",
|
|
118
|
+
dependencies: {
|
|
119
|
+
commander: "^13.1.0"
|
|
120
|
+
},
|
|
121
|
+
devDependencies: {
|
|
122
|
+
"@hasna/contracts": "0.14.0",
|
|
123
|
+
"@types/bun": "latest",
|
|
124
|
+
"@types/pg": "^8.15.6",
|
|
125
|
+
pg: "^8.16.3",
|
|
126
|
+
typescript: "^5.7.3"
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/service.ts
|
|
131
|
+
var DEFAULT_PORT = 8790;
|
|
132
|
+
var DEFAULT_HOST = "127.0.0.1";
|
|
133
|
+
function packageVersion() {
|
|
134
|
+
return package_default.version;
|
|
135
|
+
}
|
|
136
|
+
function envString(names) {
|
|
137
|
+
for (const name of names) {
|
|
138
|
+
const value = process.env[name];
|
|
139
|
+
if (value !== undefined && value !== "")
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
function envInt(names, fallback) {
|
|
145
|
+
const value = envString(names);
|
|
146
|
+
if (value === undefined)
|
|
147
|
+
return fallback;
|
|
148
|
+
const parsed = Number(value);
|
|
149
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
150
|
+
}
|
|
151
|
+
function resolveWorkflowsConfig(overrides = {}) {
|
|
152
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? ".";
|
|
153
|
+
return {
|
|
154
|
+
port: overrides.port ?? envInt(["HASNA_WORKFLOWS_PORT", "WORKFLOWS_PORT"], DEFAULT_PORT),
|
|
155
|
+
host: overrides.host ?? envString(["HASNA_WORKFLOWS_HOST", "WORKFLOWS_HOST"]) ?? DEFAULT_HOST,
|
|
156
|
+
dataDir: overrides.dataDir ?? envString(["HASNA_WORKFLOWS_DATA_DIR", "WORKFLOWS_DATA_DIR"]) ?? join(home, ".hasna", "workflows"),
|
|
157
|
+
apiUrl: overrides.apiUrl ?? envString(["WORKFLOWS_API_URL"]),
|
|
158
|
+
apiKey: overrides.apiKey ?? envString(["WORKFLOWS_API_KEY"])
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
class WorkflowsService {
|
|
163
|
+
name = "workflows";
|
|
164
|
+
version;
|
|
165
|
+
config;
|
|
166
|
+
startedAt = Date.now();
|
|
167
|
+
constructor(config = {}) {
|
|
168
|
+
this.config = resolveWorkflowsConfig(config);
|
|
169
|
+
this.version = packageVersion();
|
|
170
|
+
}
|
|
171
|
+
health() {
|
|
172
|
+
return {
|
|
173
|
+
ok: true,
|
|
174
|
+
service: this.name,
|
|
175
|
+
version: this.version,
|
|
176
|
+
pid: process.pid,
|
|
177
|
+
uptimeMs: Date.now() - this.startedAt
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
ready() {
|
|
181
|
+
return {
|
|
182
|
+
ok: true,
|
|
183
|
+
service: this.name,
|
|
184
|
+
version: this.version,
|
|
185
|
+
checks: { version: "ok" }
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function createWorkflowsService(config = {}) {
|
|
190
|
+
return new WorkflowsService(config);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/mcp/index.ts
|
|
194
|
+
var HELP_TEXT = `workflows-mcp \u2014 MCP server for @hasna/workflows
|
|
195
|
+
|
|
196
|
+
Usage:
|
|
197
|
+
workflows-mcp [--version] [--help]
|
|
198
|
+
|
|
199
|
+
Speaks the MCP protocol over stdio. Tools:
|
|
200
|
+
workflows_version report the installed version
|
|
201
|
+
workflows_health report service health
|
|
202
|
+
workflows_ready report service readiness`;
|
|
203
|
+
var argv = process.argv.slice(2);
|
|
204
|
+
if (argv.includes("--version") || argv.includes("-v")) {
|
|
205
|
+
console.log(packageVersion());
|
|
206
|
+
process.exit(0);
|
|
207
|
+
}
|
|
208
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
209
|
+
console.log(HELP_TEXT);
|
|
210
|
+
process.exit(0);
|
|
211
|
+
}
|
|
212
|
+
function respond(id, result) {
|
|
213
|
+
if (id === null || id === undefined)
|
|
214
|
+
return;
|
|
215
|
+
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, result }) + `
|
|
216
|
+
`);
|
|
217
|
+
}
|
|
218
|
+
function respondError(id, code, message) {
|
|
219
|
+
if (id === null || id === undefined)
|
|
220
|
+
return;
|
|
221
|
+
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } }) + `
|
|
222
|
+
`);
|
|
223
|
+
}
|
|
224
|
+
var service = createWorkflowsService();
|
|
225
|
+
var rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
226
|
+
rl.on("line", (line) => {
|
|
227
|
+
const trimmed = line.trim();
|
|
228
|
+
if (trimmed === "")
|
|
229
|
+
return;
|
|
230
|
+
let msg;
|
|
231
|
+
try {
|
|
232
|
+
msg = JSON.parse(trimmed);
|
|
233
|
+
} catch {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const method = msg.method ?? "";
|
|
237
|
+
if (method === "initialize") {
|
|
238
|
+
respond(msg.id ?? null, {
|
|
239
|
+
protocolVersion: "2024-11-05",
|
|
240
|
+
capabilities: { tools: {} },
|
|
241
|
+
serverInfo: { name: "workflows-mcp", version: packageVersion() }
|
|
242
|
+
});
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (method.startsWith("notifications/"))
|
|
246
|
+
return;
|
|
247
|
+
if (method === "ping") {
|
|
248
|
+
respond(msg.id ?? null, {});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (method === "tools/list") {
|
|
252
|
+
respond(msg.id ?? null, { tools: workflowsTools(service) });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (method === "tools/call") {
|
|
256
|
+
const params = msg.params ?? {};
|
|
257
|
+
const name = typeof params.name === "string" ? params.name : "";
|
|
258
|
+
const args = params.arguments ?? {};
|
|
259
|
+
try {
|
|
260
|
+
respond(msg.id ?? null, callWorkflowTool(service, name, args));
|
|
261
|
+
} catch (err) {
|
|
262
|
+
respond(msg.id ?? null, {
|
|
263
|
+
content: [{ type: "text", text: String(err instanceof Error ? err.message : err) }],
|
|
264
|
+
isError: true
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
respondError(msg.id ?? null, -32601, `Method not found: ${method}`);
|
|
270
|
+
});
|