stitchkit 0.38.0 → 0.40.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 (60) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/client-url.d.ts +2 -0
  3. package/dist/browser/client-url.d.ts.map +1 -1
  4. package/dist/browser/client.d.ts +32 -1
  5. package/dist/browser/client.d.ts.map +1 -1
  6. package/dist/browser/http.d.ts +5 -6
  7. package/dist/browser/http.d.ts.map +1 -1
  8. package/dist/cli.js +2 -2
  9. package/dist/contract/define.d.ts +36 -12
  10. package/dist/contract/define.d.ts.map +1 -1
  11. package/dist/contract/factory.d.ts +3 -3
  12. package/dist/contract/factory.d.ts.map +1 -1
  13. package/dist/contract/index.d.ts +1 -1
  14. package/dist/contract/index.d.ts.map +1 -1
  15. package/dist/contract/index.js +1 -1
  16. package/dist/{index-czmqks7r.js → index-6jypn22c.js} +1 -1
  17. package/dist/{index-p3kwf73n.js → index-7rbzbnnf.js} +28 -15
  18. package/dist/{index-bgdd42pt.js → index-92gs1m5b.js} +1 -1
  19. package/dist/{index-mzx0an0s.js → index-fyfk537k.js} +50 -5
  20. package/dist/{index-n5t4gnfz.js → index-p1x65gk7.js} +18 -3
  21. package/dist/{index-x4wbc8sz.js → index-xax049k6.js} +73 -5
  22. package/dist/index.d.ts +2 -2
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +122 -17
  25. package/dist/internal/route-pattern.d.ts +7 -0
  26. package/dist/internal/route-pattern.d.ts.map +1 -0
  27. package/dist/node.js +3 -3
  28. package/dist/observability/index.js +1 -1
  29. package/dist/react/entity-cache.d.ts +56 -42
  30. package/dist/react/entity-cache.d.ts.map +1 -1
  31. package/dist/react.d.ts +1 -1
  32. package/dist/react.d.ts.map +1 -1
  33. package/dist/react.js +98 -46
  34. package/dist/server/create.d.ts.map +1 -1
  35. package/dist/server/index.js +10 -9
  36. package/dist/server/middleware/cors.d.ts.map +1 -1
  37. package/dist/server/openapi.d.ts.map +1 -1
  38. package/dist/server/router.d.ts +2 -0
  39. package/dist/server/router.d.ts.map +1 -1
  40. package/dist/server/socket-io.d.ts +1 -1
  41. package/dist/server/types.d.ts +4 -6
  42. package/dist/server/types.d.ts.map +1 -1
  43. package/dist/tools/agent.d.ts +3 -0
  44. package/dist/tools/agent.d.ts.map +1 -1
  45. package/dist/tools/execute.d.ts +8 -4
  46. package/dist/tools/execute.d.ts.map +1 -1
  47. package/dist/tools/invoker.d.ts +37 -0
  48. package/dist/tools/invoker.d.ts.map +1 -0
  49. package/dist/tools/mcp.d.ts.map +1 -1
  50. package/dist/tools/names.d.ts +1 -1
  51. package/dist/tools/names.d.ts.map +1 -1
  52. package/dist/tools/native-mcp.d.ts +6 -33
  53. package/dist/tools/native-mcp.d.ts.map +1 -1
  54. package/dist/tools/runtime-tool.d.ts +58 -0
  55. package/dist/tools/runtime-tool.d.ts.map +1 -0
  56. package/dist/tools.d.ts +3 -1
  57. package/dist/tools.d.ts.map +1 -1
  58. package/dist/tools.js +193 -82
  59. package/llms-full.txt +492 -93
  60. package/package.json +1 -1
