@alvin0/ai-agent-sdk-mcp-server 0.1.10 → 0.1.11

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/index.d.ts CHANGED
@@ -67,7 +67,7 @@ interface SdkMcpCallToolResult {
67
67
  readonly isError?: boolean | undefined;
68
68
  }
69
69
  //#endregion
70
- //#region src/server/advanced.d.ts
70
+ //#region src/server/advanced-types.d.ts
71
71
  interface McpAgentSessionContext {
72
72
  readonly conversationId?: string;
73
73
  readonly request: SdkMcpRequestContext;
@@ -116,12 +116,11 @@ interface SdkMcpServerOptions {
116
116
  /** Opt in to returning internal exception messages to remote callers. Defaults to false. */
117
117
  readonly exposeInternalErrors?: boolean;
118
118
  }
119
+ //#endregion
120
+ //#region src/server/advanced.d.ts
119
121
  /** Create one MCP server instance for a connection or HTTP request. */
120
122
  declare function createSdkMcpServer(options: SdkMcpServerOptions, request?: SdkMcpRequestContext): SdkMcpServer;
121
- /**
122
- * Create a fetch-shaped API for Cloudflare Workers, Deno, Bun, Next.js route
123
- * handlers, or any web framework that accepts Request/Response.
124
- */
123
+ /** Create a fetch-shaped API for hosts that accept Request/Response. */
125
124
  declare function createSdkMcpHandler(options: SdkMcpServerOptions, handlerOptions?: SdkMcpHandlerOptions): SdkMcpHttpHandler;
126
125
  //#endregion
127
126
  //#region src/preferred/server.d.ts
@@ -141,5 +140,5 @@ interface McpWebServer {
141
140
  /** Capture one inert Web-standard server definition; each handle call owns its request resources. */
142
141
  declare function createMcpServer(definition: McpServerDefinition): McpWebServer;
143
142
  //#endregion
144
- export { McpAgentSessionContext, McpAgentTool, type McpRequestAuthInfo, type McpServerDefinition, McpServerErrorContext, type McpWebServer, type SdkMcpCallContext, type SdkMcpCallToolResult, type SdkMcpEventBus, type SdkMcpHandlerOptions, type SdkMcpHandlerRequestOptions, type SdkMcpHttpHandler, type SdkMcpNotifier, type SdkMcpRequestContext, type SdkMcpServer, SdkMcpServerOptions, createMcpServer, createSdkMcpHandler, createSdkMcpServer };
143
+ export { type McpAgentSessionContext, type McpAgentTool, type McpRequestAuthInfo, type McpServerDefinition, type McpServerErrorContext, type McpWebServer, type SdkMcpCallContext, type SdkMcpCallToolResult, type SdkMcpEventBus, type SdkMcpHandlerOptions, type SdkMcpHandlerRequestOptions, type SdkMcpHttpHandler, type SdkMcpNotifier, type SdkMcpRequestContext, type SdkMcpServer, type SdkMcpServerOptions, createMcpServer, createSdkMcpHandler, createSdkMcpServer };
145
144
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/common/server-public-types.ts","../src/server/advanced.ts","../src/preferred/server.ts"],"mappings":";;;;UAEiB;WACN;WACA;WACA;WACA;WACA,WAAW;WACX,QAAQ;;UAGF;WACN;WACA,WAAW;WACX,cAAc;;UAGR;WACN;aACE;aACA,QAAQ;aACR,MACP,+FACA,eACA,oBACG;;WAEE;aACE,UAAU;aACV,WAAW;;;UAIP;WACN,WAAW;WACX;;UAGM;EACf,QAAQ,OAAO,oBAAoB;EACnC,WAAW,WAAW,OAAO,qCAAqC;;UAGnD;WACN;WACA,WAAW,OAAO;WAClB;WACA,MAAM;WACN;WACA;;UAGM;EACf,QAAQ,oBAAoB;EAC5B,SAAS;;WAEA;;UAGM;EACf;EACA;EACA;EACA,gBAAgB;;UAGD;EACf,MAAM,SAAS,SAAS,UAAU,8BAA8B,QAAQ;EACxE,SAAS;WACA,QAAQ;WACR;;UAGM;YACL;WACD;WACA;WACA;;;;UCxCM;WACN;WACA,SAAS;WACT,MAAM;;UAGA;WACN;WACA;WACA,OAAO;;WAEP,gBAAgB,SAAS,2BAA2B,eAAe,QAAQ;;UAGrE;WACN;WACA;WACA;;UAGM;WACN;WACA;WACA,SAAS;;WAET;WACA;;WAEA,QAAQ;WACR,kBAAkB;WAClB,YAAY;WACZ,wBAAwB;;WAExB;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,WAAW,gBAAgB,SAAS,iCAAiC;;WAErE;;;iBAMK,mBACd,SAAS,qBACT,UAAS,uBACR;;;;;iBA+Ea,oBACd,SAAS,qBACT,iBAAiB,uBAChB;;;UCxKc;WACN;WACA,SAAS;WACT,QAAQ;WACR,SAAS,SAAS,eAAe;WACjC;WACA;;UAGM;EACf,OAAO,SAAS,SAAS;aAAqB,SAAS;MAAgB,QAAQ;;;iBAIjE,gBAAgB,YAAY,sBAAsB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/common/server-public-types.ts","../src/server/advanced-types.ts","../src/server/advanced.ts","../src/preferred/server.ts"],"mappings":";;;;UAEiB;WACN;WACA;WACA;WACA;WACA,WAAW;WACX,QAAQ;;UAGF;WACN;WACA,WAAW;WACX,cAAc;;UAGR;WACN;aACE;aACA,QAAQ;aACR,MACP,+FACA,eACA,oBACG;;WAEE;aACE,UAAU;aACV,WAAW;;;UAIP;WACN,WAAW;WACX;;UAGM;EACf,QAAQ,OAAO,oBAAoB;EACnC,WAAW,WAAW,OAAO,qCAAqC;;UAGnD;WACN;WACA,WAAW,OAAO;WAClB;WACA,MAAM;WACN;WACA;;UAGM;EACf,QAAQ,oBAAoB;EAC5B,SAAS;;WAEA;;UAGM;EACf;EACA;EACA;EACA,gBAAgB;;UAGD;EACf,MAAM,SAAS,SAAS,UAAU,8BAA8B,QAAQ;EACxE,SAAS;WACA,QAAQ;WACR;;UAGM;YACL;WACD;WACA;WACA;;;;UCtEM;WACN;WACA,SAAS;WACT,MAAM;;UAGA;WACN;WACA;WACA,OAAO;;WAEP,gBAAgB,SAAS,2BAA2B,eAAe,QAAQ;;UAGrE;WACN;WACA;WACA;;UAGM;WACN;WACA;WACA,SAAS;;WAET;WACA;;WAEA,QAAQ;WACR,kBAAkB;WAClB,YAAY;WACZ,wBAAwB;;WAExB;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,WAAW,gBAAgB,SAAS,iCAAiC;;WAErE;;;;;iBC1BK,mBACd,SAAS,qBACT,UAAS,uBACR;;iBAiBa,oBACd,SAAS,qBACT,iBAAiB,uBAChB;;;UC5Cc;WACN;WACA,SAAS;WACT,QAAQ;WACR,SAAS,SAAS,eAAe;WACjC;WACA;;UAGM;EACf,OAAO,SAAS,SAAS;aAAqB,SAAS;MAAgB,QAAQ;;;iBAIjE,gBAAgB,YAAY,sBAAsB"}
package/dist/index.js CHANGED
@@ -116,7 +116,9 @@ function emit(logger, level, message, fields) {
116
116
  } catch {}
117
117
  }
118
118
  function terminalMessage(status) {
119
- return status === "success" ? MESSAGES.success : status === "error" ? MESSAGES.failure : MESSAGES.abort;
119
+ if (status === "success") return MESSAGES.success;
120
+ if (status === "error") return MESSAGES.failure;
121
+ return MESSAGES.abort;
120
122
  }
121
123
  function monotonicNow() {
122
124
  return performance.now();
@@ -162,129 +164,71 @@ const MCP_SERVER_DEFAULTS = Object.freeze({
162
164
  });
163
165
 
164
166
  //#endregion
165
- //#region src/server/advanced.ts
166
- /** Export SDK tools and agents as a Universal fetch-shaped MCP server. */
167
- /** Create one MCP server instance for a connection or HTTP request. */
168
- function createSdkMcpServer(options, request = { era: "modern" }) {
169
- const limits = resolveLimits(options);
170
- assertIdentity(options.name, "server name");
171
- if (options.version.trim().length === 0) throw new TypeError("MCP server version must not be empty");
172
- const server = new McpServer({
173
- name: options.name,
174
- version: options.version
175
- }, {
176
- capabilities: { tools: { listChanged: false } },
177
- ...options.instructions === void 0 ? {} : { instructions: options.instructions }
178
- });
179
- const names = /* @__PURE__ */ new Set();
180
- const schemas = options.tools?.schemas() ?? [];
181
- const runtimeAgents = Object.entries(preferredState(options)?.agents ?? {});
182
- if (schemas.length + (options.agents?.length ?? 0) + runtimeAgents.length > limits.maxExports) throw new RangeError(`MCP server exceeds the ${limits.maxExports}-export limit`);
183
- if (serializedBytes([
184
- schemas,
185
- options.agents?.map((agent) => ({
186
- name: agent.name,
187
- description: agent.description,
188
- agentId: agent.agent.id
189
- })) ?? [],
190
- runtimeAgents.map(([name]) => ({ name }))
191
- ]) > limits.maxDefinitionBytes) throw new RangeError(`MCP server definitions exceed the ${limits.maxDefinitionBytes}-byte limit`);
192
- for (const schema of schemas) {
193
- if (names.has(schema.name)) throw new TypeError(`duplicate MCP export '${schema.name}'`);
194
- names.add(schema.name);
195
- server.registerTool(schema.name, {
196
- description: schema.description,
197
- inputSchema: fromJsonSchema(structuredClone(schema.parameters))
198
- }, async (args, context) => await callSdkTool(options, schema.name, args, context));
199
- }
200
- for (const agent of options.agents ?? []) {
201
- assertIdentity(agent.name, "agent MCP tool name");
202
- if (names.has(agent.name)) throw new TypeError(`duplicate MCP export '${agent.name}'`);
203
- names.add(agent.name);
204
- server.registerTool(agent.name, {
205
- description: agent.description ?? agent.agent.description ?? `Run the ${agent.agent.name} agent for one conversational turn.`,
206
- inputSchema: fromJsonSchema({
207
- type: "object",
208
- properties: {
209
- input: {
210
- type: "string",
211
- minLength: 1
212
- },
213
- conversationId: {
214
- type: "string",
215
- minLength: 1
216
- }
217
- },
218
- required: ["input"],
219
- additionalProperties: false
220
- })
221
- }, async (args, context) => await callAgent(options, agent, request, args, context));
222
- }
223
- for (const [name, agent] of runtimeAgents) {
224
- assertIdentity(name, "agent MCP tool name");
225
- if (names.has(name)) throw new TypeError(`duplicate MCP export '${name}'`);
226
- names.add(name);
227
- server.registerTool(name, {
228
- description: `Run the ${name} agent for one turn.`,
229
- inputSchema: fromJsonSchema({
230
- type: "object",
231
- properties: { input: {
232
- type: "string",
233
- minLength: 1
234
- } },
235
- required: ["input"],
236
- additionalProperties: false
237
- })
238
- }, async (args, context) => await callRuntimeAgent(options, name, agent, args, context));
239
- }
240
- return server;
167
+ //#region src/server/advanced-support.ts
168
+ function assertIdentity(value, field) {
169
+ if (value.trim().length === 0) throw new TypeError(`${field} must not be empty`);
241
170
  }
242
- /**
243
- * Create a fetch-shaped API for Cloudflare Workers, Deno, Bun, Next.js route
244
- * handlers, or any web framework that accepts Request/Response.
245
- */
246
- function createSdkMcpHandler(options, handlerOptions) {
247
- const handler = createMcpHandler((request) => createSdkMcpServer(withRequestLogger(options), request), handlerOptions);
171
+ function errorMessage(value) {
172
+ return value instanceof Error && value.message.length > 0 ? value.message : String(value);
173
+ }
174
+ function resolveLimits(options) {
248
175
  return {
249
- fetch: async (request, requestOptions) => {
250
- const operation = beginIntegrationOperation(integrationChildLogger(options.logger, "mcp-server-request"), serverFamily(options), "request");
251
- const attempt = operation.attempt(1);
252
- try {
253
- const response = await handler.fetch(request, requestOptions);
254
- if (response.status >= 500) {
255
- attempt.fail(`HTTP_${response.status}`);
256
- operation.fail(`HTTP_${response.status}`);
257
- } else {
258
- attempt.success();
259
- operation.success();
260
- }
261
- return response;
262
- } catch (error) {
263
- const code = integrationErrorCode(error);
264
- attempt.fail(code);
265
- operation.fail(code);
266
- throw error;
267
- }
268
- },
269
- close: handler.close,
270
- notify: handler.notify,
271
- bus: handler.bus
176
+ maxExports: positiveSafeInteger(options.maxExports ?? MCP_SERVER_DEFAULTS.maxExports, "maxExports"),
177
+ maxDefinitionBytes: positiveSafeInteger(options.maxDefinitionBytes ?? MCP_SERVER_DEFAULTS.maxDefinitionBytes, "maxDefinitionBytes"),
178
+ maxInputBytes: positiveSafeInteger(options.maxInputBytes ?? MCP_SERVER_DEFAULTS.maxInputBytes, "maxInputBytes"),
179
+ maxOutputBytes: positiveSafeInteger(options.maxOutputBytes ?? MCP_SERVER_DEFAULTS.maxOutputBytes, "maxOutputBytes"),
180
+ operationTimeoutMs: positiveSafeInteger(options.operationTimeoutMs ?? MCP_SERVER_DEFAULTS.operationTimeoutMs, "operationTimeoutMs"),
181
+ teardownTimeoutMs: positiveSafeInteger(options.teardownTimeoutMs ?? MCP_SERVER_DEFAULTS.teardownTimeoutMs, "teardownTimeoutMs"),
182
+ observerTimeoutMs: positiveSafeInteger(options.observerTimeoutMs ?? MCP_SERVER_DEFAULTS.observerTimeoutMs, "observerTimeoutMs")
272
183
  };
273
184
  }
274
- function withRequestLogger(options) {
275
- const logger = integrationChildLogger(options.logger, "mcp-server-request");
276
- if (logger === void 0) return options;
277
- const child = {
278
- ...options,
279
- logger
280
- };
281
- copyPreferredState(options, child);
282
- return child;
185
+ async function reportError(options, limits, error, evidence) {
186
+ if (options.onError === void 0) return;
187
+ const pending = Promise.resolve().then(() => options.onError?.(error, Object.freeze({ ...evidence })));
188
+ await waitForSettlement(pending, limits.observerTimeoutMs);
189
+ }
190
+ function internalErrorMessage(options, error, fallback) {
191
+ return options.exposeInternalErrors === true ? errorMessage(error) : fallback;
192
+ }
193
+ function positiveSafeInteger(value, label) {
194
+ if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`MCP server ${label} must be a positive safe integer`);
195
+ return value;
283
196
  }
197
+ function serializedBytes(value) {
198
+ const serialized = JSON.stringify(value);
199
+ if (serialized === void 0) throw new TypeError("MCP server value is not JSON serializable");
200
+ return new TextEncoder().encode(serialized).byteLength;
201
+ }
202
+ async function raceWithSignal(pending, signal, teardownTimeoutMs) {
203
+ if (signal.aborted) throw signal.reason ?? /* @__PURE__ */ new Error("MCP server operation aborted");
204
+ try {
205
+ return await new Promise((resolve, reject) => {
206
+ const abort = () => {
207
+ signal.removeEventListener("abort", abort);
208
+ reject(signal.reason ?? /* @__PURE__ */ new Error("MCP server operation aborted"));
209
+ };
210
+ signal.addEventListener("abort", abort, { once: true });
211
+ pending.then((value) => {
212
+ signal.removeEventListener("abort", abort);
213
+ resolve(value);
214
+ }, (error) => {
215
+ signal.removeEventListener("abort", abort);
216
+ reject(error);
217
+ });
218
+ });
219
+ } catch (error) {
220
+ if (signal.aborted) await waitForSettlement(pending, teardownTimeoutMs);
221
+ throw error;
222
+ }
223
+ }
224
+
225
+ //#endregion
226
+ //#region src/server/advanced-calls.ts
284
227
  function serverFamily(options) {
285
228
  return options.integrationFamily ?? "mcp-web-server";
286
229
  }
287
- async function callRuntimeAgent(options, name, agent, args, context) {
230
+ async function callRuntimeAgent(options, definition, args, context) {
231
+ const { name, agent } = definition;
288
232
  const limits = resolveLimits(options);
289
233
  const operation = beginIntegrationOperation(options.logger, serverFamily(options), "agent-call");
290
234
  const attempt = operation.attempt(1);
@@ -324,7 +268,11 @@ async function callRuntimeAgent(options, name, agent, args, context) {
324
268
  attempt.fail(code);
325
269
  operation.fail(code);
326
270
  }
327
- await reportError(options, limits, error, "agent", name, context);
271
+ await reportError(options, limits, error, {
272
+ operation: "agent",
273
+ exportName: name,
274
+ requestId: String(context.mcpReq.id)
275
+ });
328
276
  return errorResult(internalErrorMessage(options, error, "agent operation failed"), "AGENT_FAILED");
329
277
  }
330
278
  }
@@ -344,59 +292,37 @@ async function callSdkTool(options, toolName, args, context) {
344
292
  return errorResult(`tool '${toolName}' is not available`, "UNKNOWN_TOOL");
345
293
  }
346
294
  try {
347
- const result = await dispatchToolCall({
295
+ const result = await dispatchSdkTool({
296
+ options,
297
+ toolName,
298
+ args,
299
+ context,
348
300
  catalog,
349
- call: {
350
- callId: ToolCallId(`mcp:${String(context.mcpReq.id)}`),
351
- toolName,
352
- rawArguments: JSON.stringify(args)
353
- },
354
- position: {
355
- turn: 1,
356
- step: 1
357
- },
358
- signal: AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)]),
359
- defaultTimeoutMs: limits.operationTimeoutMs,
360
- teardownTimeoutMs: limits.teardownTimeoutMs,
361
- ...options.approvals === void 0 ? {} : { approvals: options.approvals },
362
- ...options.interceptors === void 0 ? {} : { interceptors: options.interceptors }
301
+ limits
363
302
  });
364
303
  if (serializedBytes(result) > limits.maxOutputBytes) {
365
304
  attempt.fail("OUTPUT_TOO_LARGE");
366
305
  operation.fail("OUTPUT_TOO_LARGE");
367
306
  return errorResult(`tool result exceeds the ${limits.maxOutputBytes}-byte limit`, "OUTPUT_TOO_LARGE");
368
307
  }
369
- const content = [...toMcpContent(result.content), ...toMcpContent(result.additionalContext ?? [])];
370
- if (result.isError) {
371
- attempt.fail(result.error.code);
372
- operation.fail(result.error.code);
373
- return {
374
- isError: true,
375
- content: content.length === 0 ? [{
376
- type: "text",
377
- text: result.error.message
378
- }] : content,
379
- structuredContent: { error: result.error }
380
- };
381
- }
382
- attempt.success();
383
- operation.success();
384
- return {
385
- content: content.length === 0 ? [{
386
- type: "text",
387
- text: "(no output)"
388
- }] : content,
389
- ...result.value === void 0 ? {} : { structuredContent: result.value }
390
- };
308
+ return renderToolResult(result, {
309
+ attempt,
310
+ operation
311
+ });
391
312
  } catch (error) {
392
313
  const code = integrationErrorCode(error);
393
314
  attempt.fail(code);
394
315
  operation.fail(code);
395
- await reportError(options, limits, error, "tool", toolName, context);
316
+ await reportError(options, limits, error, {
317
+ operation: "tool",
318
+ exportName: toolName,
319
+ requestId: String(context.mcpReq.id)
320
+ });
396
321
  return errorResult(internalErrorMessage(options, error, "tool operation failed"), "TOOL_OPERATION_FAILED");
397
322
  }
398
323
  }
399
- async function callAgent(options, definition, request, args, context) {
324
+ async function callAgent(options, invocation, args, context) {
325
+ const { definition, request } = invocation;
400
326
  const limits = resolveLimits(options);
401
327
  const operation = beginIntegrationOperation(options.logger, serverFamily(options), "agent-call");
402
328
  const attempt = operation.attempt(1);
@@ -407,41 +333,25 @@ async function callAgent(options, definition, request, args, context) {
407
333
  }
408
334
  const signal = AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)]);
409
335
  try {
410
- const session = await raceWithSignal(Promise.resolve(definition.createSession({
411
- ...args.conversationId === void 0 ? {} : { conversationId: args.conversationId },
336
+ const session = await createAgentSession({
337
+ definition,
412
338
  request,
413
- call: context
414
- })), signal, limits.teardownTimeoutMs);
339
+ args,
340
+ context,
341
+ signal,
342
+ limits
343
+ });
415
344
  if (session.definition.id !== definition.agent.id) {
416
345
  attempt.fail("WRONG_AGENT_SESSION");
417
346
  operation.fail("WRONG_AGENT_SESSION");
418
347
  return errorResult(`session factory for '${definition.name}' returned agent '${session.definition.id}', expected '${definition.agent.id}'`, "WRONG_AGENT_SESSION");
419
348
  }
420
- const response = await raceWithSignal(session.run(args.input, { signal }), signal, limits.teardownTimeoutMs);
421
- if (!isJsonValue(response.outcome)) {
422
- attempt.fail("INVALID_AGENT_RESULT");
423
- operation.fail("INVALID_AGENT_RESULT");
424
- return errorResult("agent outcome was not lossless JSON", "INVALID_AGENT_RESULT");
425
- }
426
- const result = {
427
- content: [{
428
- type: "text",
429
- text: response.text || "(empty response)"
430
- }],
431
- structuredContent: {
432
- text: response.text,
433
- outcome: response.outcome,
434
- conversationId: session.conversationId
435
- }
436
- };
437
- if (serializedBytes(result) > limits.maxOutputBytes) {
438
- attempt.fail("OUTPUT_TOO_LARGE");
439
- operation.fail("OUTPUT_TOO_LARGE");
440
- return errorResult(`agent result exceeds the ${limits.maxOutputBytes}-byte limit`, "OUTPUT_TOO_LARGE");
441
- }
442
- attempt.success();
443
- operation.success();
444
- return result;
349
+ return await runAgentSession(session, args.input, {
350
+ signal,
351
+ limits,
352
+ attempt,
353
+ operation
354
+ });
445
355
  } catch (error) {
446
356
  const code = integrationErrorCode(error);
447
357
  if (signal.aborted) {
@@ -451,7 +361,11 @@ async function callAgent(options, definition, request, args, context) {
451
361
  attempt.fail(code);
452
362
  operation.fail(code);
453
363
  }
454
- await reportError(options, limits, error, "agent", definition.name, context);
364
+ await reportError(options, limits, error, {
365
+ operation: "agent",
366
+ exportName: definition.name,
367
+ requestId: String(context.mcpReq.id)
368
+ });
455
369
  return errorResult(internalErrorMessage(options, error, "agent operation failed"), "AGENT_FAILED");
456
370
  }
457
371
  }
@@ -518,66 +432,245 @@ function errorResult(message, code) {
518
432
  } }
