@zeph-to/mcp-server 1.10.0 → 1.11.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/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +25 -1
- package/dist/poll.d.ts.map +1 -1
- package/dist/poll.js +4 -2
- package/dist/sanitize.d.ts +34 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +71 -0
- package/dist/tools/ask.d.ts +1 -1
- package/dist/tools/ask.d.ts.map +1 -1
- package/dist/tools/ask.js +35 -12
- package/dist/tools/file.d.ts +1 -1
- package/dist/tools/file.d.ts.map +1 -1
- package/dist/tools/file.js +2 -1
- package/dist/tools/input.d.ts +1 -1
- package/dist/tools/input.d.ts.map +1 -1
- package/dist/tools/input.js +4 -2
- package/dist/tools/notify.d.ts +1 -1
- package/dist/tools/notify.d.ts.map +1 -1
- package/dist/tools/notify.js +24 -16
- package/dist/tools/prompt.d.ts +1 -1
- package/dist/tools/prompt.d.ts.map +1 -1
- package/dist/tools/prompt.js +4 -2
- package/package.json +5 -2
package/dist/config.d.ts
CHANGED
|
@@ -4,6 +4,15 @@ export interface McpServerConfig {
|
|
|
4
4
|
hookId?: string;
|
|
5
5
|
deviceId?: string;
|
|
6
6
|
sessionId?: string;
|
|
7
|
+
/** Last path segment of the project directory — prefixed onto push titles. */
|
|
8
|
+
projectName: string;
|
|
7
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Prefix a push title with the project name so the device feed stays
|
|
12
|
+
* scannable — "zeph · Build finished" instead of a bare "Build finished".
|
|
13
|
+
* Idempotent: a title already carrying the project segment is returned
|
|
14
|
+
* unchanged (guards against double-prefixing on retries).
|
|
15
|
+
*/
|
|
16
|
+
export declare const formatPushTitle: (projectName: string, title: string) => string;
|
|
8
17
|
export declare const loadConfig: () => McpServerConfig;
|
|
9
18
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,WAAW,EAAE,MAAM,CAAC;CACvB;AAiBD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,aAAa,MAAM,EAAE,OAAO,MAAM,KAAG,MAGpE,CAAC;AAgGF,eAAO,MAAM,UAAU,QAAO,eAsB7B,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadConfig = void 0;
|
|
3
|
+
exports.loadConfig = exports.formatPushTitle = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const os_1 = require("os");
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const DEFAULT_BASE_URL = 'https://api.zeph.to/v1';
|
|
10
|
+
const PROJECT_DIR_ENV_KEYS = ['CLAUDE_PROJECT_DIR', 'CURSOR_PROJECT_DIR', 'WINDSURF_PROJECT_DIR'];
|
|
11
|
+
/** The project directory the agent runs in, across supported agents. */
|
|
12
|
+
const detectProjectDir = () => {
|
|
13
|
+
for (const key of PROJECT_DIR_ENV_KEYS) {
|
|
14
|
+
const val = process.env[key];
|
|
15
|
+
if (val)
|
|
16
|
+
return val;
|
|
17
|
+
}
|
|
18
|
+
return process.cwd();
|
|
19
|
+
};
|
|
20
|
+
/** Last path segment of a directory: "/Users/me/code/zeph" -> "zeph". */
|
|
21
|
+
const projectNameFromDir = (dir) => dir.split('/').filter(Boolean).pop() ?? 'project';
|
|
22
|
+
/**
|
|
23
|
+
* Prefix a push title with the project name so the device feed stays
|
|
24
|
+
* scannable — "zeph · Build finished" instead of a bare "Build finished".
|
|
25
|
+
* Idempotent: a title already carrying the project segment is returned
|
|
26
|
+
* unchanged (guards against double-prefixing on retries).
|
|
27
|
+
*/
|
|
28
|
+
const formatPushTitle = (projectName, title) => {
|
|
29
|
+
const prefix = `${projectName} · `;
|
|
30
|
+
return title.startsWith(prefix) ? title : prefix + title;
|
|
31
|
+
};
|
|
32
|
+
exports.formatPushTitle = formatPushTitle;
|
|
10
33
|
const resolvedEnv = (key) => {
|
|
11
34
|
const val = process.env[key];
|
|
12
35
|
return val && !val.startsWith('${') ? val : undefined;
|
|
@@ -111,6 +134,7 @@ const loadConfig = () => {
|
|
|
111
134
|
hookId: resolvedEnv('ZEPH_HOOK_ID') ?? fileConfig.hookId,
|
|
112
135
|
deviceId: resolvedEnv('ZEPH_DEVICE_ID') ?? fileConfig.deviceId,
|
|
113
136
|
sessionId,
|
|
137
|
+
projectName: projectNameFromDir(detectProjectDir()),
|
|
114
138
|
};
|
|
115
139
|
};
|
|
116
140
|
exports.loadConfig = loadConfig;
|
package/dist/poll.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../src/poll.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAE5C,gBAAgB,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAOD,eAAO,MAAM,eAAe,GAC1B,QAAQ,aAAa,EACrB,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,gBAAgB,MAAM,EACtB,KAAK,WAAW,KACf,OAAO,CAAC,iBAAiB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../src/poll.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAE5C,gBAAgB,EAAE,CAAC,YAAY,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAOD,eAAO,MAAM,eAAe,GAC1B,QAAQ,aAAa,EACrB,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,gBAAgB,MAAM,EACtB,KAAK,WAAW,KACf,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAwClC,CAAC"}
|
package/dist/poll.js
CHANGED
|
@@ -33,8 +33,10 @@ const pollForResponse = async (client, hookId, eventId, timeoutSeconds, ctx) =>
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
// Adaptive interval:
|
|
37
|
-
|
|
36
|
+
// Adaptive interval: poll every 1s while the user is likely still at
|
|
37
|
+
// their device (first ~60 attempts ≈ 1 min), then back off to 3s for
|
|
38
|
+
// long waits. The tight 1s window keeps post-tap detection snappy.
|
|
39
|
+
const interval = attempt < 60 ? 1000 : 3000;
|
|
38
40
|
await sleep(interval);
|
|
39
41
|
attempt++;
|
|
40
42
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defensive cleanup for tool arguments.
|
|
3
|
+
*
|
|
4
|
+
* An agent occasionally emits a malformed tool call where a parameter's
|
|
5
|
+
* closing tag is wrong, so the serialized markup of the *following*
|
|
6
|
+
* parameters bleeds into an earlier string argument.
|
|
7
|
+
*
|
|
8
|
+
* Observed in the wild — a zeph_ask `body` arrived as:
|
|
9
|
+
*
|
|
10
|
+
* "...Commit now or test first?</body>
|
|
11
|
+
* <parameter name=\"actions\">[{\"id\":\"commit\",...}]"
|
|
12
|
+
*
|
|
13
|
+
* The actions JSON leaked into `body`, and `actions` itself arrived
|
|
14
|
+
* undefined — so the push showed the raw markup and no buttons.
|
|
15
|
+
*
|
|
16
|
+
* sanitizeText strips the leaked markup; recoverActions pulls the
|
|
17
|
+
* swallowed actions array back out so the call still works.
|
|
18
|
+
*/
|
|
19
|
+
export interface RecoveredAction {
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
style?: 'primary' | 'secondary' | 'danger';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Strip leaked tool-call markup from a free-text argument. Returns the
|
|
26
|
+
* text unchanged when no leak is detected.
|
|
27
|
+
*/
|
|
28
|
+
export declare const sanitizeText: (text: string | undefined) => string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Recover an `actions` array that leaked into the body of a malformed
|
|
31
|
+
* zeph_ask call. Returns undefined when nothing parseable is found.
|
|
32
|
+
*/
|
|
33
|
+
export declare const recoverActions: (text: string | undefined) => RecoveredAction[] | undefined;
|
|
34
|
+
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;CAC5C;AAeD;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SAIhE,CAAC;AASF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,GAAG,SAAS,KAAG,eAAe,EAAE,GAAG,SAgB7E,CAAC"}
|
package/dist/sanitize.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Defensive cleanup for tool arguments.
|
|
4
|
+
*
|
|
5
|
+
* An agent occasionally emits a malformed tool call where a parameter's
|
|
6
|
+
* closing tag is wrong, so the serialized markup of the *following*
|
|
7
|
+
* parameters bleeds into an earlier string argument.
|
|
8
|
+
*
|
|
9
|
+
* Observed in the wild — a zeph_ask `body` arrived as:
|
|
10
|
+
*
|
|
11
|
+
* "...Commit now or test first?</body>
|
|
12
|
+
* <parameter name=\"actions\">[{\"id\":\"commit\",...}]"
|
|
13
|
+
*
|
|
14
|
+
* The actions JSON leaked into `body`, and `actions` itself arrived
|
|
15
|
+
* undefined — so the push showed the raw markup and no buttons.
|
|
16
|
+
*
|
|
17
|
+
* sanitizeText strips the leaked markup; recoverActions pulls the
|
|
18
|
+
* swallowed actions array back out so the call still works.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.recoverActions = exports.sanitizeText = void 0;
|
|
22
|
+
// Markers that should never appear in a real notification body — their
|
|
23
|
+
// presence means tool-call markup has leaked in. Cut at the earliest one.
|
|
24
|
+
const LEAK_MARKERS = ['</body>', '</parameter>', '<parameter name=', '<parameter '];
|
|
25
|
+
const findLeakStart = (text) => {
|
|
26
|
+
let earliest = -1;
|
|
27
|
+
for (const marker of LEAK_MARKERS) {
|
|
28
|
+
const idx = text.indexOf(marker);
|
|
29
|
+
if (idx !== -1 && (earliest === -1 || idx < earliest))
|
|
30
|
+
earliest = idx;
|
|
31
|
+
}
|
|
32
|
+
return earliest;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Strip leaked tool-call markup from a free-text argument. Returns the
|
|
36
|
+
* text unchanged when no leak is detected.
|
|
37
|
+
*/
|
|
38
|
+
const sanitizeText = (text) => {
|
|
39
|
+
if (!text)
|
|
40
|
+
return text;
|
|
41
|
+
const cut = findLeakStart(text);
|
|
42
|
+
return cut === -1 ? text : text.slice(0, cut).trimEnd();
|
|
43
|
+
};
|
|
44
|
+
exports.sanitizeText = sanitizeText;
|
|
45
|
+
const isActionArray = (value) => Array.isArray(value) &&
|
|
46
|
+
value.length > 0 &&
|
|
47
|
+
value.every((a) => a && typeof a.id === 'string' && typeof a.label === 'string');
|
|
48
|
+
/**
|
|
49
|
+
* Recover an `actions` array that leaked into the body of a malformed
|
|
50
|
+
* zeph_ask call. Returns undefined when nothing parseable is found.
|
|
51
|
+
*/
|
|
52
|
+
const recoverActions = (text) => {
|
|
53
|
+
if (!text)
|
|
54
|
+
return undefined;
|
|
55
|
+
const marker = text.search(/<(?:antml:)?parameter name="actions">/);
|
|
56
|
+
if (marker === -1)
|
|
57
|
+
return undefined;
|
|
58
|
+
const after = text.slice(marker);
|
|
59
|
+
const start = after.indexOf('[');
|
|
60
|
+
const end = after.lastIndexOf(']');
|
|
61
|
+
if (start === -1 || end <= start)
|
|
62
|
+
return undefined;
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(after.slice(start, end + 1));
|
|
65
|
+
return isActionArray(parsed) ? parsed : undefined;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.recoverActions = recoverActions;
|
package/dist/tools/ask.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { ZephApiClient } from '../api-client.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type McpServerConfig } from '../config.js';
|
|
4
4
|
export declare const registerAskTool: (server: McpServer, client: ZephApiClient, config: McpServerConfig) => void;
|
|
5
5
|
//# sourceMappingURL=ask.d.ts.map
|
package/dist/tools/ask.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../../src/tools/ask.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../../src/tools/ask.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAwBrE,eAAO,MAAM,eAAe,GAAI,QAAQ,SAAS,EAAE,QAAQ,aAAa,EAAE,QAAQ,eAAe,SAgIhG,CAAC"}
|
package/dist/tools/ask.js
CHANGED
|
@@ -4,10 +4,23 @@ exports.registerAskTool = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const error_format_js_1 = require("../error-format.js");
|
|
6
6
|
const poll_js_1 = require("../poll.js");
|
|
7
|
+
const config_js_1 = require("../config.js");
|
|
7
8
|
const crypto_js_1 = require("../crypto.js");
|
|
8
9
|
const mime_js_1 = require("../mime.js");
|
|
9
|
-
const
|
|
10
|
+
const sanitize_js_1 = require("../sanitize.js");
|
|
11
|
+
// The device feed shows a short preview of the body. Anything longer than
|
|
12
|
+
// this gets truncated there, so we attach the full text as a file — the
|
|
13
|
+
// user can always open the complete content instead of squinting at a
|
|
14
|
+
// clipped preview.
|
|
10
15
|
const PREVIEW_LENGTH = 200;
|
|
16
|
+
/** Self-contained Markdown for the attached response.md: heading + body + options. */
|
|
17
|
+
const buildAskMarkdown = (title, body, actions) => {
|
|
18
|
+
const parts = [`# ${title}`, '', body];
|
|
19
|
+
if (actions && actions.length > 0) {
|
|
20
|
+
parts.push('', '---', '', `**Options:** ${actions.map((a) => a.label).join(' · ')}`);
|
|
21
|
+
}
|
|
22
|
+
return parts.join('\n');
|
|
23
|
+
};
|
|
11
24
|
const registerAskTool = (server, client, config) => {
|
|
12
25
|
server.registerTool('zeph_ask', {
|
|
13
26
|
description: 'Ask the user a question with optional quick-reply buttons and a text input field. Combines prompt (buttons) and input (text) in a single notification. The user can either tap a button or type a response. Blocks until the user responds or the timeout is reached. Requires ZEPH_HOOK_ID environment variable.',
|
|
@@ -50,21 +63,31 @@ const registerAskTool = (server, client, config) => {
|
|
|
50
63
|
if (!config.hookId)
|
|
51
64
|
return (0, error_format_js_1.hookNotConfiguredError)();
|
|
52
65
|
try {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
const pushTitle = (0, config_js_1.formatPushTitle)(config.projectName, title);
|
|
67
|
+
// Defend against malformed tool calls where the actions array leaked
|
|
68
|
+
// into the body (a mis-closed `body` parameter). Recover the actions
|
|
69
|
+
// from the raw body first, then strip the leaked markup. Without this
|
|
70
|
+
// the push arrives with no buttons and raw markup in the text.
|
|
71
|
+
const effectiveActions = actions && actions.length > 0 ? actions : (0, sanitize_js_1.recoverActions)(body);
|
|
72
|
+
const cleanBody = (0, sanitize_js_1.sanitizeText)(body);
|
|
73
|
+
// Attach a file whenever the body would be clipped in the feed preview.
|
|
74
|
+
const exceedsPreview = !!cleanBody && cleanBody.length > PREVIEW_LENGTH;
|
|
75
|
+
let triggerBody = cleanBody;
|
|
56
76
|
let files;
|
|
57
|
-
if (
|
|
77
|
+
if (exceedsPreview && cleanBody) {
|
|
58
78
|
const fileName = 'response.md';
|
|
59
79
|
const fileType = (0, mime_js_1.inferMimeType)(fileName);
|
|
60
80
|
const canEncrypt = !!(0, crypto_js_1.getKeyPair)() && !!(0, crypto_js_1.getPublicKey)();
|
|
61
|
-
|
|
81
|
+
// Self-contained Markdown so the file alone tells the whole story.
|
|
82
|
+
const fileMarkdown = buildAskMarkdown(title, cleanBody, effectiveActions);
|
|
83
|
+
const fileBytes = new TextEncoder().encode(fileMarkdown).byteLength;
|
|
84
|
+
let uploadContent = fileMarkdown;
|
|
62
85
|
let uploadContentType = fileType;
|
|
63
86
|
let fileIv;
|
|
64
87
|
let fileEncryptedKey;
|
|
65
88
|
if (canEncrypt) {
|
|
66
89
|
try {
|
|
67
|
-
const encrypted = await (0, crypto_js_1.encryptFileForSelf)(
|
|
90
|
+
const encrypted = await (0, crypto_js_1.encryptFileForSelf)(fileMarkdown);
|
|
68
91
|
uploadContent = encrypted.ciphertext;
|
|
69
92
|
uploadContentType = 'application/octet-stream';
|
|
70
93
|
fileIv = encrypted.iv;
|
|
@@ -74,15 +97,15 @@ const registerAskTool = (server, client, config) => {
|
|
|
74
97
|
console.error('[Crypto] File encryption failed, sending plaintext:', err);
|
|
75
98
|
}
|
|
76
99
|
}
|
|
77
|
-
const upload = await client.requestUpload({ fileName, fileType: uploadContentType, fileSize: typeof uploadContent === 'string' ?
|
|
100
|
+
const upload = await client.requestUpload({ fileName, fileType: uploadContentType, fileSize: typeof uploadContent === 'string' ? fileBytes : uploadContent.length });
|
|
78
101
|
await client.uploadToS3(upload.data.uploadUrl, uploadContent, uploadContentType);
|
|
79
|
-
triggerBody =
|
|
80
|
-
files = [{ fileKey: upload.data.fileKey, fileName, fileSize:
|
|
102
|
+
triggerBody = cleanBody.slice(0, PREVIEW_LENGTH) + '...';
|
|
103
|
+
files = [{ fileKey: upload.data.fileKey, fileName, fileSize: fileBytes, fileType, iv: fileIv, encryptedKey: fileEncryptedKey }];
|
|
81
104
|
}
|
|
82
105
|
const trigger = await client.triggerHook(config.hookId, {
|
|
83
|
-
title,
|
|
106
|
+
title: pushTitle,
|
|
84
107
|
body: triggerBody,
|
|
85
|
-
actions,
|
|
108
|
+
actions: effectiveActions,
|
|
86
109
|
timeout,
|
|
87
110
|
fallback,
|
|
88
111
|
hookType: 'combo',
|
package/dist/tools/file.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { ZephApiClient } from '../api-client.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type McpServerConfig } from '../config.js';
|
|
4
4
|
export declare const registerFileTool: (server: McpServer, client: ZephApiClient, config: McpServerConfig) => void;
|
|
5
5
|
//# sourceMappingURL=file.d.ts.map
|
package/dist/tools/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/tools/file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/tools/file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAKrE,eAAO,MAAM,gBAAgB,GAAI,QAAQ,SAAS,EAAE,QAAQ,aAAa,EAAE,QAAQ,eAAe,SA2EjG,CAAC"}
|
package/dist/tools/file.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerFileTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
const config_js_1 = require("../config.js");
|
|
5
6
|
const error_format_js_1 = require("../error-format.js");
|
|
6
7
|
const crypto_js_1 = require("../crypto.js");
|
|
7
8
|
const mime_js_1 = require("../mime.js");
|
|
@@ -47,7 +48,7 @@ const registerFileTool = (server, client, config) => {
|
|
|
47
48
|
// Step 3: Upload content to S3
|
|
48
49
|
await client.uploadToS3(upload.data.uploadUrl, uploadContent, fileType);
|
|
49
50
|
// Step 4: Send file push (encrypt push body if possible)
|
|
50
|
-
const pushTitle = title ?? fileName;
|
|
51
|
+
const pushTitle = (0, config_js_1.formatPushTitle)(config.projectName, title ?? fileName);
|
|
51
52
|
let pushPayload = {
|
|
52
53
|
title: pushTitle,
|
|
53
54
|
type: 'file',
|
package/dist/tools/input.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { ZephApiClient } from '../api-client.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type McpServerConfig } from '../config.js';
|
|
4
4
|
export declare const registerInputTool: (server: McpServer, client: ZephApiClient, config: McpServerConfig) => void;
|
|
5
5
|
//# sourceMappingURL=input.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/tools/input.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/tools/input.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAGrE,eAAO,MAAM,iBAAiB,GAAI,QAAQ,SAAS,EAAE,QAAQ,aAAa,EAAE,QAAQ,eAAe,SAwDlG,CAAC"}
|
package/dist/tools/input.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.registerInputTool = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const error_format_js_1 = require("../error-format.js");
|
|
6
6
|
const poll_js_1 = require("../poll.js");
|
|
7
|
+
const config_js_1 = require("../config.js");
|
|
8
|
+
const sanitize_js_1 = require("../sanitize.js");
|
|
7
9
|
const registerInputTool = (server, client, config) => {
|
|
8
10
|
server.registerTool('zeph_input', {
|
|
9
11
|
description: 'Request text input from the user via push notification. The tool blocks until the user responds or the timeout is reached. Requires ZEPH_HOOK_ID environment variable.',
|
|
@@ -32,8 +34,8 @@ const registerInputTool = (server, client, config) => {
|
|
|
32
34
|
return (0, error_format_js_1.hookNotConfiguredError)();
|
|
33
35
|
try {
|
|
34
36
|
const trigger = await client.triggerHook(config.hookId, {
|
|
35
|
-
title,
|
|
36
|
-
body,
|
|
37
|
+
title: (0, config_js_1.formatPushTitle)(config.projectName, title),
|
|
38
|
+
body: (0, sanitize_js_1.sanitizeText)(body),
|
|
37
39
|
timeout,
|
|
38
40
|
hookType: 'input',
|
|
39
41
|
metadata: { placeholder, inputType },
|
package/dist/tools/notify.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { ZephApiClient } from '../api-client.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type McpServerConfig } from '../config.js';
|
|
4
4
|
export declare const registerNotifyTool: (server: McpServer, client: ZephApiClient, config: McpServerConfig) => void;
|
|
5
5
|
//# sourceMappingURL=notify.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../../src/tools/notify.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../../src/tools/notify.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AASrE,eAAO,MAAM,kBAAkB,GAAI,QAAQ,SAAS,EAAE,QAAQ,aAAa,EAAE,QAAQ,eAAe,SAmHnG,CAAC"}
|
package/dist/tools/notify.js
CHANGED
|
@@ -3,13 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.registerNotifyTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const error_format_js_1 = require("../error-format.js");
|
|
6
|
+
const config_js_1 = require("../config.js");
|
|
6
7
|
const crypto_js_1 = require("../crypto.js");
|
|
7
8
|
const mime_js_1 = require("../mime.js");
|
|
8
|
-
const
|
|
9
|
+
const sanitize_js_1 = require("../sanitize.js");
|
|
10
|
+
// The device feed shows a short preview of the body. Anything longer gets
|
|
11
|
+
// truncated there, so we attach the full text as a file for full viewing.
|
|
9
12
|
const PREVIEW_LENGTH = 200;
|
|
10
13
|
const registerNotifyTool = (server, client, config) => {
|
|
11
14
|
server.registerTool('zeph_notify', {
|
|
12
|
-
description: 'Send a one-way push notification to the user\'s devices. Use this to inform the user about task completion, errors, or status updates. Long bodies
|
|
15
|
+
description: 'Send a one-way push notification to the user\'s devices. Use this to inform the user about task completion, errors, or status updates. Long bodies are automatically uploaded as a file for full viewing.',
|
|
13
16
|
annotations: {
|
|
14
17
|
readOnlyHint: false,
|
|
15
18
|
destructiveHint: false,
|
|
@@ -28,21 +31,26 @@ const registerNotifyTool = (server, client, config) => {
|
|
|
28
31
|
}, async ({ title, body, url, priority, targetDeviceId }) => {
|
|
29
32
|
try {
|
|
30
33
|
const deviceId = targetDeviceId ?? config.deviceId;
|
|
31
|
-
const
|
|
32
|
-
|
|
34
|
+
const pushTitle = (0, config_js_1.formatPushTitle)(config.projectName, title);
|
|
35
|
+
// Strip any tool-call markup that leaked into the body argument.
|
|
36
|
+
const cleanBody = (0, sanitize_js_1.sanitizeText)(body);
|
|
37
|
+
// Attach a file whenever the body would be clipped in the feed preview.
|
|
38
|
+
const isLongBody = !!cleanBody && cleanBody.length > PREVIEW_LENGTH;
|
|
33
39
|
const canEncrypt = !!(0, crypto_js_1.getKeyPair)() && !!(0, crypto_js_1.getPublicKey)();
|
|
34
|
-
if (isLongBody &&
|
|
40
|
+
if (isLongBody && cleanBody) {
|
|
35
41
|
const fileName = 'response.md';
|
|
36
42
|
const fileType = (0, mime_js_1.inferMimeType)(fileName);
|
|
37
|
-
|
|
43
|
+
// Self-contained Markdown so the file alone carries the full text.
|
|
44
|
+
const fileMarkdown = `# ${title}\n\n${cleanBody}`;
|
|
45
|
+
const fileBytes = new TextEncoder().encode(fileMarkdown).byteLength;
|
|
38
46
|
// Encrypt file content if keys available
|
|
39
|
-
let uploadContent =
|
|
47
|
+
let uploadContent = fileMarkdown;
|
|
40
48
|
let uploadContentType = fileType;
|
|
41
49
|
let fileIv;
|
|
42
50
|
let fileEncryptedKey;
|
|
43
51
|
if (canEncrypt) {
|
|
44
52
|
try {
|
|
45
|
-
const encrypted = await (0, crypto_js_1.encryptFileForSelf)(
|
|
53
|
+
const encrypted = await (0, crypto_js_1.encryptFileForSelf)(fileMarkdown);
|
|
46
54
|
uploadContent = encrypted.ciphertext;
|
|
47
55
|
uploadContentType = 'application/octet-stream';
|
|
48
56
|
fileIv = encrypted.iv;
|
|
@@ -52,23 +60,23 @@ const registerNotifyTool = (server, client, config) => {
|
|
|
52
60
|
console.error('[Crypto] File encryption failed, sending plaintext:', err);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
|
-
const upload = await client.requestUpload({ fileName, fileType: uploadContentType, fileSize: typeof uploadContent === 'string' ?
|
|
63
|
+
const upload = await client.requestUpload({ fileName, fileType: uploadContentType, fileSize: typeof uploadContent === 'string' ? fileBytes : uploadContent.length });
|
|
56
64
|
await client.uploadToS3(upload.data.uploadUrl, uploadContent, uploadContentType);
|
|
57
|
-
const preview =
|
|
65
|
+
const preview = cleanBody.slice(0, PREVIEW_LENGTH) + '...';
|
|
58
66
|
// Encrypt push body (title/preview/url) if keys available
|
|
59
67
|
let pushPayload = {
|
|
60
|
-
title,
|
|
68
|
+
title: pushTitle,
|
|
61
69
|
body: preview,
|
|
62
70
|
url,
|
|
63
71
|
type: 'file',
|
|
64
72
|
priority,
|
|
65
|
-
files: [{ fileKey: upload.data.fileKey, fileName, fileSize, fileType, iv: fileIv, encryptedKey: fileEncryptedKey }],
|
|
73
|
+
files: [{ fileKey: upload.data.fileKey, fileName, fileSize: fileBytes, fileType, iv: fileIv, encryptedKey: fileEncryptedKey }],
|
|
66
74
|
targetDeviceId: deviceId,
|
|
67
75
|
sessionId: config.sessionId,
|
|
68
76
|
};
|
|
69
77
|
if (canEncrypt) {
|
|
70
78
|
try {
|
|
71
|
-
const enc = await (0, crypto_js_1.encryptPushBodyForSelf)({ title, body: preview, url });
|
|
79
|
+
const enc = await (0, crypto_js_1.encryptPushBodyForSelf)({ title: pushTitle, body: preview, url });
|
|
72
80
|
pushPayload = { ...pushPayload, title: undefined, body: enc.body, isEncrypted: enc.isEncrypted, encryptedKey: enc.encryptedKey, senderPublicKey: enc.senderPublicKey };
|
|
73
81
|
}
|
|
74
82
|
catch (err) {
|
|
@@ -80,8 +88,8 @@ const registerNotifyTool = (server, client, config) => {
|
|
|
80
88
|
}
|
|
81
89
|
// Short body — encrypt push only
|
|
82
90
|
let pushPayload = {
|
|
83
|
-
title,
|
|
84
|
-
body,
|
|
91
|
+
title: pushTitle,
|
|
92
|
+
body: cleanBody,
|
|
85
93
|
url,
|
|
86
94
|
type: 'hook',
|
|
87
95
|
priority,
|
|
@@ -90,7 +98,7 @@ const registerNotifyTool = (server, client, config) => {
|
|
|
90
98
|
};
|
|
91
99
|
if (canEncrypt) {
|
|
92
100
|
try {
|
|
93
|
-
const enc = await (0, crypto_js_1.encryptPushBodyForSelf)({ title, body, url });
|
|
101
|
+
const enc = await (0, crypto_js_1.encryptPushBodyForSelf)({ title: pushTitle, body: cleanBody, url });
|
|
94
102
|
pushPayload = { ...pushPayload, title: undefined, body: enc.body, isEncrypted: enc.isEncrypted, encryptedKey: enc.encryptedKey, senderPublicKey: enc.senderPublicKey };
|
|
95
103
|
}
|
|
96
104
|
catch (err) {
|
package/dist/tools/prompt.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { ZephApiClient } from '../api-client.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type McpServerConfig } from '../config.js';
|
|
4
4
|
export declare const registerPromptTool: (server: McpServer, client: ZephApiClient, config: McpServerConfig) => void;
|
|
5
5
|
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/tools/prompt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/tools/prompt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAGrE,eAAO,MAAM,kBAAkB,GAAI,QAAQ,SAAS,EAAE,QAAQ,aAAa,EAAE,QAAQ,eAAe,SAuEnG,CAAC"}
|
package/dist/tools/prompt.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.registerPromptTool = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const error_format_js_1 = require("../error-format.js");
|
|
6
6
|
const poll_js_1 = require("../poll.js");
|
|
7
|
+
const config_js_1 = require("../config.js");
|
|
8
|
+
const sanitize_js_1 = require("../sanitize.js");
|
|
7
9
|
const registerPromptTool = (server, client, config) => {
|
|
8
10
|
server.registerTool('zeph_prompt', {
|
|
9
11
|
description: 'Ask the user to choose from predefined options via push notification. The tool blocks until the user responds or the timeout is reached. Requires ZEPH_HOOK_ID environment variable.',
|
|
@@ -41,8 +43,8 @@ const registerPromptTool = (server, client, config) => {
|
|
|
41
43
|
return (0, error_format_js_1.hookNotConfiguredError)();
|
|
42
44
|
try {
|
|
43
45
|
const trigger = await client.triggerHook(config.hookId, {
|
|
44
|
-
title,
|
|
45
|
-
body,
|
|
46
|
+
title: (0, config_js_1.formatPushTitle)(config.projectName, title),
|
|
47
|
+
body: (0, sanitize_js_1.sanitizeText)(body),
|
|
46
48
|
actions,
|
|
47
49
|
timeout,
|
|
48
50
|
fallback,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeph-to/mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "Zeph MCP server — AI agent notifications, prompts, and input via MCP protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsc",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
19
21
|
"prepublishOnly": "npm run build"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
@@ -23,8 +25,9 @@
|
|
|
23
25
|
"zod": "^3.25.1"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
26
29
|
"typescript": "^5.8.0",
|
|
27
|
-
"
|
|
30
|
+
"vitest": "^2.1.9"
|
|
28
31
|
},
|
|
29
32
|
"release": {
|
|
30
33
|
"branches": [
|