@@ -0,0 +1,58 @@
1
+ import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import type { Tool } from 'ai';
3
+ import type { ZodObject, ZodType, z } from 'zod';
4
+ import type { EndpointToolAnnotations, EndpointUiMeta, HttpMethod, RuntimeContext } from '../contract';
5
+ import type { OperationIdentity } from '../server/types';
6
+ import type { MountableTool } from './mount';
7
+ export type RuntimeToolTransport = 'MCP' | 'AGENT';
8
+ export interface RuntimeToolIdentity {
9
+ serviceName: string;
10
+ action: string;
11
+ scope?: string;
12
+ /** Semantic operation verb for lifecycle and RequestEvent attribution. */
13
+ method: HttpMethod;
14
+ meta?: Record<string, unknown>;
15
+ }
16
+ export type RuntimeToolHandlerContext<TInput extends ZodObject> = RuntimeContext & {
17
+ params: undefined;
18
+ input: z.output<TInput>;
19
+ };
20
+ export type RuntimeToolOutput<TOutput extends ZodType | undefined> = TOutput extends ZodType ? z.output<TOutput> : unknown;
21
+ /** MCP-owned fields; validation and error state are always supplied by Stitchkit. */
22
+ export type RuntimeMcpPresentation = Omit<CallToolResult, 'structuredContent' | 'isError'> & {
23
+ structuredContent?: never;
24
+ isError?: never;
25
+ };
26
+ export type RuntimeAgentModelOutput = Awaited<ReturnType<NonNullable<Tool<unknown, unknown>['toModelOutput']>>>;
27
+ export interface RuntimeToolPresenters<TOutput> {
28
+ mcp?: (output: TOutput) => RuntimeMcpPresentation | Promise<RuntimeMcpPresentation>;
29
+ agent?: (output: TOutput) => RuntimeAgentModelOutput | PromiseLike<RuntimeAgentModelOutput>;
30
+ }
31
+ export interface RuntimeToolDefinitionBase<TInput extends ZodObject> {
32
+ name: string;
33
+ description: string;
34
+ identity: RuntimeToolIdentity;
35
+ input: TInput;
36
+ /** Default: both MCP and AGENT. */
37
+ transports?: readonly RuntimeToolTransport[];
38
+ annotations?: EndpointToolAnnotations;
39
+ ui?: EndpointUiMeta;
40
+ }
41
+ export interface RuntimeToolDefinitionWithOutput<TInput extends ZodObject, TOutput extends ZodType> extends RuntimeToolDefinitionBase<TInput> {
42
+ output: TOutput;
43
+ handler: (context: RuntimeToolHandlerContext<TInput>) => z.output<TOutput> | Promise<z.output<TOutput>>;
44
+ present?: RuntimeToolPresenters<z.output<TOutput>>;
45
+ }
46
+ export interface RuntimeToolDefinitionWithoutOutput<TInput extends ZodObject> extends RuntimeToolDefinitionBase<TInput> {
47
+ output?: never;
48
+ handler: (context: RuntimeToolHandlerContext<TInput>) => unknown | Promise<unknown>;
49
+ present?: never;
50
+ }
51
+ export type RuntimeToolDefinition = RuntimeToolDefinitionWithOutput<ZodObject, ZodType> | RuntimeToolDefinitionWithoutOutput<ZodObject>;
52
+ /** Typed identity helper; execution remains owned by the transport mounts. */
53
+ export declare function defineRuntimeTool<TInput extends ZodObject, TOutput extends ZodType>(definition: RuntimeToolDefinitionWithOutput<TInput, TOutput>): RuntimeToolDefinitionWithOutput<TInput, TOutput>;
54
+ export declare function defineRuntimeTool<TInput extends ZodObject>(definition: RuntimeToolDefinitionWithoutOutput<TInput>): RuntimeToolDefinitionWithoutOutput<TInput>;
55
+ export declare function runtimeToolSupports(definition: RuntimeToolDefinition, transport: RuntimeToolTransport): boolean;
56
+ export declare function runtimeToolIdentity(definition: RuntimeToolDefinition): OperationIdentity;
57
+ export declare function runtimeToolMountable(definition: RuntimeToolDefinition): MountableTool;
58
+ //# sourceMappingURL=runtime-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-tool.d.ts","sourceRoot":"","sources":["../../src/tools/runtime-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACjD,OAAO,KAAK,EACV,uBAAuB,EACvB,cAAc,EACd,UAAU,EACV,cAAc,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,OAAO,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,MAAM,yBAAyB,CAAC,MAAM,SAAS,SAAS,IAAI,cAAc,GAAG;IACjF,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,MA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@ -7,6 +7,7 @@ export type { CliWaitConfig } from './tools/cli-wait';
7
7
  export { coerceJsonArgs } from './tools/coerce';
8
8
  export type { AfterToolCallOptions, BeforeToolCallOptions, ErrorHintFn, ToolCallContext, ToolCallHooks, ToolErrorOptions, ToolLifecycle, ToolOperation, ToolResult, } from './tools/execute';
