@reneturcios/deskreply 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rene Turcios
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,81 @@
1
- # Temporary Holding Version
1
+ # deskreply
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The front desk, documented. deskreply is a small forwarding client for the hosted Larkella service — an AI receptionist that answers a business's calls and assists its owner. The tool list is served from your own machine using the captured definitions, and each call is sent upstream, with the service's answer returned exactly as it arrived.
4
+
5
+ All five of the service's captured tools are exposed, and every one of them is a pure content read: what the service is and does, the kinds of business it answers calls for, a deep look at one named industry with an example call, the questions business owners ask first, and how to try it free or talk to the team. Nothing is collected or submitted anywhere — `get_started` is documentation about signing up, not a signup.
6
+
7
+ ## The tools
8
+
9
+ - **`about`** — What the service is and does: an AI receptionist for a business's callers and an assistant for its owner, covering features, who it's for, setup, privacy, the free test and how to sign up. No arguments.
10
+ - **`industries`** — The kinds of business the service answers calls for, what it does for each, and the page for the ones with their own page. No arguments.
11
+ - **`industry`** — One kind of business in detail, with an example call and that industry's common questions. Takes a required `industry` argument: `dental`, `home-services`, `clinics`, `law-firms` or `salons`.
12
+ - **`faq`** — The service's answers to the questions business owners ask first: AI disclosure, phone numbers, the pricing approach, and putting callers through to a person. No arguments.
13
+ - **`get_started`** — How to try it free (set up in about 2 minutes, then a 5-minute test call), sign up, or talk to the team. No arguments.
14
+
15
+ ## Install and run
16
+
17
+ As an MCP server via npm:
18
+
19
+ ```bash
20
+ npx -y @reneturcios/deskreply mcp
21
+ ```
22
+
23
+ MCP client configuration:
24
+
25
+ ```json
26
+ {
27
+ "mcpServers": {
28
+ "deskreply": {
29
+ "command": "npx",
30
+ "args": ["-y", "@reneturcios/deskreply", "mcp"]
31
+ }
32
+ }
33
+ }
34
+ ```
35
+
36
+ As a container:
37
+
38
+ ```bash
39
+ docker run -i ghcr.io/cloudcorprecords/deskreply
40
+ docker run --rm ghcr.io/cloudcorprecords/deskreply about '{}'
41
+ ```
42
+
43
+ ## CLI
44
+
45
+ A single binary covers both the command line and the MCP server. Every tool is a subcommand whose one argument is a JSON string of that tool's inputs:
46
+
47
+ ```bash
48
+ deskreply about '{}'
49
+ deskreply industry '{"industry":"dental"}'
50
+ deskreply faq '{}'
51
+ deskreply --version
52
+ ```
53
+
54
+ Exit codes: `0` for a successful forwarded call, `1` when the result that comes back is an error, and `2` for usage mistakes like an unknown subcommand or a JSON argument that does not parse.
55
+
56
+ ## Configuration
57
+
58
+ - `LARKELLA_MCP_URL` — Replaces the upstream endpoint. Defaults to the pinned hosted endpoint, `https://larkella.com/mcp`. (This override variable is a reconstruction introduced by this rebuild.)
59
+
60
+ The Larkella registry record lists no headers for its remote, so deskreply never attaches an authentication header — every call goes upstream keyless.
61
+
62
+ When the upstream cannot answer — it returns a JSON-RPC error, answers with a non-2xx status, sends a body that cannot be read, or the request itself fails — the caller receives an error result whose text begins with `deskreply error:`.
63
+
64
+ ## How forwarding works
65
+
66
+ The first call of a process opens a session against the upstream: an `initialize` request (protocol version `2025-03-26`), a `notifications/initialized` notification, and then the `tools/call`. If the service issues an `Mcp-Session-Id` header during initialize, deskreply repeats it on subsequent requests and keeps reusing that one session until the process ends. Replies are understood in both plain JSON and server-sent-events framing. Successful results are passed through untouched, `isError` flag and any extra fields included.
67
+
68
+ ## Development
69
+
70
+ ```bash
71
+ npm install
72
+ npm run build # tsc -> dist/ (dist/cli.js is the bin)
73
+ npm test # tsx --test test/*.test.ts — stubbed upstream, no network
74
+ npm run dev # run the CLI from source
75
+ ```
76
+
77
+ The suite compares the served tool list against the captured surface tool for tool, walks the session handshake and its reuse, proves no `Authorization` header is sent under any environment, and confirms that arguments travel upstream unchanged and results return unchanged.
78
+
79
+ ## License
80
+
81
+ MIT — see `LICENSE`. Copyright (c) 2026 Rene Turcios.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * deskreply CLI.
4
+ *
5
+ * deskreply <tool> '<json-args>'
6
+ * deskreply mcp
7
+ * deskreply --version
8
+ *
9
+ * <tool> is one of the 5 captured forwarded tools. Each
10
+ * tool subcommand takes a single JSON argument string
11
+ * holding that tool's arguments, forwards the call the
12
+ * same way the MCP path does, and prints the forwarded
13
+ * result content. Exit codes: 0 success, 1 on an isError
14
+ * result, 2 usage error.
15
+ */
16
+ import { callTool, TOOL_NAMES, VERSION } from "./forward.js";
17
+ function usage() {
18
+ console.error(`Usage:
19
+ deskreply <tool> '<json-args>' one of: ${TOOL_NAMES.join(", ")}
20
+ deskreply mcp
21
+ deskreply --version`);
22
+ process.exit(2);
23
+ }
24
+ function firstText(result) {
25
+ const content = result.content;
26
+ if (Array.isArray(content)) {
27
+ for (const item of content) {
28
+ if (item !== null &&
29
+ typeof item === "object" &&
30
+ item.type === "text" &&
31
+ typeof item.text === "string") {
32
+ return item.text;
33
+ }
34
+ }
35
+ }
36
+ return typeof content === "string" ? content : JSON.stringify(content);
37
+ }
38
+ async function main() {
39
+ const [cmd, ...rest] = process.argv.slice(2);
40
+ if (cmd === "--version" || cmd === "-v") {
41
+ console.log(VERSION);
42
+ return;
43
+ }
44
+ if (cmd === "mcp") {
45
+ if (rest.length !== 0)
46
+ usage();
47
+ const { startMcpServer } = await import("./mcp.js");
48
+ await startMcpServer();
49
+ return;
50
+ }
51
+ if (!TOOL_NAMES.includes(cmd ?? ""))
52
+ usage();
53
+ if (rest.length > 1)
54
+ usage();
55
+ let args = {};
56
+ if (rest.length === 1) {
57
+ try {
58
+ const parsed = JSON.parse(rest[0]);
59
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
60
+ usage();
61
+ }
62
+ args = parsed;
63
+ }
64
+ catch {
65
+ console.error("error: argument must be a JSON object string");
66
+ process.exit(2);
67
+ }
68
+ }
69
+ const result = await callTool(cmd, args);
70
+ if (result.isError) {
71
+ console.error(`error: ${firstText(result)}`);
72
+ process.exit(1);
73
+ }
74
+ console.log(typeof result.content === "string"
75
+ ? result.content
76
+ : JSON.stringify(result.content, null, 2));
77
+ }
78
+ void main();
79
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG7D,SAAS,KAAK;IACZ,OAAO,CAAC,KAAK,CAAC;+CAC+B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;;sBAE9C,CAAC,CAAC;IACtB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,GAAG,CAAC;QAAE,KAAK,EAAE,CAAC;IAC7B,IAAI,IAAI,GAA4B,EAAE,CAAC;IACvC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3E,KAAK,EAAE,CAAC;YACV,CAAC;YACD,IAAI,GAAG,MAAiC,CAAC;QAC3C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACzC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,CAAC,KAAK,CAAC,UAAU,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,GAAG,CACT,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO;QAChB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAC5C,CAAC;AACJ,CAAC;AAED,KAAK,IAAI,EAAE,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * deskreply core: a forwarding client for the hosted
3
+ * Larkella MCP server.
4
+ *
5
+ * No receptionist documentation lives on this machine.
6
+ * tools/list is answered from the literal definitions
7
+ * below, which reproduce a live capture of the upstream
8
+ * server word for word (name, title, description and
9
+ * inputSchema exactly as captured, each kept inputSchema
10
+ * carrying `additionalProperties: false`). A tools/call
11
+ * travels upstream over a streamable-HTTP JSON-RPC
12
+ * session: an initialize POST, a notifications/initialized
13
+ * POST, then the tools/call POST, carrying the
14
+ * Mcp-Session-Id response header on later requests when
15
+ * the upstream issues one. The session opens lazily on
16
+ * the first forwarded call and is reused for the client's
17
+ * lifetime.
18
+ *
19
+ * The full captured surface is registered: all five
20
+ * tools are pure content reads — what the service is,
21
+ * the kinds of business it answers calls for, one named
22
+ * industry in detail, the questions owners ask first,
23
+ * and how to try it or talk to the team. Nothing in the
24
+ * surface collects or submits anything; `get_started`
25
+ * is a documentation read about signing up, not a
26
+ * signup itself.
27
+ *
28
+ * The endpoint is pinned to https://larkella.com/mcp
29
+ * and may be replaced with the LARKELLA_MCP_URL
30
+ * environment variable (that override is a labelled
31
+ * reconstruction). The registry record declares NO
32
+ * headers on the remote: no auth header is ever sent,
33
+ * under any environment.
34
+ *
35
+ * A successful upstream result is returned exactly as
36
+ * received, isError flag and extra fields included.
37
+ * Failures — an upstream JSON-RPC error, a non-2xx
38
+ * status, a body that cannot be parsed, or a fetch
39
+ * that throws or times out — become an isError result
40
+ * whose text begins with `deskreply error:` (that
41
+ * rendering is a labelled reconstruction). Replies may
42
+ * be plain JSON or SSE (`data:` lines); the JSON-RPC
43
+ * message whose id matches the request wins.
44
+ */
45
+ import type { ForwardDeps, ToolArgs, ToolDef, ToolResult } from "./types.js";
46
+ export declare const VERSION = "0.1.0";
47
+ export declare const DEFAULT_ENDPOINT_URL = "https://larkella.com/mcp";
48
+ export declare const DEFAULT_TIMEOUT_MS = 30000;
49
+ export declare const PROTOCOL_VERSION = "2025-03-26";
50
+ export declare const TOOL_DEFS: ToolDef[];
51
+ export declare const TOOL_NAMES: string[];
52
+ /** Whether `name` belongs to the captured surface. */
53
+ export declare function isKnownTool(name: string): boolean;
54
+ /**
55
+ * Read a JSON-RPC response body, tolerating SSE framing.
56
+ * Returns the message whose id matches `expectedId` when
57
+ * present, otherwise the last parseable message, otherwise
58
+ * null when nothing in the body parses.
59
+ */
60
+ export declare function parseRpcBody(text: string, expectedId?: number): Record<string, unknown> | null;
61
+ /**
62
+ * A forwarding client holding a single upstream session,
63
+ * opened lazily on first use and reused from then on
64
+ * (for the process lifetime in the MCP server, or for a
65
+ * single invocation in the CLI).
66
+ */
67
+ export declare class DeskreplyClient {
68
+ private readonly deps;
69
+ private sessionId;
70
+ private ready;
71
+ private sessionPromise;
72
+ private idCounter;
73
+ constructor(deps?: ForwardDeps);
74
+ private fetchFn;
75
+ private endpointUrl;
76
+ private timeoutMs;
77
+ private nextId;
78
+ private post;
79
+ private ensureSession;
80
+ /** Forward one tool call; upstream failures come back as isError results. */
81
+ callTool(name: string, args: ToolArgs): Promise<ToolResult>;
82
+ }
83
+ /** Build a forwarding client; tests inject a fake fetch and env through deps. */
84
+ export declare function createClient(deps?: ForwardDeps): DeskreplyClient;
85
+ /** One-shot helper: a fresh client for a single call (the CLI path). */
86
+ export declare function callTool(name: string, args: ToolArgs, deps?: ForwardDeps): Promise<ToolResult>;
@@ -0,0 +1,305 @@
1
+ export const VERSION = "0.1.0";
2
+ export const DEFAULT_ENDPOINT_URL = "https://larkella.com/mcp";
3
+ export const DEFAULT_TIMEOUT_MS = 30000;
4
+ export const PROTOCOL_VERSION = "2025-03-26";
5
+ /* ------------------------------------------------------------------ */
6
+ /* Tool definitions (tools/list literals, verbatim from the live */
7
+ /* capture in harness/fixtures/larkella-tools-original.json; */
8
+ /* generated programmatically by parsing and re-serialising the */
9
+ /* fixture JSON, never retyped) */
10
+ /* ------------------------------------------------------------------ */
11
+ // TOOL_DEFS_GENERATED_START
12
+ export const TOOL_DEFS = [
13
+ {
14
+ "name": "about",
15
+ "title": "About Larkella",
16
+ "description": "What Larkella is and does: an AI receptionist for a business's callers and an assistant for its owner. Features, who it's for, setup, privacy, the free test and how to sign up.",
17
+ "inputSchema": {
18
+ "type": "object",
19
+ "properties": {},
20
+ "additionalProperties": false
21
+ }
22
+ },
23
+ {
24
+ "name": "industries",
25
+ "title": "Who it's for",
26
+ "description": "The kinds of business Larkella answers calls for, what it does for each, and the page for the ones with their own page.",
27
+ "inputSchema": {
28
+ "type": "object",
29
+ "properties": {},
30
+ "additionalProperties": false
31
+ }
32
+ },
33
+ {
34
+ "name": "industry",
35
+ "title": "One industry in detail",
36
+ "description": "What Larkella's AI receptionist does for one kind of business, with an example call and that industry's common questions.",
37
+ "inputSchema": {
38
+ "type": "object",
39
+ "additionalProperties": false,
40
+ "required": [
41
+ "industry"
42
+ ],
43
+ "properties": {
44
+ "industry": {
45
+ "type": "string",
46
+ "enum": [
47
+ "dental",
48
+ "home-services",
49
+ "clinics",
50
+ "law-firms",
51
+ "salons"
52
+ ],
53
+ "description": "Which industry."
54
+ }
55
+ }
56
+ }
57
+ },
58
+ {
59
+ "name": "faq",
60
+ "title": "Questions owners ask",
61
+ "description": "Larkella's answers to the questions business owners ask first (AI disclosure, phone numbers, pricing approach, putting callers through to a person).",
62
+ "inputSchema": {
63
+ "type": "object",
64
+ "properties": {},
65
+ "additionalProperties": false
66
+ }
67
+ },
68
+ {
69
+ "name": "get_started",
70
+ "title": "Try it or sign up",
71
+ "description": "How to try Larkella free (set up in about 2 minutes, then a 5-minute test call), sign up, or talk to the team.",
72
+ "inputSchema": {
73
+ "type": "object",
74
+ "properties": {},
75
+ "additionalProperties": false
76
+ }
77
+ }
78
+ ];
79
+ // TOOL_DEFS_GENERATED_END
80
+ export const TOOL_NAMES = TOOL_DEFS.map((t) => t.name);
81
+ /** Whether `name` belongs to the captured surface. */
82
+ export function isKnownTool(name) {
83
+ return TOOL_NAMES.includes(name);
84
+ }
85
+ /* ------------------------------------------------------------------ */
86
+ /* Forwarding client */
87
+ /* ------------------------------------------------------------------ */
88
+ function errorResult(detail) {
89
+ return {
90
+ content: [{ type: "text", text: `deskreply error: ${detail}` }],
91
+ isError: true,
92
+ };
93
+ }
94
+ function rpcErrorMessage(error) {
95
+ if (error !== null && typeof error === "object") {
96
+ const message = error.message;
97
+ if (typeof message === "string" && message !== "")
98
+ return message;
99
+ return JSON.stringify(error);
100
+ }
101
+ return String(error);
102
+ }
103
+ /**
104
+ * Read a JSON-RPC response body, tolerating SSE framing.
105
+ * Returns the message whose id matches `expectedId` when
106
+ * present, otherwise the last parseable message, otherwise
107
+ * null when nothing in the body parses.
108
+ */
109
+ export function parseRpcBody(text, expectedId) {
110
+ const trimmed = text.trim();
111
+ if (trimmed === "")
112
+ return null;
113
+ const candidates = [];
114
+ const tryPush = (payload) => {
115
+ try {
116
+ const parsed = JSON.parse(payload);
117
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
118
+ candidates.push(parsed);
119
+ }
120
+ }
121
+ catch {
122
+ // Not a JSON payload; skip this candidate.
123
+ }
124
+ };
125
+ if (trimmed.includes("data:")) {
126
+ for (const line of trimmed.split("\n")) {
127
+ const t = line.trim();
128
+ if (!t.startsWith("data:"))
129
+ continue;
130
+ const payload = t.slice("data:".length).trim();
131
+ if (payload !== "" && payload !== "[DONE]")
132
+ tryPush(payload);
133
+ }
134
+ }
135
+ else {
136
+ tryPush(trimmed);
137
+ }
138
+ if (candidates.length === 0)
139
+ return null;
140
+ if (expectedId !== undefined) {
141
+ const match = candidates.find((c) => c.id === expectedId);
142
+ if (match !== undefined)
143
+ return match;
144
+ }
145
+ return candidates[candidates.length - 1];
146
+ }
147
+ async function defaultFetch(url, init) {
148
+ return fetch(url, init);
149
+ }
150
+ /**
151
+ * A forwarding client holding a single upstream session,
152
+ * opened lazily on first use and reused from then on
153
+ * (for the process lifetime in the MCP server, or for a
154
+ * single invocation in the CLI).
155
+ */
156
+ export class DeskreplyClient {
157
+ deps;
158
+ sessionId = null;
159
+ ready = false;
160
+ sessionPromise = null;
161
+ idCounter = 0;
162
+ constructor(deps = {}) {
163
+ this.deps = deps;
164
+ }
165
+ fetchFn() {
166
+ return this.deps.fetchFn ?? defaultFetch;
167
+ }
168
+ endpointUrl() {
169
+ if (this.deps.url && this.deps.url.trim() !== "")
170
+ return this.deps.url.trim();
171
+ const raw = (this.deps.env ?? process.env).LARKELLA_MCP_URL;
172
+ if (raw && raw.trim() !== "")
173
+ return raw.trim();
174
+ return DEFAULT_ENDPOINT_URL;
175
+ }
176
+ timeoutMs() {
177
+ if (typeof this.deps.timeoutMs === "number" && this.deps.timeoutMs > 0) {
178
+ return this.deps.timeoutMs;
179
+ }
180
+ return DEFAULT_TIMEOUT_MS;
181
+ }
182
+ nextId() {
183
+ this.idCounter += 1;
184
+ return this.idCounter;
185
+ }
186
+ async post(body, withSession) {
187
+ // The registry record declares NO headers on the remote:
188
+ // no Authorization (or any other auth) header is ever sent.
189
+ const headers = {
190
+ "Content-Type": "application/json",
191
+ Accept: "application/json, text/event-stream",
192
+ };
193
+ if (withSession && this.sessionId !== null) {
194
+ headers["Mcp-Session-Id"] = this.sessionId;
195
+ }
196
+ const controller = new AbortController();
197
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs());
198
+ try {
199
+ return await this.fetchFn()(this.endpointUrl(), {
200
+ method: "POST",
201
+ headers,
202
+ body: JSON.stringify(body),
203
+ signal: controller.signal,
204
+ });
205
+ }
206
+ finally {
207
+ clearTimeout(timer);
208
+ }
209
+ }
210
+ async ensureSession() {
211
+ if (this.ready)
212
+ return;
213
+ if (this.sessionPromise === null) {
214
+ this.sessionPromise = (async () => {
215
+ const initId = this.nextId();
216
+ const initRes = await this.post({
217
+ jsonrpc: "2.0",
218
+ id: initId,
219
+ method: "initialize",
220
+ params: {
221
+ protocolVersion: PROTOCOL_VERSION,
222
+ capabilities: {},
223
+ clientInfo: { name: "deskreply", version: VERSION },
224
+ },
225
+ }, false);
226
+ const sessionId = initRes.headers.get("mcp-session-id");
227
+ if (sessionId)
228
+ this.sessionId = sessionId;
229
+ const initText = await initRes.text();
230
+ const initParsed = parseRpcBody(initText, initId);
231
+ if (initParsed !== null && initParsed.error) {
232
+ throw new Error(rpcErrorMessage(initParsed.error));
233
+ }
234
+ if (initRes.status < 200 || initRes.status >= 300) {
235
+ throw new Error(`HTTP ${initRes.status}`);
236
+ }
237
+ if (initParsed === null && initText.trim() !== "") {
238
+ throw new Error("malformed response");
239
+ }
240
+ const initializedRes = await this.post({ jsonrpc: "2.0", method: "notifications/initialized" }, true);
241
+ try {
242
+ await initializedRes.text();
243
+ }
244
+ catch {
245
+ // Nothing needed from the notification response body.
246
+ }
247
+ this.ready = true;
248
+ })();
249
+ }
250
+ try {
251
+ await this.sessionPromise;
252
+ }
253
+ catch (err) {
254
+ this.sessionPromise = null;
255
+ this.sessionId = null;
256
+ throw err;
257
+ }
258
+ }
259
+ /** Forward one tool call; upstream failures come back as isError results. */
260
+ async callTool(name, args) {
261
+ try {
262
+ await this.ensureSession();
263
+ }
264
+ catch (err) {
265
+ return errorResult(err instanceof Error ? err.message : String(err));
266
+ }
267
+ const callId = this.nextId();
268
+ let callRes;
269
+ try {
270
+ callRes = await this.post({
271
+ jsonrpc: "2.0",
272
+ id: callId,
273
+ method: "tools/call",
274
+ params: { name, arguments: args ?? {} },
275
+ }, true);
276
+ }
277
+ catch (err) {
278
+ return errorResult(`request failed: ${err instanceof Error ? err.message : String(err)}`);
279
+ }
280
+ const parsed = parseRpcBody(await callRes.text(), callId);
281
+ if (parsed !== null && parsed.error) {
282
+ return errorResult(rpcErrorMessage(parsed.error));
283
+ }
284
+ if (callRes.status < 200 || callRes.status >= 300) {
285
+ return errorResult(`HTTP ${callRes.status}`);
286
+ }
287
+ if (parsed === null)
288
+ return errorResult("malformed response");
289
+ const result = parsed.result;
290
+ if (result === undefined || result === null || typeof result !== "object") {
291
+ return errorResult("malformed response");
292
+ }
293
+ // Hand the upstream result back exactly as received.
294
+ return result;
295
+ }
296
+ }
297
+ /** Build a forwarding client; tests inject a fake fetch and env through deps. */
298
+ export function createClient(deps = {}) {
299
+ return new DeskreplyClient(deps);
300
+ }
301
+ /** One-shot helper: a fresh client for a single call (the CLI path). */
302
+ export async function callTool(name, args, deps = {}) {
303
+ return new DeskreplyClient(deps).callTool(name, args);
304
+ }
305
+ //# sourceMappingURL=forward.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forward.js","sourceRoot":"","sources":["../src/forward.ts"],"names":[],"mappings":"AAqDA,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAE7C,wEAAwE;AACxE,yEAAyE;AACzE,yEAAyE;AACzE,yEAAyE;AACzE,yEAAyE;AACzE,wEAAwE;AAExE,4BAA4B;AAC5B,MAAM,CAAC,MAAM,SAAS,GAAc;IAChC;QACE,MAAM,EAAE,OAAO;QACf,OAAO,EAAE,gBAAgB;QACzB,aAAa,EAAE,kLAAkL;QACjM,aAAa,EAAE;YACb,MAAM,EAAE,QAAQ;YAChB,YAAY,EAAE,EAAE;YAChB,sBAAsB,EAAE,KAAK;SAC9B;KACF;IACD;QACE,MAAM,EAAE,YAAY;QACpB,OAAO,EAAE,cAAc;QACvB,aAAa,EAAE,yHAAyH;QACxI,aAAa,EAAE;YACb,MAAM,EAAE,QAAQ;YAChB,YAAY,EAAE,EAAE;YAChB,sBAAsB,EAAE,KAAK;SAC9B;KACF;IACD;QACE,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,wBAAwB;QACjC,aAAa,EAAE,2HAA2H;QAC1I,aAAa,EAAE;YACb,MAAM,EAAE,QAAQ;YAChB,sBAAsB,EAAE,KAAK;YAC7B,UAAU,EAAE;gBACV,UAAU;aACX;YACD,YAAY,EAAE;gBACZ,UAAU,EAAE;oBACV,MAAM,EAAE,QAAQ;oBAChB,MAAM,EAAE;wBACN,QAAQ;wBACR,eAAe;wBACf,SAAS;wBACT,WAAW;wBACX,QAAQ;qBACT;oBACD,aAAa,EAAE,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package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./types.js";
2
+ export * from "./forward.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * deskreply MCP server. Tools: the 5 captured Larkella
3
+ * tools, the full surface (see forward.ts).
4
+ *
5
+ * This file uses the low-level Server API rather than
6
+ * McpServer: the high-level helper rebuilds schemas from
7
+ * zod and rewrites what is served, which would break
8
+ * exact parity with the captured tools/list. Here
9
+ * tools/list is answered locally from the core's literal
10
+ * definitions — the verbatim objects from the upstream
11
+ * capture — and every tools/call is forwarded upstream.
12
+ *
13
+ * A forwarded result returns unchanged, upstream isError
14
+ * flag and extra fields included. An upstream failure
15
+ * arrives as an isError result carrying a
16
+ * `deskreply error:` text, built by the forwarding
17
+ * client. Unknown tool names are rejected with McpError
18
+ * MethodNotFound, and non-object arguments with McpError
19
+ * InvalidParams, before any network hop is made.
20
+ */
21
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
22
+ import { type DeskreplyClient } from "./forward.js";
23
+ import type { ForwardDeps, ToolResult } from "./types.js";
24
+ /**
25
+ * Validate and forward a single tools/call through
26
+ * `client`. Exported so this layer can be tested directly
27
+ * without a stdio transport.
28
+ */
29
+ export declare function handleCallTool(client: DeskreplyClient, name: string, args: unknown): Promise<ToolResult>;
30
+ /** Build the stdio MCP server (transport not yet connected). */
31
+ export declare function createServer(deps?: ForwardDeps): Server;
32
+ /** Connect the MCP server over stdio. */
33
+ export declare function startMcpServer(deps?: ForwardDeps): Promise<void>;
package/dist/mcp.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * deskreply MCP server. Tools: the 5 captured Larkella
3
+ * tools, the full surface (see forward.ts).
4
+ *
5
+ * This file uses the low-level Server API rather than
6
+ * McpServer: the high-level helper rebuilds schemas from
7
+ * zod and rewrites what is served, which would break
8
+ * exact parity with the captured tools/list. Here
9
+ * tools/list is answered locally from the core's literal
10
+ * definitions — the verbatim objects from the upstream
11
+ * capture — and every tools/call is forwarded upstream.
12
+ *
13
+ * A forwarded result returns unchanged, upstream isError
14
+ * flag and extra fields included. An upstream failure
15
+ * arrives as an isError result carrying a
16
+ * `deskreply error:` text, built by the forwarding
17
+ * client. Unknown tool names are rejected with McpError
18
+ * MethodNotFound, and non-object arguments with McpError
19
+ * InvalidParams, before any network hop is made.
20
+ */
21
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
22
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
23
+ import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } from "@modelcontextprotocol/sdk/types.js";
24
+ import { createClient, isKnownTool, TOOL_DEFS, VERSION, } from "./forward.js";
25
+ /**
26
+ * Validate and forward a single tools/call through
27
+ * `client`. Exported so this layer can be tested directly
28
+ * without a stdio transport.
29
+ */
30
+ export async function handleCallTool(client, name, args) {
31
+ if (!isKnownTool(name)) {
32
+ throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
33
+ }
34
+ if (args !== undefined &&
35
+ (typeof args !== "object" || args === null || Array.isArray(args))) {
36
+ throw new McpError(ErrorCode.InvalidParams, `Arguments for tool ${name} must be a JSON object`);
37
+ }
38
+ return client.callTool(name, (args ?? {}));
39
+ }
40
+ /** Build the stdio MCP server (transport not yet connected). */
41
+ export function createServer(deps = {}) {
42
+ const client = createClient(deps);
43
+ const server = new Server({ name: "deskreply", version: VERSION }, { capabilities: { tools: {} } });
44
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
45
+ tools: TOOL_DEFS,
46
+ }));
47
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
48
+ const { name, arguments: args } = request.params;
49
+ const result = await handleCallTool(client, name, args);
50
+ return result;
51
+ });
52
+ return server;
53
+ }
54
+ /** Connect the MCP server over stdio. */
55
+ export async function startMcpServer(deps = {}) {
56
+ await createServer(deps).connect(new StdioServerTransport());
57
+ }
58
+ //# sourceMappingURL=mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,sBAAsB,EACtB,QAAQ,GACT,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,YAAY,EACZ,WAAW,EACX,SAAS,EACT,OAAO,GAER,MAAM,cAAc,CAAC;AAGtB;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAuB,EACvB,IAAY,EACZ,IAAa;IAEb,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,iBAAiB,IAAI,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,IACE,IAAI,KAAK,SAAS;QAClB,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAClE,CAAC;QACD,MAAM,IAAI,QAAQ,CAChB,SAAS,CAAC,aAAa,EACvB,sBAAsB,IAAI,wBAAwB,CACnD,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAA4B,CAAC,CAAC;AACxE,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,YAAY,CAAC,OAAoB,EAAE;IACjD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,EACvC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;IAEF,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;QAC5D,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC,CAAC;IAEJ,MAAM,CAAC,iBAAiB,CAAC,qBAAqB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;QACjD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACxD,OAAO,MAAe,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,yCAAyC;AACzC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAoB,EAAE;IACzD,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * deskreply types.
3
+ *
4
+ * This package holds no receptionist documentation of its own.
5
+ * It is a forwarding client: the captured Larkella tool surface
6
+ * is held as plain data (ToolDef entries served verbatim for
7
+ * tools/list) and each tools/call is sent on to the hosted
8
+ * Larkella MCP endpoint through an injectable fetch, so the
9
+ * whole test suite can run against a stubbed upstream with no
10
+ * live network.
11
+ */
12
+ /** One captured tool definition, served exactly as captured for tools/list. */
13
+ export interface ToolDef {
14
+ name: string;
15
+ title?: string;
16
+ description: string;
17
+ inputSchema: Record<string, unknown>;
18
+ [key: string]: unknown;
19
+ }
20
+ /** Arguments for a tool call, as decoded JSON. */
21
+ export type ToolArgs = Record<string, unknown>;
22
+ /** A tools/call result: upstream payloads pass through verbatim; local failures use this shape too. */
23
+ export interface ToolResult {
24
+ content?: unknown;
25
+ isError?: boolean;
26
+ [key: string]: unknown;
27
+ }
28
+ /** The narrow slice of a fetch Response the forwarding client relies on. */
29
+ export interface FetchResponseLike {
30
+ ok: boolean;
31
+ status: number;
32
+ headers: {
33
+ get(name: string): string | null;
34
+ };
35
+ text(): Promise<string>;
36
+ }
37
+ /** Injectable fetch function, so tests never reach the live network. */
38
+ export type FetchFn = (url: string, init?: {
39
+ method?: string;
40
+ headers?: Record<string, string>;
41
+ body?: string;
42
+ signal?: AbortSignal;
43
+ }) => Promise<FetchResponseLike>;
44
+ /** Injectable runtime dependencies for the forwarding client. */
45
+ export interface ForwardDeps {
46
+ /** Fetch implementation. Defaults to the global fetch. */
47
+ fetchFn?: FetchFn;
48
+ /** Environment (LARKELLA_MCP_URL). Defaults to process.env. */
49
+ env?: Record<string, string | undefined>;
50
+ /** Endpoint URL override. Defaults to env LARKELLA_MCP_URL or the pinned default. */
51
+ url?: string;
52
+ /** Per-request timeout in milliseconds. Defaults to 30000. */
53
+ timeoutMs?: number;
54
+ }
package/dist/types.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * deskreply types.
3
+ *
4
+ * This package holds no receptionist documentation of its own.
5
+ * It is a forwarding client: the captured Larkella tool surface
6
+ * is held as plain data (ToolDef entries served verbatim for
7
+ * tools/list) and each tools/call is sent on to the hosted
8
+ * Larkella MCP endpoint through an injectable fetch, so the
9
+ * whole test suite can run against a stubbed upstream with no
10
+ * live network.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
package/package.json CHANGED
@@ -1,6 +1 @@
1
- {
2
- "name": "@reneturcios/deskreply",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {"bin":{"deskreply":"dist/cli.js"},"dependencies":{"@modelcontextprotocol/sdk":"^1","zod":"^4"},"description":"Forwarding client for the Larkella AI receptionist service: what it does, the industries it answers calls for, one industry in detail, owner FAQs, and how to get started. One bin serves a small CLI and the MCP server.","devDependencies":{"@types/node":"^20","tsx":"^4","typescript":"^5"},"engines":{"node":">=20"},"files":["dist","server.json"],"homepage":"https://github.com/CloudCorpRecords/deskreply#readme","license":"MIT","mcpName":"io.github.CloudCorpRecords/deskreply","name":"@reneturcios/deskreply","private":false,"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/CloudCorpRecords/deskreply.git"},"scripts":{"build":"tsc","dev":"tsx src/cli.ts","test":"tsx --test test/*.test.ts"},"type":"module","version":"0.1.0"}
package/server.json ADDED
@@ -0,0 +1 @@
1
+ {"$schema":"https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json","description":"What an AI receptionist service does: overview, industries served, example calls and owner FAQs.","name":"io.github.CloudCorpRecords/deskreply","packages":[{"identifier":"@reneturcios/deskreply","packageArguments":[{"type":"positional","value":"mcp"}],"registryBaseUrl":"https://registry.npmjs.org","registryType":"npm","runtimeHint":"npx","transport":{"type":"stdio"},"version":"0.1.0"},{"identifier":"ghcr.io/cloudcorprecords/deskreply:0.1.0","packageArguments":[{"type":"positional","value":"mcp"}],"registryType":"oci","runtimeArguments":[{"name":"--rm","type":"named"},{"name":"-i","type":"named"}],"runtimeHint":"docker","transport":{"type":"stdio"}}],"repository":{"source":"github","url":"https://github.com/CloudCorpRecords/deskreply"},"version":"0.1.0"}