@draht/mcp 2026.11.22-1 → 2026.11.23-1

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
@@ -2,11 +2,13 @@ export type { AuthProvider, McpFetch, UnauthorizedContext } from "./auth-provide
2
2
  export { McpClient, type McpClientOptions, type McpRequestOptions } from "./client.ts";
3
3
  export { isMcpServerOverride, type McpHttpServerConfig, type McpOAuthConfig, type McpServerConfig, type McpServerConfigOptions, type McpServerConfigResult, type McpStdioServerConfig, validateMcpServerConfig, } from "./config.ts";
4
4
  export { normalizeMcpInputSchema } from "./input-schema.ts";
5
+ export { type McpModelContentOptions, toMcpModelContent } from "./model-content.ts";
5
6
  export { createMcpToolName, mcpNamespace, mcpServerSummary } from "./naming.ts";
6
7
  export { type LimitedMcpContent, limitMcpContent, MCP_OUTPUT_MAX_BYTES, type McpOutputSaver, } from "./output-limit.ts";
7
8
  export { type AudioContent, type BlobResourceContents, type CallToolResult, type ContentAnnotations, type ContentBlock, type EmbeddedResourceContent, type ImageContent, type LlmContent, type ResourceLinkContent, type TextContent, type TextResourceContents, toLlmContent, } from "./protocol/content.ts";
8
9
  export { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, type JsonRpcErrorObject, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, McpAbortError, McpConnectionClosedError, McpError, McpTimeoutError, parseJsonRpcMessage, } from "./protocol/jsonrpc.ts";
9
10
  export { type CancelledNotification, type ClientCapabilities, type Implementation, type InitializeParams, type InitializeResult, LATEST_PROTOCOL_VERSION, type ListResourcesResult, type ListResourceTemplatesResult, type ListToolsResult, type ProgressNotification, type ReadResourceResult, type Resource, type ResourceTemplate, type Root, type ServerCapabilities, SUPPORTED_PROTOCOL_VERSIONS, type SupportedProtocolVersion, type Tool, type ToolAnnotations, type ToolExecution, } from "./protocol/types.ts";
11
+ export { createMcpResultSchema } from "./result-schema.ts";
10
12
  export { type McpPipe, type McpPipeHandlers, PipeTransport, type PipeTransportOptions, } from "./transports/pipe.ts";
11
13
  export { StdioTransport, type StdioTransportOptions } from "./transports/stdio.ts";
12
14
  export { McpAuthRequiredError, McpHttpError, McpSessionExpiredError, StreamableHttpTransport, type StreamableHttpTransportOptions, } from "./transports/streamable-http.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EACN,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,uBAAuB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EACN,KAAK,iBAAiB,EACtB,eAAe,EACf,oBAAoB,EACpB,KAAK,cAAc,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gB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Ac,EACnB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,kBAAkB,EACvB,2BAA2B,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,IAAI,EACT,KAAK,eAAe,EACpB,KAAK,aAAa,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,eAAe,EACpB,aAAa,EACb,KAAK,oBAAoB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,8BAA8B,GACnC,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACX,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,EAC3B,uBAAuB,GACvB,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  export { McpClient } from "./client.js";
2
2
  export { isMcpServerOverride, validateMcpServerConfig, } from "./config.js";
3
3
  export { normalizeMcpInputSchema } from "./input-schema.js";
4
+ export { toMcpModelContent } from "./model-content.js";
4
5
  export { createMcpToolName, mcpNamespace, mcpServerSummary } from "./naming.js";
5
6
  export { limitMcpContent, MCP_OUTPUT_MAX_BYTES, } from "./output-limit.js";
6
7
  export { toLlmContent, } from "./protocol/content.js";
7
8
  export { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, McpAbortError, McpConnectionClosedError, McpError, McpTimeoutError, parseJsonRpcMessage, } from "./protocol/jsonrpc.js";
8
9
  export { LATEST_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_VERSIONS, } from "./protocol/types.js";