9
9
  export { flattenToolJsonSchema, type ToolPresentationSchema, } from './tools/flatten';
10
+ export { createToolInvoker, type ToolInvocationOptions, type ToolInvoker, type ToolInvokerConfig, type ToolInvokerTransport, } from './tools/invoker';
10
11
  export { listToolNames, type ToolNameEntry } from './tools/list-names';
11
12
  export { buildToolManifest, type ToolManifestEntry } from './tools/manifest';
12
13
  export { buildMcpServer, type IncompatibleSchemaPolicy, type McpMountConfig, type McpSchemaValidationConfig, type McpServerBuildConfig, mountMcp, mountMcpResource, type ValidateMcpSchemasConfig, validateMcpSchemas, } from './tools/mcp';
@@ -17,11 +18,12 @@ export { type CollectToolsConfig, collectTools, type MountableTool, type ToolExt
17
18
  export { type DownloadToolConfig, mountDownload } from './tools/mount-download';
18
19
  export { mountUpload, type UploadToolConfig } from './tools/mount-upload';
19
20
  export { mountWait, type WaitToolConfig } from './tools/mount-wait';
20
- export type { NativeMcpHandlerContext, NativeMcpOperationIdentity, NativeMcpRegistrar, NativeMcpResult, NativeMcpToolDefinition, } from './tools/native-mcp';
21
+ export type { NativeMcpRegistrar } from './tools/native-mcp';
21
22
  export { oauthProtectedResourceRoute, PROTECTED_RESOURCE_PATH, type ProtectedResourceConfig, protectedResourceMetadataUrl, wwwAuthenticateHeader, } from './tools/oauth-metadata';
22
23
  export { type ApplicationType, type AuthCodeData, type AuthRequest, type ClientMetadata, mountOAuthProvider, type OAuthProviderConfig, type RefreshData, type RegisteredClient, } from './tools/oauth-provider';
23
24
  export { findNonPortableFormats, type NonPortableFormat, PORTABLE_JSON_SCHEMA_FORMATS, } from './tools/portable-formats';
24
25
  export { type ImplementRemoteOptions, implementRemote } from './tools/remote';
26
+ export { defineRuntimeTool, type RuntimeAgentModelOutput, type RuntimeMcpPresentation, type RuntimeToolDefinition, type RuntimeToolDefinitionBase, type RuntimeToolDefinitionWithOutput, type RuntimeToolDefinitionWithoutOutput, type RuntimeToolHandlerContext, type RuntimeToolIdentity, type RuntimeToolOutput, type RuntimeToolPresenters, type RuntimeToolTransport, } from './tools/runtime-tool';
25
27
  export { createToolLogger, type ToolCallRecord, type ToolLoggerConfig, } from './tools/tool-logger';
26
28
  export { createToolkit, type Toolkit } from './tools/toolkit';
27
29
  export { summarizeTransports, type TransportCounts, type TransportSummary, } from './tools/transports';
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EACL,c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";
5
+ } from "./index-92gs1m5b.js";
6
6
  import {
7
7
  DEFAULT_CORS_ALLOW_HEADERS
8
- } from "./index-czmqks7r.js";
8
+ } from "./index-6jypn22c.js";
9
9
  import {
10
10
  assertToolName,
11
11
  assertUniqueToolName,
@@ -22,9 +22,10 @@ import {
22
22
  pollUntil,
23
23
  presentationMetadata,
24
24
  readCapped,
25
+ toolErrorFromResult,
25
26
  toolResultFromError,
26
27
  writeDownload
27
- } from "./index-n5t4gnfz.js";
28
+ } from "./index-p1x65gk7.js";
28
29
  import {
29
30
  toJsonSchema
30
31
  } from "./index-frfyw9fa.js";
@@ -33,15 +34,63 @@ import {
33
34
  } from "./index-x3fcszf8.js";
34
35
  import {
35
36
  AppError,
36
- formatZodError,
37
37
  getTraceId,
38
38
  isRecord,
39
39
  mergeMeta,
40
+ parseTrailingWildcard,
40
41
  typedEntries
41
- } from "./index-mzx0an0s.js";
42
+ } from "./index-fyfk537k.js";
42
43
 
