@ts-pf/mcp 0.0.0-stage → 0.0.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.
Files changed (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +191 -2
  3. package/dist/all.d.ts +63 -0
  4. package/dist/all.d.ts.map +1 -0
  5. package/dist/all.js +55 -0
  6. package/dist/all.js.map +1 -0
  7. package/dist/audit.d.ts +21 -0
  8. package/dist/audit.d.ts.map +1 -0
  9. package/dist/audit.js +85 -0
  10. package/dist/audit.js.map +1 -0
  11. package/dist/bind.d.ts +42 -0
  12. package/dist/bind.d.ts.map +1 -0
  13. package/dist/bind.js +46 -0
  14. package/dist/bind.js.map +1 -0
  15. package/dist/bound-tool.d.ts +18 -0
  16. package/dist/bound-tool.d.ts.map +1 -0
  17. package/dist/bound-tool.js +31 -0
  18. package/dist/bound-tool.js.map +1 -0
  19. package/dist/call.d.ts +12 -0
  20. package/dist/call.d.ts.map +1 -0
  21. package/dist/call.js +104 -0
  22. package/dist/call.js.map +1 -0
  23. package/dist/composite.d.ts +17 -0
  24. package/dist/composite.d.ts.map +1 -0
  25. package/dist/composite.js +14 -0
  26. package/dist/composite.js.map +1 -0
  27. package/dist/coverage.d.ts +11 -0
  28. package/dist/coverage.d.ts.map +1 -0
  29. package/dist/coverage.js +35 -0
  30. package/dist/coverage.js.map +1 -0
  31. package/dist/error-text.d.ts +25 -0
  32. package/dist/error-text.d.ts.map +1 -0
  33. package/dist/error-text.js +56 -0
  34. package/dist/error-text.js.map +1 -0
  35. package/dist/executor.d.ts +19 -0
  36. package/dist/executor.d.ts.map +1 -0
  37. package/dist/executor.js +49 -0
  38. package/dist/executor.js.map +1 -0
  39. package/dist/host.d.ts +13 -0
  40. package/dist/host.d.ts.map +1 -0
  41. package/dist/host.js +226 -0
  42. package/dist/host.js.map +1 -0
  43. package/dist/index.d.ts +11 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +5 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/infer.d.ts +17 -0
  48. package/dist/infer.d.ts.map +1 -0
  49. package/dist/infer.js +2 -0
  50. package/dist/infer.js.map +1 -0
  51. package/dist/meta.d.ts +20 -0
  52. package/dist/meta.d.ts.map +1 -0
  53. package/dist/meta.js +10 -0
  54. package/dist/meta.js.map +1 -0
  55. package/dist/names.d.ts +22 -0
  56. package/dist/names.d.ts.map +1 -0
  57. package/dist/names.js +14 -0
  58. package/dist/names.js.map +1 -0
  59. package/dist/node.d.ts +41 -0
  60. package/dist/node.d.ts.map +1 -0
  61. package/dist/node.js +47 -0
  62. package/dist/node.js.map +1 -0
  63. package/dist/result.d.ts +7 -0
  64. package/dist/result.d.ts.map +1 -0
  65. package/dist/result.js +31 -0
  66. package/dist/result.js.map +1 -0
  67. package/dist/schema.d.ts +23 -0
  68. package/dist/schema.d.ts.map +1 -0
  69. package/dist/schema.js +172 -0
  70. package/dist/schema.js.map +1 -0
  71. package/dist/sdk.d.ts +31 -0
  72. package/dist/sdk.d.ts.map +1 -0
  73. package/dist/sdk.js +87 -0
  74. package/dist/sdk.js.map +1 -0
  75. package/dist/search.d.ts +13 -0
  76. package/dist/search.d.ts.map +1 -0
  77. package/dist/search.js +52 -0
  78. package/dist/search.js.map +1 -0
  79. package/dist/tool-meta.d.ts +14 -0
  80. package/dist/tool-meta.d.ts.map +1 -0
  81. package/dist/tool-meta.js +44 -0
  82. package/dist/tool-meta.js.map +1 -0
  83. package/dist/tool.d.ts +102 -0
  84. package/dist/tool.d.ts.map +1 -0
  85. package/dist/tool.js +30 -0
  86. package/dist/tool.js.map +1 -0
  87. package/dist/toolkit.d.ts +36 -0
  88. package/dist/toolkit.d.ts.map +1 -0
  89. package/dist/toolkit.js +22 -0
  90. package/dist/toolkit.js.map +1 -0
  91. package/dist/toolset.d.ts +89 -0
  92. package/dist/toolset.d.ts.map +1 -0
  93. package/dist/toolset.js +67 -0
  94. package/dist/toolset.js.map +1 -0
  95. package/dist/types.d.ts +57 -0
  96. package/dist/types.d.ts.map +1 -0
  97. package/dist/types.js +2 -0
  98. package/dist/types.js.map +1 -0
  99. package/package.json +80 -4
  100. package/skills/ts-pf-mcp/SKILL.md +134 -0
package/dist/call.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { BoundTool } from './bound-tool.js';
2
+ import { type McpOnError } from './error-text.js';
3
+ import type { Executor } from './executor.js';
4
+ import type { McpCallInfo, McpToolResult } from './types.js';
5
+ export type CallOptions = {
6
+ readonly executor: Executor;
7
+ readonly onError: McpOnError | undefined;
8
+ readonly maxResultChars: number;
9
+ };
10
+ /** Run one tool: context, inject / input map, procedure, output map + check, then errors → next-step text. */
11
+ export declare function callTool(tool: BoundTool, args: unknown, info: McpCallInfo, options: CallOptions): Promise<McpToolResult>;
12
+ //# sourceMappingURL=call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../src/call.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAa,KAAK,UAAU,EAAe,MAAM,iBAAiB,CAAA;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAG7C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE5D,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAAA;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;CAChC,CAAA;AAqED,8GAA8G;AAC9G,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAqCxB"}
package/dist/call.js ADDED
@@ -0,0 +1,104 @@
1
+ import { validateSchema } from '@ts-pf/contract';
2
+ import { PFError } from '@ts-pf/protocol';
3
+ import { errorText, reportError } from './error-text.js';
4
+ import { errorResult, successResult } from './result.js';
5
+ function isRecord(value) {
6
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
7
+ }
8
+ async function parse(schema, value) {
9
+ const result = await validateSchema(schema, value);
10
+ if (!result.success) {
11
+ throw new PFError({
12
+ code: 'VALIDATION',
13
+ message: 'Validation failed',
14
+ data: { issues: result.issues },
15
+ });
16
+ }
17
+ return result.value;
18
+ }
19
+ /** Model arguments → procedure input: `.input()` map, or the arguments plus injected keys. */
20
+ async function procedureInput(spec, args, opts) {
21
+ if (spec.input?.map) {
22
+ return spec.input.map(await parse(spec.input.schema, args), opts);
23
+ }
24
+ if (spec.procedure?.['~pf'].input === undefined)
25
+ return undefined;
26
+ const keys = Object.keys(spec.inject);
27
+ if (keys.length === 0)
28
+ return args ?? {};
29
+ // Injected values always win over anything the model sent under that key.
30
+ const input = isRecord(args) ? { ...args } : {};
31
+ for (const key of keys) {
32
+ input[key] = await spec.inject[key]?.({
33
+ context: opts.context,
34
+ info: opts.info,
35
+ });
36
+ }
37
+ return input;
38
+ }
39
+ async function execute(tool, args, opts, executor) {
40
+ const { spec } = tool;
41
+ if (spec.run) {
42
+ const input = spec.input ? await parse(spec.input.schema, args) : args;
43
+ return spec.run({ ...opts, input });
44
+ }
45
+ const input = await procedureInput(spec, args, opts);
46
+ const output = await executor.run(spec.path, input, opts.context, opts.info);
47
+ if (!spec.output)
48
+ return output;
49
+ const mapped = await spec.output.map(output, opts);
50
+ if (!spec.output.schema)
51
+ return mapped;
52
+ const result = await validateSchema(spec.output.schema, mapped);
53
+ if (!result.success) {
54
+ // A server bug: the model gets INTERNAL; `cause` (the issues) is for the log only.
55
+ throw new PFError({
56
+ code: 'INTERNAL',
57
+ message: 'Internal server error',
58
+ cause: result.issues,
59
+ });
60
+ }
61
+ return result.value;
62
+ }
63
+ /** Run one tool: context, inject / input map, procedure, output map + check, then errors → next-step text. */
64
+ export async function callTool(tool, args, info, options) {
65
+ const callInfo = {
66
+ ...info,
67
+ tool: { name: tool.name, path: tool.spec.path },
68
+ };
69
+ let context;
70
+ try {
71
+ context = await options.executor.context(callInfo);
72
+ const opts = {
73
+ context,
74
+ info: callInfo,
75
+ call: options.executor.client(context, callInfo),
76
+ };
77
+ const value = await execute(tool, args, opts, options.executor);
78
+ return successResult(value, options.maxResultChars, tool.structured);
79
+ }
80
+ catch (error) {
81
+ let reported = error;
82
+ let text;
83
+ try {
84
+ text = errorText(error, {
85
+ name: tool.name,
86
+ schema: tool.inputSchema,
87
+ errors: tool.spec.errors,
88
+ context,
89
+ });
90
+ }
91
+ catch (mapperError) {
92
+ reported = mapperError;
93
+ text = errorText(mapperError, {
94
+ name: tool.name,
95
+ schema: tool.inputSchema,
96
+ errors: {},
97
+ context,
98
+ });
99
+ }
100
+ reportError(reported, callInfo, options.onError);
101
+ return errorResult(text, options.maxResultChars);
102
+ }
103
+ }
104
+ //# sourceMappingURL=call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.js","sourceRoot":"","sources":["../src/call.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAmB,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAEzE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAUxD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED,KAAK,UAAU,KAAK,CAAC,MAAiB,EAAE,KAAc;IACpD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,KAAK,CAA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ACxB,MAAM,EAAE,EAAE;gBACV,OAAO;aACR,CAAC,CAAA;QACJ,CAAC;QACD,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;QAChD,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAClD,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { AnySchema, InferSchemaInput, InferSchemaOutput } from '@ts-pf/contract';
2
+ import type { Effect } from './meta.js';
3
+ import type { MapperOpts, ToolPhantom } from './tool.js';
4
+ export type CompositeToolDef<T, Ctx, Sch extends AnySchema> = {
5
+ description: string;
6
+ effect: Effect;
7
+ input: Sch;
8
+ run: (o: MapperOpts<T, Ctx> & {
9
+ input: InferSchemaOutput<Sch>;
10
+ }) => unknown;
11
+ };
12
+ /** An N→1 tool: no procedure path, so `$coverage` never counts it. */
13
+ export type CompositeTool<Ctx, Model> = {
14
+ readonly '~tool': ToolPhantom<never, Ctx, Model>;
15
+ };
16
+ export declare function createCompositeTool<T, Ctx, Sch extends AnySchema>(def: CompositeToolDef<T, Ctx, Sch>): CompositeTool<Ctx, InferSchemaInput<Sch>>;
17
+ //# sourceMappingURL=composite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../src/composite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAY,MAAM,WAAW,CAAA;AAElE,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,SAAS,IAAI;IAC5D,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,GAAG,CAAA;IACV,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG;QAAE,KAAK,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAA;KAAE,KAAK,OAAO,CAAA;CAC5E,CAAA;AAED,sEAAsE;AACtE,MAAM,MAAM,aAAa,CAAC,GAAG,EAAE,KAAK,IAAI;IACtC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;CACjD,CAAA;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,SAAS,EAC/D,GAAG,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GACjC,aAAa,CAAC,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAY3C"}
@@ -0,0 +1,14 @@
1
+ export function createCompositeTool(def) {
2
+ const spec = {
3
+ path: '',
4
+ description: def.description,
5
+ effect: def.effect,
6
+ inject: {},
7
+ input: { schema: def.input },
8
+ errors: {},
9
+ examples: [],
10
+ run: def.run,
11
+ };
12
+ return { '~tool': spec };
13
+ }
14
+ //# sourceMappingURL=composite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.js","sourceRoot":"","sources":["../src/composite.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,mBAAmB,CACjC,GAAkC;IAElC,MAAM,IAAI,GAAa;QACrB,IAAI,EAAE,EAAE;QACR,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,KAAK,EAAE;QAC5B,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE;QACZ,GAAG,EAAE,GAAG,CAAC,GAAmC;KAC7C,CAAA;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAW,CAAA;AACnC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { ExcludedPath } from './all.js';
2
+ import type { ProcPaths } from './infer.js';
3
+ import { type AnyToolset, type Toolset } from './toolset.js';
4
+ type Uncovered<T, S, X> = Exclude<ProcPaths<T>, (S extends readonly Toolset<unknown, never, infer P>[] ? P : never) | ExcludedPath<X>>;
5
+ export type CoverageCheck<T, S, X> = [Uncovered<T, S, X>] extends [never] ? unknown : {
6
+ uncovered: `"${Uncovered<T, S, X>}" is not exposed by any toolset nor excluded`;
7
+ };
8
+ /** Paths no toolset exposes (flat or through a host) and no exclusion names. `docs({ hidden: true })` counts as decided. */
9
+ export declare function uncoveredPaths(contract: unknown, toolsets: readonly AnyToolset[], exclude: readonly unknown[]): string[];
10
+ export {};
11
+ //# sourceMappingURL=coverage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAI3C,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,OAAO,EAAe,MAAM,cAAc,CAAA;AAEzE,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,OAAO,CAC/B,SAAS,CAAC,CAAC,CAAC,EACV,CAAC,CAAC,SAAS,SAAS,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,GACnE,YAAY,CAAC,CAAC,CAAC,CAClB,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACrE,OAAO,GACP;IACE,SAAS,EAAE,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,8CAA8C,CAAA;CAChF,CAAA;AAEL,4HAA4H;AAC5H,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,SAAS,UAAU,EAAE,EAC/B,OAAO,EAAE,SAAS,OAAO,EAAE,GAC1B,MAAM,EAAE,CA4BV"}
@@ -0,0 +1,35 @@
1
+ import { walkContract } from '@ts-pf/docs';
2
+ import { nodeInfo } from './node.js';
3
+ import { isTool, procedureSpec, toolSpec } from './tool.js';
4
+ import { isHidden } from './tool-meta.js';
5
+ import { toolsetSpec } from './toolset.js';
6
+ /** Paths no toolset exposes (flat or through a host) and no exclusion names. `docs({ hidden: true })` counts as decided. */
7
+ export function uncoveredPaths(contract, toolsets, exclude) {
8
+ const covered = new Set();
9
+ for (const toolset of toolsets) {
10
+ const spec = toolsetSpec(toolset);
11
+ for (const tool of Object.values(spec.tools))
12
+ covered.add(tool.path);
13
+ for (const host of Object.values(spec.hosts)) {
14
+ for (const tool of Object.values(host.tools))
15
+ covered.add(tool.path);
16
+ }
17
+ }
18
+ const prefixes = [];
19
+ for (const value of exclude) {
20
+ if (isTool(value))
21
+ covered.add(toolSpec(value).path);
22
+ else {
23
+ const info = nodeInfo(value);
24
+ if (!info)
25
+ throw new TypeError('$coverage() exclude takes tools or nodes');
26
+ prefixes.push(info.path.join('.'));
27
+ }
28
+ }
29
+ return walkContract(contract)
30
+ .filter((entry) => !isHidden(procedureSpec('', entry.procedure)))
31
+ .map((entry) => entry.path.join('.'))
32
+ .filter((path) => !covered.has(path) &&
33
+ !prefixes.some((p) => p === '' || path === p || path.startsWith(`${p}.`)));
34
+ }
35
+ //# sourceMappingURL=coverage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.js","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,EAAE,QAAQ,EAAE,M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AAC,GAAG,CAAC,CAAC,CAAA;QACpC,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC,QAAQ,CAAC;SAC1B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;SAChE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACpC,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QAClB,CAAC,QAAQ,CAAC,IAAI,CACZ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAC1D,CACJ,CAAA;AACL,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { ValidationIssue } from '@ts-pf/contract';
2
+ import type { JsonSchema } from '@ts-pf/docs';
3
+ import type { ErrorText } from './tool.js';
4
+ import type { McpCallInfo } from './types.js';
5
+ /** Side-effect only; replaces the default `console.error`, like `FetchHandler`'s `onError`. */
6
+ export type McpOnError = (error: unknown, info: McpCallInfo) => void;
7
+ /** The issues plus the expected schema, so the model can repair the call in one turn. */
8
+ export declare function invalidInputText(name: string, issues: readonly ValidationIssue[], schema: JsonSchema): string;
9
+ type ErrorTextOptions = {
10
+ name: string;
11
+ schema: JsonSchema;
12
+ errors: Readonly<Record<string, ErrorText>>;
13
+ context: unknown;
14
+ };
15
+ /**
16
+ * Model-facing text for a thrown value: invalid input → issues + schema; a
17
+ * declared code with a `.errors()` mapper → its next-step text; any other
18
+ * `PFError` → its code and message; anything else → `toWireError` (no leak).
19
+ * A throwing mapper propagates, so the caller reports it as unknown.
20
+ */
21
+ export declare function errorText(error: unknown, options: ErrorTextOptions): string;
22
+ /** `onError` when given; otherwise log unknown throws and `INTERNAL` `PFError`s, as `FetchHandler` does. */
23
+ export declare function reportError(error: unknown, info: McpCallInfo, onError: McpOnError | undefined): void;
24
+ export {};
25
+ //# sourceMappingURL=error-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-text.d.ts","sourceRoot":"","sources":["../src/error-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,+FAA+F;AAC/F,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,KAAK,IAAI,CAAA;AAEpE,yFAAyF;AACzF,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,eAAe,EAAE,EAClC,MAAM,EAAE,UAAU,GACjB,MAAM,CASR;AAQD,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,UAAU,CAAA;IAClB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;IAC3C,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAkB3E;AAED,4GAA4G;AAC5G,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,UAAU,GAAG,SAAS,GAC9B,IAAI,CAWN"}
@@ -0,0 +1,56 @@
1
+ import { isPFError, toWireError } from '@ts-pf/protocol';
2
+ /** The issues plus the expected schema, so the model can repair the call in one turn. */
3
+ export function invalidInputText(name, issues, schema) {
4
+ const list = issues
5
+ .map((issue) => issue.path.length > 0
6
+ ? `${issue.path.join('.')}: ${issue.message}`
7
+ : issue.message)
8
+ .join('; ');
9
+ return `Invalid input for ${name}: ${list}\nExpected schema: ${JSON.stringify(schema)}`;
10
+ }
11
+ function validationIssues(error) {
12
+ if (!isPFError(error) || error.code !== 'VALIDATION')
13
+ return undefined;
14
+ const issues = error.data?.issues;
15
+ return Array.isArray(issues) ? issues : undefined;
16
+ }
17
+ /**
18
+ * Model-facing text for a thrown value: invalid input → issues + schema; a
19
+ * declared code with a `.errors()` mapper → its next-step text; any other
20
+ * `PFError` → its code and message; anything else → `toWireError` (no leak).
21
+ * A throwing mapper propagates, so the caller reports it as unknown.
22
+ */
23
+ export function errorText(error, options) {
24
+ const issues = validationIssues(error);
25
+ if (issues)
26
+ return invalidInputText(options.name, issues, options.schema);
27
+ if (isPFError(error) && error.code !== 'INTERNAL') {
28
+ const mapper = options.errors[error.code];
29
+ if (mapper) {
30
+ return mapper({
31
+ data: error.data,
32
+ message: error.message,
33
+ context: options.context,
34
+ });
35
+ }
36
+ const data = error.data === undefined ? '' : `\n${JSON.stringify(error.data)}`;
37
+ return `${error.code}: ${error.message}${data}`;
38
+ }
39
+ const wire = toWireError(error);
40
+ return `${wire.code}: ${wire.message}`;
41
+ }
42
+ /** `onError` when given; otherwise log unknown throws and `INTERNAL` `PFError`s, as `FetchHandler` does. */
43
+ export function reportError(error, info, onError) {
44
+ if (onError) {
45
+ onError(error, info);
46
+ return;
47
+ }
48
+ const where = `"${info.tool?.name ?? '?'}"`;
49
+ if (!isPFError(error)) {
50
+ console.error(`[ts-pf/mcp] Unhandled error in ${where}:`, error);
51
+ }
52
+ else if (error.code === 'INTERNAL') {
53
+ console.error(`[ts-pf/mcp] INTERNAL error in ${where}:`, error);
54
+ }
55
+ }
56
+ //# sourceMappingURL=error-text.js.map
@@ -0,0 +1 @@
1
+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@ -0,0 +1,19 @@
1
+ import type { ContractClient } from '@ts-pf/contract';
2
+ import { type CallInterceptor, type ImplementedRouter } from '@ts-pf/server';
3
+ import type { MaybePromise } from './infer.js';
4
+ import type { McpCallInfo } from './types.js';
5
+ /** Where tools run: the contract defines them, an executor only runs them. */
6
+ export interface Executor {
7
+ context(info: McpCallInfo): Promise<unknown>;
8
+ run(path: string, input: unknown, context: unknown, info: McpCallInfo): Promise<unknown>;
9
+ /** The typed `call` client mappers get, on the same executor. */
10
+ client(context: unknown, info: McpCallInfo): ContractClient<unknown>;
11
+ }
12
+ /** In-process: `lookupProcedure` + `runProcedure`, so middleware, auth, and interceptors all run. */
13
+ export declare function appExecutor(app: ImplementedRouter, context: ((info: McpCallInfo) => MaybePromise<unknown>) | undefined, interceptors: readonly CallInterceptor[] | undefined): Executor;
14
+ type AnyClient = ContractClient<unknown>;
15
+ export type ClientSource<C> = C | ((info: McpCallInfo) => C);
16
+ /** Remote: calls a typed client, which may be built per caller (a gateway calling upstream as the user). */
17
+ export declare function clientExecutor(source: ClientSource<AnyClient>, context: ((info: McpCallInfo) => MaybePromise<unknown>) | undefined): Executor;
18
+ export {};
19
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAGvB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,8EAA8E;AAC9E,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5C,GAAG,CACD,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,OAAO,CAAC,CAAA;IACnB,iEAAiE;IACjE,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;CACrE;AAED,qGAAqG;AACrG,wBAAgB,WAAW,CACzB,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,WAAW,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,EACnE,YAAY,EAAE,SAAS,eAAe,EAAE,GAAG,SAAS,GACnD,QAAQ,CAsBV;AAED,KAAK,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;AACxC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,WAAW,KAAK,CAAC,CAAC,CAAA;AA4B5D,4GAA4G;AAC5G,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC,EAC/B,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,WAAW,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,GAClE,QAAQ,CASV"}
@@ -0,0 +1,49 @@
1
+ import { defined } from '@ts-pf/protocol';
2
+ import { createLocalClient, lookupProcedure, runProcedure, } from '@ts-pf/server';
3
+ /** In-process: `lookupProcedure` + `runProcedure`, so middleware, auth, and interceptors all run. */
4
+ export function appExecutor(app, context, interceptors) {
5
+ const chain = interceptors && interceptors.length > 0 ? interceptors : undefined;
6
+ return {
7
+ context: async (info) => context?.(info),
8
+ async run(path, input, ctx, info) {
9
+ const procedure = lookupProcedure(app, path.split('.'));
10
+ if (!procedure) {
11
+ throw new Error(`No procedure at "${path}" in the bound app`);
12
+ }
13
+ return runProcedure(procedure, input, ctx, defined({ signal: info.signal, interceptors: chain }));
14
+ },
15
+ client: (ctx) => chain
16
+ ? createLocalClient(app, { context: ctx, interceptors: chain })
17
+ : createLocalClient(app, { context: ctx }),
18
+ };
19
+ }
20
+ function procedureAt(client, path) {
21
+ let node = client;
22
+ for (const segment of path.split('.')) {
23
+ node = node?.[segment];
24
+ }
25
+ if (typeof node !== 'function') {
26
+ throw new Error(`No procedure at "${path}" on the bound client`);
27
+ }
28
+ return node;
29
+ }
30
+ /**
31
+ * `createClient()` returns a callable proxy, so `typeof` cannot tell it from a
32
+ * per-caller `(info) => client`. A client answers every key with a callable
33
+ * child; a plain factory function has no such key.
34
+ */
35
+ function isClientFactory(source) {
36
+ return (typeof source === 'function' &&
37
+ typeof source['~ts-pf-mcp'] !==
38
+ 'function');
39
+ }
40
+ /** Remote: calls a typed client, which may be built per caller (a gateway calling upstream as the user). */
41
+ export function clientExecutor(source, context) {
42
+ const resolve = (info) => isClientFactory(source) ? source(info) : source;
43
+ return {
44
+ context: async (info) => (context ? context(info) : {}),
45
+ run: async (path, input, _ctx, info) => procedureAt(resolve(info), path)(input, defined({ signal: info.signal })),
46
+ client: (_ctx, info) => resolve(info),
47
+ };
48
+ }
49
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAEL,iBAAiB,EAEjB,eAAe,EACf,YAAY,GACb,MAAM,eAAe,CAAA;AAiBtB,qGAAqG;AACrG,MAAM,UAAU,WAAW,CACzB,GAAsB,EACtB,OAAmE,EACnE,YAAoD;IAEpD,MAAM,KAAK,GACT,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAA;IACpE,OAAO;QACL,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;QACx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ACb,CAAA;AACH,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,cAAc,CAC5B,MAA+B,EAC/B,OAAmE;IAEnE,MAAM,OAAO,GAAG,CAAC,IAAiB,EAAa,EAAE,CAC/C,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;IACjD,OAAO;QACL,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CACrC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3E,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;KACtC,CAAA;AACH,CAAC"}
package/dist/host.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { BoundTool } from './bound-tool.js';
2
+ import type { HostSpec } from './toolset.js';
3
+ import type { McpCallInfo, McpToolDefinition, McpToolResult } from './types.js';
4
+ /** A listed MCP tool and how to run it. */
5
+ export type ToolEntry = {
6
+ readonly definition: McpToolDefinition;
7
+ invoke(args: unknown, info: McpCallInfo): Promise<McpToolResult>;
8
+ };
9
+ type Invoke = (tool: BoundTool, args: unknown, info: McpCallInfo) => Promise<McpToolResult>;
10
+ /** The `get_*_capabilities` / `call_*_capability` pairs of one host; empty buckets list nothing. */
11
+ export declare function hostEntries(key: string, host: HostSpec, tools: readonly BoundTool[], invoke: Invoke, maxChars: number): ToolEntry[];
12
+ export {};
13
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAWhD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EACV,WAAW,EAEX,iBAAiB,EACjB,aAAa,EACd,MAAM,YAAY,CAAA;AAEnB,2CAA2C;AAC3C,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAA;IACtC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;CACjE,CAAA;AAED,KAAK,MAAM,GAAG,CACZ,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,WAAW,KACd,OAAO,CAAC,aAAa,CAAC,CAAA;AAqP3B,oGAAoG;AACpG,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,SAAS,EAAE,CAoBb"}