10
+ export { createMcpResultSchema } from "./result-schema.js";
9
11
  export { PipeTransport, } from "./transports/pipe.js";
10
12
  export { StdioTransport } from "./transports/stdio.js";
11
13
  export { McpAuthRequiredError, McpHttpError, McpSessionExpiredError, StreamableHttpTransport, } from "./transports/streamable-http.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiD,MAAM,aAAa,CAAC;AACvF,OAAO,EACN,mBAAmB,EAOnB,uBAAuB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAEN,eAAe,EACf,oBAAoB,GAEpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAYN,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EASpB,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAMN,uBAAuB,EAUvB,2BAA2B,GAK3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGN,aAAa,GAEb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAA8B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GAEvB,MAAM,iCAAiC,CAAC","sourcesContent":["export type { AuthProvider, McpFetch, UnauthorizedContext } from \"./auth-provider.ts\";\nexport { McpClient, type McpClientOptions, type McpRequestOptions } from \"./client.ts\";\nexport {\n\tisMcpServerOverride,\n\ttype McpHttpServerConfig,\n\ttype McpOAuthConfig,\n\ttype McpServerConfig,\n\ttype McpServerConfigOptions,\n\ttype McpServerConfigResult,\n\ttype McpStdioServerConfig,\n\tvalidateMcpServerConfig,\n} from \"./config.ts\";\nexport { normalizeMcpInputSchema } from \"./input-schema.ts\";\nexport { createMcpToolName, mcpNamespace, mcpServerSummary } from \"./naming.ts\";\nexport {\n\ttype LimitedMcpContent,\n\tlimitMcpContent,\n\tMCP_OUTPUT_MAX_BYTES,\n\ttype McpOutputSaver,\n} from \"./output-limit.ts\";\nexport {\n\ttype AudioContent,\n\ttype BlobResourceContents,\n\ttype CallToolResult,\n\ttype ContentAnnotations,\n\ttype ContentBlock,\n\ttype EmbeddedResourceContent,\n\ttype ImageContent,\n\ttype LlmContent,\n\ttype ResourceLinkContent,\n\ttype TextContent,\n\ttype TextResourceContents,\n\ttoLlmContent,\n} from \"./protocol/content.ts\";\nexport {\n\tisJsonRpcNotification,\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcErrorObject,\n\ttype JsonRpcErrorResponse,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\ttype JsonRpcNotification,\n\ttype JsonRpcRequest,\n\ttype JsonRpcResponse,\n\ttype JsonRpcSuccessResponse,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tMcpError,\n\tMcpTimeoutError,\n\tparseJsonRpcMessage,\n} from \"./protocol/jsonrpc.ts\";\nexport {\n\ttype CancelledNotification,\n\ttype ClientCapabilities,\n\ttype Implementation,\n\ttype InitializeParams,\n\ttype InitializeResult,\n\tLATEST_PROTOCOL_VERSION,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\ttype ListToolsResult,\n\ttype ProgressNotification,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\ttype Root,\n\ttype ServerCapabilities,\n\tSUPPORTED_PROTOCOL_VERSIONS,\n\ttype SupportedProtocolVersion,\n\ttype Tool,\n\ttype ToolAnnotations,\n\ttype ToolExecution,\n} from \"./protocol/types.ts\";\nexport {\n\ttype McpPipe,\n\ttype McpPipeHandlers,\n\tPipeTransport,\n\ttype PipeTransportOptions,\n} from \"./transports/pipe.ts\";\nexport { StdioTransport, type StdioTransportOptions } from \"./transports/stdio.ts\";\nexport {\n\tMcpAuthRequiredError,\n\tMcpHttpError,\n\tMcpSessionExpiredError,\n\tStreamableHttpTransport,\n\ttype StreamableHttpTransportOptions,\n} from \"./transports/streamable-http.ts\";\nexport type {\n\tMcpTransport,\n\tMcpTransportCloseListener,\n\tMcpTransportErrorListener,\n\tMcpTransportMessageListener,\n\tMcpTransportSendOptions,\n} from \"./transports/transport.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiD,MAAM,aAAa,CAAC;AACvF,OAAO,EACN,mBAAmB,EAOnB,uBAAuB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAA+B,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAEN,eAAe,EACf,oBAAoB,GAEpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAYN,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EASpB,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAMN,uBAAuB,EAUvB,2BAA2B,GAK3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAGN,aAAa,GAEb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAA8B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GAEvB,MAAM,iCAAiC,CAAC","sourcesContent":["export type { AuthProvider, McpFetch, UnauthorizedContext } from \"./auth-provider.ts\";\nexport { McpClient, type McpClientOptions, type McpRequestOptions } from \"./client.ts\";\nexport {\n\tisMcpServerOverride,\n\ttype McpHttpServerConfig,\n\ttype McpOAuthConfig,\n\ttype McpServerConfig,\n\ttype McpServerConfigOptions,\n\ttype McpServerConfigResult,\n\ttype McpStdioServerConfig,\n\tvalidateMcpServerConfig,\n} from \"./config.ts\";\nexport { normalizeMcpInputSchema } from \"./input-schema.ts\";\nexport { type McpModelContentOptions, toMcpModelContent } from \"./model-content.ts\";\nexport { createMcpToolName, mcpNamespace, mcpServerSummary } from \"./naming.ts\";\nexport {\n\ttype LimitedMcpContent,\n\tlimitMcpContent,\n\tMCP_OUTPUT_MAX_BYTES,\n\ttype McpOutputSaver,\n} from \"./output-limit.ts\";\nexport {\n\ttype AudioContent,\n\ttype BlobResourceContents,\n\ttype CallToolResult,\n\ttype ContentAnnotations,\n\ttype ContentBlock,\n\ttype EmbeddedResourceContent,\n\ttype ImageContent,\n\ttype LlmContent,\n\ttype ResourceLinkContent,\n\ttype TextContent,\n\ttype TextResourceContents,\n\ttoLlmContent,\n} from \"./protocol/content.ts\";\nexport {\n\tisJsonRpcNotification,\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcErrorObject,\n\ttype JsonRpcErrorResponse,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\ttype JsonRpcNotification,\n\ttype JsonRpcRequest,\n\ttype JsonRpcResponse,\n\ttype JsonRpcSuccessResponse,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tMcpError,\n\tMcpTimeoutError,\n\tparseJsonRpcMessage,\n} from \"./protocol/jsonrpc.ts\";\nexport {\n\ttype CancelledNotification,\n\ttype ClientCapabilities,\n\ttype Implementation,\n\ttype InitializeParams,\n\ttype InitializeResult,\n\tLATEST_PROTOCOL_VERSION,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\ttype ListToolsResult,\n\ttype ProgressNotification,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\ttype Root,\n\ttype ServerCapabilities,\n\tSUPPORTED_PROTOCOL_VERSIONS,\n\ttype SupportedProtocolVersion,\n\ttype Tool,\n\ttype ToolAnnotations,\n\ttype ToolExecution,\n} from \"./protocol/types.ts\";\nexport { createMcpResultSchema } from \"./result-schema.ts\";\nexport {\n\ttype McpPipe,\n\ttype McpPipeHandlers,\n\tPipeTransport,\n\ttype PipeTransportOptions,\n} from \"./transports/pipe.ts\";\nexport { StdioTransport, type StdioTransportOptions } from \"./transports/stdio.ts\";\nexport {\n\tMcpAuthRequiredError,\n\tMcpHttpError,\n\tMcpSessionExpiredError,\n\tStreamableHttpTransport,\n\ttype StreamableHttpTransportOptions,\n} from \"./transports/streamable-http.ts\";\nexport type {\n\tMcpTransport,\n\tMcpTransportCloseListener,\n\tMcpTransportErrorListener,\n\tMcpTransportMessageListener,\n\tMcpTransportSendOptions,\n} from \"./transports/transport.ts\";\n"]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The model-facing content of an MCP result as draht's coding agent shows it: text and images, embedded text resources
3
+ * as text, binary resources saved where the model can read them, and resource links that name the tool reading them.
4
+ */
5
+ import type { McpOutputSaver } from "./output-limit.ts";
6
+ import { type CallToolResult, type LlmContent } from "./protocol/content.ts";
7
+ /** How {@link toMcpModelContent} handles what the model cannot read inline. */
8
+ export interface McpModelContentOptions {
9
+ /** Saves binary resources other than images where the model can read them. Without it they are left out. */
10
+ saveOutput?: McpOutputSaver;
11
+ /** The tool that reads the server's resources, which resource links then name. */
12
+ readResourceTool?: string;
13
+ }
14
+ /**
15
+ * Model-facing content of `server`'s result, before the output limit ({@link limitMcpContent}). A result without
16
+ * content blocks becomes its structured content as JSON, as in {@link toLlmContent}.
17
+ */
18
+ export declare function toMcpModelContent(server: string, result: Pick<CallToolResult, "content" | "structuredContent">, options?: McpModelContentOptions): Promise<LlmContent[]>;
19
+ //# sourceMappingURL=model-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-content.d.ts","sourceRoot":"","sources":["../src/model-content.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,KAAK,cAAc,EAAqB,KAAK,UAAU,EAAgB,MAAM,uBAAuB,CAAC;AAE9G,+EAA+E;AAC/E,MAAM,WAAW,sBAAsB;IACtC,4GAA4G;IAC5G,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,kFAAkF;IAClF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,mBAAmB,CAAC,EAC7D,OAAO,GAAE,sBAA2B,GAClC,OAAO,CAAC,UAAU,EAAE,CAAC,CAGvB"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The model-facing content of an MCP result as draht's coding agent shows it: text and images, embedded text resources
3
+ * as text, binary resources saved where the model can read them, and resource links that name the tool reading them.
4
+ */
5
+ import { toLlmContent } from "./protocol/content.js";
6
+ /**
7
+ * Model-facing content of `server`'s result, before the output limit ({@link limitMcpContent}). A result without
8
+ * content blocks becomes its structured content as JSON, as in {@link toLlmContent}.
9
+ */
10
+ export async function toMcpModelContent(server, result, options = {}) {
11
+ if (result.content.length === 0)
12
+ return toLlmContent(result);
13
+ return (await Promise.all(result.content.map((block) => blockToContent(server, block, options)))).flat();
14
+ }
15
+ /** Model-facing content of one block of `server`'s result. */
16
+ async function blockToContent(server, block, options) {
17
+ if (block.type === "resource_link") {
18
+ const details = [block.mimeType, block.size === undefined ? undefined : formatSize(block.size)].filter(Boolean);
19
+ const read = options.readResourceTool ? `. Read it with ${options.readResourceTool} (server "${server}")` : "";
20
+ const description = block.description ? `: ${block.description}` : "";
21
+ return [
22
+ {
23
+ type: "text",
24
+ text: `[Resource ${block.uri} "${block.title ?? block.name}"${details.length > 0 ? ` (${details.join(", ")})` : ""}${description}${read}]`,
25
+ },
26
+ ];
27
+ }
28
+ if (block.type === "resource" && "blob" in block.resource && !block.resource.mimeType?.startsWith("image/")) {
29
+ const { uri, mimeType, blob } = block.resource;
30
+ const data = Buffer.from(blob, "base64");
31
+ if (isTextMimeType(mimeType))
32
+ return [{ type: "text", text: data.toString("utf8") }];
33
+ if (!options.saveOutput)
34
+ return toLlmContent({ content: [block] });
35
+ const kind = `${mimeType ?? "unknown type"}, ${formatSize(data.length)}`;
36
+ try {
37
+ const path = await options.saveOutput(data, extensionOf(uri));
38
+ return [{ type: "text", text: `[Binary resource ${uri} (${kind}) saved to ${path}]` }];
39
+ }
40
+ catch (error) {
41
+ const reason = error instanceof Error ? error.message : String(error);
42
+ return [{ type: "text", text: `[Binary resource ${uri} (${kind}) could not be saved: ${reason}]` }];
43
+ }
44
+ }
45
+ return toLlmContent({ content: [block] });
46
+ }
47
+ /** A byte count as draht's coding agent shows sizes: `512B`, `2.0KB`, `1.5MB`. */
48
+ function formatSize(bytes) {
49
+ if (bytes < 1024)
50
+ return `${bytes}B`;
51
+ if (bytes < 1024 * 1024)
52
+ return `${(bytes / 1024).toFixed(1)}KB`;
53
+ return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
54
+ }
55
+ /** Blobs of these types are shown as text. */
56
+ function isTextMimeType(mimeType) {
57
+ if (!mimeType)
58
+ return false;
59
+ const type = mimeType.split(";", 1)[0].trim().toLowerCase();
60
+ return type.startsWith("text/") || type === "application/json" || type.endsWith("+json") || type.endsWith("+xml");
61
+ }
62
+ /** File extension for a saved binary resource: the one its URI ends in, else `.bin`. */
63
+ function extensionOf(uri) {
64
+ const path = URL.canParse(uri) ? new URL(uri).pathname : uri;
65
+ return /\.[A-Za-z0-9]{1,8}$/.exec(path)?.[0] ?? ".bin";
66
+ }
67
+ //# sourceMappingURL=model-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-content.js","sourceRoot":"","sources":["../src/model-content.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA2D,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAU9G;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,MAAc,EACd,MAA6D,EAC7D,OAAO,GAA2B,EAAE;IAEpC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7D,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC1G,CAAC;AAED,8DAA8D;AAC9D,KAAK,UAAU,cAAc,CAC5B,MAAc,EACd,KAAmB,EACnB,OAA+B;IAE/B,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAChH,MAAM,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CA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AE,CAAC;IAC5D,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,kBAAkB,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACnH,CAAC;AAED,wFAAwF;AACxF,SAAS,WAAW,CAAC,GAAW;IAC/B,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7D,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC;AACxD,CAAC","sourcesContent":["/**\n * The model-facing content of an MCP result as draht's coding agent shows it: text and images, embedded text resources\n * as text, binary resources saved where the model can read them, and resource links that name the tool reading them.\n */\n\nimport type { McpOutputSaver } from \"./output-limit.ts\";\nimport { type CallToolResult, type ContentBlock, type LlmContent, toLlmContent } from \"./protocol/content.ts\";\n\n/** How {@link toMcpModelContent} handles what the model cannot read inline. */\nexport interface McpModelContentOptions {\n\t/** Saves binary resources other than images where the model can read them. Without it they are left out. */\n\tsaveOutput?: McpOutputSaver;\n\t/** The tool that reads the server's resources, which resource links then name. */\n\treadResourceTool?: string;\n}\n\n/**\n * Model-facing content of `server`'s result, before the output limit ({@link limitMcpContent}). A result without\n * content blocks becomes its structured content as JSON, as in {@link toLlmContent}.\n */\nexport async function toMcpModelContent(\n\tserver: string,\n\tresult: Pick<CallToolResult, \"content\" | \"structuredContent\">,\n\toptions: McpModelContentOptions = {},\n): Promise<LlmContent[]> {\n\tif (result.content.length === 0) return toLlmContent(result);\n\treturn (await Promise.all(result.content.map((block) => blockToContent(server, block, options)))).flat();\n}\n\n/** Model-facing content of one block of `server`'s result. */\nasync function blockToContent(\n\tserver: string,\n\tblock: ContentBlock,\n\toptions: McpModelContentOptions,\n): Promise<LlmContent[]> {\n\tif (block.type === \"resource_link\") {\n\t\tconst details = [block.mimeType, block.size === undefined ? undefined : formatSize(block.size)].filter(Boolean);\n\t\tconst read = options.readResourceTool ? `. Read it with ${options.readResourceTool} (server \"${server}\")` : \"\";\n\t\tconst description = block.description ? `: ${block.description}` : \"\";\n\t\treturn [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `[Resource ${block.uri} \"${block.title ?? block.name}\"${details.length > 0 ? ` (${details.join(\", \")})` : \"\"}${description}${read}]`,\n\t\t\t},\n\t\t];\n\t}\n\tif (block.type === \"resource\" && \"blob\" in block.resource && !block.resource.mimeType?.startsWith(\"image/\")) {\n\t\tconst { uri, mimeType, blob } = block.resource;\n\t\tconst data = Buffer.from(blob, \"base64\");\n\t\tif (isTextMimeType(mimeType)) return [{ type: \"text\", text: data.toString(\"utf8\") }];\n\t\tif (!options.saveOutput) return toLlmContent({ content: [block] });\n\t\tconst kind = `${mimeType ?? \"unknown type\"}, ${formatSize(data.length)}`;\n\t\ttry {\n\t\t\tconst path = await options.saveOutput(data, extensionOf(uri));\n\t\t\treturn [{ type: \"text\", text: `[Binary resource ${uri} (${kind}) saved to ${path}]` }];\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? error.message : String(error);\n\t\t\treturn [{ type: \"text\", text: `[Binary resource ${uri} (${kind}) could not be saved: ${reason}]` }];\n\t\t}\n\t}\n\treturn toLlmContent({ content: [block] });\n}\n\n/** A byte count as draht's coding agent shows sizes: `512B`, `2.0KB`, `1.5MB`. */\nfunction formatSize(bytes: number): string {\n\tif (bytes < 1024) return `${bytes}B`;\n\tif (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;\n\treturn `${(bytes / (1024 * 1024)).toFixed(1)}MB`;\n}\n\n/** Blobs of these types are shown as text. */\nfunction isTextMimeType(mimeType: string | undefined): boolean {\n\tif (!mimeType) return false;\n\tconst type = mimeType.split(\";\", 1)[0].trim().toLowerCase();\n\treturn type.startsWith(\"text/\") || type === \"application/json\" || type.endsWith(\"+json\") || type.endsWith(\"+xml\");\n}\n\n/** File extension for a saved binary resource: the one its URI ends in, else `.bin`. */\nfunction extensionOf(uri: string): string {\n\tconst path = URL.canParse(uri) ? new URL(uri).pathname : uri;\n\treturn /\\.[A-Za-z0-9]{1,8}$/.exec(path)?.[0] ?? \".bin\";\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The output schema of an MCP tool for programs that call it: the whole `CallToolResult`, with the tool's own output
3
+ * schema as `structuredContent`.
4
+ */
5
+ /**
6
+ * Output schema of an MCP tool: the `CallToolResult` programs receive (without `_meta`, which callers drop), with the
7
+ * tool's own output schema as `structuredContent`. Without one, structured content may be any JSON value.
8
+ */
9
+ export declare function createMcpResultSchema(structuredContentSchema: Record<string, unknown> | undefined): Record<string, unknown>;
10
+ //# sourceMappingURL=result-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-schema.d.ts","sourceRoot":"","sources":["../src/result-schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH;;;GAGG;AACH,wBAAgB,qBAAqB,CACpC,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC1D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAczB"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The output schema of an MCP tool for programs that call it: the whole `CallToolResult`, with the tool's own output
3
+ * schema as `structuredContent`.
4
+ */
5
+ /**
6
+ * MCP content blocks as one compact type with the fields of text and image blocks, which scripts
7
+ * read most. Rendered into every MCP tool's declaration.
8
+ */
9
+ const CONTENT_BLOCK_SCHEMA = {
10
+ type: "object",
11
+ properties: {
12
+ type: { enum: ["text", "image", "audio", "resource_link", "resource"] },
13
+ text: { type: "string" },
14
+ data: { type: "string" },
15
+ mimeType: { type: "string" },
16
+ },
17
+ required: ["type"],
18
+ additionalProperties: true,
19
+ };
20
+ /**
21
+ * Output schema of an MCP tool: the `CallToolResult` programs receive (without `_meta`, which callers drop), with the
22
+ * tool's own output schema as `structuredContent`. Without one, structured content may be any JSON value.
23
+ */
24
+ export function createMcpResultSchema(structuredContentSchema) {
25
+ return {
26
+ type: "object",
27
+ properties: {
28
+ content: { type: "array", items: CONTENT_BLOCK_SCHEMA },
29
+ structuredContent: structuredContentSchema
30
+ ? relocateSchema(structuredContentSchema, "#/properties/structuredContent")
31
+ : {},
32
+ isError: { type: "boolean" },
33
+ },
34
+ required: ["content"],
35
+ // Fields newer protocol versions add.
36
+ additionalProperties: true,
37
+ };
38
+ }
39
+ /** Keywords whose values are data, so a `$ref` key in them is not a reference. */
40
+ const SCHEMA_DATA_KEYWORDS = new Set(["const", "enum", "default", "examples"]);
41
+ /** Keywords whose values map names to schemas, so their keys are names, not keywords. */
42
+ const SCHEMA_MAP_KEYWORDS = new Set([
43
+ "properties",
44
+ "patternProperties",
45
+ "dependentSchemas",
46
+ "dependencies",
47
+ "$defs",
48
+ "definitions",
49
+ ]);
50
+ /**
51
+ * `schema` as a subschema at the JSON pointer `pointer` (`#/properties/structuredContent`) of
52
+ * another schema: its local references (`#`, `#/$defs/Item`) are rewritten to point below
53
+ * `pointer`, so they resolve to the same subschemas as before.
54
+ */
55
+ function relocateSchema(schema, pointer) {
56
+ // The server's schema is wire input of any JSON shape.
57
+ if (Array.isArray(schema))
58
+ return schema.map((item) => relocateSchema(item, pointer));
59
+ if (typeof schema !== "object" || schema === null)
60
+ return schema;
61
+ const relocated = {};
62
+ for (const [key, value] of Object.entries(schema)) {
63
+ if (key === "$ref" && typeof value === "string" && (value === "#" || value.startsWith("#/"))) {
64
+ relocated[key] = `${pointer}${value.slice(1)}`;
65
+ }
66
+ else if (SCHEMA_DATA_KEYWORDS.has(key)) {
67
+ relocated[key] = value;
68
+ }
69
+ else if (SCHEMA_MAP_KEYWORDS.has(key) && typeof value === "object" && value !== null && !Array.isArray(value)) {
70
+ relocated[key] = Object.fromEntries(Object.entries(value).map(([name, subschema]) => [name, relocateSchema(subschema, pointer)]));
71
+ }
72
+ else {
73
+ relocated[key] = relocateSchema(value, pointer);
74
+ }
75
+ }
76
+ return relocated;
77
+ }
78
+ //# sourceMappingURL=result-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-schema.js","sourceRoot":"","sources":["../src/result-schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC5B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACX,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,CAAC,EAAE;QACvE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACxB,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACxB,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC5B;IACD,QAAQ,EAAE,CAAC,MAAM,CAAC;IAClB,oBAAoB,EAAE,IAAI;CAC1B,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACpC,uBAA4D;IAE5D,OAAO;QACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACX,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE;YACvD,iBAAiB,EAAE,uBAAuB;gBACzC,CAAC,CAAC,cAAc,CAAC,uBAAuB,EAAE,gCAAgC,CAAC;gBAC3E,CAAC,CAAC,EAAE;YACL,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;SAC5B;QACD,QAAQ,EAAE,CAAC,SAAS,CAAC;QACrB,sCAAsC;QACtC,oBAAoB,EAAE,IAAI;KAC1B,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU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AAC,WAAW,CAClC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAC5F,CAAC;QACH,CAAC;aAAM,CAAC;YACP,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * The output schema of an MCP tool for programs that call it: the whole `CallToolResult`, with the tool's own output\n * schema as `structuredContent`.\n */\n\n/**\n * MCP content blocks as one compact type with the fields of text and image blocks, which scripts\n * read most. Rendered into every MCP tool's declaration.\n */\nconst CONTENT_BLOCK_SCHEMA = {\n\ttype: \"object\",\n\tproperties: {\n\t\ttype: { enum: [\"text\", \"image\", \"audio\", \"resource_link\", \"resource\"] },\n\t\ttext: { type: \"string\" },\n\t\tdata: { type: \"string\" },\n\t\tmimeType: { type: \"string\" },\n\t},\n\trequired: [\"type\"],\n\tadditionalProperties: true,\n};\n\n/**\n * Output schema of an MCP tool: the `CallToolResult` programs receive (without `_meta`, which callers drop), with the\n * tool's own output schema as `structuredContent`. Without one, structured content may be any JSON value.\n */\nexport function createMcpResultSchema(\n\tstructuredContentSchema: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n\treturn {\n\t\ttype: \"object\",\n\t\tproperties: {\n\t\t\tcontent: { type: \"array\", items: CONTENT_BLOCK_SCHEMA },\n\t\t\tstructuredContent: structuredContentSchema\n\t\t\t\t? relocateSchema(structuredContentSchema, \"#/properties/structuredContent\")\n\t\t\t\t: {},\n\t\t\tisError: { type: \"boolean\" },\n\t\t},\n\t\trequired: [\"content\"],\n\t\t// Fields newer protocol versions add.\n\t\tadditionalProperties: true,\n\t};\n}\n\n/** Keywords whose values are data, so a `$ref` key in them is not a reference. */\nconst SCHEMA_DATA_KEYWORDS: ReadonlySet<string> = new Set([\"const\", \"enum\", \"default\", \"examples\"]);\n\n/** Keywords whose values map names to schemas, so their keys are names, not keywords. */\nconst SCHEMA_MAP_KEYWORDS: ReadonlySet<string> = new Set([\n\t\"properties\",\n\t\"patternProperties\",\n\t\"dependentSchemas\",\n\t\"dependencies\",\n\t\"$defs\",\n\t\"definitions\",\n]);\n\n/**\n * `schema` as a subschema at the JSON pointer `pointer` (`#/properties/structuredContent`) of\n * another schema: its local references (`#`, `#/$defs/Item`) are rewritten to point below\n * `pointer`, so they resolve to the same subschemas as before.\n */\nfunction relocateSchema(schema: unknown, pointer: string): unknown {\n\t// The server's schema is wire input of any JSON shape.\n\tif (Array.isArray(schema)) return schema.map((item) => relocateSchema(item, pointer));\n\tif (typeof schema !== \"object\" || schema === null) return schema;\n\tconst relocated: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(schema)) {\n\t\tif (key === \"$ref\" && typeof value === \"string\" && (value === \"#\" || value.startsWith(\"#/\"))) {\n\t\t\trelocated[key] = `${pointer}${value.slice(1)}`;\n\t\t} else if (SCHEMA_DATA_KEYWORDS.has(key)) {\n\t\t\trelocated[key] = value;\n\t\t} else if (SCHEMA_MAP_KEYWORDS.has(key) && typeof value === \"object\" && value !== null && !Array.isArray(value)) {\n\t\t\trelocated[key] = Object.fromEntries(\n\t\t\t\tObject.entries(value).map(([name, subschema]) => [name, relocateSchema(subschema, pointer)]),\n\t\t\t);\n\t\t} else {\n\t\t\trelocated[key] = relocateSchema(value, pointer);\n\t\t}\n\t}\n\treturn relocated;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@draht/mcp",
3
- "version": "2026.11.22-1",
3
+ "version": "2026.11.23-1",
4
4
  "description": "Standalone Model Context Protocol client for draht and other applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",