43
44
  // src/tools/agent.ts
44
45
  import { jsonSchema, tool } from "ai";
46
+
47
+ // src/tools/runtime-tool.ts
48
+ function defineRuntimeTool(definition) {
49
+ if (definition.transports?.length === 0) {
50
+ throw new Error(`Runtime tool "${definition.name}" must expose at least one transport`);
51
+ }
52
+ return definition;
53
+ }
54
+ function runtimeToolSupports(definition, transport) {
55
+ if (definition.transports?.length === 0) {
56
+ throw new Error(`Runtime tool "${definition.name}" must expose at least one transport`);
57
+ }
58
+ return !definition.transports || definition.transports.includes(transport);
59
+ }
60
+ function runtimeToolIdentity(definition) {
61
+ return {
62
+ method: definition.identity.method,
63
+ desc: definition.description,
64
+ serviceName: definition.identity.serviceName,
65
+ key: definition.identity.action,
66
+ toolName: definition.name,
67
+ scope: definition.identity.scope,
68
+ meta: definition.identity.meta,
69
+ annotations: definition.annotations,
70
+ ui: definition.ui
71
+ };
72
+ }
73
+ function runtimeToolMountable(definition) {
74
+ assertToolName(definition.name, definition.identity.serviceName, definition.identity.action);
75
+ const method = {
76
+ ...runtimeToolIdentity(definition),
77
+ inputSchema: definition.input,
78
+ outputSchema: definition.output,
79
+ handler: definition.handler
80
+ };
81
+ return {
82
+ method,
83
+ name: definition.name,
84
+ argumentSchema: definition.input,
85
+ presentationSchema: buildToolPresentationSchema({
86
+ inputSchema: definition.input,
87
+ unrepresentable: "any"
88
+ }),
89
+ shouldExtend: false
90
+ };
91
+ }
92
+
93
+ // src/tools/agent.ts
45
94
  function mountAgent(services, config = {}) {
46
95
  const serviceList = Array.isArray(services) ? services : [services];
47
96
  const tools = {};
@@ -80,8 +129,99 @@ function mountAgent(services, config = {}) {
80
129
  });
81
130
  }
82
131
  }
132
+ for (const definition of config.runtimeTools ?? []) {
133
+ if (!runtimeToolSupports(definition, "AGENT"))
134
+ continue;
135
+ const mountable = runtimeToolMountable(definition);
136
+ assertUniqueToolName(definition.name, Object.hasOwn(tools, definition.name), "agent tool name");
137
+ const inputSchema = jsonSchema(mountable.presentationSchema, {
138
+ validate: async (value) => isRecord(value) ? { success: true, value } : { success: false, error: new Error("Tool arguments must be an object") }
139
+ });
140
+ const execute = async (rawArgs) => {
141
+ const args = isRecord(rawArgs) ? rawArgs : {};
142
+ try {
143
+ const result = await runTool(mountable, args);
144
+ if (result.ok)
145
+ return result.data;
146
+ return formatToolError(result, mountable.name, config.errorHint);
147
+ } catch (err) {
148
+ return formatToolError(toolResultFromError(err), mountable.name, config.errorHint);
149
+ }
150
+ };
151
+ if (definition.present?.agent) {
152
+ const presenter = definition.present.agent;
153
+ const output = definition.output;
154
+ tools[definition.name] = tool({
155
+ description: definition.description,
156
+ inputSchema,
157
+ outputSchema: output,
158
+ execute,
159
+ toModelOutput: async ({ output: rawOutput }) => {
160
+ const parsed = output.safeParse(rawOutput);
161
+ if (!parsed.success) {
162
+ return { type: "text", value: JSON.stringify(rawOutput) };
163
+ }
164
+ return presenter(parsed.data);
165
+ }
166
+ });
167
+ } else {
168
+ tools[definition.name] = tool({
169
+ description: definition.description,
170
+ inputSchema,
171
+ ...definition.output && { outputSchema: definition.output },
172
+ execute
173
+ });
174
+ }
175
+ }
83
176
  return tools;
84
177
  }
