theokit 0.18.0 → 0.19.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/dist/agent-Y4W4X46A.js +15 -0
- package/dist/{build-5PSDDMFB.js → build-ESXLJKYY.js} +2 -2
- package/dist/{chunk-DEO2VAJE.js → chunk-7NTXG7SI.js} +6 -113
- package/dist/chunk-7NTXG7SI.js.map +1 -0
- package/dist/chunk-DMC6HYUR.js +141 -0
- package/dist/chunk-DMC6HYUR.js.map +1 -0
- package/dist/{chunk-XVFMSNDE.js → chunk-DXF64KS5.js} +8 -138
- package/dist/chunk-DXF64KS5.js.map +1 -0
- package/dist/{chunk-CC5WOQUV.js → chunk-ULFNEG27.js} +5 -3
- package/dist/{chunk-CC5WOQUV.js.map → chunk-ULFNEG27.js.map} +1 -1
- package/dist/{chunk-XWS4RZCE.js → chunk-W4YO6S4I.js} +110 -1
- package/dist/chunk-W4YO6S4I.js.map +1 -0
- package/dist/{agent-TZ5JZUJ7.js → chunk-ZYMFKYLM.js} +5 -4
- package/dist/{agent-TZ5JZUJ7.js.map → chunk-ZYMFKYLM.js.map} +1 -1
- package/dist/cli/index.js +16 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/{dev-A7NESJ7S.js → dev-D7PKQUL2.js} +4 -3
- package/dist/{dev-A7NESJ7S.js.map → dev-D7PKQUL2.js.map} +1 -1
- package/dist/index.js +2 -2
- package/dist/mcp-3C4CMHP4.js +77 -0
- package/dist/mcp-3C4CMHP4.js.map +1 -0
- package/dist/server/index.d.ts +31 -1
- package/dist/server/index.js +30 -1
- package/dist/server/index.js.map +1 -1
- package/dist/{start-WGOKQEUW.js → start-5UDUXYKC.js} +3 -2
- package/dist/{start-WGOKQEUW.js.map → start-5UDUXYKC.js.map} +1 -1
- package/dist/vite-plugin/index.js +2 -2
- package/dist/{vite-plugin-DBS2USI4.js → vite-plugin-GXRWNESN.js} +4 -3
- package/dist/vite-plugin-GXRWNESN.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-DEO2VAJE.js.map +0 -1
- package/dist/chunk-XVFMSNDE.js.map +0 -1
- package/dist/chunk-XWS4RZCE.js.map +0 -1
- /package/dist/{vite-plugin-DBS2USI4.js.map → agent-Y4W4X46A.js.map} +0 -0
- /package/dist/{build-5PSDDMFB.js.map → build-ESXLJKYY.js.map} +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "tsx/esm";
|
|
3
|
+
import {
|
|
4
|
+
createAgentSsrLoader
|
|
5
|
+
} from "./chunk-ZYMFKYLM.js";
|
|
6
|
+
import {
|
|
7
|
+
extractAppResources,
|
|
8
|
+
handleMcpJsonRpc
|
|
9
|
+
} from "./chunk-DMC6HYUR.js";
|
|
10
|
+
import "./chunk-M6NMS5LR.js";
|
|
11
|
+
import "./chunk-GDN3PXFH.js";
|
|
12
|
+
import {
|
|
13
|
+
scanAgents
|
|
14
|
+
} from "./chunk-34YQOXGM.js";
|
|
15
|
+
import "./chunk-P37RZRFV.js";
|
|
16
|
+
|
|
17
|
+
// src/cli/commands/mcp.ts
|
|
18
|
+
import { createInterface } from "readline";
|
|
19
|
+
|
|
20
|
+
// src/server/agent/mcp-stdio.ts
|
|
21
|
+
async function handleMcpStdioLine(line, mod, name, appResources = []) {
|
|
22
|
+
const trimmed = line.trim();
|
|
23
|
+
if (trimmed.length === 0) return null;
|
|
24
|
+
let body;
|
|
25
|
+
try {
|
|
26
|
+
body = JSON.parse(trimmed);
|
|
27
|
+
} catch {
|
|
28
|
+
return JSON.stringify({
|
|
29
|
+
jsonrpc: "2.0",
|
|
30
|
+
id: null,
|
|
31
|
+
error: { code: -32700, message: "Parse error" }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const response = handleMcpJsonRpc(mod, name, body, appResources);
|
|
35
|
+
const payload = await response.json();
|
|
36
|
+
return JSON.stringify(payload);
|
|
37
|
+
}
|
|
38
|
+
async function serveMcpStdio(mod, name, appResources, streams) {
|
|
39
|
+
for await (const line of streams.lines) {
|
|
40
|
+
const out = await handleMcpStdioLine(line, mod, name, appResources);
|
|
41
|
+
if (out !== null) streams.write(`${out}
|
|
42
|
+
`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/cli/commands/mcp.ts
|
|
47
|
+
async function mcpCommand(name, deps = {}) {
|
|
48
|
+
const projectRoot = deps.projectRoot ?? process.cwd();
|
|
49
|
+
const agent = scanAgents(projectRoot).find((a) => a.name === name);
|
|
50
|
+
if (!agent) {
|
|
51
|
+
const names = scanAgents(projectRoot).map((a) => a.name).join(", ");
|
|
52
|
+
throw new Error(
|
|
53
|
+
`theokit mcp: agent '${name}' not found. Available: ${names || "(none in agents/)"}`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
let loadModule = deps.loadModule;
|
|
57
|
+
let dispose;
|
|
58
|
+
if (!loadModule) {
|
|
59
|
+
const loader = await createAgentSsrLoader(projectRoot);
|
|
60
|
+
loadModule = loader.load;
|
|
61
|
+
dispose = loader.dispose;
|
|
62
|
+
}
|
|
63
|
+
const streams = deps.streams ?? {
|
|
64
|
+
lines: createInterface({ input: process.stdin }),
|
|
65
|
+
write: (line) => process.stdout.write(line)
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
const mod = await loadModule(agent.filePath);
|
|
69
|
+
await serveMcpStdio(mod, agent.name, extractAppResources(mod), streams);
|
|
70
|
+
} finally {
|
|
71
|
+
if (dispose) await dispose();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
mcpCommand
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=mcp-3C4CMHP4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/commands/mcp.ts","../src/server/agent/mcp-stdio.ts"],"sourcesContent":["/**\n * `theokit mcp <agent>` — expose a scanned agent as an MCP server over stdio.\n *\n * The stdio sibling of the M16 HTTP route (`POST /api/agents/<name>/mcp`): a desktop MCP client\n * (e.g. Claude Desktop) spawns this command and speaks newline-delimited JSON-RPC over the pipe.\n * It reuses the framework's OWN `serveMcpStdio` / `handleMcpJsonRpc` (no LLM call, no runtime — a\n * TRANSPORT, like the HTTP route). `deps` is injectable so the routing is tested without Vite/stdin.\n */\nimport { createInterface } from 'node:readline'\n\nimport { extractAppResources } from '../../server/agent/mcp-app-resources.js'\nimport { type StdioStreams, serveMcpStdio } from '../../server/agent/mcp-stdio.js'\nimport { scanAgents } from '../../server/scan/agent-scan.js'\n\nimport { createAgentSsrLoader } from './agent.js'\n\nexport interface McpCommandDeps {\n projectRoot?: string\n /** Load a TS agent module; defaults to the framework's Vite SSR loader (same transpile as dev). */\n loadModule?: (filePath: string) => Promise<Record<string, unknown>>\n /** stdio streams; defaults to `readline(process.stdin)` + `process.stdout`. Injected in tests. */\n streams?: StdioStreams\n}\n\nexport async function mcpCommand(name: string, deps: McpCommandDeps = {}): Promise<void> {\n const projectRoot = deps.projectRoot ?? process.cwd()\n const agent = scanAgents(projectRoot).find((a) => a.name === name)\n if (!agent) {\n const names = scanAgents(projectRoot)\n .map((a) => a.name)\n .join(', ')\n throw new Error(\n `theokit mcp: agent '${name}' not found. Available: ${names || '(none in agents/)'}`,\n )\n }\n\n let loadModule = deps.loadModule\n let dispose: (() => Promise<void>) | undefined\n if (!loadModule) {\n const loader = await createAgentSsrLoader(projectRoot)\n loadModule = loader.load\n dispose = loader.dispose\n }\n\n const streams =\n deps.streams ??\n ({\n lines: createInterface({ input: process.stdin }),\n write: (line: string) => process.stdout.write(line),\n } satisfies StdioStreams)\n\n try {\n const mod = await loadModule(agent.filePath)\n await serveMcpStdio(mod, agent.name, extractAppResources(mod), streams)\n } finally {\n if (dispose) await dispose()\n }\n}\n","/**\n * MCP stdio transport (M16 follow-up) — expose a TheoKit agent as an MCP server over stdin/stdout,\n * the sibling of the M16 HTTP route (`POST /api/agents/<name>/mcp`). A desktop MCP client (e.g.\n * Claude Desktop) spawns `theokit mcp <agent>` and speaks newline-delimited JSON-RPC over the pipe.\n *\n * This is a TRANSPORT over the framework's OWN {@link handleMcpJsonRpc} — it reuses the exact handler\n * the HTTP route uses; it calls no LLM, spawns no MCP client, and reimplements no runtime (G2 /\n * sdk-runtime.md). Distinct from the SDK's MCP CLIENT stdio (which spawns external MCP servers via\n * `mcpServers` command/args) — that stays SDK-side per ADR-0040. Here TheoKit is the SERVER.\n */\nimport type { AppResource } from './mcp-app-resources.js'\nimport { handleMcpJsonRpc } from './mcp-handler.js'\n\n/**\n * Handle one newline-delimited JSON-RPC line. Returns the response line to write to stdout, or\n * `null` for a blank line (nothing to emit). A malformed JSON line yields a `-32700` (Parse error)\n * envelope — never throws, so the stdio loop never dies on bad input.\n */\nexport async function handleMcpStdioLine(\n line: string,\n mod: unknown,\n name: string,\n appResources: readonly AppResource[] = [],\n): Promise<string | null> {\n const trimmed = line.trim()\n if (trimmed.length === 0) return null\n let body: unknown\n try {\n body = JSON.parse(trimmed)\n } catch {\n return JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: { code: -32700, message: 'Parse error' },\n })\n }\n const response = handleMcpJsonRpc(mod, name, body, appResources)\n const payload: unknown = await response.json()\n return JSON.stringify(payload)\n}\n\n/** A minimal readable line source (an async iterable of lines) + a writable sink. */\nexport interface StdioStreams {\n /** Async iterable of newline-delimited input lines (e.g. `readline.createInterface({ input })`). */\n lines: AsyncIterable<string>\n /** Write a response line (the caller appends no newline). */\n write: (line: string) => void\n}\n\n/**\n * Drive the MCP stdio server loop: for each input line, dispatch via {@link handleMcpStdioLine} and\n * write the response line (with a trailing `\\n`). Returns when the input stream ends (EOF).\n */\nexport async function serveMcpStdio(\n mod: unknown,\n name: string,\n appResources: readonly AppResource[],\n streams: StdioStreams,\n): Promise<void> {\n for await (const line of streams.lines) {\n const out = await handleMcpStdioLine(line, mod, name, appResources)\n if (out !== null) streams.write(`${out}\\n`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAQA,SAAS,uBAAuB;;;ACUhC,eAAsB,mBACpB,MACA,KACA,MACA,eAAuC,CAAC,GAChB;AACxB,QAAM,UAAU,KAAK,KAAK;AAC1B,MAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,MAAI;AACJ,MAAI;AACF,WAAO,KAAK,MAAM,OAAO;AAAA,EAC3B,QAAQ;AACN,WAAO,KAAK,UAAU;AAAA,MACpB,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,OAAO,EAAE,MAAM,QAAQ,SAAS,cAAc;AAAA,IAChD,CAAC;AAAA,EACH;AACA,QAAM,WAAW,iBAAiB,KAAK,MAAM,MAAM,YAAY;AAC/D,QAAM,UAAmB,MAAM,SAAS,KAAK;AAC7C,SAAO,KAAK,UAAU,OAAO;AAC/B;AAcA,eAAsB,cACpB,KACA,MACA,cACA,SACe;AACf,mBAAiB,QAAQ,QAAQ,OAAO;AACtC,UAAM,MAAM,MAAM,mBAAmB,MAAM,KAAK,MAAM,YAAY;AAClE,QAAI,QAAQ,KAAM,SAAQ,MAAM,GAAG,GAAG;AAAA,CAAI;AAAA,EAC5C;AACF;;;ADvCA,eAAsB,WAAW,MAAc,OAAuB,CAAC,GAAkB;AACvF,QAAM,cAAc,KAAK,eAAe,QAAQ,IAAI;AACpD,QAAM,QAAQ,WAAW,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AACjE,MAAI,CAAC,OAAO;AACV,UAAM,QAAQ,WAAW,WAAW,EACjC,IAAI,CAAC,MAAM,EAAE,IAAI,EACjB,KAAK,IAAI;AACZ,UAAM,IAAI;AAAA,MACR,uBAAuB,IAAI,2BAA2B,SAAS,mBAAmB;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK;AACtB,MAAI;AACJ,MAAI,CAAC,YAAY;AACf,UAAM,SAAS,MAAM,qBAAqB,WAAW;AACrD,iBAAa,OAAO;AACpB,cAAU,OAAO;AAAA,EACnB;AAEA,QAAM,UACJ,KAAK,WACJ;AAAA,IACC,OAAO,gBAAgB,EAAE,OAAO,QAAQ,MAAM,CAAC;AAAA,IAC/C,OAAO,CAAC,SAAiB,QAAQ,OAAO,MAAM,IAAI;AAAA,EACpD;AAEF,MAAI;AACF,UAAM,MAAM,MAAM,WAAW,MAAM,QAAQ;AAC3C,UAAM,cAAc,KAAK,MAAM,MAAM,oBAAoB,GAAG,GAAG,OAAO;AAAA,EACxE,UAAE;AACA,QAAI,QAAS,OAAM,QAAQ;AAAA,EAC7B;AACF;","names":[]}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -929,6 +929,36 @@ declare function readAppResource(resources: readonly AppResource[], uri: string)
|
|
|
929
929
|
*/
|
|
930
930
|
declare function extractAppResources(mod: unknown): AppResource[];
|
|
931
931
|
|
|
932
|
+
/**
|
|
933
|
+
* MCP stdio transport (M16 follow-up) — expose a TheoKit agent as an MCP server over stdin/stdout,
|
|
934
|
+
* the sibling of the M16 HTTP route (`POST /api/agents/<name>/mcp`). A desktop MCP client (e.g.
|
|
935
|
+
* Claude Desktop) spawns `theokit mcp <agent>` and speaks newline-delimited JSON-RPC over the pipe.
|
|
936
|
+
*
|
|
937
|
+
* This is a TRANSPORT over the framework's OWN {@link handleMcpJsonRpc} — it reuses the exact handler
|
|
938
|
+
* the HTTP route uses; it calls no LLM, spawns no MCP client, and reimplements no runtime (G2 /
|
|
939
|
+
* sdk-runtime.md). Distinct from the SDK's MCP CLIENT stdio (which spawns external MCP servers via
|
|
940
|
+
* `mcpServers` command/args) — that stays SDK-side per ADR-0040. Here TheoKit is the SERVER.
|
|
941
|
+
*/
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Handle one newline-delimited JSON-RPC line. Returns the response line to write to stdout, or
|
|
945
|
+
* `null` for a blank line (nothing to emit). A malformed JSON line yields a `-32700` (Parse error)
|
|
946
|
+
* envelope — never throws, so the stdio loop never dies on bad input.
|
|
947
|
+
*/
|
|
948
|
+
declare function handleMcpStdioLine(line: string, mod: unknown, name: string, appResources?: readonly AppResource[]): Promise<string | null>;
|
|
949
|
+
/** A minimal readable line source (an async iterable of lines) + a writable sink. */
|
|
950
|
+
interface StdioStreams {
|
|
951
|
+
/** Async iterable of newline-delimited input lines (e.g. `readline.createInterface({ input })`). */
|
|
952
|
+
lines: AsyncIterable<string>;
|
|
953
|
+
/** Write a response line (the caller appends no newline). */
|
|
954
|
+
write: (line: string) => void;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Drive the MCP stdio server loop: for each input line, dispatch via {@link handleMcpStdioLine} and
|
|
958
|
+
* write the response line (with a trailing `\n`). Returns when the input stream ends (EOF).
|
|
959
|
+
*/
|
|
960
|
+
declare function serveMcpStdio(mod: unknown, name: string, appResources: readonly AppResource[], streams: StdioStreams): Promise<void>;
|
|
961
|
+
|
|
932
962
|
interface UploadedFile {
|
|
933
963
|
fieldname: string;
|
|
934
964
|
filename: string;
|
|
@@ -1125,4 +1155,4 @@ interface LoadEnvResult {
|
|
|
1125
1155
|
declare function _resetEnvCache(): void;
|
|
1126
1156
|
declare function loadEnv(options?: LoadEnvOptions): LoadEnvResult;
|
|
1127
1157
|
|
|
1128
|
-
export { type AcpToolConfig, ActionError, type ActionErrorCode, ActionInputError, type ActionManifestEntry, type ActionResult, type AppResource, type AppResourceInput, type BodyParserOptions, DEFAULT_MAX_AGE as CACHE_DEFAULT_MAX_AGE, DEFAULT_MAX_ENTRY_SIZE as CACHE_DEFAULT_MAX_ENTRY_SIZE, DEFAULT_SWR_MULTIPLIER as CACHE_DEFAULT_SWR_MULTIPLIER, CACHE_TAG_MAX_ITEMS, CACHE_TAG_MAX_LENGTH, type CacheControlInput, type CacheEngine, type CacheEngineOptions, type CacheEntry, type CacheStatus, type CacheStorageAdapter, type CacheStore, type CacheStoreAdmin, type ValidationResult as CacheValidationResult, type CachedFunction, type CachedRouteConfig, type ChannelMessage, type ChannelWebhookConfig, type CodeModeApi, type CodeModeConfig, type CodeModePermission, CodeModePermissionDeniedError, type CompiledRouteRule, CustomTool, DEFAULT_EXCLUDED_QUERY_PARAMS, type DefineCachedFunctionOptions, FileTooLargeError, type GetOrComputeOptions, InMemoryCacheAdapter, type InMemoryCacheAdapterOptions, type KeyDerivationOptions, type LoadEnvOptions, type LoadEnvResult, type McpResourceContents, type McpResourceDescriptor, NodeAcpTransport, type NormalizedCacheConfig, type OpenApiDocsOptions, type ParsedBody, type RevalidateResult, type RouteCacheOptions, RouteConfig, type RouteRule, type RouteRules, type Sandbox, type SerializedActionResult, type SerializedResponse, THEO_T_PREFIX, type UniversalZodIssue, type UploadedFile, type VendorAgentClient, type VendorAgentToolConfig, VerifyFn, type WorkflowLike, type WorkflowToolConfig, _resetCacheEngine, _resetEnvCache, buildResourceDescriptors, compileRouteRules, createACPTool, createCacheEngine, createCodeMode, createOpenApiHandler, createVendorAgentTool, createWorkflowTool, defineAppResource, defineCachedFunction, defineCachedRoute, deriveKey as deriveCacheKey, deserializeResponse, executeWebRequest, extractAppResources, extractUniversalIssues, getCacheControlHeader, getCacheEngine, handleChannelWebhook, initCacheEngine, isActionError, isChannelPath, isInputError, loadEnv, parseChannelPath, parseRequestBody, readAppResource, resolveRouteRule, revalidatePath, revalidateTag, serializeResponse, updateTag, validateExpire as validateCacheExpire, validateMaxAge as validateCacheMaxAge, validateTags as validateCacheTags };
|
|
1158
|
+
export { type AcpToolConfig, ActionError, type ActionErrorCode, ActionInputError, type ActionManifestEntry, type ActionResult, type AppResource, type AppResourceInput, type BodyParserOptions, DEFAULT_MAX_AGE as CACHE_DEFAULT_MAX_AGE, DEFAULT_MAX_ENTRY_SIZE as CACHE_DEFAULT_MAX_ENTRY_SIZE, DEFAULT_SWR_MULTIPLIER as CACHE_DEFAULT_SWR_MULTIPLIER, CACHE_TAG_MAX_ITEMS, CACHE_TAG_MAX_LENGTH, type CacheControlInput, type CacheEngine, type CacheEngineOptions, type CacheEntry, type CacheStatus, type CacheStorageAdapter, type CacheStore, type CacheStoreAdmin, type ValidationResult as CacheValidationResult, type CachedFunction, type CachedRouteConfig, type ChannelMessage, type ChannelWebhookConfig, type CodeModeApi, type CodeModeConfig, type CodeModePermission, CodeModePermissionDeniedError, type CompiledRouteRule, CustomTool, DEFAULT_EXCLUDED_QUERY_PARAMS, type DefineCachedFunctionOptions, FileTooLargeError, type GetOrComputeOptions, InMemoryCacheAdapter, type InMemoryCacheAdapterOptions, type KeyDerivationOptions, type LoadEnvOptions, type LoadEnvResult, type McpResourceContents, type McpResourceDescriptor, NodeAcpTransport, type NormalizedCacheConfig, type OpenApiDocsOptions, type ParsedBody, type RevalidateResult, type RouteCacheOptions, RouteConfig, type RouteRule, type RouteRules, type Sandbox, type SerializedActionResult, type SerializedResponse, type StdioStreams, THEO_T_PREFIX, type UniversalZodIssue, type UploadedFile, type VendorAgentClient, type VendorAgentToolConfig, VerifyFn, type WorkflowLike, type WorkflowToolConfig, _resetCacheEngine, _resetEnvCache, buildResourceDescriptors, compileRouteRules, createACPTool, createCacheEngine, createCodeMode, createOpenApiHandler, createVendorAgentTool, createWorkflowTool, defineAppResource, defineCachedFunction, defineCachedRoute, deriveKey as deriveCacheKey, deserializeResponse, executeWebRequest, extractAppResources, extractUniversalIssues, getCacheControlHeader, getCacheEngine, handleChannelWebhook, handleMcpStdioLine, initCacheEngine, isActionError, isChannelPath, isInputError, loadEnv, parseChannelPath, parseRequestBody, readAppResource, resolveRouteRule, revalidatePath, revalidateTag, serializeResponse, serveMcpStdio, updateTag, validateExpire as validateCacheExpire, validateMaxAge as validateCacheMaxAge, validateTags as validateCacheTags };
|
package/dist/server/index.js
CHANGED
|
@@ -54,12 +54,13 @@ import {
|
|
|
54
54
|
defineAppResource,
|
|
55
55
|
executeWebRequest,
|
|
56
56
|
extractAppResources,
|
|
57
|
+
handleMcpJsonRpc,
|
|
57
58
|
jsonTransformer,
|
|
58
59
|
loadEnv,
|
|
59
60
|
readAppResource,
|
|
60
61
|
resolveTransformer,
|
|
61
62
|
superjsonTransformer
|
|
62
|
-
} from "../chunk-
|
|
63
|
+
} from "../chunk-W4YO6S4I.js";
|
|
63
64
|
import {
|
|
64
65
|
findSuggestion,
|
|
65
66
|
levenshtein
|
|
@@ -1313,6 +1314,32 @@ async function handleChannelWebhook(request, urlPath, config) {
|
|
|
1313
1314
|
});
|
|
1314
1315
|
}
|
|
1315
1316
|
|
|
1317
|
+
// src/server/agent/mcp-stdio.ts
|
|
1318
|
+
async function handleMcpStdioLine(line, mod, name, appResources = []) {
|
|
1319
|
+
const trimmed = line.trim();
|
|
1320
|
+
if (trimmed.length === 0) return null;
|
|
1321
|
+
let body;
|
|
1322
|
+
try {
|
|
1323
|
+
body = JSON.parse(trimmed);
|
|
1324
|
+
} catch {
|
|
1325
|
+
return JSON.stringify({
|
|
1326
|
+
jsonrpc: "2.0",
|
|
1327
|
+
id: null,
|
|
1328
|
+
error: { code: -32700, message: "Parse error" }
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
const response = handleMcpJsonRpc(mod, name, body, appResources);
|
|
1332
|
+
const payload = await response.json();
|
|
1333
|
+
return JSON.stringify(payload);
|
|
1334
|
+
}
|
|
1335
|
+
async function serveMcpStdio(mod, name, appResources, streams) {
|
|
1336
|
+
for await (const line of streams.lines) {
|
|
1337
|
+
const out = await handleMcpStdioLine(line, mod, name, appResources);
|
|
1338
|
+
if (out !== null) streams.write(`${out}
|
|
1339
|
+
`);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1316
1343
|
// src/server/serialization.ts
|
|
1317
1344
|
import superjson from "superjson";
|
|
1318
1345
|
function serializeResponse(data) {
|
|
@@ -1498,6 +1525,7 @@ export {
|
|
|
1498
1525
|
handleCspReportRequest,
|
|
1499
1526
|
handleCsrfReadiness,
|
|
1500
1527
|
handleCsrfReadinessRequest,
|
|
1528
|
+
handleMcpStdioLine,
|
|
1501
1529
|
handleRequestError,
|
|
1502
1530
|
handleWebRequestError,
|
|
1503
1531
|
initCacheEngine,
|
|
@@ -1546,6 +1574,7 @@ export {
|
|
|
1546
1574
|
serializeCookie,
|
|
1547
1575
|
serializeResponse,
|
|
1548
1576
|
serializeSpansToOtlp,
|
|
1577
|
+
serveMcpStdio,
|
|
1549
1578
|
serveReservedRoute,
|
|
1550
1579
|
serveStaticFile,
|
|
1551
1580
|
serverErrorToEnvelope,
|