stitchkit 0.1.0 → 0.2.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/README.md +10 -7
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +4 -3
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/{index-gfzn1n4n.js → index-a35v22fh.js} +1 -1
- package/dist/{index-7wfkbvss.js → index-kckky6zw.js} +6 -2
- package/dist/index-v2z2v3mq.js +587 -0
- package/dist/index.js +2 -2
- package/dist/node.d.ts +4 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +26 -0
- package/dist/server/create.d.ts +3 -3
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +10 -576
- package/dist/server/node.d.ts +12 -0
- package/dist/server/node.d.ts.map +1 -0
- package/dist/server/types.d.ts +24 -21
- package/dist/server/types.d.ts.map +1 -1
- package/dist/tools/agent.d.ts +15 -2
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/coerce.d.ts +8 -0
- package/dist/tools/coerce.d.ts.map +1 -0
- package/dist/tools/execute.d.ts +26 -2
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/flatten.d.ts +15 -0
- package/dist/tools/flatten.d.ts.map +1 -0
- package/dist/tools/json-schema.d.ts +18 -0
- package/dist/tools/json-schema.d.ts.map +1 -0
- package/dist/tools/manifest.d.ts +13 -0
- package/dist/tools/manifest.d.ts.map +1 -0
- package/dist/tools/mcp-handler.d.ts.map +1 -1
- package/dist/tools/mcp.d.ts +53 -3
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +18 -6
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/schema.d.ts +19 -2
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools.d.ts +6 -2
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +337 -154
- package/package.json +15 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,cAAc,EACd,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AACtE,KAAK,WAAW,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AACjF,KAAK,UAAU,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AAC/E,KAAK,WAAW,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE7E,MAAM,MAAM,QAAQ,CAClB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACrC,IAAI,SAAS,cAAc,GAAG,cAAc,IAC1C;KACD,CAAC,IAAI,MAAM,CAAC,GAAG,CACd,GAAG,EAAE,IAAI,GAAG;QAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KAAE,KAC/D,IA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ACnB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,GAAG,CAAC,EAAE,iBAAiB,CAAC;CACzB;AAED,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxC,CAAC"}
|
package/dist/tools/agent.d.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import type { ToolSet } from 'ai';
|
|
2
2
|
import type { ServiceDef } from '../server/types';
|
|
3
|
-
import type
|
|
3
|
+
import { type ToolCallHooks, type ToolLifecycle } from './execute';
|
|
4
4
|
import { type ToolExtend } from './mount';
|
|
5
5
|
export interface AgentContext {
|
|
6
6
|
[key: string]: unknown;
|
|
7
7
|
}
|
|
8
8
|
export interface AgentMountConfig {
|
|
9
9
|
context?: AgentContext;
|
|
10
|
+
/** Tool-call observability hooks. */
|
|
10
11
|
hooks?: ToolCallHooks;
|
|
12
|
+
/**
|
|
13
|
+
* Auth / scope gate and result transform for every tool call — the tool-side
|
|
14
|
+
* twin of `createServer`'s `beforeHandle` / `afterHandle`. Without it an
|
|
15
|
+
* agent tool call bypasses the auth a `createServer` `beforeHandle` enforces.
|
|
16
|
+
*/
|
|
17
|
+
lifecycle?: ToolLifecycle;
|
|
11
18
|
extend?: ToolExtend;
|
|
19
|
+
/** Coerce JSON-stringified arrays/objects in tool arguments. Default: true. */
|
|
20
|
+
coerceJsonArgs?: boolean;
|
|
21
|
+
/** Flatten discriminated union inputs into a single object. Default: false. */
|
|
22
|
+
flattenUnionInput?: boolean;
|
|
23
|
+
/** Global error hint injected into every failed tool result. */
|
|
24
|
+
errorHint?: (toolName: string, errorCode: string) => string | null;
|
|
12
25
|
}
|
|
13
|
-
export declare function mountAgent(
|
|
26
|
+
export declare function mountAgent(services: ServiceDef | ServiceDef[], config?: AgentMountConfig): ToolSet;
|
|
14
27
|
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/tools/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/tools/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAuB,MAAM,WAAW,CAAC;AACxF,OAAO,EAAmD,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3F,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,qCAAqC;IACrC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACpE;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,UAAU,GAAG,UAAU,EAAE,EACnC,MAAM,GAAE,gBAAqB,GAC5B,OAAO,CAyCT"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Wrap array/object fields with `z.preprocess(jsonCoerce)` — tolerant of
|
|
4
|
+
* LLM double-serialization (sending `"[1,2]"` instead of `[1,2]`).
|
|
5
|
+
* Preserves optional/nullable wrappers so the emitted JSON Schema is identical.
|
|
6
|
+
*/
|
|
7
|
+
export declare function withJsonCoercion(schema: z.ZodObject<z.ZodRawShape>): z.ZodObject<z.ZodRawShape>;
|
|
8
|
+
//# sourceMappingURL=coerce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../../src/tools/coerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GACjC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAyB5B"}
|
package/dist/tools/execute.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TransportSource } from '../contract';
|
|
1
|
+
import type { RuntimeContext, TransportSource } from '../contract';
|
|
2
2
|
import type { MethodDef } from '../server/types';
|
|
3
3
|
export type ToolResult = {
|
|
4
4
|
ok: true;
|
|
@@ -17,5 +17,29 @@ export interface ToolCallHooks {
|
|
|
17
17
|
beforeToolCall?: (toolName: string, args: Record<string, unknown>, context: ToolCallContext) => void | Promise<void>;
|
|
18
18
|
afterToolCall?: (toolName: string, args: Record<string, unknown>, result: ToolResult, durationMs: number, context: ToolCallContext) => void | Promise<void>;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The tool-side twin of the HTTP server's `beforeHandle` / `afterHandle`. A
|
|
22
|
+
* tool call runs the same handler an HTTP request would — `ToolLifecycle` makes
|
|
23
|
+
* it run the same gate. Pass a `createAuthHook` result as `beforeHandle` here
|
|
24
|
+
* and tools are scope-guarded exactly as HTTP routes are; without it a tool
|
|
25
|
+
* call bypasses the auth a `createServer` `beforeHandle` enforces.
|
|
26
|
+
*
|
|
27
|
+
* Structurally a subset of `LifecycleHooks` — the same hook object used for
|
|
28
|
+
* `createServer({ hooks })` is assignable here.
|
|
29
|
+
*/
|
|
30
|
+
export interface ToolLifecycle {
|
|
31
|
+
/** Auth / scope gate — throw to reject the call. */
|
|
32
|
+
beforeHandle?: (ctx: RuntimeContext, endpoint: MethodDef) => void | Promise<void>;
|
|
33
|
+
/** Transform the handler result before it is returned. */
|
|
34
|
+
afterHandle?: (ctx: RuntimeContext, result: unknown, endpoint: MethodDef) => unknown | Promise<unknown>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalise any thrown value into a failed `ToolResult` — the one place an
|
|
38
|
+
* `AppError` becomes a tool error. Shared by `executeToolMethod` and both
|
|
39
|
+
* transport mounts so every tool error has one shape.
|
|
40
|
+
*/
|
|
41
|
+
export declare function toolResultFromError(err: unknown): Extract<ToolResult, {
|
|
42
|
+
ok: false;
|
|
43
|
+
}>;
|
|
44
|
+
export declare function executeToolMethod(method: MethodDef<unknown, unknown, unknown>, toolName: string, rawArgs: Record<string, unknown>, context: ToolCallContext, hooks?: ToolCallHooks, lifecycle?: ToolLifecycle): Promise<ToolResult>;
|
|
21
45
|
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"execute.d.ts","s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AAQ,EAAE,SAAS,KAChB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,CAQpF;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAC5C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,eAAe,EACxB,KAAK,CAAC,EAAE,aAAa,EACrB,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,UAAU,CAAC,CA8FrB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Flatten a `ZodDiscriminatedUnion` into a single `ZodObject` for LLM
|
|
4
|
+
* transports that cannot represent `oneOf` (MCP).
|
|
5
|
+
*
|
|
6
|
+
* The discriminator becomes a `z.enum(...)` of all variant values; fields
|
|
7
|
+
* from each variant become optional with a `.describe()` hint indicating
|
|
8
|
+
* which variant requires them.
|
|
9
|
+
*
|
|
10
|
+
* **Lossy:** per-variant field requiredness is replaced with optional +
|
|
11
|
+
* description hint. The original union remains the validation schema in
|
|
12
|
+
* `executeToolMethod` — this is the advertised schema only.
|
|
13
|
+
*/
|
|
14
|
+
export declare function flattenDiscriminatedUnion(union: z.ZodDiscriminatedUnion): z.ZodObject<z.ZodRawShape>;
|
|
15
|
+
//# sourceMappingURL=flatten.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/tools/flatten.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,CAAC,CAAC,qBAAqB,GAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAkD5B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single Zod → JSON Schema conversion point for the tools layer.
|
|
3
|
+
*
|
|
4
|
+
* MCP and agent both ultimately turn a contract schema into JSON Schema. This
|
|
5
|
+
* is the one place stitchkit converts — with the options that match what the
|
|
6
|
+
* transport SDKs emit, so a build-time validity probe tests the same thing the
|
|
7
|
+
* SDK will later emit, not a divergent code path.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
/** Conversion direction — `input` for tool arguments, `output` for results. */
|
|
11
|
+
export type JsonSchemaIo = 'input' | 'output';
|
|
12
|
+
/**
|
|
13
|
+
* Convert a Zod schema to JSON Schema. Throws on a construct JSON Schema cannot
|
|
14
|
+
* represent (`z.date()`, `z.bigint()`, `z.map()`, …). The caller decides what
|
|
15
|
+
* to do with that failure — see `onIncompatibleSchema`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo): Record<string, unknown>;
|
|
18
|
+
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/tools/json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MountableTool } from './mount';
|
|
2
|
+
export interface ToolManifestEntry {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Build a searchable manifest from collected tools — name, description and
|
|
9
|
+
* JSON Schema for each. Use it to power a `tool_search` native tool: the app
|
|
10
|
+
* decides the search algorithm and the unlock mechanism.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildToolManifest(tools: MountableTool[]): ToolManifestEntry[];
|
|
13
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/tools/manifest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,iBAAiB,EAAE,CAM7E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-handler.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-handler.ts"],"names":[],"mappings":"AASA,OAAO,EAAkB,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"mcp-handler.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-handler.ts"],"names":[],"mappings":"AASA,OAAO,EAAkB,KAAK,oBAAoB,EAAsB,MAAM,OAAO,CAAC;AAyDtF,MAAM,WAAW,gBAAgB,CAAC,KAAK,CAAE,SAAQ,oBAAoB,CAAC,KAAK,CAAC;IAC1E,uEAAuE;IACvE,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;CAC9D;AAYD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EACpC,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAC9B,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA+DrC"}
|
package/dist/tools/mcp.d.ts
CHANGED
|
@@ -1,12 +1,48 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import type { ServiceDef } from '../server/types';
|
|
3
|
-
import type
|
|
2
|
+
import type { ServiceDef, StitchLogger } from '../server/types';
|
|
3
|
+
import { type ToolCallHooks, type ToolLifecycle } from './execute';
|
|
4
4
|
import { type ToolExtend } from './mount';
|
|
5
|
+
/**
|
|
6
|
+
* What to do when a tool's schema cannot be advertised on the MCP surface — a
|
|
7
|
+
* union / discriminated-union input (MCP needs an object), or a construct
|
|
8
|
+
* JSON Schema cannot represent (`z.date()`, `z.map()`, …):
|
|
9
|
+
* - `throw` (default) — fail the build loudly, listing every bad tool. Better
|
|
10
|
+
* a failed deploy than a tool that silently vanishes from the MCP surface.
|
|
11
|
+
* - `warn` — log and drop the tool.
|
|
12
|
+
* - `skip` — drop the tool silently.
|
|
13
|
+
*/
|
|
14
|
+
export type IncompatibleSchemaPolicy = 'throw' | 'skip' | 'warn';
|
|
5
15
|
export interface McpMountConfig {
|
|
6
16
|
context?: Record<string, unknown>;
|
|
17
|
+
/** Tool-call observability hooks. */
|
|
7
18
|
hooks?: ToolCallHooks;
|
|
19
|
+
/**
|
|
20
|
+
* Auth / scope gate and result transform for every tool call — the tool-side
|
|
21
|
+
* twin of `createServer`'s `beforeHandle` / `afterHandle`. Pass the same
|
|
22
|
+
* `createAuthHook` result here as on the HTTP server to guard tools too;
|
|
23
|
+
* without it a tool call bypasses the HTTP `beforeHandle` auth gate.
|
|
24
|
+
*/
|
|
25
|
+
lifecycle?: ToolLifecycle;
|
|
8
26
|
extend?: ToolExtend;
|
|
27
|
+
/** What to do when a tool's schema is not MCP-compatible. Default `'throw'`. */
|
|
28
|
+
onIncompatibleSchema?: IncompatibleSchemaPolicy;
|
|
29
|
+
/** Logger for the `'warn'` policy — defaults to `console`. */
|
|
30
|
+
logger?: StitchLogger;
|
|
31
|
+
/** Coerce JSON-stringified arrays/objects in tool arguments. Default: true. */
|
|
32
|
+
coerceJsonArgs?: boolean;
|
|
33
|
+
/** Flatten discriminated union inputs into a single object. Default: false. */
|
|
34
|
+
flattenUnionInput?: boolean;
|
|
35
|
+
/** Global error hint injected into every failed tool result. */
|
|
36
|
+
errorHint?: (toolName: string, errorCode: string) => string | null;
|
|
9
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Validate that every contract tool in `services` can be advertised on the MCP
|
|
40
|
+
* surface — object-shaped, JSON Schema-compatible input / output, no tool-name
|
|
41
|
+
* collision across services. The build-time check behind `mountMcp` — also
|
|
42
|
+
* callable on its own (a startup assertion, a test) to fail a deploy before
|
|
43
|
+
* the first request.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateMcpSchemas(services: ServiceDef[], onIncompatibleSchema?: IncompatibleSchemaPolicy, logger?: StitchLogger): void;
|
|
10
46
|
export declare function mountMcp(mcpServer: McpServer, services: ServiceDef | ServiceDef[], config?: McpMountConfig): void;
|
|
11
47
|
/**
|
|
12
48
|
* Transport-neutral build config for an MCP server — everything needed to turn
|
|
@@ -24,15 +60,29 @@ export interface McpServerBuildConfig<TAuth> {
|
|
|
24
60
|
services: ServiceDef[] | ((auth: TAuth) => ServiceDef[]);
|
|
25
61
|
/** Context merged into every contract handler (`mountMcp` context). */
|
|
26
62
|
context?: (auth: TAuth) => Record<string, unknown>;
|
|
27
|
-
/** Tool-call
|
|
63
|
+
/** Tool-call observability hooks — `afterToolCall` fires for every result
|
|
28
64
|
* (success and error), so the consuming app can log MCP tool outcomes. */
|
|
29
65
|
hooks?: ToolCallHooks;
|
|
66
|
+
/** Auth / scope gate and result transform for every tool call — pass the
|
|
67
|
+
* same `createAuthHook` result used for the HTTP `beforeHandle` to guard
|
|
68
|
+
* tools with the identical rules. */
|
|
69
|
+
lifecycle?: ToolLifecycle;
|
|
70
|
+
/** What to do when a tool's schema is not MCP-compatible. Default `'throw'`. */
|
|
71
|
+
onIncompatibleSchema?: IncompatibleSchemaPolicy;
|
|
72
|
+
/** Logger for schema-incompatibility warnings — defaults to `console`. */
|
|
73
|
+
logger?: StitchLogger;
|
|
30
74
|
/** Register native (non-contract) MCP tools — receives the `McpServer`
|
|
31
75
|
* directly. For tools returning multimodal content, e.g. `mountViewFile`. */
|
|
32
76
|
nativeTools?: (server: McpServer) => void;
|
|
33
77
|
/** Server instructions — a short (≤2KB) hint to the host on when and how to
|
|
34
78
|
* use these tools. Surfaced to MCP tool-search. */
|
|
35
79
|
instructions?: string;
|
|
80
|
+
/** Coerce JSON-stringified arrays/objects in tool arguments. Default: true. */
|
|
81
|
+
coerceJsonArgs?: boolean;
|
|
82
|
+
/** Flatten discriminated union inputs into a single object. Default: false. */
|
|
83
|
+
flattenUnionInput?: boolean;
|
|
84
|
+
/** Global error hint injected into every failed tool result. */
|
|
85
|
+
errorHint?: (toolName: string, errorCode: string) => string | null;
|
|
36
86
|
}
|
|
37
87
|
/**
|
|
38
88
|
* Build an `McpServer` from contract services for a resolved identity.
|
package/dist/tools/mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,C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IAC9C,2EAA2E;IAC3E,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,KAAK,UAAU,EAAE,CAAC,CAAC;IACzD,uEAAuE;IACvE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnD;+EAC2E;IAC3E,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;0CAEsC;IACtC,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,gFAAgF;IAChF,oBAAoB,CAAC,EAAE,wBAAwB,CAAC;IAChD,0EAA0E;IAC1E,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;kFAC8E;IAC9E,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C;wDACoD;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACpE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAClC,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACnC,IAAI,EAAE,KAAK,GACV,SAAS,CAoBX"}
|
package/dist/tools/mount.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import type { Transport, TransportSource } from '../contract';
|
|
8
8
|
import type { MethodDef, ServiceDef } from '../server/types';
|
|
9
|
-
import { type ToolCallHooks, type ToolResult } from './execute';
|
|
9
|
+
import { type ToolCallHooks, type ToolLifecycle, type ToolResult } from './execute';
|
|
10
10
|
/**
|
|
11
11
|
* Extra arguments folded into a mounted tool's schema — the host supplies them,
|
|
12
12
|
* `resolve` turns them into handler context. Shared by `mountMcp` / `mountAgent`.
|
|
@@ -26,15 +26,22 @@ export interface MountableTool {
|
|
|
26
26
|
/** Tool name — the `toolName` override, else derived from service + method. */
|
|
27
27
|
name: string;
|
|
28
28
|
/** Merged params + input schema, with the extend fields folded in when they apply. */
|
|
29
|
-
schema: z.
|
|
29
|
+
schema: z.ZodType;
|
|
30
30
|
/** Whether `ToolExtend` applies to this method. */
|
|
31
31
|
shouldExtend: boolean;
|
|
32
32
|
}
|
|
33
|
+
export interface CollectToolsConfig {
|
|
34
|
+
extend?: ToolExtend;
|
|
35
|
+
/** Coerce JSON-stringified arrays/objects in tool arguments. Default: true. */
|
|
36
|
+
coerceJsonArgs?: boolean;
|
|
37
|
+
/** Flatten discriminated union inputs into a single object for MCP. Default: false. */
|
|
38
|
+
flattenUnionInput?: boolean;
|
|
39
|
+
}
|
|
33
40
|
/**
|
|
34
41
|
* Walk a service's methods and resolve each one exposed on `transport` to a
|
|
35
42
|
* tool name and schema — the shared front half of `mountMcp` / `mountAgent`.
|
|
36
43
|
*/
|
|
37
|
-
export declare function collectTools(service: ServiceDef, transport: Transport,
|
|
44
|
+
export declare function collectTools(service: ServiceDef, transport: Transport, config?: CollectToolsConfig): MountableTool[];
|
|
38
45
|
/** Per-mount config a tool runner closes over. */
|
|
39
46
|
export interface ToolRunnerConfig {
|
|
40
47
|
/** Transport tag put on every call's context. */
|
|
@@ -43,8 +50,12 @@ export interface ToolRunnerConfig {
|
|
|
43
50
|
extend?: ToolExtend;
|
|
44
51
|
/** Static context merged into every handler. */
|
|
45
52
|
context?: Record<string, unknown>;
|
|
46
|
-
/** Tool-call
|
|
53
|
+
/** Tool-call observability hooks. */
|
|
47
54
|
hooks?: ToolCallHooks;
|
|
55
|
+
/** Auth / scope gate and result transform — runs for every tool call. */
|
|
56
|
+
lifecycle?: ToolLifecycle;
|
|
57
|
+
/** Global error hint injected into every failed tool result. */
|
|
58
|
+
errorHint?: (toolName: string, errorCode: string) => string | null;
|
|
48
59
|
}
|
|
49
60
|
/**
|
|
50
61
|
* Build the call executor for a mount — resolve the extend context, strip the
|
|
@@ -53,9 +64,10 @@ export interface ToolRunnerConfig {
|
|
|
53
64
|
export declare function createToolRunner(config: ToolRunnerConfig): (tool: MountableTool, rawArgs: Record<string, unknown>) => Promise<ToolResult>;
|
|
54
65
|
/**
|
|
55
66
|
* Shape a failed `ToolResult` into the `{ error, details?, _hint? }` object
|
|
56
|
-
* both transports return on error.
|
|
67
|
+
* both transports return on error. When a global `errorHint` is provided, it
|
|
68
|
+
* is appended after the per-error `AppError.hint` (if any).
|
|
57
69
|
*/
|
|
58
70
|
export declare function formatToolError(result: Extract<ToolResult, {
|
|
59
71
|
ok: false;
|
|
60
|
-
}
|
|
72
|
+
}>, toolName?: string, errorHint?: (toolName: string, errorCode: string) => string | null): Record<string, unknown>;
|
|
61
73
|
//# sourceMappingURL=mount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/tools/mount.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/tools/mount.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK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AAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,qCAAqC;IACrC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,yEAAyE;IACzE,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,gEAAgE;IAChE,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACpE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,gBAAgB,GACvB,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAqBhF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,EAC1C,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GACjE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
|
package/dist/tools/schema.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
/** Keys of a Zod object schema's shape — `[]` for a non-object or absent schema. */
|
|
3
|
+
export declare function objectShapeKeys(schema?: z.ZodType): string[];
|
|
4
|
+
/**
|
|
5
|
+
* Merge an endpoint's `params` and `input` schemas into the single schema a
|
|
6
|
+
* tool advertises.
|
|
7
|
+
*
|
|
8
|
+
* - Both object → one merged `z.object`. A key declared in both is a contract
|
|
9
|
+
* bug and throws.
|
|
10
|
+
* - A non-object `input` (a union, a discriminated union, a refined / piped
|
|
11
|
+
* schema) is kept intact and intersected with `params` when present — the
|
|
12
|
+
* transport SDK converts it natively (a discriminated union becomes a clean
|
|
13
|
+
* `oneOf`).
|
|
14
|
+
*
|
|
15
|
+
* The merged schema is exactly the two source schemas side by side: nothing is
|
|
16
|
+
* coerced, flattened or transformed, so the schema a tool advertises is the
|
|
17
|
+
* schema its arguments are validated against (`executeToolMethod` parses each
|
|
18
|
+
* source schema over its own slice of the args).
|
|
19
|
+
*/
|
|
20
|
+
export declare function mergeSchemas(paramsSchema?: z.ZodType<unknown>, inputSchema?: z.ZodType<unknown>): z.ZodType;
|
|
4
21
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/tools/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/tools/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,MAAM,EAAE,CAE5D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,YAAY,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EACjC,WAAW,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAC/B,CAAC,CAAC,OAAO,CA2BX"}
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export { type AgentContext, type AgentMountConfig, mountAgent } from './tools/agent';
|
|
2
|
-
export {
|
|
2
|
+
export { withJsonCoercion } from './tools/coerce';
|
|
3
|
+
export type { ToolCallHooks, ToolLifecycle, ToolResult } from './tools/execute';
|
|
4
|
+
export { flattenDiscriminatedUnion } from './tools/flatten';
|
|
5
|
+
export { buildToolManifest, type ToolManifestEntry } from './tools/manifest';
|
|
6
|
+
export { buildMcpServer, type IncompatibleSchemaPolicy, type McpMountConfig, type McpServerBuildConfig, mountMcp, validateMcpSchemas, } from './tools/mcp';
|
|
3
7
|
export { createMcpHandler, type McpHandlerConfig } from './tools/mcp-handler';
|
|
4
8
|
export { createStdioMcpServer, type StdioMcpServerConfig } from './tools/mcp-stdio';
|
|
5
|
-
export type
|
|
9
|
+
export { collectTools, type MountableTool, type ToolExtend } from './tools/mount';
|
|
6
10
|
export { type ImplementRemoteOptions, implementRemote } from './tools/remote';
|
|
7
11
|
export { type McpMediaContent, mountViewFile, resolveMedia } from './tools/view-file';
|
|
8
12
|
//# sourceMappingURL=tools.d.ts.map
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EACL,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,QAAQ,
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EACL,cAAc,EACd,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,QAAQ,EACR,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,KAAK,sBAAsB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,KAAK,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|