178
+ // src/tools/invoker.ts
179
+ function createToolInvoker(services, config) {
180
+ const serviceList = Array.isArray(services) ? services : [services];
181
+ const tools = new Map;
182
+ for (const service of serviceList) {
183
+ for (const tool2 of collectTools(service, config.transport, {
184
+ extend: config.extend,
185
+ flattenUnionInput: config.flattenUnionInput
186
+ })) {
187
+ assertUniqueToolName(tool2.name, tools.has(tool2.name), "in-process tool name");
188
+ tools.set(tool2.name, tool2);
189
+ }
190
+ }
191
+ const names = Object.freeze([...tools.keys()].sort());
192
+ const operation = (name) => {
193
+ const tool2 = tools.get(name);
194
+ if (tool2)
195
+ return tool2;
196
+ throw new AppError("NOT_FOUND", `Unknown tool: ${name}`, 404, {
197
+ available: names
198
+ });
199
+ };
200
+ const run = (name, args, options = {}) => {
201
+ const runTool = createToolRunner({
202
+ source: options.source ?? "internal",
203
+ context: options.context,
204
+ hooks: options.hooks,
205
+ lifecycle: options.lifecycle,
206
+ extend: config.extend,
207
+ coerceJsonArgs: config.coerceJsonArgs,
208
+ onOutputStrip: options.onOutputStrip
209
+ });
210
+ return runTool(operation(name), args);
211
+ };
212
+ return Object.freeze({
213
+ names,
214
+ invoke(name, args, options) {
215
+ return run(name, args, options);
216
+ },
217
+ async invokeOrThrow(name, args, options) {
218
+ const result = await run(name, args, options);
219
+ if (!result.ok)
220
+ throw toolErrorFromResult(result);
221
+ return result.data;
222
+ }
223
+ });
224
+ }
85
225
  // src/tools/list-names.ts
86
226
  var TOOL_TRANSPORTS = ["MCP", "AGENT", "CLI"];