519
433
  };
520
434
  }
521
- function assertIdentity(value, field) {
522
- if (value.trim().length === 0) throw new TypeError(`${field} must not be empty`);
523
- }
524
- function errorMessage(value) {
525
- return value instanceof Error && value.message.length > 0 ? value.message : String(value);
435
+ function dispatchSdkTool(input) {
436
+ const { options, toolName, args, context, catalog, limits } = input;
437
+ return dispatchToolCall({
438
+ catalog,
439
+ call: {
440
+ callId: ToolCallId(`mcp:${String(context.mcpReq.id)}`),
441
+ toolName,
442
+ rawArguments: JSON.stringify(args)
443
+ },
444
+ position: {
445
+ turn: 1,
446
+ step: 1
447
+ },
448
+ signal: AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)]),
449
+ defaultTimeoutMs: limits.operationTimeoutMs,
450
+ teardownTimeoutMs: limits.teardownTimeoutMs,
451
+ ...options.approvals === void 0 ? {} : { approvals: options.approvals },
452
+ ...options.interceptors === void 0 ? {} : { interceptors: options.interceptors }
453
+ });
526
454
  }
527
- function resolveLimits(options) {
455
+ function renderToolResult(result, evidence) {
456
+ const { attempt, operation } = evidence;
457
+ const content = [...toMcpContent(result.content), ...toMcpContent(result.additionalContext ?? [])];
458
+ if (result.isError) {
459
+ attempt.fail(result.error.code);
460
+ operation.fail(result.error.code);
461
+ return {
462
+ isError: true,
463
+ content: content.length === 0 ? [{
464
+ type: "text",
465
+ text: result.error.message
466
+ }] : content,
467
+ structuredContent: { error: result.error }
468
+ };
469
+ }
470
+ attempt.success();
471
+ operation.success();
528
472
  return {
529
- maxExports: positiveSafeInteger(options.maxExports ?? MCP_SERVER_DEFAULTS.maxExports, "maxExports"),
530
- maxDefinitionBytes: positiveSafeInteger(options.maxDefinitionBytes ?? MCP_SERVER_DEFAULTS.maxDefinitionBytes, "maxDefinitionBytes"),
531
- maxInputBytes: positiveSafeInteger(options.maxInputBytes ?? MCP_SERVER_DEFAULTS.maxInputBytes, "maxInputBytes"),
532
- maxOutputBytes: positiveSafeInteger(options.maxOutputBytes ?? MCP_SERVER_DEFAULTS.maxOutputBytes, "maxOutputBytes"),
533
- operationTimeoutMs: positiveSafeInteger(options.operationTimeoutMs ?? MCP_SERVER_DEFAULTS.operationTimeoutMs, "operationTimeoutMs"),
534
- teardownTimeoutMs: positiveSafeInteger(options.teardownTimeoutMs ?? MCP_SERVER_DEFAULTS.teardownTimeoutMs, "teardownTimeoutMs"),
535
- observerTimeoutMs: positiveSafeInteger(options.observerTimeoutMs ?? MCP_SERVER_DEFAULTS.observerTimeoutMs, "observerTimeoutMs")
473
+ content: content.length === 0 ? [{
474
+ type: "text",
475
+ text: "(no output)"
476
+ }] : content,
477
+ ...result.value === void 0 ? {} : { structuredContent: result.value }
536
478
  };
537
479
  }
538
- async function reportError(options, limits, error, operation, exportName, context) {
539
- if (options.onError === void 0) return;
540
- const pending = Promise.resolve().then(() => options.onError?.(error, Object.freeze({
541
- operation,
542
- exportName,
543
- requestId: String(context.mcpReq.id)
544
- })));
545
- await waitForSettlement(pending, limits.observerTimeoutMs);
480
+ function createAgentSession(input) {
481
+ const { definition, request, args, context, signal, limits } = input;
482
+ const creating = Promise.resolve(definition.createSession({
483
+ ...args.conversationId === void 0 ? {} : { conversationId: args.conversationId },
484
+ request,
485
+ call: context
486
+ }));
487
+ return raceWithSignal(creating, signal, limits.teardownTimeoutMs);
488
+ }
489
+ async function runAgentSession(session, input, evidence) {
490
+ const { signal, limits, attempt, operation } = evidence;
491
+ const running = session.run(input, { signal });
492
+ const response = await raceWithSignal(running, signal, limits.teardownTimeoutMs);
493
+ if (!isJsonValue(response.outcome)) {
494
+ attempt.fail("INVALID_AGENT_RESULT");
495
+ operation.fail("INVALID_AGENT_RESULT");
496
+ return errorResult("agent outcome was not lossless JSON", "INVALID_AGENT_RESULT");
497
+ }
498
+ const result = {
499
+ content: [{
500
+ type: "text",
501
+ text: response.text || "(empty response)"
502
+ }],
503
+ structuredContent: {
504
+ text: response.text,
505
+ outcome: response.outcome,
506
+ conversationId: session.conversationId
507
+ }
508
+ };
509
+ if (serializedBytes(result) > limits.maxOutputBytes) {
510
+ attempt.fail("OUTPUT_TOO_LARGE");
511
+ operation.fail("OUTPUT_TOO_LARGE");
512
+ return errorResult(`agent result exceeds the ${limits.maxOutputBytes}-byte limit`, "OUTPUT_TOO_LARGE");
513
+ }
514
+ attempt.success();
515
+ operation.success();
516
+ return result;
546
517
  }
547
- function internalErrorMessage(options, error, fallback) {
548
- return options.exposeInternalErrors === true ? errorMessage(error) : fallback;
518
+
519
+ //#endregion
520
+ //#region src/server/advanced-registration.ts
521
+ function registerExports(ctx, limits) {
522
+ const { options } = ctx;
523
+ const schemas = options.tools?.schemas() ?? [];
524
+ const runtimeAgents = Object.entries(preferredState(options)?.agents ?? {});
525
+ validateExports({
526
+ options,
527
+ schemas,
528
+ runtimeAgents,
529
+ limits
530
+ });
531
+ registerTools(ctx, schemas);
532
+ registerAgents(ctx);
533
+ registerRuntimeAgents(ctx, runtimeAgents);
549
534
  }
550
- function positiveSafeInteger(value, label) {
551
- if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`MCP server ${label} must be a positive safe integer`);
552
- return value;
535
+ function registerTools(ctx, schemas) {
536
+ const { server, names, options } = ctx;
537
+ for (const schema of schemas) {
538
+ if (names.has(schema.name)) throw new TypeError(`duplicate MCP export '${schema.name}'`);
539
+ names.add(schema.name);
540
+ server.registerTool(schema.name, {
541
+ description: schema.description,
542
+ inputSchema: fromJsonSchema(structuredClone(schema.parameters))
543
+ }, async (args, context) => await callSdkTool(options, schema.name, args, context));
544
+ }
553
545
  }
554
- function serializedBytes(value) {
555
- const serialized = JSON.stringify(value);
556
- if (serialized === void 0) throw new TypeError("MCP server value is not JSON serializable");
557
- return new TextEncoder().encode(serialized).byteLength;
546
+ function registerAgents(ctx) {
547
+ const { server, names, options, request } = ctx;
548
+ for (const agent of options.agents ?? []) {
549
+ assertIdentity(agent.name, "agent MCP tool name");
550
+ if (names.has(agent.name)) throw new TypeError(`duplicate MCP export '${agent.name}'`);
551
+ names.add(agent.name);
552
+ server.registerTool(agent.name, {
553
+ description: agent.description ?? agent.agent.description ?? `Run the ${agent.agent.name} agent for one conversational turn.`,
554
+ inputSchema: fromJsonSchema({
555
+ type: "object",
556
+ properties: {
557
+ input: {
558
+ type: "string",
559
+ minLength: 1
560
+ },
561
+ conversationId: {
562
+ type: "string",
563
+ minLength: 1
564
+ }
565
+ },
566
+ required: ["input"],
567
+ additionalProperties: false
568
+ })
569
+ }, async (args, context) => await callAgent(options, {
570
+ definition: agent,
571
+ request
572
+ }, args, context));
573
+ }
558
574
  }
559
- async function raceWithSignal(pending, signal, teardownTimeoutMs) {
560
- if (signal.aborted) throw signal.reason ?? /* @__PURE__ */ new Error("MCP server operation aborted");
561
- try {
562
- return await new Promise((resolve, reject) => {
563
- const abort = () => {
564
- signal.removeEventListener("abort", abort);
565
- reject(signal.reason ?? /* @__PURE__ */ new Error("MCP server operation aborted"));
566
- };
567
- signal.addEventListener("abort", abort, { once: true });
568
- pending.then((value) => {
569
- signal.removeEventListener("abort", abort);
570
- resolve(value);
571
- }, (error) => {
572
- signal.removeEventListener("abort", abort);
573
- reject(error);
574
- });
575
- });
576
- } catch (error) {
577
- if (signal.aborted) await waitForSettlement(pending, teardownTimeoutMs);
578
- throw error;
575
+ function registerRuntimeAgents(ctx, runtimeAgents) {
576
+ const { server, names, options } = ctx;
577
+ for (const [name, agent] of runtimeAgents) {
578
+ assertIdentity(name, "agent MCP tool name");
579
+ if (names.has(name)) throw new TypeError(`duplicate MCP export '${name}'`);
580
+ names.add(name);
581
+ server.registerTool(name, {
582
+ description: `Run the ${name} agent for one turn.`,
583
+ inputSchema: fromJsonSchema({
584
+ type: "object",
585
+ properties: { input: {
586
+ type: "string",
587
+ minLength: 1
588
+ } },
589
+ required: ["input"],
590
+ additionalProperties: false
591
+ })
592
+ }, async (args, context) => await callRuntimeAgent(options, {
593
+ name,
594
+ agent
595
+ }, args, context));
579
596
  }
580
597
  }
598
+ function validateExports(input) {
599
+ const { options, schemas, runtimeAgents, limits } = input;
600
+ if (schemas.length + (options.agents?.length ?? 0) + runtimeAgents.length > limits.maxExports) throw new RangeError(`MCP server exceeds the ${limits.maxExports}-export limit`);
601
+ if (serializedBytes([
602
+ schemas,
603
+ options.agents?.map((agent) => ({
604
+ name: agent.name,
605
+ description: agent.description,
606
+ agentId: agent.agent.id
607
+ })) ?? [],
608
+ runtimeAgents.map(([name]) => ({ name }))
609
+ ]) > limits.maxDefinitionBytes) throw new RangeError(`MCP server definitions exceed the ${limits.maxDefinitionBytes}-byte limit`);
610
+ }
611
+
612
+ //#endregion
613
+ //#region src/server/advanced.ts
614
+ /** Export SDK tools and agents as a Universal fetch-shaped MCP server. */
615
+ /** Create one MCP server instance for a connection or HTTP request. */
616
+ function createSdkMcpServer(options, request = { era: "modern" }) {
617
+ const limits = resolveLimits(options);
618
+ assertIdentity(options.name, "server name");
619
+ if (options.version.trim().length === 0) throw new TypeError("MCP server version must not be empty");
620
+ const server = new McpServer({
621
+ name: options.name,
622
+ version: options.version
623
+ }, {
624
+ capabilities: { tools: { listChanged: false } },
625
+ ...options.instructions === void 0 ? {} : { instructions: options.instructions }
626
+ });
627
+ registerExports({
628
+ server,
629
+ names: /* @__PURE__ */ new Set(),
630
+ options,
631
+ request
632
+ }, limits);
633
+ return server;
634
+ }
635
+ /** Create a fetch-shaped API for hosts that accept Request/Response. */
636
+ function createSdkMcpHandler(options, handlerOptions) {
637
+ const handler = createMcpHandler((request) => createSdkMcpServer(withRequestLogger(options), request), handlerOptions);
638
+ return {
639
+ fetch: async (request, requestOptions) => {
640
+ const operation = beginIntegrationOperation(integrationChildLogger(options.logger, "mcp-server-request"), serverFamily(options), "request");
641
+ const attempt = operation.attempt(1);
642
+ try {
643
+ const response = await handler.fetch(request, requestOptions);
644
+ if (response.status >= 500) {
645
+ attempt.fail(`HTTP_${response.status}`);
646
+ operation.fail(`HTTP_${response.status}`);
647
+ } else {
648
+ attempt.success();
649
+ operation.success();
650
+ }
651
+ return response;
652
+ } catch (error) {
653
+ const code = integrationErrorCode(error);
654
+ attempt.fail(code);
655
+ operation.fail(code);
656
+ throw error;
657
+ }
658
+ },
659
+ close: handler.close,
660
+ notify: handler.notify,
661
+ bus: handler.bus
662
+ };
663
+ }
664
+ function withRequestLogger(options) {
665
+ const logger = integrationChildLogger(options.logger, "mcp-server-request");
666
+ if (logger === void 0) return options;
667
+ const child = {
668
+ ...options,
669
+ logger
670
+ };
671
+ copyPreferredState(options, child);
672
+ return child;
673
+ }
581
674
 
582
675
  //#endregion
583
676
  //#region src/preferred/server.ts
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["assertIdentity"],"sources":["../src/common/integration-operation.ts","../src/common/preferred-state.ts","../src/common/config.ts","../src/server/advanced.ts","../src/preferred/server.ts"],"sourcesContent":["import type { IntegrationOperationEvidenceFields, SdkLogger } from '@alvin0/ai-agent-sdk-core/observability'\n\nexport const MCP_SERVER_INTEGRATION_OPERATIONS = Object.freeze({\n 'mcp-web-server': Object.freeze(['request', 'tool-call', 'agent-call']),\n 'mcp-stdio-server': Object.freeze(['request', 'tool-call', 'agent-call', 'close']),\n} as const)\n\nexport type McpServerIntegrationFamily = keyof typeof MCP_SERVER_INTEGRATION_OPERATIONS\nexport type McpServerIntegrationOperation =\n (typeof MCP_SERVER_INTEGRATION_OPERATIONS)[McpServerIntegrationFamily][number]\n\nexport interface IntegrationAttempt {\n success(): void\n fail(errorCode?: string): void\n abort(): void\n}\n\nexport interface IntegrationOperation {\n attempt(attemptNumber: number): IntegrationAttempt\n success(): void\n fail(errorCode?: string): void\n abort(): void\n}\n\nconst MESSAGES = Object.freeze({\n start: 'SDK integration operation started',\n attempt: 'SDK integration attempt started',\n success: 'SDK integration operation completed',\n failure: 'SDK integration operation failed',\n abort: 'SDK integration operation aborted',\n})\n\nexport function beginIntegrationOperation(\n logger: SdkLogger | undefined,\n family: McpServerIntegrationFamily,\n operation: McpServerIntegrationOperation,\n): IntegrationOperation {\n validateOperation(family, operation)\n const operationId = crypto.randomUUID(), startedAt = monotonicNow()\n emit(logger, 'info', MESSAGES.start, {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'logical-start',\n })\n let terminal = false\n const finish = (status: 'success' | 'error' | 'aborted', errorCode?: string): void => {\n if (terminal) return\n terminal = true\n emit(logger, status === 'error' ? 'error' : 'info', terminalMessage(status), {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'logical-terminal',\n status, durationMs: durationSince(startedAt),\n ...(errorCode === undefined ? {} : { errorCode: boundedCode(errorCode) }),\n })\n }\n return Object.freeze({\n attempt(attemptNumber: number) {\n if (!Number.isSafeInteger(attemptNumber) || attemptNumber < 1) {\n throw new TypeError('integration attemptNumber must be a positive safe integer')\n }\n const attemptId = crypto.randomUUID(), attemptStartedAt = monotonicNow()\n emit(logger, 'info', MESSAGES.attempt, {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'attempt-start',\n attemptId, attemptNumber,\n })\n let attemptTerminal = false\n const finishAttempt = (status: 'success' | 'error' | 'aborted', errorCode?: string): void => {\n if (attemptTerminal) return\n attemptTerminal = true\n emit(logger, status === 'error' ? 'error' : 'info', terminalMessage(status), {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'attempt-terminal',\n attemptId, attemptNumber, status, durationMs: durationSince(attemptStartedAt),\n ...(errorCode === undefined ? {} : { errorCode: boundedCode(errorCode) }),\n })\n }\n return Object.freeze({\n success: () => finishAttempt('success'),\n fail: (code?: string) => finishAttempt('error', code),\n abort: () => finishAttempt('aborted'),\n })\n },\n success: () => finish('success'),\n fail: (code?: string) => finish('error', code),\n abort: () => finish('aborted'),\n })\n}\n\nexport function integrationErrorCode(error: unknown): string {\n if (typeof error === 'object' && error !== null) {\n for (const key of ['code', 'name']) {\n const descriptor = Object.getOwnPropertyDescriptor(error, key)\n if (descriptor !== undefined && 'value' in descriptor && typeof descriptor.value === 'string') {\n return boundedCode(descriptor.value)\n }\n }\n }\n return 'INTEGRATION_ERROR'\n}\n\nexport function integrationChildLogger(logger: SdkLogger | undefined, scope: string): SdkLogger | undefined {\n assertIdentity(scope, 64, 'integration scope')\n try { return logger?.child({ integrationScope: scope }) } catch { return undefined }\n}\n\nfunction validateOperation(family: McpServerIntegrationFamily, operation: McpServerIntegrationOperation): void {\n const operations = MCP_SERVER_INTEGRATION_OPERATIONS[family] as readonly string[] | undefined\n assertIdentity(family, 64, 'integration family')\n assertIdentity(operation, 64, 'integration operation')\n if (operations === undefined || !operations.includes(operation)) throw new TypeError('Invalid MCP integration operation')\n}\n\nfunction emit(logger: SdkLogger | undefined, level: 'info' | 'error', message: string,\n fields: IntegrationOperationEvidenceFields): void {\n try { logger?.[level](message, fields) } catch { /* logging never owns protocol completion */ }\n}\n\nfunction terminalMessage(status: 'success' | 'error' | 'aborted'): string {\n return status === 'success' ? MESSAGES.success : status === 'error' ? MESSAGES.failure : MESSAGES.abort\n}\nfunction monotonicNow(): number { return performance.now() }\nfunction durationSince(startedAt: number): number {\n const value = monotonicNow() - startedAt\n return Number.isFinite(value) ? Math.max(0, value) : 0\n}\nfunction boundedCode(value: string): string {\n const normalized = value.replace(/[^A-Za-z0-9_.:-]/g, '_')\n return (normalized.length === 0 ? 'INTEGRATION_ERROR' : normalized).slice(0, 128)\n}\nfunction assertIdentity(value: string, limit: number, label: string): void {\n if (typeof value !== 'string' || value.length === 0 || value.length > limit) {\n throw new TypeError(`${label} must contain 1-${limit} characters`)\n }\n}\n","import type { RuntimeAgentResponse } from '@alvin0/ai-agent-sdk-core/agent'\nimport type { SdkMcpRequestContext, SdkMcpServer } from './server-public-types.ts'\n\nexport type McpServerRuntimeFamily = 'mcp-web-server' | 'mcp-stdio-server'\n\nexport interface PreferredServerState {\n readonly agents: Readonly<Record<string, PreferredServerAgent>>\n}\n\nexport interface PreferredServerAgent {\n generate(input: string, options: { readonly signal?: AbortSignal }): Promise<RuntimeAgentResponse>\n}\n\nexport type InternalMcpServerFactory = (\n request: SdkMcpRequestContext,\n family: McpServerRuntimeFamily,\n) => SdkMcpServer\n\nexport const MCP_WEB_SERVER_FACTORY = Symbol.for('ai-agent-sdk.mcp-web-server.factory.v1')\n\nconst STATES = new WeakMap<object, PreferredServerState>()\n\nexport function attachPreferredState(options: object, state: PreferredServerState): void {\n STATES.set(options, state)\n}\n\nexport function copyPreferredState(source: object, target: object): void {\n const state = STATES.get(source)\n if (state !== undefined) STATES.set(target, state)\n}\n\nexport function preferredState(options: object): PreferredServerState | undefined {\n return STATES.get(options)\n}\n\nexport function internalMcpServerFactory(value: unknown): InternalMcpServerFactory | undefined {\n if ((typeof value !== 'object' || value === null) && typeof value !== 'function') return undefined\n const descriptor = Object.getOwnPropertyDescriptor(value, MCP_WEB_SERVER_FACTORY)\n return descriptor !== undefined && 'value' in descriptor && typeof descriptor.value === 'function'\n ? descriptor.value as InternalMcpServerFactory : undefined\n}\n","/** Internal limits shared by preferred and advanced Universal MCP servers. */\nexport const MCP_SERVER_DEFAULTS = Object.freeze({\n maxExports: 1_024,\n maxDefinitionBytes: 4 * 1024 * 1024,\n maxInputBytes: 1024 * 1024,\n maxOutputBytes: 4 * 1024 * 1024,\n operationTimeoutMs: 10 * 60_000,\n teardownTimeoutMs: 30_000,\n observerTimeoutMs: 5_000,\n})\n","/** Export SDK tools and agents as a Universal fetch-shaped MCP server. */\n\nimport {\n McpServer,\n createMcpHandler,\n fromJsonSchema,\n type CallToolResult,\n type CreateMcpHandlerOptions,\n type ServerContext,\n} from '@modelcontextprotocol/server'\nimport type { ContentBlock } from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId, isJsonValue, type JsonValue } from '@alvin0/ai-agent-sdk-core'\nimport type { AgentSession, DefinedAgent } from '@alvin0/ai-agent-sdk-core/agent'\nimport type { ApprovalBroker, SdkLogger, ToolCatalog, ToolInterceptor } from '@alvin0/ai-agent-sdk-core/tools'\nimport {\n dispatchToolCall,\n} from '@alvin0/ai-agent-sdk-core/tools'\nimport { waitForSettlement } from '@alvin0/ai-agent-sdk-core'\nimport {\n beginIntegrationOperation,\n integrationChildLogger,\n integrationErrorCode,\n type McpServerIntegrationFamily,\n} from '../common/integration-operation.ts'\nimport { copyPreferredState, preferredState, type PreferredServerAgent } from '../common/preferred-state.ts'\nimport { MCP_SERVER_DEFAULTS } from '../common/config.ts'\nimport type {\n SdkMcpCallContext,\n SdkMcpHandlerOptions,\n SdkMcpHandlerRequestOptions,\n SdkMcpHttpHandler,\n SdkMcpRequestContext,\n SdkMcpServer,\n} from '../common/server-public-types.ts'\n\nexport type * from '../common/server-public-types.ts'\n\nexport interface McpAgentSessionContext {\n readonly conversationId?: string\n readonly request: SdkMcpRequestContext\n readonly call: SdkMcpCallContext\n}\n\nexport interface McpAgentTool {\n readonly name: string\n readonly description?: string\n readonly agent: DefinedAgent\n /** Host-owned persistence seam: return a fresh or resumed session. */\n readonly createSession: (context: McpAgentSessionContext) => AgentSession | Promise<AgentSession>\n}\n\nexport interface McpServerErrorContext {\n readonly operation: 'tool' | 'agent'\n readonly exportName: string\n readonly requestId: string\n}\n\nexport interface SdkMcpServerOptions {\n readonly name: string\n readonly version: string\n readonly logger?: SdkLogger\n /** Internal family selected by the official Web/stdio host factory. */\n readonly integrationFamily?: 'mcp-web-server' | 'mcp-stdio-server'\n readonly instructions?: string\n /** SDK tools exposed through the existing validation/policy pipeline. */\n readonly tools?: ToolCatalog\n readonly agents?: readonly McpAgentTool[]\n readonly approvals?: ApprovalBroker\n readonly interceptors?: readonly ToolInterceptor[]\n /** Maximum exported tools and agents. Defaults to 1,024. */\n readonly maxExports?: number\n /** Maximum serialized export schema bytes. Defaults to 4 MiB. */\n readonly maxDefinitionBytes?: number\n /** Maximum serialized request arguments. Defaults to 1 MiB. */\n readonly maxInputBytes?: number\n /** Maximum serialized tool/agent result. Defaults to 4 MiB. */\n readonly maxOutputBytes?: number\n /** Default tool/agent operation deadline. Defaults to 10 minutes. */\n readonly operationTimeoutMs?: number\n /** Maximum wait after cancellation. Defaults to 30 seconds. */\n readonly teardownTimeoutMs?: number\n /** Maximum time granted to the diagnostic observer. Defaults to 5 seconds. */\n readonly observerTimeoutMs?: number\n /** Report host/runtime failures without giving the observer control over request completion. */\n readonly onError?: (error: unknown, context: McpServerErrorContext) => void | Promise<void>\n /** Opt in to returning internal exception messages to remote callers. Defaults to false. */\n readonly exposeInternalErrors?: boolean\n}\n\ntype McpResultBlock = CallToolResult['content'][number]\n\n/** Create one MCP server instance for a connection or HTTP request. */\nexport function createSdkMcpServer(\n options: SdkMcpServerOptions,\n request: SdkMcpRequestContext = { era: 'modern' },\n): SdkMcpServer {\n const limits = resolveLimits(options)\n assertIdentity(options.name, 'server name')\n if (options.version.trim().length === 0) throw new TypeError('MCP server version must not be empty')\n const server = new McpServer(\n { name: options.name, version: options.version },\n {\n capabilities: { tools: { listChanged: false } },\n ...(options.instructions === undefined ? {} : { instructions: options.instructions }),\n },\n )\n const names = new Set<string>()\n const schemas = options.tools?.schemas() ?? []\n const runtimeAgents = Object.entries(preferredState(options)?.agents ?? {})\n if (schemas.length + (options.agents?.length ?? 0) + runtimeAgents.length > limits.maxExports) {\n throw new RangeError(`MCP server exceeds the ${limits.maxExports}-export limit`)\n }\n if (serializedBytes([schemas, options.agents?.map(agent => ({\n name: agent.name, description: agent.description, agentId: agent.agent.id,\n })) ?? [], runtimeAgents.map(([name]) => ({ name }))]) > limits.maxDefinitionBytes) {\n throw new RangeError(`MCP server definitions exceed the ${limits.maxDefinitionBytes}-byte limit`)\n }\n for (const schema of schemas) {\n if (names.has(schema.name)) throw new TypeError(`duplicate MCP export '${schema.name}'`)\n names.add(schema.name)\n server.registerTool(\n schema.name,\n {\n description: schema.description,\n // The Worker/browser validator dereferences by attaching private\n // metadata. SDK tool schemas are intentionally frozen, so give the\n // protocol boundary an isolated mutable copy.\n inputSchema: fromJsonSchema<Record<string, unknown>>(structuredClone(schema.parameters)),\n },\n async (args, context) => await callSdkTool(options, schema.name, args, context),\n )\n }\n for (const agent of options.agents ?? []) {\n assertIdentity(agent.name, 'agent MCP tool name')\n if (names.has(agent.name)) throw new TypeError(`duplicate MCP export '${agent.name}'`)\n names.add(agent.name)\n server.registerTool(\n agent.name,\n {\n description: agent.description\n ?? agent.agent.description\n ?? `Run the ${agent.agent.name} agent for one conversational turn.`,\n inputSchema: fromJsonSchema<{ input: string; conversationId?: string }>({\n type: 'object',\n properties: {\n input: { type: 'string', minLength: 1 },\n conversationId: { type: 'string', minLength: 1 },\n },\n required: ['input'],\n additionalProperties: false,\n }),\n },\n async (args, context) => await callAgent(options, agent, request, args, context),\n )\n }\n for (const [name, agent] of runtimeAgents) {\n assertIdentity(name, 'agent MCP tool name')\n if (names.has(name)) throw new TypeError(`duplicate MCP export '${name}'`)\n names.add(name)\n server.registerTool(name, {\n description: `Run the ${name} agent for one turn.`,\n inputSchema: fromJsonSchema<{ input: string }>({\n type: 'object', properties: { input: { type: 'string', minLength: 1 } },\n required: ['input'], additionalProperties: false,\n }),\n }, async (args, context) => await callRuntimeAgent(options, name, agent, args, context))\n }\n return server as unknown as SdkMcpServer\n}\n\n/**\n * Create a fetch-shaped API for Cloudflare Workers, Deno, Bun, Next.js route\n * handlers, or any web framework that accepts Request/Response.\n */\nexport function createSdkMcpHandler(\n options: SdkMcpServerOptions,\n handlerOptions?: SdkMcpHandlerOptions,\n): SdkMcpHttpHandler {\n const handler = createMcpHandler(\n request => createSdkMcpServer(withRequestLogger(options), request as SdkMcpRequestContext) as unknown as McpServer,\n handlerOptions as CreateMcpHandlerOptions,\n )\n return {\n fetch: async (request: Request, requestOptions?: SdkMcpHandlerRequestOptions) => {\n const operation = beginIntegrationOperation(\n integrationChildLogger(options.logger, 'mcp-server-request'), serverFamily(options), 'request',\n )\n const attempt = operation.attempt(1)\n try {\n const response = await handler.fetch(request, requestOptions as never)\n if (response.status >= 500) {\n attempt.fail(`HTTP_${response.status}`); operation.fail(`HTTP_${response.status}`)\n } else {\n attempt.success(); operation.success()\n }\n return response\n } catch (error: unknown) {\n const code = integrationErrorCode(error)\n attempt.fail(code); operation.fail(code)\n throw error\n }\n },\n close: handler.close,\n notify: handler.notify,\n bus: handler.bus,\n } as unknown as SdkMcpHttpHandler\n}\n\nfunction withRequestLogger(options: SdkMcpServerOptions): SdkMcpServerOptions {\n const logger = integrationChildLogger(options.logger, 'mcp-server-request')\n if (logger === undefined) return options\n const child = { ...options, logger }\n copyPreferredState(options, child)\n return child\n}\n\nfunction serverFamily(options: SdkMcpServerOptions): McpServerIntegrationFamily {\n return options.integrationFamily ?? 'mcp-web-server'\n}\n\nasync function callRuntimeAgent(\n options: SdkMcpServerOptions,\n name: string,\n agent: PreferredServerAgent,\n args: { input: string },\n context: ServerContext,\n): Promise<CallToolResult> {\n const limits = resolveLimits(options)\n const operation = beginIntegrationOperation(options.logger, serverFamily(options), 'agent-call')\n const attempt = operation.attempt(1)\n if (serializedBytes(args) > limits.maxInputBytes) {\n attempt.fail('INPUT_TOO_LARGE'); operation.fail('INPUT_TOO_LARGE')\n return errorResult(`agent input exceeds the ${limits.maxInputBytes}-byte limit`, 'INPUT_TOO_LARGE')\n }\n const signal = AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)])\n try {\n const response = await raceWithSignal(agent.generate(args.input, { signal }), signal, limits.teardownTimeoutMs)\n const result: CallToolResult = {\n content: [{ type: 'text', text: response.text || '(empty response)' }],\n structuredContent: { text: response.text, runId: response.runId, traceId: response.traceId },\n }\n if (serializedBytes(result) > limits.maxOutputBytes) {\n attempt.fail('OUTPUT_TOO_LARGE'); operation.fail('OUTPUT_TOO_LARGE')\n return errorResult(`agent result exceeds the ${limits.maxOutputBytes}-byte limit`, 'OUTPUT_TOO_LARGE')\n }\n attempt.success(); operation.success()\n return result\n } catch (error: unknown) {\n const code = integrationErrorCode(error)\n if (signal.aborted) { attempt.abort(); operation.abort() }\n else { attempt.fail(code); operation.fail(code) }\n await reportError(options, limits, error, 'agent', name, context)\n return errorResult(internalErrorMessage(options, error, 'agent operation failed'), 'AGENT_FAILED')\n }\n}\n\nasync function callSdkTool(\n options: SdkMcpServerOptions,\n toolName: string,\n args: Record<string, unknown>,\n context: ServerContext,\n): Promise<CallToolResult> {\n const limits = resolveLimits(options)\n const operation = beginIntegrationOperation(options.logger, serverFamily(options), 'tool-call')\n const attempt = operation.attempt(1)\n if (serializedBytes(args) > limits.maxInputBytes) {\n attempt.fail('INPUT_TOO_LARGE'); operation.fail('INPUT_TOO_LARGE')\n return errorResult(`tool input exceeds the ${limits.maxInputBytes}-byte limit`, 'INPUT_TOO_LARGE')\n }\n const catalog = options.tools\n if (catalog === undefined) {\n attempt.fail('UNKNOWN_TOOL'); operation.fail('UNKNOWN_TOOL')\n return errorResult(`tool '${toolName}' is not available`, 'UNKNOWN_TOOL')\n }\n try {\n const result = await dispatchToolCall({\n catalog,\n call: {\n callId: ToolCallId(`mcp:${String(context.mcpReq.id)}`),\n toolName,\n rawArguments: JSON.stringify(args),\n },\n position: { turn: 1, step: 1 },\n signal: AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)]),\n defaultTimeoutMs: limits.operationTimeoutMs,\n teardownTimeoutMs: limits.teardownTimeoutMs,\n ...(options.approvals === undefined ? {} : { approvals: options.approvals }),\n ...(options.interceptors === undefined ? {} : { interceptors: options.interceptors }),\n })\n if (serializedBytes(result) > limits.maxOutputBytes) {\n attempt.fail('OUTPUT_TOO_LARGE'); operation.fail('OUTPUT_TOO_LARGE')\n return errorResult(`tool result exceeds the ${limits.maxOutputBytes}-byte limit`, 'OUTPUT_TOO_LARGE')\n }\n const content = [\n ...toMcpContent(result.content),\n ...toMcpContent(result.additionalContext ?? []),\n ]\n if (result.isError) {\n attempt.fail(result.error.code); operation.fail(result.error.code)\n return {\n isError: true,\n content: content.length === 0 ? [{ type: 'text', text: result.error.message }] : content,\n structuredContent: { error: result.error },\n }\n }\n attempt.success(); operation.success()\n return {\n content: content.length === 0 ? [{ type: 'text', text: '(no output)' }] : content,\n ...(result.value === undefined ? {} : { structuredContent: result.value }),\n }\n } catch (error: unknown) {\n const code = integrationErrorCode(error)\n attempt.fail(code); operation.fail(code)\n await reportError(options, limits, error, 'tool', toolName, context)\n return errorResult(internalErrorMessage(options, error, 'tool operation failed'), 'TOOL_OPERATION_FAILED')\n }\n}\n\nasync function callAgent(\n options: SdkMcpServerOptions,\n definition: McpAgentTool,\n request: SdkMcpRequestContext,\n args: { input: string; conversationId?: string },\n context: ServerContext,\n): Promise<CallToolResult> {\n const limits = resolveLimits(options)\n const operation = beginIntegrationOperation(options.logger, serverFamily(options), 'agent-call')\n const attempt = operation.attempt(1)\n if (serializedBytes(args) > limits.maxInputBytes) {\n attempt.fail('INPUT_TOO_LARGE'); operation.fail('INPUT_TOO_LARGE')\n return errorResult(`agent input exceeds the ${limits.maxInputBytes}-byte limit`, 'INPUT_TOO_LARGE')\n }\n const signal = AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)])\n try {\n const creating = Promise.resolve(definition.createSession({\n ...(args.conversationId === undefined ? {} : { conversationId: args.conversationId }),\n request,\n call: context,\n }))\n const session = await raceWithSignal(creating, signal, limits.teardownTimeoutMs)\n if (session.definition.id !== definition.agent.id) {\n attempt.fail('WRONG_AGENT_SESSION'); operation.fail('WRONG_AGENT_SESSION')\n return errorResult(\n `session factory for '${definition.name}' returned agent '${session.definition.id}', expected '${definition.agent.id}'`,\n 'WRONG_AGENT_SESSION',\n )\n }\n const running = session.run(args.input, { signal })\n const response = await raceWithSignal(running, signal, limits.teardownTimeoutMs)\n if (!isJsonValue(response.outcome)) {\n attempt.fail('INVALID_AGENT_RESULT'); operation.fail('INVALID_AGENT_RESULT')\n return errorResult('agent outcome was not lossless JSON', 'INVALID_AGENT_RESULT')\n }\n const result: CallToolResult = {\n content: [{ type: 'text', text: response.text || '(empty response)' }],\n structuredContent: {\n text: response.text,\n outcome: response.outcome,\n conversationId: session.conversationId,\n },\n }\n if (serializedBytes(result) > limits.maxOutputBytes) {\n attempt.fail('OUTPUT_TOO_LARGE'); operation.fail('OUTPUT_TOO_LARGE')\n return errorResult(`agent result exceeds the ${limits.maxOutputBytes}-byte limit`, 'OUTPUT_TOO_LARGE')\n }\n attempt.success(); operation.success()\n return result\n } catch (error: unknown) {\n const code = integrationErrorCode(error)\n if (signal.aborted) { attempt.abort(); operation.abort() }\n else { attempt.fail(code); operation.fail(code) }\n await reportError(options, limits, error, 'agent', definition.name, context)\n return errorResult(internalErrorMessage(options, error, 'agent operation failed'), 'AGENT_FAILED')\n }\n}\n\nfunction toMcpContent(blocks: readonly ContentBlock[]): McpResultBlock[] {\n const result: McpResultBlock[] = []\n for (const block of blocks) {\n if (block.type === 'text') {\n result.push({ type: 'text', text: block.text })\n continue\n }\n if (block.type === 'image' && block.source.kind === 'base64') {\n result.push({\n type: 'image',\n data: block.source.data,\n mimeType: block.source.mediaType,\n })\n continue\n }\n if (block.type === 'image' && block.source.kind === 'url') {\n result.push({ type: 'text', text: `[image](${block.source.url})` })\n continue\n }\n if (block.type === 'image' && block.source.kind === 'file') {\n result.push({ type: 'text', text: `[image file: ${block.source.fileId}]` })\n continue\n }\n if (block.type === 'reasoning') {\n result.push({ type: 'text', text: block.text })\n continue\n }\n result.push({ type: 'text', text: JSON.stringify(jsonSafeBlock(block)) })\n }\n return result\n}\n\nfunction jsonSafeBlock(block: ContentBlock): JsonValue {\n if (isJsonValue(block)) return block\n return { type: block.type }\n}\n\nfunction errorResult(message: string, code: string): CallToolResult {\n return {\n isError: true,\n content: [{ type: 'text', text: `Error: ${message}` }],\n structuredContent: { error: { message, code } },\n }\n}\n\nfunction assertIdentity(value: string, field: string): void {\n if (value.trim().length === 0) throw new TypeError(`${field} must not be empty`)\n}\n\nfunction errorMessage(value: unknown): string {\n return value instanceof Error && value.message.length > 0 ? value.message : String(value)\n}\n\ninterface ResolvedMcpServerLimits {\n readonly maxExports: number\n readonly maxDefinitionBytes: number\n readonly maxInputBytes: number\n readonly maxOutputBytes: number\n readonly operationTimeoutMs: number\n readonly teardownTimeoutMs: number\n readonly observerTimeoutMs: number\n}\n\nfunction resolveLimits(options: SdkMcpServerOptions): ResolvedMcpServerLimits {\n return {\n maxExports: positiveSafeInteger(options.maxExports ?? MCP_SERVER_DEFAULTS.maxExports, 'maxExports'),\n maxDefinitionBytes: positiveSafeInteger(\n options.maxDefinitionBytes ?? MCP_SERVER_DEFAULTS.maxDefinitionBytes, 'maxDefinitionBytes',\n ),\n maxInputBytes: positiveSafeInteger(options.maxInputBytes ?? MCP_SERVER_DEFAULTS.maxInputBytes, 'maxInputBytes'),\n maxOutputBytes: positiveSafeInteger(options.maxOutputBytes ?? MCP_SERVER_DEFAULTS.maxOutputBytes, 'maxOutputBytes'),\n operationTimeoutMs: positiveSafeInteger(\n options.operationTimeoutMs ?? MCP_SERVER_DEFAULTS.operationTimeoutMs, 'operationTimeoutMs',\n ),\n teardownTimeoutMs: positiveSafeInteger(\n options.teardownTimeoutMs ?? MCP_SERVER_DEFAULTS.teardownTimeoutMs, 'teardownTimeoutMs',\n ),\n observerTimeoutMs: positiveSafeInteger(\n options.observerTimeoutMs ?? MCP_SERVER_DEFAULTS.observerTimeoutMs, 'observerTimeoutMs',\n ),\n }\n}\n\nasync function reportError(\n options: SdkMcpServerOptions,\n limits: ResolvedMcpServerLimits,\n error: unknown,\n operation: McpServerErrorContext['operation'],\n exportName: string,\n context: ServerContext,\n): Promise<void> {\n if (options.onError === undefined) return\n const pending = Promise.resolve().then(() => options.onError?.(error, Object.freeze({\n operation,\n exportName,\n requestId: String(context.mcpReq.id),\n })))\n await waitForSettlement(pending, limits.observerTimeoutMs)\n}\n\nfunction internalErrorMessage(options: SdkMcpServerOptions, error: unknown, fallback: string): string {\n return options.exposeInternalErrors === true ? errorMessage(error) : fallback\n}\n\nfunction positiveSafeInteger(value: number, label: string): number {\n if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`MCP server ${label} must be a positive safe integer`)\n return value\n}\n\nfunction serializedBytes(value: unknown): number {\n const serialized = JSON.stringify(value)\n if (serialized === undefined) throw new TypeError('MCP server value is not JSON serializable')\n return new TextEncoder().encode(serialized).byteLength\n}\n\nasync function raceWithSignal<T>(\n pending: Promise<T>,\n signal: AbortSignal,\n teardownTimeoutMs: number,\n): Promise<T> {\n if (signal.aborted) throw signal.reason ?? new Error('MCP server operation aborted')\n try {\n return await new Promise<T>((resolve, reject) => {\n const abort = () => {\n signal.removeEventListener('abort', abort)\n reject(signal.reason ?? new Error('MCP server operation aborted'))\n }\n signal.addEventListener('abort', abort, { once: true })\n void pending.then(\n value => { signal.removeEventListener('abort', abort); resolve(value) },\n error => { signal.removeEventListener('abort', abort); reject(error) },\n )\n })\n } catch (error: unknown) {\n if (signal.aborted) await waitForSettlement(pending, teardownTimeoutMs)\n throw error\n }\n}\n","import type { RuntimeAgent, RuntimeAgentInvocationOptions, RuntimeAgentResponse } from '@alvin0/ai-agent-sdk-core/agent'\nimport type { SdkLogger, ToolCatalog } from '@alvin0/ai-agent-sdk-core/tools'\nimport { createSdkMcpHandler, createSdkMcpServer, type SdkMcpServerOptions } from '../server/advanced.ts'\nimport {\n attachPreferredState, copyPreferredState, MCP_WEB_SERVER_FACTORY,\n type InternalMcpServerFactory, type PreferredServerAgent,\n} from '../common/preferred-state.ts'\nimport { MCP_SERVER_DEFAULTS } from '../common/config.ts'\n\nexport interface McpServerDefinition {\n readonly id: string\n readonly logger?: SdkLogger\n readonly tools?: ToolCatalog\n readonly agents?: Readonly<Record<string, RuntimeAgent>>\n readonly maxRequestBytes?: number\n readonly maxResponseBytes?: number\n}\n\nexport interface McpWebServer {\n handle(request: Request, options?: { readonly signal?: AbortSignal }): Promise<Response>\n}\n\n/** Capture one inert Web-standard server definition; each handle call owns its request resources. */\nexport function createMcpServer(definition: McpServerDefinition): McpWebServer {\n const source = objectValue(definition)\n const id = identity(ownValue(source, 'id'), 'MCP server id')\n const logger = optionalObject<SdkLogger>(ownValue(source, 'logger', false), 'MCP server logger')\n const tools = captureToolCatalog(ownValue(source, 'tools', false))\n const agents = captureAgents(ownValue(source, 'agents', false))\n const maxRequestBytes = positive(\n ownValue(source, 'maxRequestBytes', false) ?? MCP_SERVER_DEFAULTS.maxInputBytes, 'maxRequestBytes',\n )\n const maxResponseBytes = positive(\n ownValue(source, 'maxResponseBytes', false) ?? MCP_SERVER_DEFAULTS.maxOutputBytes, 'maxResponseBytes',\n )\n const advanced: SdkMcpServerOptions = Object.freeze({\n name: id, version: '1.0.0',\n ...(logger === undefined ? {} : { logger }),\n ...(tools === undefined ? {} : { tools }),\n maxInputBytes: maxRequestBytes, maxOutputBytes: maxResponseBytes,\n })\n attachPreferredState(advanced, Object.freeze({ agents }))\n\n const factory: InternalMcpServerFactory = (request, family) => {\n const scoped: SdkMcpServerOptions = { ...advanced, integrationFamily: family }\n copyPreferredState(advanced, scoped)\n return createSdkMcpServer(scoped, request)\n }\n const handle = async (request: Request, options?: { readonly signal?: AbortSignal }): Promise<Response> => {\n if (!(request instanceof Request)) throw new TypeError('MCP Web server requires a Request')\n const signal = options?.signal === undefined ? request.signal\n : AbortSignal.any([request.signal, options.signal])\n signal.throwIfAborted()\n const forwarded = signal === request.signal ? request : new Request(request, { signal })\n if (!await requestFits(forwarded, maxRequestBytes)) return payloadTooLarge()\n const handlerOptions: SdkMcpServerOptions = { ...advanced, integrationFamily: 'mcp-web-server' }\n copyPreferredState(advanced, handlerOptions)\n const handler = createSdkMcpHandler(handlerOptions)\n try {\n const response = await handler.fetch(forwarded)\n return boundedResponse(response, maxResponseBytes, handler.close)\n } catch (error: unknown) {\n await settleClose(handler.close)\n throw error\n }\n }\n const result = { handle }\n Object.defineProperty(result, MCP_WEB_SERVER_FACTORY, { value: factory, enumerable: false })\n return Object.freeze(result)\n}\n\nfunction captureAgents(value: unknown): Readonly<Record<string, PreferredServerAgent>> {\n if (value === undefined) return Object.freeze({})\n const source = objectValue(value), entries: [string, PreferredServerAgent][] = []\n for (const key of Reflect.ownKeys(source)) {\n if (typeof key !== 'string') throw new TypeError('MCP agent names must be strings')\n identity(key, 'MCP agent name')\n const agent = objectValue(ownValue(source, key)) as RuntimeAgent\n const generate = method(agent, 'generate')\n entries.push([key, Object.freeze({\n generate: (input: string, options: RuntimeAgentInvocationOptions): Promise<RuntimeAgentResponse> =>\n Reflect.apply(generate, agent, [input, options]) as Promise<RuntimeAgentResponse>,\n })])\n }\n return Object.freeze(Object.fromEntries(entries))\n}\n\nfunction captureToolCatalog(value: unknown): ToolCatalog | undefined {\n if (value === undefined) return undefined\n const catalog = objectValue(value) as ToolCatalog\n const get = method(catalog, 'get'), has = method(catalog, 'has'), names = method(catalog, 'names')\n const schemas = method(catalog, 'schemas'), executionMode = method(catalog, 'executionMode')\n return Object.freeze({\n get: (name: string) => Reflect.apply(get, catalog, [name]) as ReturnType<ToolCatalog['get']>,\n has: (name: string) => Reflect.apply(has, catalog, [name]) as boolean,\n names: () => Reflect.apply(names, catalog, []) as readonly string[],\n schemas: () => Reflect.apply(schemas, catalog, []) as ReturnType<ToolCatalog['schemas']>,\n executionMode(name: string, args: unknown): 'parallel' | 'exclusive' {\n return Reflect.apply(executionMode, catalog, [name, args]) as 'parallel' | 'exclusive'\n },\n })\n}\n\nasync function requestFits(request: Request, limit: number): Promise<boolean> {\n const declared = request.headers.get('content-length')\n if (declared !== null) {\n const bytes = Number(declared)\n if (!Number.isSafeInteger(bytes) || bytes < 0 || bytes > limit) return false\n }\n if (request.body === null) return true\n try { return (await request.clone().arrayBuffer()).byteLength <= limit } catch { return false }\n}\n\nfunction boundedResponse(response: Response, limit: number, close: () => Promise<void>): Response {\n if (response.body === null) { void settleClose(close); return response }\n const declared = response.headers.get('content-length')\n if (declared !== null && Number(declared) > limit) {\n void response.body.cancel(); void settleClose(close)\n return responseTooLarge()\n }\n const reader = response.body.getReader()\n let bytes = 0, closed = false\n const finish = async (): Promise<void> => {\n if (closed) return\n closed = true\n await settleClose(close)\n }\n const body = new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const next = await reader.read()\n if (next.done) { controller.close(); await finish(); return }\n bytes += next.value.byteLength\n if (bytes > limit) {\n await reader.cancel(); await finish()\n controller.error(new RangeError('MCP response exceeded maxResponseBytes'))\n return\n }\n controller.enqueue(next.value)\n } catch (error: unknown) { await finish(); controller.error(error) }\n },\n async cancel(reason) { try { await reader.cancel(reason) } finally { await finish() } },\n })\n return new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers })\n}\n\nfunction payloadTooLarge(): Response {\n return Response.json({ jsonrpc: '2.0', id: null,\n error: { code: -32600, message: 'MCP request exceeds maxRequestBytes' } }, { status: 413 })\n}\nfunction responseTooLarge(): Response {\n return Response.json({ jsonrpc: '2.0', id: null,\n error: { code: -32603, message: 'MCP response exceeds maxResponseBytes' } }, { status: 500 })\n}\nasync function settleClose(close: () => Promise<void>): Promise<void> { try { await close() } catch {} }\nfunction objectValue(value: unknown): object {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) throw new TypeError('Invalid MCP server definition')\n return value\n}\nfunction ownValue(source: object, key: PropertyKey, required = true): unknown {\n const descriptor = Object.getOwnPropertyDescriptor(source, key)\n if (descriptor === undefined) {\n if (!required) return undefined\n throw new TypeError(`Missing MCP server field ${String(key)}`)\n }\n if (!('value' in descriptor)) throw new TypeError(`MCP server field ${String(key)} must be data`)\n return descriptor.value\n}\nfunction method(source: object, key: PropertyKey): Function {\n const value = Reflect.get(source, key)\n if (typeof value !== 'function') throw new TypeError(`MCP server method ${String(key)} is invalid`)\n return value\n}\nfunction identity(value: unknown, label: string): string {\n if (typeof value !== 'string' || value.length < 1 || value.length > 128) throw new TypeError(`${label} is invalid`)\n return value\n}\nfunction positive(value: unknown, label: string): number {\n if (!Number.isSafeInteger(value) || Number(value) < 1) throw new TypeError(`MCP server ${label} is invalid`)\n return Number(value)\n}\nfunction optionalObject<T>(value: unknown, label: string): T | undefined {\n if (value === undefined) return undefined\n if ((typeof value !== 'object' || value === null) && typeof value !== 'function') throw new TypeError(`${label} is invalid`)\n return value as T\n}\n"],"mappings":";;;;;AAEA,MAAa,oCAAoC,OAAO,OAAO;CAC7D,kBAAkB,OAAO,OAAO;EAAC;EAAW;EAAa;CAAY,CAAC;CACtE,oBAAoB,OAAO,OAAO;EAAC;EAAW;EAAa;EAAc;CAAO,CAAC;AACnF,CAAU;AAmBV,MAAM,WAAW,OAAO,OAAO;CAC7B,OAAO;CACP,SAAS;CACT,SAAS;CACT,SAAS;CACT,OAAO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,OAAO,QAAgB,KAA4B;CAC1D,MAAM,QAAQ,QAAQ,IAAI,QAAQ,GAAG;CACrC,IAAI,OAAO,UAAU,YAAY,MAAM,IAAI,UAAU,qBAAqB,OAAO,GAAG,EAAE,YAAY;CAClG,OAAO;AACT;AACA,SAAS,SAAS,OAAgB,OAAuB;CACvD,IAAI,OAAO,UAAU,YAAY,MAAM,SAAS,KAAK,MAAM,SAAS,KAAK,MAAM,IAAI,UAAU,GAAG,MAAM,YAAY;CAClH,OAAO;AACT;AACA,SAAS,SAAS,OAAgB,OAAuB;CACvD,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,UAAU,cAAc,MAAM,YAAY;CAC3G,OAAO,OAAO,KAAK;AACrB;AACA,SAAS,eAAkB,OAAgB,OAA8B;CACvE,IAAI,UAAU,QAAW,OAAO;CAChC,KAAK,OAAO,UAAU,YAAY,UAAU,SAAS,OAAO,UAAU,YAAY,MAAM,IAAI,UAAU,GAAG,MAAM,YAAY;CAC3H,OAAO;AACT"}
1
+ {"version":3,"file":"index.js","names":["assertIdentity"],"sources":["../src/common/integration-operation.ts","../src/common/preferred-state.ts","../src/common/config.ts","../src/server/advanced-support.ts","../src/server/advanced-calls.ts","../src/server/advanced-registration.ts","../src/server/advanced.ts","../src/preferred/server.ts"],"sourcesContent":["import type { IntegrationOperationEvidenceFields, SdkLogger } from '@alvin0/ai-agent-sdk-core/observability'\n\nexport const MCP_SERVER_INTEGRATION_OPERATIONS = Object.freeze({\n 'mcp-web-server': Object.freeze(['request', 'tool-call', 'agent-call']),\n 'mcp-stdio-server': Object.freeze(['request', 'tool-call', 'agent-call', 'close']),\n} as const)\n\nexport type McpServerIntegrationFamily = keyof typeof MCP_SERVER_INTEGRATION_OPERATIONS\nexport type McpServerIntegrationOperation =\n (typeof MCP_SERVER_INTEGRATION_OPERATIONS)[McpServerIntegrationFamily][number]\n\nexport interface IntegrationAttempt {\n success(): void\n fail(errorCode?: string): void\n abort(): void\n}\n\nexport interface IntegrationOperation {\n attempt(attemptNumber: number): IntegrationAttempt\n success(): void\n fail(errorCode?: string): void\n abort(): void\n}\n\nconst MESSAGES = Object.freeze({\n start: 'SDK integration operation started',\n attempt: 'SDK integration attempt started',\n success: 'SDK integration operation completed',\n failure: 'SDK integration operation failed',\n abort: 'SDK integration operation aborted',\n})\n\nexport function beginIntegrationOperation(\n logger: SdkLogger | undefined,\n family: McpServerIntegrationFamily,\n operation: McpServerIntegrationOperation,\n): IntegrationOperation {\n validateOperation(family, operation)\n const operationId = crypto.randomUUID(), startedAt = monotonicNow()\n emit(logger, 'info', MESSAGES.start, {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'logical-start',\n })\n let terminal = false\n const finish = (status: 'success' | 'error' | 'aborted', errorCode?: string): void => {\n if (terminal) return\n terminal = true\n emit(logger, status === 'error' ? 'error' : 'info', terminalMessage(status), {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'logical-terminal',\n status, durationMs: durationSince(startedAt),\n ...(errorCode === undefined ? {} : { errorCode: boundedCode(errorCode) }),\n })\n }\n return Object.freeze({\n attempt(attemptNumber: number) {\n if (!Number.isSafeInteger(attemptNumber) || attemptNumber < 1) {\n throw new TypeError('integration attemptNumber must be a positive safe integer')\n }\n const attemptId = crypto.randomUUID(), attemptStartedAt = monotonicNow()\n emit(logger, 'info', MESSAGES.attempt, {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'attempt-start',\n attemptId, attemptNumber,\n })\n let attemptTerminal = false\n const finishAttempt = (status: 'success' | 'error' | 'aborted', errorCode?: string): void => {\n if (attemptTerminal) return\n attemptTerminal = true\n emit(logger, status === 'error' ? 'error' : 'info', terminalMessage(status), {\n integrationSchemaVersion: 1, integrationFamily: family,\n integrationOperation: operation, operationId, kind: 'attempt-terminal',\n attemptId, attemptNumber, status, durationMs: durationSince(attemptStartedAt),\n ...(errorCode === undefined ? {} : { errorCode: boundedCode(errorCode) }),\n })\n }\n return Object.freeze({\n success: () => finishAttempt('success'),\n fail: (code?: string) => finishAttempt('error', code),\n abort: () => finishAttempt('aborted'),\n })\n },\n success: () => finish('success'),\n fail: (code?: string) => finish('error', code),\n abort: () => finish('aborted'),\n })\n}\n\nexport function integrationErrorCode(error: unknown): string {\n if (typeof error === 'object' && error !== null) {\n for (const key of ['code', 'name']) {\n const descriptor = Object.getOwnPropertyDescriptor(error, key)\n if (descriptor !== undefined && 'value' in descriptor && typeof descriptor.value === 'string') {\n return boundedCode(descriptor.value)\n }\n }\n }\n return 'INTEGRATION_ERROR'\n}\n\nexport function integrationChildLogger(logger: SdkLogger | undefined, scope: string): SdkLogger | undefined {\n assertIdentity(scope, 64, 'integration scope')\n try { return logger?.child({ integrationScope: scope }) } catch { return undefined }\n}\n\nfunction validateOperation(family: McpServerIntegrationFamily, operation: McpServerIntegrationOperation): void {\n const operations = MCP_SERVER_INTEGRATION_OPERATIONS[family] as readonly string[] | undefined\n assertIdentity(family, 64, 'integration family')\n assertIdentity(operation, 64, 'integration operation')\n if (operations === undefined || !operations.includes(operation)) {\n throw new TypeError('Invalid MCP integration operation')\n }\n}\n\nfunction emit(logger: SdkLogger | undefined, level: 'info' | 'error', message: string,\n fields: IntegrationOperationEvidenceFields): void {\n try { logger?.[level](message, fields) } catch { /* logging never owns protocol completion */ }\n}\n\nfunction terminalMessage(status: 'success' | 'error' | 'aborted'): string {\n if (status === 'success') return MESSAGES.success\n if (status === 'error') return MESSAGES.failure\n return MESSAGES.abort\n}\nfunction monotonicNow(): number { return performance.now() }\nfunction durationSince(startedAt: number): number {\n const value = monotonicNow() - startedAt\n return Number.isFinite(value) ? Math.max(0, value) : 0\n}\nfunction boundedCode(value: string): string {\n const normalized = value.replace(/[^A-Za-z0-9_.:-]/g, '_')\n return (normalized.length === 0 ? 'INTEGRATION_ERROR' : normalized).slice(0, 128)\n}\nfunction assertIdentity(value: string, limit: number, label: string): void {\n if (typeof value !== 'string' || value.length === 0 || value.length > limit) {\n throw new TypeError(`${label} must contain 1-${limit} characters`)\n }\n}\n","import type { RuntimeAgentResponse } from '@alvin0/ai-agent-sdk-core/agent'\nimport type { SdkMcpRequestContext, SdkMcpServer } from './server-public-types.ts'\n\nexport type McpServerRuntimeFamily = 'mcp-web-server' | 'mcp-stdio-server'\n\nexport interface PreferredServerState {\n readonly agents: Readonly<Record<string, PreferredServerAgent>>\n}\n\nexport interface PreferredServerAgent {\n generate(input: string, options: { readonly signal?: AbortSignal }): Promise<RuntimeAgentResponse>\n}\n\nexport type InternalMcpServerFactory = (\n request: SdkMcpRequestContext,\n family: McpServerRuntimeFamily,\n) => SdkMcpServer\n\nexport const MCP_WEB_SERVER_FACTORY = Symbol.for('ai-agent-sdk.mcp-web-server.factory.v1')\n\nconst STATES = new WeakMap<object, PreferredServerState>()\n\nexport function attachPreferredState(options: object, state: PreferredServerState): void {\n STATES.set(options, state)\n}\n\nexport function copyPreferredState(source: object, target: object): void {\n const state = STATES.get(source)\n if (state !== undefined) STATES.set(target, state)\n}\n\nexport function preferredState(options: object): PreferredServerState | undefined {\n return STATES.get(options)\n}\n\nexport function internalMcpServerFactory(value: unknown): InternalMcpServerFactory | undefined {\n if ((typeof value !== 'object' || value === null) && typeof value !== 'function') return undefined\n const descriptor = Object.getOwnPropertyDescriptor(value, MCP_WEB_SERVER_FACTORY)\n return descriptor !== undefined && 'value' in descriptor && typeof descriptor.value === 'function'\n ? descriptor.value as InternalMcpServerFactory : undefined\n}\n","/** Internal limits shared by preferred and advanced Universal MCP servers. */\nexport const MCP_SERVER_DEFAULTS = Object.freeze({\n maxExports: 1_024,\n maxDefinitionBytes: 4 * 1024 * 1024,\n maxInputBytes: 1024 * 1024,\n maxOutputBytes: 4 * 1024 * 1024,\n operationTimeoutMs: 10 * 60_000,\n teardownTimeoutMs: 30_000,\n observerTimeoutMs: 5_000,\n})\n","import { waitForSettlement } from '@alvin0/ai-agent-sdk-core'\nimport { MCP_SERVER_DEFAULTS } from '../common/config.ts'\nimport type { SdkMcpServerOptions, McpServerErrorContext } from './advanced-types.ts'\n\nexport interface ResolvedMcpServerLimits {\n readonly maxExports: number\n readonly maxDefinitionBytes: number\n readonly maxInputBytes: number\n readonly maxOutputBytes: number\n readonly operationTimeoutMs: number\n readonly teardownTimeoutMs: number\n readonly observerTimeoutMs: number\n}\n\n\nexport function assertIdentity(value: string, field: string): void {\n if (value.trim().length === 0) throw new TypeError(`${field} must not be empty`)\n}\n\nfunction errorMessage(value: unknown): string {\n return value instanceof Error && value.message.length > 0 ? value.message : String(value)\n}\n\nexport function resolveLimits(options: SdkMcpServerOptions): ResolvedMcpServerLimits {\n return {\n maxExports: positiveSafeInteger(options.maxExports ?? MCP_SERVER_DEFAULTS.maxExports, 'maxExports'),\n maxDefinitionBytes: positiveSafeInteger(\n options.maxDefinitionBytes ?? MCP_SERVER_DEFAULTS.maxDefinitionBytes, 'maxDefinitionBytes',\n ),\n maxInputBytes: positiveSafeInteger(options.maxInputBytes ?? MCP_SERVER_DEFAULTS.maxInputBytes, 'maxInputBytes'),\n maxOutputBytes: positiveSafeInteger(options.maxOutputBytes ?? MCP_SERVER_DEFAULTS.maxOutputBytes, 'maxOutputBytes'),\n operationTimeoutMs: positiveSafeInteger(\n options.operationTimeoutMs ?? MCP_SERVER_DEFAULTS.operationTimeoutMs, 'operationTimeoutMs',\n ),\n teardownTimeoutMs: positiveSafeInteger(\n options.teardownTimeoutMs ?? MCP_SERVER_DEFAULTS.teardownTimeoutMs, 'teardownTimeoutMs',\n ),\n observerTimeoutMs: positiveSafeInteger(\n options.observerTimeoutMs ?? MCP_SERVER_DEFAULTS.observerTimeoutMs, 'observerTimeoutMs',\n ),\n }\n}\n\nexport async function reportError(\n options: SdkMcpServerOptions,\n limits: ResolvedMcpServerLimits,\n error: unknown,\n evidence: McpServerErrorContext,\n): Promise<void> {\n if (options.onError === undefined) return\n const pending = Promise.resolve().then(() => options.onError?.(error, Object.freeze({\n ...evidence,\n })))\n await waitForSettlement(pending, limits.observerTimeoutMs)\n}\n\nexport function internalErrorMessage(options: SdkMcpServerOptions, error: unknown, fallback: string): string {\n return options.exposeInternalErrors === true ? errorMessage(error) : fallback\n}\n\nfunction positiveSafeInteger(value: number, label: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`MCP server ${label} must be a positive safe integer`)\n }\n return value\n}\n\nexport function serializedBytes(value: unknown): number {\n const serialized = JSON.stringify(value)\n if (serialized === undefined) throw new TypeError('MCP server value is not JSON serializable')\n return new TextEncoder().encode(serialized).byteLength\n}\n\nexport async function raceWithSignal<T>(\n pending: Promise<T>,\n signal: AbortSignal,\n teardownTimeoutMs: number,\n): Promise<T> {\n if (signal.aborted) throw signal.reason ?? new Error('MCP server operation aborted')\n try {\n return await new Promise<T>((resolve, reject) => {\n const abort = () => {\n signal.removeEventListener('abort', abort)\n reject(signal.reason ?? new Error('MCP server operation aborted'))\n }\n signal.addEventListener('abort', abort, { once: true })\n void pending.then(\n value => { signal.removeEventListener('abort', abort); resolve(value) },\n error => { signal.removeEventListener('abort', abort); reject(error) },\n )\n })\n } catch (error: unknown) {\n if (signal.aborted) await waitForSettlement(pending, teardownTimeoutMs)\n throw error\n }\n}","import type { AgentSession } from '@alvin0/ai-agent-sdk-core/agent'\nimport {\n type CallToolResult,\n type ServerContext,\n} from '@modelcontextprotocol/server'\nimport type { ContentBlock } from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId, isJsonValue, type JsonValue } from '@alvin0/ai-agent-sdk-core'\nimport type { ToolCatalog } from '@alvin0/ai-agent-sdk-core/tools'\nimport {\n dispatchToolCall,\n} from '@alvin0/ai-agent-sdk-core/tools'\nimport {\n beginIntegrationOperation,\n integrationErrorCode,\n type McpServerIntegrationFamily,\n} from '../common/integration-operation.ts'\nimport { type PreferredServerAgent } from '../common/preferred-state.ts'\nimport type {\n SdkMcpRequestContext,\n} from '../common/server-public-types.ts'\nimport type { SdkMcpServerOptions, McpAgentTool } from './advanced-types.ts'\nimport type { IntegrationAttempt, IntegrationOperation } from '../common/integration-operation.ts'\nimport { resolveLimits, serializedBytes, raceWithSignal, reportError, internalErrorMessage,\n type ResolvedMcpServerLimits ,\n} from './advanced-support.ts'\n\ntype McpResultBlock = CallToolResult['content'][number]\n\nexport function serverFamily(options: SdkMcpServerOptions): McpServerIntegrationFamily {\n return options.integrationFamily ?? 'mcp-web-server'\n}\n\nexport async function callRuntimeAgent(\n options: SdkMcpServerOptions,\n definition: { name: string; agent: PreferredServerAgent },\n args: { input: string },\n context: ServerContext,\n): Promise<CallToolResult> {\n const { name, agent } = definition\n const limits = resolveLimits(options)\n const operation = beginIntegrationOperation(options.logger, serverFamily(options), 'agent-call')\n const attempt = operation.attempt(1)\n if (serializedBytes(args) > limits.maxInputBytes) {\n attempt.fail('INPUT_TOO_LARGE'); operation.fail('INPUT_TOO_LARGE')\n return errorResult(`agent input exceeds the ${limits.maxInputBytes}-byte limit`, 'INPUT_TOO_LARGE')\n }\n const signal = AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)])\n try {\n const response = await raceWithSignal(agent.generate(args.input, { signal }), signal, limits.teardownTimeoutMs)\n const result: CallToolResult = {\n content: [{ type: 'text', text: response.text || '(empty response)' }],\n structuredContent: { text: response.text, runId: response.runId, traceId: response.traceId },\n }\n if (serializedBytes(result) > limits.maxOutputBytes) {\n attempt.fail('OUTPUT_TOO_LARGE'); operation.fail('OUTPUT_TOO_LARGE')\n return errorResult(`agent result exceeds the ${limits.maxOutputBytes}-byte limit`, 'OUTPUT_TOO_LARGE')\n }\n attempt.success(); operation.success()\n return result\n } catch (error: unknown) {\n const code = integrationErrorCode(error)\n if (signal.aborted) { attempt.abort(); operation.abort() }\n else { attempt.fail(code); operation.fail(code) }\n await reportError(options, limits, error, {\n operation: 'agent', exportName: name, requestId: String(context.mcpReq.id),\n })\n return errorResult(internalErrorMessage(options, error, 'agent operation failed'), 'AGENT_FAILED')\n }\n}\n\nexport async function callSdkTool(\n options: SdkMcpServerOptions,\n toolName: string,\n args: Record<string, unknown>,\n context: ServerContext,\n): Promise<CallToolResult> {\n const limits = resolveLimits(options)\n const operation = beginIntegrationOperation(options.logger, serverFamily(options), 'tool-call')\n const attempt = operation.attempt(1)\n if (serializedBytes(args) > limits.maxInputBytes) {\n attempt.fail('INPUT_TOO_LARGE'); operation.fail('INPUT_TOO_LARGE')\n return errorResult(`tool input exceeds the ${limits.maxInputBytes}-byte limit`, 'INPUT_TOO_LARGE')\n }\n const catalog = options.tools\n if (catalog === undefined) {\n attempt.fail('UNKNOWN_TOOL'); operation.fail('UNKNOWN_TOOL')\n return errorResult(`tool '${toolName}' is not available`, 'UNKNOWN_TOOL')\n }\n try {\n const result = await dispatchSdkTool({ options, toolName, args, context, catalog, limits })\n if (serializedBytes(result) > limits.maxOutputBytes) {\n attempt.fail('OUTPUT_TOO_LARGE'); operation.fail('OUTPUT_TOO_LARGE')\n return errorResult(`tool result exceeds the ${limits.maxOutputBytes}-byte limit`, 'OUTPUT_TOO_LARGE')\n }\n return renderToolResult(result, { attempt, operation })\n } catch (error: unknown) {\n const code = integrationErrorCode(error)\n attempt.fail(code); operation.fail(code)\n await reportError(options, limits, error, {\n operation: 'tool', exportName: toolName, requestId: String(context.mcpReq.id),\n })\n return errorResult(internalErrorMessage(options, error, 'tool operation failed'), 'TOOL_OPERATION_FAILED')\n }\n}\n\nexport async function callAgent(\n options: SdkMcpServerOptions,\n invocation: { definition: McpAgentTool; request: SdkMcpRequestContext },\n args: { input: string; conversationId?: string },\n context: ServerContext,\n): Promise<CallToolResult> {\n const { definition, request } = invocation\n const limits = resolveLimits(options)\n const operation = beginIntegrationOperation(options.logger, serverFamily(options), 'agent-call')\n const attempt = operation.attempt(1)\n if (serializedBytes(args) > limits.maxInputBytes) {\n attempt.fail('INPUT_TOO_LARGE'); operation.fail('INPUT_TOO_LARGE')\n return errorResult(`agent input exceeds the ${limits.maxInputBytes}-byte limit`, 'INPUT_TOO_LARGE')\n }\n const signal = AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)])\n try {\n const session = await createAgentSession({ definition, request, args, context, signal, limits })\n if (session.definition.id !== definition.agent.id) {\n attempt.fail('WRONG_AGENT_SESSION'); operation.fail('WRONG_AGENT_SESSION')\n return errorResult(\n `session factory for '${definition.name}' returned agent '${session.definition.id}', `\n + `expected '${definition.agent.id}'`,\n 'WRONG_AGENT_SESSION',\n )\n }\n return await runAgentSession(session, args.input, { signal, limits, attempt, operation })\n } catch (error: unknown) {\n const code = integrationErrorCode(error)\n if (signal.aborted) { attempt.abort(); operation.abort() }\n else { attempt.fail(code); operation.fail(code) }\n await reportError(options, limits, error, {\n operation: 'agent', exportName: definition.name, requestId: String(context.mcpReq.id),\n })\n return errorResult(internalErrorMessage(options, error, 'agent operation failed'), 'AGENT_FAILED')\n }\n}\n\nfunction toMcpContent(blocks: readonly ContentBlock[]): McpResultBlock[] {\n const result: McpResultBlock[] = []\n for (const block of blocks) {\n if (block.type === 'text') {\n result.push({ type: 'text', text: block.text })\n continue\n }\n if (block.type === 'image' && block.source.kind === 'base64') {\n result.push({\n type: 'image',\n data: block.source.data,\n mimeType: block.source.mediaType,\n })\n continue\n }\n if (block.type === 'image' && block.source.kind === 'url') {\n result.push({ type: 'text', text: `[image](${block.source.url})` })\n continue\n }\n if (block.type === 'image' && block.source.kind === 'file') {\n result.push({ type: 'text', text: `[image file: ${block.source.fileId}]` })\n continue\n }\n if (block.type === 'reasoning') {\n result.push({ type: 'text', text: block.text })\n continue\n }\n result.push({ type: 'text', text: JSON.stringify(jsonSafeBlock(block)) })\n }\n return result\n}\n\nfunction jsonSafeBlock(block: ContentBlock): JsonValue {\n if (isJsonValue(block)) return block\n return { type: block.type }\n}\n\nfunction errorResult(message: string, code: string): CallToolResult {\n return {\n isError: true,\n content: [{ type: 'text', text: `Error: ${message}` }],\n structuredContent: { error: { message, code } },\n }\n}\n\nfunction dispatchSdkTool(input: {\n options: SdkMcpServerOptions; toolName: string; args: Record<string, unknown>; context: ServerContext;\n catalog: ToolCatalog; limits: ResolvedMcpServerLimits;\n}) {\n const { options, toolName, args, context, catalog, limits } = input\n return dispatchToolCall({\n catalog,\n call: {\n callId: ToolCallId(`mcp:${String(context.mcpReq.id)}`),\n toolName,\n rawArguments: JSON.stringify(args),\n },\n position: { turn: 1, step: 1 },\n signal: AbortSignal.any([context.mcpReq.signal, AbortSignal.timeout(limits.operationTimeoutMs)]),\n defaultTimeoutMs: limits.operationTimeoutMs,\n teardownTimeoutMs: limits.teardownTimeoutMs,\n ...(options.approvals === undefined ? {} : { approvals: options.approvals }),\n ...(options.interceptors === undefined ? {} : { interceptors: options.interceptors }),\n })\n}\n\nfunction renderToolResult(\n result: Awaited<ReturnType<typeof dispatchSdkTool>>,\n evidence: { attempt: IntegrationAttempt; operation: IntegrationOperation },\n): CallToolResult {\n const { attempt, operation } = evidence\n const content = [\n ...toMcpContent(result.content),\n ...toMcpContent(result.additionalContext ?? []),\n ]\n if (result.isError) {\n attempt.fail(result.error.code); operation.fail(result.error.code)\n return {\n isError: true,\n content: content.length === 0 ? [{ type: 'text', text: result.error.message }] : content,\n structuredContent: { error: result.error },\n }\n }\n attempt.success(); operation.success()\n return {\n content: content.length === 0 ? [{ type: 'text', text: '(no output)' }] : content,\n ...(result.value === undefined ? {} : { structuredContent: result.value }),\n }\n}\n\nfunction createAgentSession(input: {\n definition: McpAgentTool; request: SdkMcpRequestContext; args: { conversationId?: string };\n context: ServerContext; signal: AbortSignal; limits: ResolvedMcpServerLimits;\n}) {\n const { definition, request, args, context, signal, limits } = input\n const creating = Promise.resolve(definition.createSession({\n ...(args.conversationId === undefined ? {} : { conversationId: args.conversationId }),\n request,\n call: context,\n }))\n return raceWithSignal(creating, signal, limits.teardownTimeoutMs)\n}\n\nasync function runAgentSession(\n session: AgentSession, input: string,\n evidence: { signal: AbortSignal; limits: ResolvedMcpServerLimits;\n attempt: IntegrationAttempt; operation: IntegrationOperation },\n): Promise<CallToolResult> {\n const { signal, limits, attempt, operation } = evidence\n const running = session.run(input, { signal })\n const response = await raceWithSignal(running, signal, limits.teardownTimeoutMs)\n if (!isJsonValue(response.outcome)) {\n attempt.fail('INVALID_AGENT_RESULT'); operation.fail('INVALID_AGENT_RESULT')\n return errorResult('agent outcome was not lossless JSON', 'INVALID_AGENT_RESULT')\n }\n const result: CallToolResult = {\n content: [{ type: 'text', text: response.text || '(empty response)' }],\n structuredContent: {\n text: response.text,\n outcome: response.outcome,\n conversationId: session.conversationId,\n },\n }\n if (serializedBytes(result) > limits.maxOutputBytes) {\n attempt.fail('OUTPUT_TOO_LARGE'); operation.fail('OUTPUT_TOO_LARGE')\n return errorResult(`agent result exceeds the ${limits.maxOutputBytes}-byte limit`, 'OUTPUT_TOO_LARGE')\n }\n attempt.success(); operation.success()\n return result\n}\n","import {\n McpServer,\n fromJsonSchema,\n} from '@modelcontextprotocol/server'\nimport type { ToolCatalog } from '@alvin0/ai-agent-sdk-core/tools'\nimport { preferredState, type PreferredServerAgent } from '../common/preferred-state.ts'\nimport type {\n SdkMcpRequestContext,\n} from '../common/server-public-types.ts'\nimport type { SdkMcpServerOptions } from './advanced-types.ts'\nimport { assertIdentity, serializedBytes, type ResolvedMcpServerLimits } from './advanced-support.ts'\nimport { callAgent, callRuntimeAgent, callSdkTool } from './advanced-calls.ts'\n\ninterface RegistrationContext {\n server: McpServer; names: Set<string>; options: SdkMcpServerOptions; request: SdkMcpRequestContext;\n}\n\nexport function registerExports(ctx: RegistrationContext, limits: ResolvedMcpServerLimits): void {\n const { options } = ctx\n const schemas = options.tools?.schemas() ?? []\n const runtimeAgents = Object.entries(preferredState(options)?.agents ?? {})\n validateExports({ options, schemas, runtimeAgents, limits })\n registerTools(ctx, schemas)\n registerAgents(ctx)\n registerRuntimeAgents(ctx, runtimeAgents)\n}\n\nfunction registerTools(ctx: RegistrationContext, schemas: ReturnType<ToolCatalog['schemas']>): void {\n const { server, names, options } = ctx\n for (const schema of schemas) {\n if (names.has(schema.name)) throw new TypeError(`duplicate MCP export '${schema.name}'`)\n names.add(schema.name)\n server.registerTool(\n schema.name,\n {\n description: schema.description,\n // The Worker/browser validator dereferences by attaching private\n // metadata. SDK tool schemas are intentionally frozen, so give the\n // protocol boundary an isolated mutable copy.\n inputSchema: fromJsonSchema<Record<string, unknown>>(structuredClone(schema.parameters)),\n },\n async (args, context) => await callSdkTool(options, schema.name, args, context),\n )\n }\n}\n\nfunction registerAgents(ctx: RegistrationContext): void {\n const { server, names, options, request } = ctx\n for (const agent of options.agents ?? []) {\n assertIdentity(agent.name, 'agent MCP tool name')\n if (names.has(agent.name)) throw new TypeError(`duplicate MCP export '${agent.name}'`)\n names.add(agent.name)\n server.registerTool(\n agent.name,\n {\n description: agent.description\n ?? agent.agent.description\n ?? `Run the ${agent.agent.name} agent for one conversational turn.`,\n inputSchema: fromJsonSchema<{ input: string; conversationId?: string }>({\n type: 'object',\n properties: {\n input: { type: 'string', minLength: 1 },\n conversationId: { type: 'string', minLength: 1 },\n },\n required: ['input'],\n additionalProperties: false,\n }),\n },\n async (args, context) => await callAgent(options, { definition: agent, request }, args, context),\n )\n }\n}\n\nfunction registerRuntimeAgents(\n ctx: RegistrationContext, runtimeAgents: [string, PreferredServerAgent][],\n): void {\n const { server, names, options } = ctx\n for (const [name, agent] of runtimeAgents) {\n assertIdentity(name, 'agent MCP tool name')\n if (names.has(name)) throw new TypeError(`duplicate MCP export '${name}'`)\n names.add(name)\n server.registerTool(name, {\n description: `Run the ${name} agent for one turn.`,\n inputSchema: fromJsonSchema<{ input: string }>({\n type: 'object', properties: { input: { type: 'string', minLength: 1 } },\n required: ['input'], additionalProperties: false,\n }),\n }, async (args, context) => await callRuntimeAgent(options, { name, agent }, args, context))\n }\n}\n\nfunction validateExports(input: {\n options: SdkMcpServerOptions; schemas: ReturnType<ToolCatalog['schemas']>;\n runtimeAgents: [string, PreferredServerAgent][]; limits: ResolvedMcpServerLimits;\n}): void {\n const { options, schemas, runtimeAgents, limits } = input\n if (schemas.length + (options.agents?.length ?? 0) + runtimeAgents.length > limits.maxExports) {\n throw new RangeError(`MCP server exceeds the ${limits.maxExports}-export limit`)\n }\n if (serializedBytes([schemas, options.agents?.map(agent => ({\n name: agent.name, description: agent.description, agentId: agent.agent.id,\n })) ?? [], runtimeAgents.map(([name]) => ({ name }))]) > limits.maxDefinitionBytes) {\n throw new RangeError(`MCP server definitions exceed the ${limits.maxDefinitionBytes}-byte limit`)\n }\n}\n","/** Export SDK tools and agents as a Universal fetch-shaped MCP server. */\n\nimport {\n McpServer,\n createMcpHandler,\n type CreateMcpHandlerOptions,\n} from '@modelcontextprotocol/server'\nimport {\n beginIntegrationOperation,\n integrationChildLogger,\n integrationErrorCode,\n} from '../common/integration-operation.ts'\nimport { copyPreferredState } from '../common/preferred-state.ts'\nimport type {\n SdkMcpHandlerOptions,\n SdkMcpHandlerRequestOptions,\n SdkMcpHttpHandler,\n SdkMcpRequestContext,\n SdkMcpServer,\n} from '../common/server-public-types.ts'\n\nexport type * from '../common/server-public-types.ts'\nexport type { McpAgentSessionContext, McpAgentTool, McpServerErrorContext, SdkMcpServerOptions }\n from './advanced-types.ts'\nimport type { SdkMcpServerOptions } from './advanced-types.ts'\nimport { assertIdentity, resolveLimits } from './advanced-support.ts'\nimport { registerExports } from './advanced-registration.ts'\nimport { serverFamily } from './advanced-calls.ts'\n\n/** Create one MCP server instance for a connection or HTTP request. */\nexport function createSdkMcpServer(\n options: SdkMcpServerOptions,\n request: SdkMcpRequestContext = { era: 'modern' },\n): SdkMcpServer {\n const limits = resolveLimits(options)\n assertIdentity(options.name, 'server name')\n if (options.version.trim().length === 0) throw new TypeError('MCP server version must not be empty')\n const server = new McpServer(\n { name: options.name, version: options.version },\n {\n capabilities: { tools: { listChanged: false } },\n ...(options.instructions === undefined ? {} : { instructions: options.instructions }),\n },\n )\n const names = new Set<string>()\n registerExports({ server, names, options, request }, limits)\n return server as unknown as SdkMcpServer\n}\n\n/** Create a fetch-shaped API for hosts that accept Request/Response. */\nexport function createSdkMcpHandler(\n options: SdkMcpServerOptions,\n handlerOptions?: SdkMcpHandlerOptions,\n): SdkMcpHttpHandler {\n const handler = createMcpHandler(\n request => createSdkMcpServer(withRequestLogger(options), request as SdkMcpRequestContext) as unknown as McpServer,\n handlerOptions as CreateMcpHandlerOptions,\n )\n return {\n fetch: async (request: Request, requestOptions?: SdkMcpHandlerRequestOptions) => {\n const operation = beginIntegrationOperation(\n integrationChildLogger(options.logger, 'mcp-server-request'), serverFamily(options), 'request',\n )\n const attempt = operation.attempt(1)\n try {\n const response = await handler.fetch(request, requestOptions as never)\n if (response.status >= 500) {\n attempt.fail(`HTTP_${response.status}`); operation.fail(`HTTP_${response.status}`)\n } else {\n attempt.success(); operation.success()\n }\n return response\n } catch (error: unknown) {\n const code = integrationErrorCode(error)\n attempt.fail(code); operation.fail(code)\n throw error\n }\n },\n close: handler.close,\n notify: handler.notify,\n bus: handler.bus,\n } as unknown as SdkMcpHttpHandler\n}\n\nfunction withRequestLogger(options: SdkMcpServerOptions): SdkMcpServerOptions {\n const logger = integrationChildLogger(options.logger, 'mcp-server-request')\n if (logger === undefined) return options\n const child = { ...options, logger }\n copyPreferredState(options, child)\n return child\n}\n","import type { RuntimeAgent, RuntimeAgentInvocationOptions, RuntimeAgentResponse } from '@alvin0/ai-agent-sdk-core/agent'\nimport type { SdkLogger, ToolCatalog } from '@alvin0/ai-agent-sdk-core/tools'\nimport { createSdkMcpHandler, createSdkMcpServer, type SdkMcpServerOptions } from '../server/advanced.ts'\nimport {\n attachPreferredState, copyPreferredState, MCP_WEB_SERVER_FACTORY,\n type InternalMcpServerFactory, type PreferredServerAgent,\n} from '../common/preferred-state.ts'\nimport { MCP_SERVER_DEFAULTS } from '../common/config.ts'\n\nexport interface McpServerDefinition {\n readonly id: string\n readonly logger?: SdkLogger\n readonly tools?: ToolCatalog\n readonly agents?: Readonly<Record<string, RuntimeAgent>>\n readonly maxRequestBytes?: number\n readonly maxResponseBytes?: number\n}\n\nexport interface McpWebServer {\n handle(request: Request, options?: { readonly signal?: AbortSignal }): Promise<Response>\n}\n\n/** Capture one inert Web-standard server definition; each handle call owns its request resources. */\nexport function createMcpServer(definition: McpServerDefinition): McpWebServer {\n const source = objectValue(definition)\n const id = identity(ownValue(source, 'id'), 'MCP server id')\n const logger = optionalObject<SdkLogger>(ownValue(source, 'logger', false), 'MCP server logger')\n const tools = captureToolCatalog(ownValue(source, 'tools', false))\n const agents = captureAgents(ownValue(source, 'agents', false))\n const maxRequestBytes = positive(\n ownValue(source, 'maxRequestBytes', false) ?? MCP_SERVER_DEFAULTS.maxInputBytes, 'maxRequestBytes',\n )\n const maxResponseBytes = positive(\n ownValue(source, 'maxResponseBytes', false) ?? MCP_SERVER_DEFAULTS.maxOutputBytes, 'maxResponseBytes',\n )\n const advanced: SdkMcpServerOptions = Object.freeze({\n name: id, version: '1.0.0',\n ...(logger === undefined ? {} : { logger }),\n ...(tools === undefined ? {} : { tools }),\n maxInputBytes: maxRequestBytes, maxOutputBytes: maxResponseBytes,\n })\n attachPreferredState(advanced, Object.freeze({ agents }))\n\n const factory: InternalMcpServerFactory = (request, family) => {\n const scoped: SdkMcpServerOptions = { ...advanced, integrationFamily: family }\n copyPreferredState(advanced, scoped)\n return createSdkMcpServer(scoped, request)\n }\n const handle = async (request: Request, options?: { readonly signal?: AbortSignal }): Promise<Response> => {\n if (!(request instanceof Request)) throw new TypeError('MCP Web server requires a Request')\n const signal = options?.signal === undefined ? request.signal\n : AbortSignal.any([request.signal, options.signal])\n signal.throwIfAborted()\n const forwarded = signal === request.signal ? request : new Request(request, { signal })\n if (!await requestFits(forwarded, maxRequestBytes)) return payloadTooLarge()\n const handlerOptions: SdkMcpServerOptions = { ...advanced, integrationFamily: 'mcp-web-server' }\n copyPreferredState(advanced, handlerOptions)\n const handler = createSdkMcpHandler(handlerOptions)\n try {\n const response = await handler.fetch(forwarded)\n return boundedResponse(response, maxResponseBytes, handler.close)\n } catch (error: unknown) {\n await settleClose(handler.close)\n throw error\n }\n }\n const result = { handle }\n Object.defineProperty(result, MCP_WEB_SERVER_FACTORY, { value: factory, enumerable: false })\n return Object.freeze(result)\n}\n\nfunction captureAgents(value: unknown): Readonly<Record<string, PreferredServerAgent>> {\n if (value === undefined) return Object.freeze({})\n const source = objectValue(value), entries: [string, PreferredServerAgent][] = []\n for (const key of Reflect.ownKeys(source)) {\n if (typeof key !== 'string') throw new TypeError('MCP agent names must be strings')\n identity(key, 'MCP agent name')\n const agent = objectValue(ownValue(source, key)) as RuntimeAgent\n const generate = method(agent, 'generate')\n entries.push([key, Object.freeze({\n generate: (input: string, options: RuntimeAgentInvocationOptions): Promise<RuntimeAgentResponse> =>\n Reflect.apply(generate, agent, [input, options]) as Promise<RuntimeAgentResponse>,\n })])\n }\n return Object.freeze(Object.fromEntries(entries))\n}\n\nfunction captureToolCatalog(value: unknown): ToolCatalog | undefined {\n if (value === undefined) return undefined\n const catalog = objectValue(value) as ToolCatalog\n const get = method(catalog, 'get'), has = method(catalog, 'has'), names = method(catalog, 'names')\n const schemas = method(catalog, 'schemas'), executionMode = method(catalog, 'executionMode')\n return Object.freeze({\n get: (name: string) => Reflect.apply(get, catalog, [name]) as ReturnType<ToolCatalog['get']>,\n has: (name: string) => Reflect.apply(has, catalog, [name]) as boolean,\n names: () => Reflect.apply(names, catalog, []) as readonly string[],\n schemas: () => Reflect.apply(schemas, catalog, []) as ReturnType<ToolCatalog['schemas']>,\n executionMode(name: string, args: unknown): 'parallel' | 'exclusive' {\n return Reflect.apply(executionMode, catalog, [name, args]) as 'parallel' | 'exclusive'\n },\n })\n}\n\nasync function requestFits(request: Request, limit: number): Promise<boolean> {\n const declared = request.headers.get('content-length')\n if (declared !== null) {\n const bytes = Number(declared)\n if (!Number.isSafeInteger(bytes) || bytes < 0 || bytes > limit) return false\n }\n if (request.body === null) return true\n try { return (await request.clone().arrayBuffer()).byteLength <= limit } catch { return false }\n}\n\nfunction boundedResponse(response: Response, limit: number, close: () => Promise<void>): Response {\n if (response.body === null) { void settleClose(close); return response }\n const declared = response.headers.get('content-length')\n if (declared !== null && Number(declared) > limit) {\n void response.body.cancel(); void settleClose(close)\n return responseTooLarge()\n }\n const reader = response.body.getReader()\n let bytes = 0, closed = false\n const finish = async (): Promise<void> => {\n if (closed) return\n closed = true\n await settleClose(close)\n }\n const body = new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const next = await reader.read()\n if (next.done) { controller.close(); await finish(); return }\n bytes += next.value.byteLength\n if (bytes > limit) {\n await reader.cancel(); await finish()\n controller.error(new RangeError('MCP response exceeded maxResponseBytes'))\n return\n }\n controller.enqueue(next.value)\n } catch (error: unknown) { await finish(); controller.error(error) }\n },\n async cancel(reason) { try { await reader.cancel(reason) } finally { await finish() } },\n })\n return new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers })\n}\n\nfunction payloadTooLarge(): Response {\n return Response.json({ jsonrpc: '2.0', id: null,\n error: { code: -32600, message: 'MCP request exceeds maxRequestBytes' } }, { status: 413 })\n}\nfunction responseTooLarge(): Response {\n return Response.json({ jsonrpc: '2.0', id: null,\n error: { code: -32603, message: 'MCP response exceeds maxResponseBytes' } }, { status: 500 })\n}\nasync function settleClose(close: () => Promise<void>): Promise<void> { try { await close() } catch {} }\nfunction objectValue(value: unknown): object {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError('Invalid MCP server definition')\n }\n return value\n}\nfunction ownValue(source: object, key: PropertyKey, required = true): unknown {\n const descriptor = Object.getOwnPropertyDescriptor(source, key)\n if (descriptor === undefined) {\n if (!required) return undefined\n throw new TypeError(`Missing MCP server field ${String(key)}`)\n }\n if (!('value' in descriptor)) throw new TypeError(`MCP server field ${String(key)} must be data`)\n return descriptor.value\n}\nfunction method(source: object, key: PropertyKey): Function {\n const value = Reflect.get(source, key)\n if (typeof value !== 'function') throw new TypeError(`MCP server method ${String(key)} is invalid`)\n return value\n}\nfunction identity(value: unknown, label: string): string {\n if (typeof value !== 'string' || value.length < 1 || value.length > 128) throw new TypeError(`${label} is invalid`)\n return value\n}\nfunction positive(value: unknown, label: string): number {\n if (!Number.isSafeInteger(value) || Number(value) < 1) throw new TypeError(`MCP server ${label} is invalid`)\n return Number(value)\n}\nfunction optionalObject<T>(value: unknown, label: string): T | undefined {\n if (value === undefined) return undefined\n if ((typeof value !== 'object' || value === null) && typeof value !== 'function') {\n throw new TypeError(`${label} is invalid`)\n }\n return value as T\n}\n"],"mappings":";;;;;AAEA,MAAa,oCAAoC,OAAO,OAAO;CAC7D,kBAAkB,OAAO,OAAO;EAAC;EAAW;EAAa;CAAY,CAAC;CACtE,oBAAoB,OAAO,OAAO;EAAC;EAAW;EAAa;EAAc;CAAO,CAAC;AACnF,CAAU;AAmBV,MAAM,WAAW,OAAO,OAAO;CAC7B,OAAO;CACP,SAAS;CACT,SAAS;CACT,SAAS;CACT,OAAO;AACT,CAAC;AAED,SAAgB,0BACd,QACA,QACA,WACsB;CACtB,kBAAkB,QAAQ,SAAS;CACnC,MAAM,cAAc,OAAO,WAAW,GAAG,YAAY,aAAa;CAClE,KAAK,QAAQ,QAAQ,SAAS,OAAO;EACnC,0BAA0B;EAAG,mBAAmB;EAChD,sBAAsB;EAAW;EAAa,MAAM;CACtD,CAAC;CACD,IAAI,WAAW;CACf,MAAM,UAAU,QAAyC,cAA6B;EACpF,IAAI,UAAU;EACd,WAAW;EACX,KAAK,QAAQ,WAAW,UAAU,UAAU,QAAQ,gBAAgB,MAAM,GAAG;GAC3E,0BAA0B;GAAG,mBAAmB;GAChD,sBAAsB;GAAW;GAAa,MAAM;GACpD;GAAQ,YAAY,cAAc,SAAS;GAC3C,GAAI,cAAc,SAAY,CAAC,IAAI,EAAE,WAAW,YAAY,SAAS,EAAE;EACzE,CAAC;CACH;CACA,OAAO,OAAO,OAAO;EACnB,QAAQ,eAAuB;GAC7B,IAAI,CAAC,OAAO,cAAc,aAAa,KAAK,gBAAgB,GAC1D,MAAM,IAAI,UAAU,2DAA2D;G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AAkB,OAAgB,OAA8B;CACvE,IAAI,UAAU,QAAW,OAAO;CAChC,KAAK,OAAO,UAAU,YAAY,UAAU,SAAS,OAAO,UAAU,YACpE,MAAM,IAAI,UAAU,GAAG,MAAM,YAAY;CAE3C,OAAO;AACT"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "alvin0 - chaulamdinhai",
5
5
  "email": "chaulamdinhai@gmail.com"
6
6
  },
7
- "version": "0.1.10",
7
+ "version": "0.1.11",
8
8
  "description": "Universal Web Standards MCP server hosting for ai-agent-sdk",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -38,13 +38,13 @@
38
38
  "provenance": true
39
39
  },
40
40
  "dependencies": {
41
- "@modelcontextprotocol/server": "2.0.0"
41
+ "@modelcontextprotocol/server": "2.2.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@alvin0/ai-agent-sdk-core": "^0.1.10"
44
+ "@alvin0/ai-agent-sdk-core": "^0.1.11"
45
45
  },
46
46
  "devDependencies": {
47
- "@alvin0/ai-agent-sdk-core": "^0.1.10",
47
+ "@alvin0/ai-agent-sdk-core": "^0.1.11",
48
48
  "@arethetypeswrong/cli": "0.18.5",
49
49
  "playwright": "1.62.1",
50
50
  "publint": "0.3.24",