87
227
  function listToolNames(services) {
@@ -142,72 +282,21 @@ function inlineMcpAppBundle(html) {
142
282
  // src/tools/native-mcp.ts
143
283
  import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
144
284
  import { z } from "zod";
145
- function operationIdentity(definition) {
146
- return {
147
- method: definition.identity.method,
148
- desc: definition.description,
149
- serviceName: definition.identity.serviceName,
150
- key: definition.identity.action,
151
- toolName: definition.name,
152
- scope: definition.identity.scope,
153
- meta: definition.identity.meta,
154
- annotations: definition.annotations,
155
- ui: definition.ui
156
- };
157
- }
158
285
  function isCallToolResult(value) {
159
286
  return CallToolResultSchema.safeParse(value).success;
160
287
  }
161
- function nativeResultSchema(output) {
162
- const envelope = z.custom(isCallToolResult, {
163
- error: "Native MCP handler must return a valid CallToolResult"
164
- });
165
- if (!output)
166
- return envelope;
167
- return envelope.transform((result, context) => {
168
- const parsed = output.safeParse(result.structuredContent);
169
- if (!parsed.success) {
170
- context.addIssue({
171
- code: "custom",
172
- message: `Invalid structuredContent: ${formatZodError(parsed.error)}`
173
- });
174
- return z.NEVER;
175
- }
176
- return { ...result, structuredContent: parsed.data };
177
- });
178
- }
179
288
  function createNativeMcpRegistrar(server, config) {
180
289
  return {
181
290
  rawServer: server,
182
291
  registerTool: (definition) => {
183
- const identity = operationIdentity(definition);
184
- const advertisedOperation = {
185
- ...identity,
186
- inputSchema: definition.input,
187
- outputSchema: definition.output,
188
- handler: () => {
189
- return;
190
- }
191
- };
192
- const mountable = {
193
- method: advertisedOperation,
194
- name: definition.name,
195
- argumentSchema: definition.input,
196
- presentationSchema: buildToolPresentationSchema({
197
- inputSchema: definition.input,
198
- unrepresentable: "any"
199
- }),
200
- shouldExtend: false
201
- };
292
+ if (!runtimeToolSupports(definition, "MCP"))
293
+ return;
294
+ assertUniqueToolName(definition.name, config.takenNames.has(definition.name), "MCP tool name");
295
+ config.takenNames.add(definition.name);
296
+ const mountable = runtimeToolMountable(definition);
202
297
  const [prepared] = config.prepare(mountable);
203
298
  if (!prepared)
204
299
  return;
205
- const executionOperation = {
206
- ...identity,
207
- inputSchema: definition.input,
208
- outputSchema: nativeResultSchema(definition.output),
209
- handler: definition.handler
210
- };
211
300
  const toolConfig = {
212
301
  description: definition.description,
213
302
  inputSchema: z.looseObject({}).meta(presentationMetadata(prepared.inputSchema))
@@ -224,16 +313,32 @@ function createNativeMcpRegistrar(server, config) {
224
313
  }
225
314
  server.registerTool(definition.name, toolConfig, async (rawArgs) => {
226
315
  const args = isRecord(rawArgs) ? rawArgs : {};
227
- const result = await executeToolMethod(executionOperation, definition.name, args, { ...config.context, source: "mcp" }, config.hooks, config.lifecycle, config.coerceJsonArgs ?? true, config.onOutputStrip ? (paths) => config.onOutputStrip?.(definition.name, paths) : undefined);
228
- if (!result.ok)
229
- return config.formatError(result, definition.name);
230
- if (isCallToolResult(result.data))
231
- return result.data;
232
- return config.formatError({
316
+ const result = await executeToolMethod(mountable.method, definition.name, args, { ...config.context, source: "mcp" }, config.hooks, config.lifecycle, config.coerceJsonArgs ?? true, config.onOutputStrip ? (paths) => config.onOutputStrip?.(definition.name, paths) : undefined);
317
+ if (!result.ok || !definition.present?.mcp) {
318
+ return config.formatResult(result, prepared.outputMode, definition.name);
319
+ }
320
+ const presented = await definition.present.mcp(result.data);
321
+ if ("structuredContent" in presented || "isError" in presented) {
322
+ return config.formatResult({
323
+ ok: false,
324
+ code: "INTERNAL_SERVER_ERROR",
325
+ details: {
326
+ message: "Runtime MCP presenter cannot set framework-owned structuredContent or isError"
327
+ }
328
+ }, "none", definition.name);
329
+ }
330
+ const structured = config.formatResult(result, prepared.outputMode, definition.name).structuredContent;
331
+ const response = {
332
+ ...presented,
333
+ ...structured && { structuredContent: structured }
334
+ };
335
+ if (isCallToolResult(response))
336
+ return response;
337
+ return config.formatResult({
233
338
  ok: false,
234
339
  code: "INTERNAL_SERVER_ERROR",
235
- details: { message: "Native MCP handler returned an invalid result" }
236
- }, definition.name);
340
+ details: { message: "Runtime MCP presenter returned an invalid CallToolResult" }
341
+ }, "none", definition.name);
237
342
  });
238
343
  }
239
344
  };
@@ -606,17 +711,19 @@ function buildMcpServerFromPrepared(config, auth, prepared) {
606
711
  onOutputStrip: config.onOutputStrip
607
712
  });
608
713
  if (config.nativeTools) {
714
+ const takenNames = new Set(prepared.map((tool2) => tool2.mountable.name));
609
715
  const registrar = createNativeMcpRegistrar(server, {
610
716
  context,
611
717
  hooks: config.hooks,
612
718
  lifecycle: config.lifecycle,
613
719
  coerceJsonArgs: config.coerceJsonArgs,
614
720
  onOutputStrip: config.onOutputStrip,
721
+ takenNames,
615
722
  prepare: (tool2) => prepareMcpTools([tool2], {
616
723
  schemaValidation: config.schemaValidation,
617
724
  logger: config.logger
618
725
  }),
619
- formatError: (result, toolName) => formatMcpResult(result, "none", toolName, config.errorHint)
726
+ formatResult: (result, mode, toolName) => formatMcpResult(result, mode, toolName, config.errorHint)
620
727
  });
621
728
  config.nativeTools(registrar, auth);
622
729
  }
@@ -1277,11 +1384,13 @@ function resolvePathPrefix(config, args) {
1277
1384
  function extractParamNames(path) {
1278
1385
  const matches = path.match(/:(\w+)/g);
1279
1386
  const names = matches ? matches.map((match) => match.slice(1)) : [];
1280
- if (path.endsWith("/*"))
1281
- names.push("*");
1387
+ const wildcard = parseTrailingWildcard(path);
1388
+ if (wildcard)
1389
+ names.push(wildcard.name);
1282
1390
  return names;
1283
1391
  }
1284
1392
  function fillPathParams(path, args) {
1393
+ const wildcard = parseTrailingWildcard(path);
1285
1394
  let filled = path.replace(/:(\w+)/g, (_, key) => {
1286
1395
  const value = args[key];
1287
1396
  if (value === undefined || value === null) {
@@ -1289,14 +1398,14 @@ function fillPathParams(path, args) {
1289
1398
  }
1290
1399
  return encodeURIComponent(String(value));
1291
1400
  });
1292
- if (!filled.endsWith("/*"))
1401
+ if (!wildcard)
1293
1402
  return filled;
1294
- const wildcard = args["*"];
1295
- if (wildcard === undefined || wildcard === null) {
1296
- throw new Error("Missing path param: *");
1403
+ const wildcardValue = args[wildcard.name];
1404
+ if (wildcardValue === undefined || wildcardValue === null) {
1405
+ throw new Error(`Missing path param: ${wildcard.name}`);
1297
1406
  }
1298
- const remainder = String(wildcard).split("/").map((segment) => encodeURIComponent(segment)).join("/");
1299
- filled = `${filled.slice(0, -1)}${remainder}`;
1407
+ const remainder = String(wildcardValue).split("/").map((segment) => encodeURIComponent(segment)).join("/");
1408
+ filled = `${filled.slice(0, -(wildcard.name.length + 1))}${remainder}`;
1300
1409
  return filled;
1301
1410
  }
1302
1411
  function stripConsumedArgs(args, path, scopeKeys) {
@@ -1422,7 +1531,7 @@ function createHttpMethod(endpoint, prefix, client, config) {
1422
1531
  if (!isMultipartFile(file)) {
1423
1532
  throw new Error(`Missing multipart file field: ${endpoint.multipart}`);
1424
1533
  }
1425
- if (httpMethod === "get" || httpMethod === "delete") {
1534
+ if (httpMethod === "get" || httpMethod === "head" || httpMethod === "delete") {
1426
1535
  throw new Error(`Multipart endpoint ${endpoint.method} ${endpoint.path} must be POST / PUT / PATCH`);
1427
1536
  }
1428
1537
  const formData = new FormData;
@@ -1430,8 +1539,8 @@ function createHttpMethod(endpoint, prefix, client, config) {
1430
1539
  appendFormFields(formData, plan.remainingArgs, new Set([endpoint.multipart]));
1431
1540
  return withOutput(endpoint, client[httpMethod](plan.relativeUrl, formData, withTimeout(undefined, endpoint)));
1432
1541
  }
1433
- if (httpMethod === "get") {
1434
- return withOutput(endpoint, client.get(plan.relativeUrl, withTimeout(undefined, endpoint)));
1542
+ if (httpMethod === "get" || httpMethod === "head") {
1543
+ return withOutput(endpoint, client[httpMethod](plan.relativeUrl, withTimeout(undefined, endpoint)));
1435
1544
  }
1436
1545
  if (httpMethod === "delete") {
1437
1546
  return withOutput(endpoint, client.delete(plan.relativeUrl, withTimeout(undefined, endpoint)));
@@ -1448,7 +1557,7 @@ function createFetchMethod(endpoint, prefix, config, contractConfig) {
1448
1557
  ...typeof config.headers === "function" ? config.headers() : config.headers
1449
1558
  };
1450
1559
  const signal = endpoint.timeout !== undefined ? AbortSignal.timeout(endpoint.timeout) : undefined;
1451
- const hasBody = endpoint.method !== "GET" && endpoint.method !== "DELETE" && !endpoint.multipart && endpoint.input && args;
1560
+ const hasBody = endpoint.method !== "GET" && endpoint.method !== "HEAD" && endpoint.method !== "DELETE" && !endpoint.multipart && endpoint.input && args;
1452
1561
  if (hasBody)
1453
1562
  headers["Content-Type"] = "application/json";
1454
1563
  if (endpoint.multipart && args) {
@@ -1765,8 +1874,10 @@ export {
1765
1874
  flattenToolJsonSchema,
1766
1875
  findUntypedProperties,
1767
1876
  findNonPortableFormats,
1877
+ defineRuntimeTool,
1768
1878
  createToolkit,
1769
1879
  createToolLogger,
1880
+ createToolInvoker,
1770
1881
  createStdioMcpServer,
1771
1882
  createMcpHandler,
1772
1883
  createCli,