@nemesis-oss/ollama-sdk 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +14 -2
  2. package/README.md +31 -0
  3. package/dist/anthropic-B_UXplNF.d.ts +1647 -0
  4. package/dist/anthropic-CVDFy_a0.d.cts +1647 -0
  5. package/dist/generated-api.cjs +74 -6
  6. package/dist/generated-api.cjs.map +1 -1
  7. package/dist/generated-api.d.cts +230 -629
  8. package/dist/generated-api.d.ts +230 -629
  9. package/dist/generated-api.js +72 -7
  10. package/dist/generated-api.js.map +1 -1
  11. package/dist/generated-models-schemas.cjs +89 -1
  12. package/dist/generated-models-schemas.cjs.map +1 -1
  13. package/dist/generated-models-schemas.d.cts +121 -1
  14. package/dist/generated-models-schemas.d.ts +121 -1
  15. package/dist/generated-models-schemas.js +79 -2
  16. package/dist/generated-models-schemas.js.map +1 -1
  17. package/dist/generated-runtime.cjs +576 -57
  18. package/dist/generated-runtime.cjs.map +1 -1
  19. package/dist/generated-runtime.d.cts +21 -23
  20. package/dist/generated-runtime.d.ts +21 -23
  21. package/dist/generated-runtime.js +575 -58
  22. package/dist/generated-runtime.js.map +1 -1
  23. package/dist/index.cjs +1210 -81
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +395 -876
  26. package/dist/index.d.ts +395 -876
  27. package/dist/index.js +1207 -82
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp/tools.json +287 -73
  30. package/dist/mcp-generated.cjs +96 -7
  31. package/dist/mcp-generated.cjs.map +1 -1
  32. package/dist/mcp-generated.d.cts +3 -3
  33. package/dist/mcp-generated.d.ts +3 -3
  34. package/dist/mcp-generated.js +96 -7
  35. package/dist/mcp-generated.js.map +1 -1
  36. package/dist/mcp-http.cjs +43 -4
  37. package/dist/mcp-http.cjs.map +1 -1
  38. package/dist/mcp-http.d.cts +5 -1
  39. package/dist/mcp-http.d.ts +5 -1
  40. package/dist/mcp-http.js +43 -4
  41. package/dist/mcp-http.js.map +1 -1
  42. package/dist/mcp-stdio.cjs +43 -4
  43. package/dist/mcp-stdio.cjs.map +1 -1
  44. package/dist/mcp-stdio.d.cts +5 -1
  45. package/dist/mcp-stdio.d.ts +5 -1
  46. package/dist/mcp-stdio.js +43 -4
  47. package/dist/mcp-stdio.js.map +1 -1
  48. package/dist/{runtime-CVQkbYgF.d.ts → runtime-C6UYtBRB.d.ts} +222 -6
  49. package/dist/{runtime-IxRpUBjN.d.cts → runtime-DTmUeU6K.d.cts} +222 -6
  50. package/dist/skills.cjs.map +1 -1
  51. package/dist/skills.js.map +1 -1
  52. package/dist/types-CI-gM2u5.d.cts +139 -0
  53. package/dist/types-CI-gM2u5.d.ts +139 -0
  54. package/package.json +4 -2
  55. package/dist/types-MOsWXEE7.d.cts +0 -66
  56. package/dist/types-MOsWXEE7.d.ts +0 -66
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mcp/http.ts"],"names":[],"mappings":";;;AAUA,IAAM,kBAAA,GAAqB,8BAAA;AA+C3B,eAAe,gBAAA,GAA8C;AAC3D,EAAA,IAAI;AACF,IAAA,OAAQ,MAAM,OAAO,kBAAA,CAAA;AAAA,EACvB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,4HAAA;AAAA,MAEA,EAAE,OAAO,KAAA;AAAM,KACjB;AAAA,EACF;AACF;AAEA,SAAS,eAAe,KAAA,EAA0B;AAChD,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,KAAA,YAAiB,MAAM,IAAI,GAAA,CAAI,MAAM,IAAI,CAAA,GAAI,IAAI,GAAA,CAAI,KAAK,CAAA;AAAA,EAClE,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,SAAA,CAAU,kDAAA,EAAoD,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAC1F;AAEA,EAAA,IAAI,GAAA,CA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,EAAM,GAAA,EAAK,OAAA,EAAS,MAAM,kBAAkB,CAAA;AAAA,EAC1E;AAEA,EAAA,MAAM,OAAA,GAAU,MAAM,gBAAA,EAAiB;AACvC,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,oBAAA,CAAqB,iBAAA,EAAmB,GAAA,EAAK,SAAS,OAAO,CAAA;AAAA,EAC5E,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,CAAC,mBAAA,CAAoB,KAAK,CAAA,EAAG,MAAM,KAAA;AACvC,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,oBAAA,CAAqB,KAAA,EAAO,GAAA,EAAK,SAAS,OAAO,CAAA;AAAA,IAChE,SAAS,QAAA,EAAU;AACjB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,8EAAA;AAAA,QACA,EAAE,OAAO,QAAA;AAAS,OACpB;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAsB,+BACpB,OAAA,EAC4B;AAC5B,EAAA,OAAO,qBAAqB,EAAE,GAAG,OAAA,EAAS,SAAA,EAAW,mBAAmB,CAAA;AAC1E;AAEA,eAAsB,oBACpB,OAAA,EAC4B;AAC5B,EAAA,OAAO,qBAAqB,EAAE,GAAG,OAAA,EAAS,SAAA,EAAW,OAAO,CAAA;AAC9D","file":"mcp-http.cjs","sourcesContent":["/**\n * Optional remote MCP transport connectors.\n *\n * The root SDK stays transport-agnostic and Edge-compatible. This subpath dynamically\n * loads the official MCP TypeScript client so applications can connect to remote servers\n * over modern Streamable HTTP or legacy SSE.\n */\n\nimport type { McpClientLike } from './types.js';\n\nconst MCP_CLIENT_PACKAGE = '@modelcontextprotocol/client';\n\nexport type McpHttpTransport = 'streamable-http' | 'sse' | 'auto';\n\nexport interface HttpMcpClientOptions {\n /** Absolute MCP server URL, for example https://example.com/mcp. */\n readonly url: string | URL;\n /**\n * Transport selection. Defaults to Streamable HTTP. In 'auto' mode, a compatible 4xx\n * from the modern transport triggers a retry with the legacy SSE transport.\n */\n readonly transport?: McpHttpTransport | undefined;\n readonly name?: string | undefined;\n readonly version?: string | undefined;\n /** Fetch RequestInit forwarded to the MCP transport for remote authentication/proxy headers. */\n readonly requestInit?: RequestInit | undefined;\n /** Optional fetch implementation forwarded to the MCP transport. */\n readonly fetch?: typeof globalThis.fetch | undefined;\n}\n\nexport interface HttpMcpConnection {\n readonly client: McpClientLike;\n readonly transport: 'streamable-http' | 'sse';\n readonly close: () => Promise<void>;\n /**\n * Streamable HTTP only: terminate the server-side MCP session when one exists.\n * Undefined for legacy SSE connections.\n */\n readonly terminateSession?: (() => Promise<void>) | undefined;\n}\n\ninterface DynamicMcpClient {\n readonly Client: new (\n metadata: { name: string; version: string },\n ) => {\n connect: (transport: unknown) => Promise<void>;\n close: () => Promise<void>;\n listTools: McpClientLike['listTools'];\n callTool: McpClientLike['callTool'];\n };\n readonly StreamableHTTPClientTransport: new (\n url: URL,\n options?: unknown,\n ) => unknown;\n readonly SSEClientTransport: new (url: URL, options?: unknown) => unknown;\n}\n\nasync function loadClientModule(): Promise<DynamicMcpClient> {\n try {\n return (await import(MCP_CLIENT_PACKAGE)) as unknown as DynamicMcpClient;\n } catch (error) {\n throw new Error(\n 'MCP HTTP support requires @modelcontextprotocol/client >= 2.0.0. ' +\n 'Install it with npm install @modelcontextprotocol/client.',\n { cause: error },\n );\n }\n}\n\nfunction parseServerUrl(value: string | URL): URL {\n let url: URL;\n try {\n url = value instanceof URL ? new URL(value.href) : new URL(value);\n } catch (error) {\n throw new TypeError('MCP HTTP server URL must be a valid absolute URL', { cause: error });\n }\n\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n throw new TypeError('MCP HTTP server URL must use http: or https:');\n }\n return url;\n}\n\nfunction transportOptions(options: HttpMcpClientOptions): Record<string, unknown> {\n return {\n ...(options.requestInit !== undefined ? { requestInit: options.requestInit } : {}),\n ...(options.fetch !== undefined ? { fetch: options.fetch } : {}),\n };\n}\n\nfunction connectionFrom(\n client: DynamicMcpClient['Client'] extends new (...args: infer _Args) => infer C ? C : never,\n transport: unknown,\n kind: 'streamable-http' | 'sse',\n): HttpMcpConnection {\n const transportWithTermination = transport as {\n terminateSession?: (() => Promise<void>) | undefined;\n };\n\n return {\n client,\n transport: kind,\n close: () => client.close(),\n ...(kind === 'streamable-http' && typeof transportWithTermination.terminateSession === 'function'\n ? { terminateSession: () => transportWithTermination.terminateSession!() }\n : {}),\n };\n}\n\nasync function connectWithTransport(\n mode: Exclude<McpHttpTransport, 'auto'>,\n url: URL,\n options: HttpMcpClientOptions,\n modules: DynamicMcpClient,\n): Promise<HttpMcpConnection> {\n const client = new modules.Client({\n name: options.name ?? '@nemesis-oss/ollama-sdk',\n version: options.version ?? '1.0.0',\n });\n const transport =\n mode === 'streamable-http'\n ? new modules.StreamableHTTPClientTransport(url, transportOptions(options))\n : new modules.SSEClientTransport(url, transportOptions(options));\n\n await client.connect(transport);\n return connectionFrom(client, transport, mode);\n}\n\nfunction responseStatus(error: unknown): number | undefined {\n if (typeof error !== 'object' || error === null) return undefined;\n const value = error as Record<string, unknown>;\n if (typeof value.status === 'number') return value.status;\n if (typeof value.statusCode === 'number') return value.statusCode;\n\n const response = value.response;\n if (typeof response === 'object' && response !== null && typeof (response as Record<string, unknown>).status === 'number') {\n return (response as Record<string, number>).status;\n }\n\n const cause = value.cause;\n if (cause !== error) return responseStatus(cause);\n return undefined;\n}\n\nfunction shouldFallbackToSse(error: unknown): boolean {\n const status = responseStatus(error);\n return status !== undefined && status >= 400 && status < 500 && status !== 401 && status !== 403 && status !== 429;\n}\n\n/**\n * Connect to a remote MCP server.\n *\n * Defaults to modern Streamable HTTP. Use 'sse' for an explicitly legacy server or\n * 'auto' to try Streamable HTTP and fall back to SSE only for a non-authentication 4xx\n * response, avoiding accidental downgrade on credentials, throttling, or server failures.\n */\nexport async function connectMcpHttpClient(\n options: HttpMcpClientOptions,\n): Promise<HttpMcpConnection> {\n const url = parseServerUrl(options.url);\n const mode = options.transport ?? 'streamable-http';\n if (mode !== 'auto') {\n return connectWithTransport(mode, url, options, await loadClientModule());\n }\n\n const modules = await loadClientModule();\n try {\n return await connectWithTransport('streamable-http', url, options, modules);\n } catch (error) {\n if (!shouldFallbackToSse(error)) throw error;\n try {\n return await connectWithTransport('sse', url, options, modules);\n } catch (sseError) {\n throw new Error(\n 'MCP Streamable HTTP was unavailable and the legacy SSE fallback also failed.',\n { cause: sseError },\n );\n }\n }\n}\n\nexport async function connectStreamableHttpMcpClient(\n options: Omit<HttpMcpClientOptions, 'transport'>,\n): Promise<HttpMcpConnection> {\n return connectMcpHttpClient({ ...options, transport: 'streamable-http' });\n}\n\nexport async function connectSseMcpClient(\n options: Omit<HttpMcpClientOptions, 'transport'>,\n): Promise<HttpMcpConnection> {\n return connectMcpHttpClient({ ...options, transport: 'sse' });\n}\n"]}
1
+ {"version":3,"sources":["../src/mcp/client-options.ts","../src/mcp/http.ts"],"names":["request"],"mappings":";;;AA2BO,SAAS,2BAAA,CACd,QACA,QAAA,EACM;AACN,EAAA,IAAI,aAAa,MAAA,EAAW;AAE5B,EAAA,MAAM,YAAA,GAAe,SAAS,IAAA,KAAS,MAAA;AACvC,EAAA,MAAM,WAAA,GAAc,SAAS,GAAA,KAAQ,MAAA;AACrC,EAAA,IAAI,CAAC,YAAA,IAAgB,CAAC,WAAA,EAAa;AACjC,IAAA,MAAM,IAAI,UAAU,uDAAuD,CAAA;AAAA,EAC7E;AACA,EAAA,IAAI,MAAA,CAAO,oBAAA,KAAyB,MAAA,IAAa,MAAA,CAAO,sBAAsB,MAAA,EAAW;AACvF,IAAA,MAAM,IAAI,SAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,MAAA,CAAO,oBAAA,CAAqB;AAAA,IAC1B,WAAA,EAAa;AAAA,MACX,GAAI,YAAA,GAAe,EAAE,MAAM,EAAC,KAAM,EAAC;AAAA,MACnC,GAAI,WAAA,GAAc,EAAE,KAAK,EAAC,KAAM;AAAC;AACnC,GACD,CAAA;AACD,EAAA,MAAA,CAAO,i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AA,EAAQ;AACnB,IAAA,OAAO,qBAAqB,IAAA,EAAM,GAAA,EAAK,OAAA,EAAS,MAAM,kBAAkB,CAAA;AAAA,EAC1E;AAEA,EAAA,MAAM,OAAA,GAAU,MAAM,gBAAA,EAAiB;AACvC,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,oBAAA,CAAqB,iBAAA,EAAmB,GAAA,EAAK,SAAS,OAAO,CAAA;AAAA,EAC5E,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,CAAC,mBAAA,CAAoB,KAAK,CAAA,EAAG,MAAM,KAAA;AACvC,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,oBAAA,CAAqB,KAAA,EAAO,GAAA,EAAK,SAAS,OAAO,CAAA;AAAA,IAChE,SAAS,QAAA,EAAU;AACjB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,8EAAA;AAAA,QACA,EAAE,OAAO,QAAA;AAAS,OACpB;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAsB,+BACpB,OAAA,EAC4B;AAC5B,EAAA,OAAO,qBAAqB,EAAE,GAAG,OAAA,EAAS,SAAA,EAAW,mBAAmB,CAAA;AAC1E;AAEA,eAAsB,oBACpB,OAAA,EAC4B;AAC5B,EAAA,OAAO,qBAAqB,EAAE,GAAG,OAAA,EAAS,SAAA,EAAW,OAAO,CAAA;AAC9D","file":"mcp-http.cjs","sourcesContent":["import type {\n McpElicitationFormRequest,\n McpElicitationHandlers,\n McpElicitationRequest,\n McpElicitationResult,\n McpElicitationUrlRequest,\n} from './types.js';\n\nexport interface McpClientRequestHandler {\n registerCapabilities?:\n | ((capabilities: {\n readonly elicitation: {\n readonly form?: Record<string, never> | undefined;\n readonly url?: Record<string, never> | undefined;\n };\n }) => void)\n | undefined;\n setRequestHandler?:\n | ((\n method: 'elicitation/create',\n handler: (request: {\n readonly params: McpElicitationRequest;\n }) => Promise<McpElicitationResult>,\n ) => void)\n | undefined;\n}\n\nexport function registerElicitationHandlers(\n client: McpClientRequestHandler,\n handlers: McpElicitationHandlers | undefined,\n): void {\n if (handlers === undefined) return;\n\n const supportsForm = handlers.form !== undefined;\n const supportsUrl = handlers.url !== undefined;\n if (!supportsForm && !supportsUrl) {\n throw new TypeError('At least one MCP elicitation handler must be provided');\n }\n if (client.registerCapabilities === undefined || client.setRequestHandler === undefined) {\n throw new TypeError(\n 'The MCP client does not support elicitation capabilities and request handlers',\n );\n }\n\n client.registerCapabilities({\n elicitation: {\n ...(supportsForm ? { form: {} } : {}),\n ...(supportsUrl ? { url: {} } : {}),\n },\n });\n client.setRequestHandler('elicitation/create', async ({ params }) => {\n if (params.mode === 'url') {\n const request = params as McpElicitationUrlRequest;\n if (handlers.url === undefined) {\n throw new Error('MCP server requested URL elicitation, but no URL handler is configured');\n }\n return handlers.url(request);\n }\n\n const request = params as McpElicitationFormRequest;\n if (handlers.form === undefined) {\n throw new Error('MCP server requested form elicitation, but no form handler is configured');\n }\n return handlers.form(request);\n });\n}\n","/**\n * Optional remote MCP transport connectors.\n *\n * The root SDK stays transport-agnostic and Edge-compatible. This subpath dynamically\n * loads the official MCP TypeScript client so applications can connect to remote servers\n * over modern Streamable HTTP or legacy SSE.\n */\n\nimport { registerElicitationHandlers, type McpClientRequestHandler } from './client-options.js';\nimport type { McpClientLike, McpElicitationHandlers } from './types.js';\n\nconst MCP_CLIENT_PACKAGE = '@modelcontextprotocol/client';\n\nexport type McpHttpTransport = 'streamable-http' | 'sse' | 'auto';\n\nexport interface HttpMcpClientOptions {\n /** Absolute MCP server URL, for example https://example.com/mcp. */\n readonly url: string | URL;\n /**\n * Transport selection. Defaults to Streamable HTTP. In 'auto' mode, a compatible 4xx\n * from the modern transport triggers a retry with the legacy SSE transport.\n */\n readonly transport?: McpHttpTransport | undefined;\n readonly name?: string | undefined;\n readonly version?: string | undefined;\n /** Fetch RequestInit forwarded to the MCP transport for remote authentication/proxy headers. */\n readonly requestInit?: RequestInit | undefined;\n /** Optional fetch implementation forwarded to the MCP transport. */\n readonly fetch?: typeof globalThis.fetch | undefined;\n readonly elicitation?: McpElicitationHandlers | undefined;\n /** Defaults to manual so input_required responses are returned to the caller. */\n readonly inputRequiredMode?: 'manual' | 'automatic' | undefined;\n}\n\nexport interface HttpMcpConnection {\n readonly client: McpClientLike;\n readonly transport: 'streamable-http' | 'sse';\n readonly close: () => Promise<void>;\n /**\n * Streamable HTTP only: terminate the server-side MCP session when one exists.\n * Undefined for legacy SSE connections.\n */\n readonly terminateSession?: (() => Promise<void>) | undefined;\n}\n\ninterface DynamicMcpClient {\n readonly Client: new (\n metadata: { name: string; version: string },\n options?: { readonly inputRequired?: { readonly autoFulfill: boolean } },\n ) => {\n connect: (transport: unknown) => Promise<void>;\n close: () => Promise<void>;\n listTools: McpClientLike['listTools'];\n callTool: McpClientLike['callTool'];\n } & McpClientRequestHandler;\n readonly StreamableHTTPClientTransport: new (\n url: URL,\n options?: unknown,\n ) => unknown;\n readonly SSEClientTransport: new (url: URL, options?: unknown) => unknown;\n}\n\nasync function loadClientModule(): Promise<DynamicMcpClient> {\n try {\n return (await import(MCP_CLIENT_PACKAGE)) as unknown as DynamicMcpClient;\n } catch (error) {\n throw new Error(\n 'MCP HTTP support requires @modelcontextprotocol/client >= 2.0.0. ' +\n 'Install it with npm install @modelcontextprotocol/client.',\n { cause: error },\n );\n }\n}\n\nfunction parseServerUrl(value: string | URL): URL {\n let url: URL;\n try {\n url = value instanceof URL ? new URL(value.href) : new URL(value);\n } catch (error) {\n throw new TypeError('MCP HTTP server URL must be a valid absolute URL', { cause: error });\n }\n\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n throw new TypeError('MCP HTTP server URL must use http: or https:');\n }\n return url;\n}\n\nfunction transportOptions(options: HttpMcpClientOptions): Record<string, unknown> {\n return {\n ...(options.requestInit !== undefined ? { requestInit: options.requestInit } : {}),\n ...(options.fetch !== undefined ? { fetch: options.fetch } : {}),\n };\n}\n\nfunction connectionFrom(\n client: DynamicMcpClient['Client'] extends new (...args: infer _Args) => infer C ? C : never,\n transport: unknown,\n kind: 'streamable-http' | 'sse',\n): HttpMcpConnection {\n const transportWithTermination = transport as {\n terminateSession?: (() => Promise<void>) | undefined;\n };\n\n return {\n client,\n transport: kind,\n close: () => client.close(),\n ...(kind === 'streamable-http' && typeof transportWithTermination.terminateSession === 'function'\n ? { terminateSession: () => transportWithTermination.terminateSession!() }\n : {}),\n };\n}\n\nasync function connectWithTransport(\n mode: Exclude<McpHttpTransport, 'auto'>,\n url: URL,\n options: HttpMcpClientOptions,\n modules: DynamicMcpClient,\n): Promise<HttpMcpConnection> {\n const client = new modules.Client(\n {\n name: options.name ?? '@nemesis-oss/ollama-sdk',\n version: options.version ?? '1.0.0',\n },\n { inputRequired: { autoFulfill: options.inputRequiredMode === 'automatic' } },\n );\n registerElicitationHandlers(client, options.elicitation);\n const transport =\n mode === 'streamable-http'\n ? new modules.StreamableHTTPClientTransport(url, transportOptions(options))\n : new modules.SSEClientTransport(url, transportOptions(options));\n\n await client.connect(transport);\n return connectionFrom(client, transport, mode);\n}\n\nfunction responseStatus(error: unknown): number | undefined {\n if (typeof error !== 'object' || error === null) return undefined;\n const value = error as Record<string, unknown>;\n if (typeof value.status === 'number') return value.status;\n if (typeof value.statusCode === 'number') return value.statusCode;\n\n const response = value.response;\n if (typeof response === 'object' && response !== null && typeof (response as Record<string, unknown>).status === 'number') {\n return (response as Record<string, number>).status;\n }\n\n const cause = value.cause;\n if (cause !== error) return responseStatus(cause);\n return undefined;\n}\n\nfunction shouldFallbackToSse(error: unknown): boolean {\n const status = responseStatus(error);\n return status !== undefined && status >= 400 && status < 500 && status !== 401 && status !== 403 && status !== 429;\n}\n\n/**\n * Connect to a remote MCP server.\n *\n * Defaults to modern Streamable HTTP. Use 'sse' for an explicitly legacy server or\n * 'auto' to try Streamable HTTP and fall back to SSE only for a non-authentication 4xx\n * response, avoiding accidental downgrade on credentials, throttling, or server failures.\n */\nexport async function connectMcpHttpClient(\n options: HttpMcpClientOptions,\n): Promise<HttpMcpConnection> {\n const url = parseServerUrl(options.url);\n const mode = options.transport ?? 'streamable-http';\n if (mode !== 'auto') {\n return connectWithTransport(mode, url, options, await loadClientModule());\n }\n\n const modules = await loadClientModule();\n try {\n return await connectWithTransport('streamable-http', url, options, modules);\n } catch (error) {\n if (!shouldFallbackToSse(error)) throw error;\n try {\n return await connectWithTransport('sse', url, options, modules);\n } catch (sseError) {\n throw new Error(\n 'MCP Streamable HTTP was unavailable and the legacy SSE fallback also failed.',\n { cause: sseError },\n );\n }\n }\n}\n\nexport async function connectStreamableHttpMcpClient(\n options: Omit<HttpMcpClientOptions, 'transport'>,\n): Promise<HttpMcpConnection> {\n return connectMcpHttpClient({ ...options, transport: 'streamable-http' });\n}\n\nexport async function connectSseMcpClient(\n options: Omit<HttpMcpClientOptions, 'transport'>,\n): Promise<HttpMcpConnection> {\n return connectMcpHttpClient({ ...options, transport: 'sse' });\n}\n"]}
@@ -1,4 +1,5 @@
1
- import { M as McpClientLike } from './types-MOsWXEE7.cjs';
1
+ import { g as McpElicitationHandlers, M as McpClientLike } from './types-CI-gM2u5.cjs';
2
+ import 'zod';
2
3
 
3
4
  /**
4
5
  * Optional remote MCP transport connectors.
@@ -23,6 +24,9 @@ interface HttpMcpClientOptions {
23
24
  readonly requestInit?: RequestInit | undefined;
24
25
  /** Optional fetch implementation forwarded to the MCP transport. */
25
26
  readonly fetch?: typeof globalThis.fetch | undefined;
27
+ readonly elicitation?: McpElicitationHandlers | undefined;
28
+ /** Defaults to manual so input_required responses are returned to the caller. */
29
+ readonly inputRequiredMode?: 'manual' | 'automatic' | undefined;
26
30
  }
27
31
  interface HttpMcpConnection {
28
32
  readonly client: McpClientLike;
@@ -1,4 +1,5 @@
1
- import { M as McpClientLike } from './types-MOsWXEE7.js';
1
+ import { g as McpElicitationHandlers, M as McpClientLike } from './types-CI-gM2u5.js';
2
+ import 'zod';
2
3
 
3
4
  /**
4
5
  * Optional remote MCP transport connectors.
@@ -23,6 +24,9 @@ interface HttpMcpClientOptions {
23
24
  readonly requestInit?: RequestInit | undefined;
24
25
  /** Optional fetch implementation forwarded to the MCP transport. */
25
26
  readonly fetch?: typeof globalThis.fetch | undefined;
27
+ readonly elicitation?: McpElicitationHandlers | undefined;
28
+ /** Defaults to manual so input_required responses are returned to the caller. */
29
+ readonly inputRequiredMode?: 'manual' | 'automatic' | undefined;
26
30
  }
27
31
  interface HttpMcpConnection {
28
32
  readonly client: McpClientLike;
package/dist/mcp-http.js CHANGED
@@ -1,3 +1,38 @@
1
+ // src/mcp/client-options.ts
2
+ function registerElicitationHandlers(client, handlers) {
3
+ if (handlers === void 0) return;
4
+ const supportsForm = handlers.form !== void 0;
5
+ const supportsUrl = handlers.url !== void 0;
6
+ if (!supportsForm && !supportsUrl) {
7
+ throw new TypeError("At least one MCP elicitation handler must be provided");
8
+ }
9
+ if (client.registerCapabilities === void 0 || client.setRequestHandler === void 0) {
10
+ throw new TypeError(
11
+ "The MCP client does not support elicitation capabilities and request handlers"
12
+ );
13
+ }
14
+ client.registerCapabilities({
15
+ elicitation: {
16
+ ...supportsForm ? { form: {} } : {},
17
+ ...supportsUrl ? { url: {} } : {}
18
+ }
19
+ });
20
+ client.setRequestHandler("elicitation/create", async ({ params }) => {
21
+ if (params.mode === "url") {
22
+ const request2 = params;
23
+ if (handlers.url === void 0) {
24
+ throw new Error("MCP server requested URL elicitation, but no URL handler is configured");
25
+ }
26
+ return handlers.url(request2);
27
+ }
28
+ const request = params;
29
+ if (handlers.form === void 0) {
30
+ throw new Error("MCP server requested form elicitation, but no form handler is configured");
31
+ }
32
+ return handlers.form(request);
33
+ });
34
+ }
35
+
1
36
  // src/mcp/http.ts
2
37
  var MCP_CLIENT_PACKAGE = "@modelcontextprotocol/client";
3
38
  async function loadClientModule() {
@@ -38,10 +73,14 @@ function connectionFrom(client, transport, kind) {
38
73
  };
39
74
  }
40
75
  async function connectWithTransport(mode, url, options, modules) {
41
- const client = new modules.Client({
42
- name: options.name ?? "@nemesis-oss/ollama-sdk",
43
- version: options.version ?? "1.0.0"
44
- });
76
+ const client = new modules.Client(
77
+ {
78
+ name: options.name ?? "@nemesis-oss/ollama-sdk",
79
+ version: options.version ?? "1.0.0"
80
+ },
81
+ { inputRequired: { autoFulfill: options.inputRequiredMode === "automatic" } }
82
+ );
83
+ registerElicitationHandlers(client, options.elicitation);
45
84
  const transport = mode === "streamable-http" ? new modules.StreamableHTTPClientTransport(url, transportOptions(options)) : new modules.SSEClientTransport(url, transportOptions(options));
46
85
  await client.connect(transport);
47
86
  return connectionFrom(client, transport, mode);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mcp/http.ts"],"names":[],"mappings":";AAUA,IAAM,kBAAA,GAAqB,8BAAA;AA+C3B,eAAe,gBAAA,GAA8C;AAC3D,EAAA,IAAI;AACF,IAAA,OAAQ,MAAM,OAAO,kBAAA,CAAA;AAAA,EACvB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,4HAAA;AAAA,MAEA,EAAE,OAAO,KAAA;AAAM,KACjB;AAAA,EACF;AACF;AAEA,SAAS,eAAe,KAAA,EAA0B;AAChD,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,KAAA,YAAiB,MAAM,IAAI,GAAA,CAAI,MAAM,IAAI,CAAA,GAAI,IAAI,GAAA,CAAI,KAAK,CAAA;AAAA,EAClE,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,SAAA,CAAU,kDAAA,EAAoD,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAC1F;AAEA,EAAA,IAAI,GAAA,CAAI,QAAA,KAAa,OAAA,IAAW,GAAA,CAAI,aAAa,QAAA,EAAU;AACzD,IAAA,MAAM,IAAI,UAAU,8CAA8C,CAAA;AAAA,EACpE;AACA,EAAA,OAAO,GAAA;AACT;AAEA,SAAS,iBAAiB,OAAA,EAAwD;AAChF,EAAA,OAAO;AAAA,IACL,GAAI,QAAQ,WAAA,KAAgB,MAAA,GAAY,EA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;AACd,IAAA,IAAI,CAAC,mBAAA,CAAoB,KAAK,CAAA,EAAG,MAAM,KAAA;AACvC,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,oBAAA,CAAqB,KAAA,EAAO,GAAA,EAAK,SAAS,OAAO,CAAA;AAAA,IAChE,SAAS,QAAA,EAAU;AACjB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,8EAAA;AAAA,QACA,EAAE,OAAO,QAAA;AAAS,OACpB;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAsB,+BACpB,OAAA,EAC4B;AAC5B,EAAA,OAAO,qBAAqB,EAAE,GAAG,OAAA,EAAS,SAAA,EAAW,mBAAmB,CAAA;AAC1E;AAEA,eAAsB,oBACpB,OAAA,EAC4B;AAC5B,EAAA,OAAO,qBAAqB,EAAE,GAAG,OAAA,EAAS,SAAA,EAAW,OAAO,CAAA;AAC9D","file":"mcp-http.js","sourcesContent":["/**\n * Optional remote MCP transport connectors.\n *\n * The root SDK stays transport-agnostic and Edge-compatible. This subpath dynamically\n * loads the official MCP TypeScript client so applications can connect to remote servers\n * over modern Streamable HTTP or legacy SSE.\n */\n\nimport type { McpClientLike } from './types.js';\n\nconst MCP_CLIENT_PACKAGE = '@modelcontextprotocol/client';\n\nexport type McpHttpTransport = 'streamable-http' | 'sse' | 'auto';\n\nexport interface HttpMcpClientOptions {\n /** Absolute MCP server URL, for example https://example.com/mcp. */\n readonly url: string | URL;\n /**\n * Transport selection. Defaults to Streamable HTTP. In 'auto' mode, a compatible 4xx\n * from the modern transport triggers a retry with the legacy SSE transport.\n */\n readonly transport?: McpHttpTransport | undefined;\n readonly name?: string | undefined;\n readonly version?: string | undefined;\n /** Fetch RequestInit forwarded to the MCP transport for remote authentication/proxy headers. */\n readonly requestInit?: RequestInit | undefined;\n /** Optional fetch implementation forwarded to the MCP transport. */\n readonly fetch?: typeof globalThis.fetch | undefined;\n}\n\nexport interface HttpMcpConnection {\n readonly client: McpClientLike;\n readonly transport: 'streamable-http' | 'sse';\n readonly close: () => Promise<void>;\n /**\n * Streamable HTTP only: terminate the server-side MCP session when one exists.\n * Undefined for legacy SSE connections.\n */\n readonly terminateSession?: (() => Promise<void>) | undefined;\n}\n\ninterface DynamicMcpClient {\n readonly Client: new (\n metadata: { name: string; version: string },\n ) => {\n connect: (transport: unknown) => Promise<void>;\n close: () => Promise<void>;\n listTools: McpClientLike['listTools'];\n callTool: McpClientLike['callTool'];\n };\n readonly StreamableHTTPClientTransport: new (\n url: URL,\n options?: unknown,\n ) => unknown;\n readonly SSEClientTransport: new (url: URL, options?: unknown) => unknown;\n}\n\nasync function loadClientModule(): Promise<DynamicMcpClient> {\n try {\n return (await import(MCP_CLIENT_PACKAGE)) as unknown as DynamicMcpClient;\n } catch (error) {\n throw new Error(\n 'MCP HTTP support requires @modelcontextprotocol/client >= 2.0.0. ' +\n 'Install it with npm install @modelcontextprotocol/client.',\n { cause: error },\n );\n }\n}\n\nfunction parseServerUrl(value: string | URL): URL {\n let url: URL;\n try {\n url = value instanceof URL ? new URL(value.href) : new URL(value);\n } catch (error) {\n throw new TypeError('MCP HTTP server URL must be a valid absolute URL', { cause: error });\n }\n\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n throw new TypeError('MCP HTTP server URL must use http: or https:');\n }\n return url;\n}\n\nfunction transportOptions(options: HttpMcpClientOptions): Record<string, unknown> {\n return {\n ...(options.requestInit !== undefined ? { requestInit: options.requestInit } : {}),\n ...(options.fetch !== undefined ? { fetch: options.fetch } : {}),\n };\n}\n\nfunction connectionFrom(\n client: DynamicMcpClient['Client'] extends new (...args: infer _Args) => infer C ? C : never,\n transport: unknown,\n kind: 'streamable-http' | 'sse',\n): HttpMcpConnection {\n const transportWithTermination = transport as {\n terminateSession?: (() => Promise<void>) | undefined;\n };\n\n return {\n client,\n transport: kind,\n close: () => client.close(),\n ...(kind === 'streamable-http' && typeof transportWithTermination.terminateSession === 'function'\n ? { terminateSession: () => transportWithTermination.terminateSession!() }\n : {}),\n };\n}\n\nasync function connectWithTransport(\n mode: Exclude<McpHttpTransport, 'auto'>,\n url: URL,\n options: HttpMcpClientOptions,\n modules: DynamicMcpClient,\n): Promise<HttpMcpConnection> {\n const client = new modules.Client({\n name: options.name ?? '@nemesis-oss/ollama-sdk',\n version: options.version ?? '1.0.0',\n });\n const transport =\n mode === 'streamable-http'\n ? new modules.StreamableHTTPClientTransport(url, transportOptions(options))\n : new modules.SSEClientTransport(url, transportOptions(options));\n\n await client.connect(transport);\n return connectionFrom(client, transport, mode);\n}\n\nfunction responseStatus(error: unknown): number | undefined {\n if (typeof error !== 'object' || error === null) return undefined;\n const value = error as Record<string, unknown>;\n if (typeof value.status === 'number') return value.status;\n if (typeof value.statusCode === 'number') return value.statusCode;\n\n const response = value.response;\n if (typeof response === 'object' && response !== null && typeof (response as Record<string, unknown>).status === 'number') {\n return (response as Record<string, number>).status;\n }\n\n const cause = value.cause;\n if (cause !== error) return responseStatus(cause);\n return undefined;\n}\n\nfunction shouldFallbackToSse(error: unknown): boolean {\n const status = responseStatus(error);\n return status !== undefined && status >= 400 && status < 500 && status !== 401 && status !== 403 && status !== 429;\n}\n\n/**\n * Connect to a remote MCP server.\n *\n * Defaults to modern Streamable HTTP. Use 'sse' for an explicitly legacy server or\n * 'auto' to try Streamable HTTP and fall back to SSE only for a non-authentication 4xx\n * response, avoiding accidental downgrade on credentials, throttling, or server failures.\n */\nexport async function connectMcpHttpClient(\n options: HttpMcpClientOptions,\n): Promise<HttpMcpConnection> {\n const url = parseServerUrl(options.url);\n const mode = options.transport ?? 'streamable-http';\n if (mode !== 'auto') {\n return connectWithTransport(mode, url, options, await loadClientModule());\n }\n\n const modules = await loadClientModule();\n try {\n return await connectWithTransport('streamable-http', url, options, modules);\n } catch (error) {\n if (!shouldFallbackToSse(error)) throw error;\n try {\n return await connectWithTransport('sse', url, options, modules);\n } catch (sseError) {\n throw new Error(\n 'MCP Streamable HTTP was unavailable and the legacy SSE fallback also failed.',\n { cause: sseError },\n );\n }\n }\n}\n\nexport async function connectStreamableHttpMcpClient(\n options: Omit<HttpMcpClientOptions, 'transport'>,\n): Promise<HttpMcpConnection> {\n return connectMcpHttpClient({ ...options, transport: 'streamable-http' });\n}\n\nexport async function connectSseMcpClient(\n options: Omit<HttpMcpClientOptions, 'transport'>,\n): Promise<HttpMcpConnection> {\n return connectMcpHttpClient({ ...options, transport: 'sse' });\n}\n"]}
1
+ {"version":3,"sources":["../src/mcp/client-options.ts","../src/mcp/http.ts"],"names":["request"],"mappings":";AA2BO,SAAS,2BAAA,CACd,QACA,QAAA,EACM;AACN,EAAA,IAAI,aAAa,MAAA,EAAW;AAE5B,EAAA,MAAM,YAAA,GAAe,SAAS,IAAA,KAAS,MAAA;AACvC,EAAA,MAAM,WAAA,GAAc,SAAS,GAAA,KAAQ,MAAA;AACrC,EAAA,IAAI,CAAC,YAAA,IAAgB,CAAC,WAAA,EAAa;AACjC,IAAA,MAAM,IAAI,UAAU,uDAAuD,CAAA;AAAA,EAC7E;AACA,EAAA,IAAI,MAAA,CAAO,oBAAA,KAAyB,MAAA,IAAa,MAAA,CAAO,sBAAsB,MAAA,EAAW;AACvF,IAAA,MAAM,IAAI,SAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,MAAA,CAAO,oBAAA,CAAqB;AAAA,IAC1B,WAAA,EAAa;AAAA,MACX,GAAI,YAAA,GAAe,EAAE,MAAM,EAAC,KAAM,EAAC;AAAA,MACnC,GAAI,WAAA,GAAc,EAAE,KAAK,EAAC,KAAM;AAAC;AACnC,GACD,CAAA;AACD,EAAA,MAAA,CAAO,iBAAA,CAAkB,oBAAA,EAAsB,OAAO,EAAE,QAAO,KAAM;AACnE,IAAA,IAAI,MAAA,CAAO,SAAS,KAAA,EAAO;AACzB,MAAA,MAAMA,QAAAA,GAAU,MAAA;AAChB,MAAA,IAAI,QAAA,CAAS,QAAQ,MAAA,EAAW;AAC9B,QAAA,MAAM,IAAI,MAAM,wEAAwE,CAAA;AAAA,MAC1F;AACA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,CAAA;AAAA,EAC5E,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,CAAC,mBAAA,CAAoB,KAAK,CAAA,EAAG,MAAM,KAAA;AACvC,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,oBAAA,CAAqB,KAAA,EAAO,GAAA,EAAK,SAAS,OAAO,CAAA;AAAA,IAChE,SAAS,QAAA,EAAU;AACjB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,8EAAA;AAAA,QACA,EAAE,OAAO,QAAA;AAAS,OACpB;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAsB,+BACpB,OAAA,EAC4B;AAC5B,EAAA,OAAO,qBAAqB,EAAE,GAAG,OAAA,EAAS,SAAA,EAAW,mBAAmB,CAAA;AAC1E;AAEA,eAAsB,oBACpB,OAAA,EAC4B;AAC5B,EAAA,OAAO,qBAAqB,EAAE,GAAG,OAAA,EAAS,SAAA,EAAW,OAAO,CAAA;AAC9D","file":"mcp-http.js","sourcesContent":["import type {\n McpElicitationFormRequest,\n McpElicitationHandlers,\n McpElicitationRequest,\n McpElicitationResult,\n McpElicitationUrlRequest,\n} from './types.js';\n\nexport interface McpClientRequestHandler {\n registerCapabilities?:\n | ((capabilities: {\n readonly elicitation: {\n readonly form?: Record<string, never> | undefined;\n readonly url?: Record<string, never> | undefined;\n };\n }) => void)\n | undefined;\n setRequestHandler?:\n | ((\n method: 'elicitation/create',\n handler: (request: {\n readonly params: McpElicitationRequest;\n }) => Promise<McpElicitationResult>,\n ) => void)\n | undefined;\n}\n\nexport function registerElicitationHandlers(\n client: McpClientRequestHandler,\n handlers: McpElicitationHandlers | undefined,\n): void {\n if (handlers === undefined) return;\n\n const supportsForm = handlers.form !== undefined;\n const supportsUrl = handlers.url !== undefined;\n if (!supportsForm && !supportsUrl) {\n throw new TypeError('At least one MCP elicitation handler must be provided');\n }\n if (client.registerCapabilities === undefined || client.setRequestHandler === undefined) {\n throw new TypeError(\n 'The MCP client does not support elicitation capabilities and request handlers',\n );\n }\n\n client.registerCapabilities({\n elicitation: {\n ...(supportsForm ? { form: {} } : {}),\n ...(supportsUrl ? { url: {} } : {}),\n },\n });\n client.setRequestHandler('elicitation/create', async ({ params }) => {\n if (params.mode === 'url') {\n const request = params as McpElicitationUrlRequest;\n if (handlers.url === undefined) {\n throw new Error('MCP server requested URL elicitation, but no URL handler is configured');\n }\n return handlers.url(request);\n }\n\n const request = params as McpElicitationFormRequest;\n if (handlers.form === undefined) {\n throw new Error('MCP server requested form elicitation, but no form handler is configured');\n }\n return handlers.form(request);\n });\n}\n","/**\n * Optional remote MCP transport connectors.\n *\n * The root SDK stays transport-agnostic and Edge-compatible. This subpath dynamically\n * loads the official MCP TypeScript client so applications can connect to remote servers\n * over modern Streamable HTTP or legacy SSE.\n */\n\nimport { registerElicitationHandlers, type McpClientRequestHandler } from './client-options.js';\nimport type { McpClientLike, McpElicitationHandlers } from './types.js';\n\nconst MCP_CLIENT_PACKAGE = '@modelcontextprotocol/client';\n\nexport type McpHttpTransport = 'streamable-http' | 'sse' | 'auto';\n\nexport interface HttpMcpClientOptions {\n /** Absolute MCP server URL, for example https://example.com/mcp. */\n readonly url: string | URL;\n /**\n * Transport selection. Defaults to Streamable HTTP. In 'auto' mode, a compatible 4xx\n * from the modern transport triggers a retry with the legacy SSE transport.\n */\n readonly transport?: McpHttpTransport | undefined;\n readonly name?: string | undefined;\n readonly version?: string | undefined;\n /** Fetch RequestInit forwarded to the MCP transport for remote authentication/proxy headers. */\n readonly requestInit?: RequestInit | undefined;\n /** Optional fetch implementation forwarded to the MCP transport. */\n readonly fetch?: typeof globalThis.fetch | undefined;\n readonly elicitation?: McpElicitationHandlers | undefined;\n /** Defaults to manual so input_required responses are returned to the caller. */\n readonly inputRequiredMode?: 'manual' | 'automatic' | undefined;\n}\n\nexport interface HttpMcpConnection {\n readonly client: McpClientLike;\n readonly transport: 'streamable-http' | 'sse';\n readonly close: () => Promise<void>;\n /**\n * Streamable HTTP only: terminate the server-side MCP session when one exists.\n * Undefined for legacy SSE connections.\n */\n readonly terminateSession?: (() => Promise<void>) | undefined;\n}\n\ninterface DynamicMcpClient {\n readonly Client: new (\n metadata: { name: string; version: string },\n options?: { readonly inputRequired?: { readonly autoFulfill: boolean } },\n ) => {\n connect: (transport: unknown) => Promise<void>;\n close: () => Promise<void>;\n listTools: McpClientLike['listTools'];\n callTool: McpClientLike['callTool'];\n } & McpClientRequestHandler;\n readonly StreamableHTTPClientTransport: new (\n url: URL,\n options?: unknown,\n ) => unknown;\n readonly SSEClientTransport: new (url: URL, options?: unknown) => unknown;\n}\n\nasync function loadClientModule(): Promise<DynamicMcpClient> {\n try {\n return (await import(MCP_CLIENT_PACKAGE)) as unknown as DynamicMcpClient;\n } catch (error) {\n throw new Error(\n 'MCP HTTP support requires @modelcontextprotocol/client >= 2.0.0. ' +\n 'Install it with npm install @modelcontextprotocol/client.',\n { cause: error },\n );\n }\n}\n\nfunction parseServerUrl(value: string | URL): URL {\n let url: URL;\n try {\n url = value instanceof URL ? new URL(value.href) : new URL(value);\n } catch (error) {\n throw new TypeError('MCP HTTP server URL must be a valid absolute URL', { cause: error });\n }\n\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n throw new TypeError('MCP HTTP server URL must use http: or https:');\n }\n return url;\n}\n\nfunction transportOptions(options: HttpMcpClientOptions): Record<string, unknown> {\n return {\n ...(options.requestInit !== undefined ? { requestInit: options.requestInit } : {}),\n ...(options.fetch !== undefined ? { fetch: options.fetch } : {}),\n };\n}\n\nfunction connectionFrom(\n client: DynamicMcpClient['Client'] extends new (...args: infer _Args) => infer C ? C : never,\n transport: unknown,\n kind: 'streamable-http' | 'sse',\n): HttpMcpConnection {\n const transportWithTermination = transport as {\n terminateSession?: (() => Promise<void>) | undefined;\n };\n\n return {\n client,\n transport: kind,\n close: () => client.close(),\n ...(kind === 'streamable-http' && typeof transportWithTermination.terminateSession === 'function'\n ? { terminateSession: () => transportWithTermination.terminateSession!() }\n : {}),\n };\n}\n\nasync function connectWithTransport(\n mode: Exclude<McpHttpTransport, 'auto'>,\n url: URL,\n options: HttpMcpClientOptions,\n modules: DynamicMcpClient,\n): Promise<HttpMcpConnection> {\n const client = new modules.Client(\n {\n name: options.name ?? '@nemesis-oss/ollama-sdk',\n version: options.version ?? '1.0.0',\n },\n { inputRequired: { autoFulfill: options.inputRequiredMode === 'automatic' } },\n );\n registerElicitationHandlers(client, options.elicitation);\n const transport =\n mode === 'streamable-http'\n ? new modules.StreamableHTTPClientTransport(url, transportOptions(options))\n : new modules.SSEClientTransport(url, transportOptions(options));\n\n await client.connect(transport);\n return connectionFrom(client, transport, mode);\n}\n\nfunction responseStatus(error: unknown): number | undefined {\n if (typeof error !== 'object' || error === null) return undefined;\n const value = error as Record<string, unknown>;\n if (typeof value.status === 'number') return value.status;\n if (typeof value.statusCode === 'number') return value.statusCode;\n\n const response = value.response;\n if (typeof response === 'object' && response !== null && typeof (response as Record<string, unknown>).status === 'number') {\n return (response as Record<string, number>).status;\n }\n\n const cause = value.cause;\n if (cause !== error) return responseStatus(cause);\n return undefined;\n}\n\nfunction shouldFallbackToSse(error: unknown): boolean {\n const status = responseStatus(error);\n return status !== undefined && status >= 400 && status < 500 && status !== 401 && status !== 403 && status !== 429;\n}\n\n/**\n * Connect to a remote MCP server.\n *\n * Defaults to modern Streamable HTTP. Use 'sse' for an explicitly legacy server or\n * 'auto' to try Streamable HTTP and fall back to SSE only for a non-authentication 4xx\n * response, avoiding accidental downgrade on credentials, throttling, or server failures.\n */\nexport async function connectMcpHttpClient(\n options: HttpMcpClientOptions,\n): Promise<HttpMcpConnection> {\n const url = parseServerUrl(options.url);\n const mode = options.transport ?? 'streamable-http';\n if (mode !== 'auto') {\n return connectWithTransport(mode, url, options, await loadClientModule());\n }\n\n const modules = await loadClientModule();\n try {\n return await connectWithTransport('streamable-http', url, options, modules);\n } catch (error) {\n if (!shouldFallbackToSse(error)) throw error;\n try {\n return await connectWithTransport('sse', url, options, modules);\n } catch (sseError) {\n throw new Error(\n 'MCP Streamable HTTP was unavailable and the legacy SSE fallback also failed.',\n { cause: sseError },\n );\n }\n }\n}\n\nexport async function connectStreamableHttpMcpClient(\n options: Omit<HttpMcpClientOptions, 'transport'>,\n): Promise<HttpMcpConnection> {\n return connectMcpHttpClient({ ...options, transport: 'streamable-http' });\n}\n\nexport async function connectSseMcpClient(\n options: Omit<HttpMcpClientOptions, 'transport'>,\n): Promise<HttpMcpConnection> {\n return connectMcpHttpClient({ ...options, transport: 'sse' });\n}\n"]}
@@ -1,5 +1,40 @@
1
1
  'use strict';
2
2
 
3
+ // src/mcp/client-options.ts
4
+ function registerElicitationHandlers(client, handlers) {
5
+ if (handlers === void 0) return;
6
+ const supportsForm = handlers.form !== void 0;
7
+ const supportsUrl = handlers.url !== void 0;
8
+ if (!supportsForm && !supportsUrl) {
9
+ throw new TypeError("At least one MCP elicitation handler must be provided");
10
+ }
11
+ if (client.registerCapabilities === void 0 || client.setRequestHandler === void 0) {
12
+ throw new TypeError(
13
+ "The MCP client does not support elicitation capabilities and request handlers"
14
+ );
15
+ }
16
+ client.registerCapabilities({
17
+ elicitation: {
18
+ ...supportsForm ? { form: {} } : {},
19
+ ...supportsUrl ? { url: {} } : {}
20
+ }
21
+ });
22
+ client.setRequestHandler("elicitation/create", async ({ params }) => {
23
+ if (params.mode === "url") {
24
+ const request2 = params;
25
+ if (handlers.url === void 0) {
26
+ throw new Error("MCP server requested URL elicitation, but no URL handler is configured");
27
+ }
28
+ return handlers.url(request2);
29
+ }
30
+ const request = params;
31
+ if (handlers.form === void 0) {
32
+ throw new Error("MCP server requested form elicitation, but no form handler is configured");
33
+ }
34
+ return handlers.form(request);
35
+ });
36
+ }
37
+
3
38
  // src/mcp/stdio.ts
4
39
  var MCP_CLIENT_PACKAGE = "@modelcontextprotocol/client";
5
40
  var MCP_STDIO_PACKAGE = "@modelcontextprotocol/client/stdio";
@@ -25,10 +60,14 @@ async function connectStdioMcpClient(server, options = {}) {
25
60
  throw new TypeError("MCP stdio server command must be a non-empty string");
26
61
  }
27
62
  const { clientModule, stdioModule } = await loadStdioModules();
28
- const client = new clientModule.Client({
29
- name: options.name ?? "@nemesis-oss/ollama-sdk",
30
- version: options.version ?? "1.0.0"
31
- });
63
+ const client = new clientModule.Client(
64
+ {
65
+ name: options.name ?? "@nemesis-oss/ollama-sdk",
66
+ version: options.version ?? "1.0.0"
67
+ },
68
+ { inputRequired: { autoFulfill: options.inputRequiredMode === "automatic" } }
69
+ );
70
+ registerElicitationHandlers(client, options.elicitation);
32
71
  const transport = new stdioModule.StdioClientTransport({
33
72
  command: server.command,
34
73
  ...server.args !== void 0 ? { args: [...server.args] } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mcp/stdio.ts"],"names":[],"mappings":";;;AAWA,IAAM,kBAAA,GAAqB,8BAAA;AAC3B,IAAM,iBAAA,GAAoB,oCAAA;AAkC1B,eAAe,gBAAA,GAGZ;AACD,EAAA,IAAI;AACF,IAAA,MAAM,CAAC,YAAA,EAAc,WAAW,CAAA,GAAI,MAAM,QAAQ,GAAA,CAAI;AAAA,MACpD,OAAO,kBAAA,CAAA;AAAA,MACP,OAAO,iBAAA;AAAA,KACR,CAAA;AACD,IAAA,OAAO;AAAA,MACL,YAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,6HAAA;AAAA,MAEA,EAAE,OAAO,KAAA;AAAM,KACjB;AAAA,EACF;AACF;AAMA,eAAsB,qBAAA,CACpB,MAAA,EACA,OAAA,GAAiC,EAAC,EACL;AAC7B,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,MAAM,IAAI,UAAU,qDAAqD,CAAA;AAAA,EAC3E;AAEA,EAAA,MAAM,EAAE,YAAA,EAAc,WAAA,EAAY,GAAI,MAAM,gBAAA,EAAiB;AAC7D,EAAA,MAAM,MAAA,GAAS,IAAI,YAAA,CAAa,MAAA,CAAO;AAAA,IACrC,IAAA,EAAM,QAAQ,IAAA,IAAQ,yBAAA;AAAA,IACtB,OAAA,EAAS,QAAQ,OAAA,IAAW;AAAA,GAC7B,CAAA;AACD,EAAA,MAAM,SAAA,GAAY,IAAI,WAAA,CAAY,oBAAA,CAAqB;AAAA,IACrD,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,GAAI,MAAA,CAAO,IAAA,KAAS,MAAA,GAAY,EAAE,IAAA,EAAM,CAAC,GAAG,MAAA,CAAO,IAAI,CAAA,EAAE,GAAI,EAAC;AAAA,IAC9D,GAAI,OAAO,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,EAAK,MAAA,CAAO,GAAA,EAAI,GAAI,EAAC;AAAA,IACtD,GAAI,OAAO,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,EAAK,MAAA,CAAO,GAAA,EAAI,GAAI,EAAC;AAAA,IACtD,GAAI,OAAO,aAAA,KAAkB,MAAA,GAAY,EAAE,aAAA,EAAe,MAAA,CAAO,aAAA,EAAc,GAAI,EAAC;AAAA,IACpF,GAAI,OAAO,MAAA,KAAW,MAAA,GAAY,EAAE,MAAA,EAAQ,MAAA,CAAO,MAAA,EAAO,GAAI;AAAC,GAChE,CAAA;AAED,EAAA,MAAM,MAAA,CAAO,QAAQ,SAAS,CAAA;AAE9B,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,KAAA,EAAO,MAAM,MAAA,CAAO,KAAA;AAAM,GAC5B;AACF","file":"mcp-stdio.cjs","sourcesContent":["/**\n * Optional Node.js MCP stdio connector.\n *\n * This subpath uses the official @modelcontextprotocol/client v2 package dynamically so\n * the root SDK entrypoint remains transport-agnostic and Edge-runtime compatible.\n *\n * Install @modelcontextprotocol/client separately when using this adapter.\n */\n\nimport type { McpClientLike } from './types.js';\n\nconst MCP_CLIENT_PACKAGE = '@modelcontextprotocol/client';\nconst MCP_STDIO_PACKAGE = '@modelcontextprotocol/client/stdio';\n\nexport interface StdioMcpServerParameters {\n readonly command: string;\n readonly args?: readonly string[] | undefined;\n readonly cwd?: string | undefined;\n readonly env?: Record<string, string> | undefined;\n readonly maxBufferSize?: number | undefined;\n readonly stderr?: 'inherit' | 'pipe' | 'ignore' | undefined;\n}\n\nexport interface StdioMcpClientOptions {\n readonly name?: string | undefined;\n readonly version?: string | undefined;\n}\n\nexport interface StdioMcpConnection {\n readonly client: McpClientLike;\n readonly close: () => Promise<void>;\n}\n\ninterface DynamicMcpClientModule {\n readonly Client: new (metadata: { name: string; version: string }) => {\n connect: (transport: unknown) => Promise<void>;\n close: () => Promise<void>;\n listTools: McpClientLike['listTools'];\n callTool: McpClientLike['callTool'];\n };\n}\n\ninterface DynamicMcpStdioModule {\n readonly StdioClientTransport: new (server: StdioMcpServerParameters) => unknown;\n}\n\nasync function loadStdioModules(): Promise<{\n readonly clientModule: DynamicMcpClientModule;\n readonly stdioModule: DynamicMcpStdioModule;\n}> {\n try {\n const [clientModule, stdioModule] = await Promise.all([\n import(MCP_CLIENT_PACKAGE) as Promise<unknown>,\n import(MCP_STDIO_PACKAGE) as Promise<unknown>,\n ]);\n return {\n clientModule: clientModule as DynamicMcpClientModule,\n stdioModule: stdioModule as DynamicMcpStdioModule,\n };\n } catch (error) {\n throw new Error(\n 'MCP stdio support requires @modelcontextprotocol/client >= 2.0.0. ' +\n 'Install it with npm install @modelcontextprotocol/client.',\n { cause: error },\n );\n }\n}\n\n/**\n * Connects to a local MCP server over stdin/stdout using the official MCP TypeScript\n * client's Node-only StdioClientTransport.\n */\nexport async function connectStdioMcpClient(\n server: StdioMcpServerParameters,\n options: StdioMcpClientOptions = {},\n): Promise<StdioMcpConnection> {\n if (!server.command) {\n throw new TypeError('MCP stdio server command must be a non-empty string');\n }\n\n const { clientModule, stdioModule } = await loadStdioModules();\n const client = new clientModule.Client({\n name: options.name ?? '@nemesis-oss/ollama-sdk',\n version: options.version ?? '1.0.0',\n });\n const transport = new stdioModule.StdioClientTransport({\n command: server.command,\n ...(server.args !== undefined ? { args: [...server.args] } : {}),\n ...(server.cwd !== undefined ? { cwd: server.cwd } : {}),\n ...(server.env !== undefined ? { env: server.env } : {}),\n ...(server.maxBufferSize !== undefined ? { maxBufferSize: server.maxBufferSize } : {}),\n ...(server.stderr !== undefined ? { stderr: server.stderr } : {}),\n });\n\n await client.connect(transport);\n\n return {\n client,\n close: () => client.close(),\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/mcp/client-options.ts","../src/mcp/stdio.ts"],"names":["request"],"mappings":";;;AA2BO,SAAS,2BAAA,CACd,QACA,QAAA,EACM;AACN,EAAA,IAAI,aAAa,MAAA,EAAW;AAE5B,EAAA,MAAM,YAAA,GAAe,SAAS,IAAA,KAAS,MAAA;AACvC,EAAA,MAAM,WAAA,GAAc,SAAS,GAAA,KAAQ,MAAA;AACrC,EAAA,IAAI,CAAC,YAAA,IAAgB,CAAC,WAAA,EAAa;AACjC,IAAA,MAAM,IAAI,UAAU,uDAAuD,CAAA;AAAA,EAC7E;AACA,EAAA,IAAI,MAAA,CAAO,oBAAA,KAAyB,MAAA,IAAa,MAAA,CAAO,sBAAsB,MAAA,EAAW;AACvF,IAAA,MAAM,IAAI,SAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,MAAA,CAAO,oBAAA,CAAqB;AAAA,IAC1B,WAAA,EAAa;AAAA,MACX,GAAI,YAAA,GAAe,EAAE,MAAM,EAAC,KAAM,EAAC;AAAA,MACnC,GAAI,WAAA,GAAc,EAAE,KAAK,EAAC,KAAM;AAAC;AACnC,GACD,CAAA;AACD,EAAA,MAAA,CAAO,iBAAA,CAAkB,oBAAA,EAAsB,OAAO,EAAE,QAAO,KAAM;AACnE,IAAA,IAAI,MAAA,CAAO,SAAS,KAAA,EAAO;AACzB,MAAA,MAAMA,QAAAA,GAAU,MAAA;AAChB,MAAA,IAAI,QAAA,CAAS,QAAQ,MAAA,EAAW;AAC9B,QAAA,MAAM,IAAI,MAAM,wEAAwE,CAAA;AAAA,MAC1F;AACA,MAAA,OAAO,QAAA,CAAS,I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B,MAAA,EAAQ,QAAQ,WAAW,CAAA;AACvD,EAAA,MAAM,SAAA,GAAY,IAAI,WAAA,CAAY,oBAAA,CAAqB;AAAA,IACrD,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,GAAI,MAAA,CAAO,IAAA,KAAS,MAAA,GAAY,EAAE,IAAA,EAAM,CAAC,GAAG,MAAA,CAAO,IAAI,CAAA,EAAE,GAAI,EAAC;AAAA,IAC9D,GAAI,OAAO,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,EAAK,MAAA,CAAO,GAAA,EAAI,GAAI,EAAC;AAAA,IACtD,GAAI,OAAO,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,EAAK,MAAA,CAAO,GAAA,EAAI,GAAI,EAAC;AAAA,IACtD,GAAI,OAAO,aAAA,KAAkB,MAAA,GAAY,EAAE,aAAA,EAAe,MAAA,CAAO,aAAA,EAAc,GAAI,EAAC;AAAA,IACpF,GAAI,OAAO,MAAA,KAAW,MAAA,GAAY,EAAE,MAAA,EAAQ,MAAA,CAAO,MAAA,EAAO,GAAI;AAAC,GAChE,CAAA;AAED,EAAA,MAAM,MAAA,CAAO,QAAQ,SAAS,CAAA;AAE9B,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,KAAA,EAAO,MAAM,MAAA,CAAO,KAAA;AAAM,GAC5B;AACF","file":"mcp-stdio.cjs","sourcesContent":["import type {\n McpElicitationFormRequest,\n McpElicitationHandlers,\n McpElicitationRequest,\n McpElicitationResult,\n McpElicitationUrlRequest,\n} from './types.js';\n\nexport interface McpClientRequestHandler {\n registerCapabilities?:\n | ((capabilities: {\n readonly elicitation: {\n readonly form?: Record<string, never> | undefined;\n readonly url?: Record<string, never> | undefined;\n };\n }) => void)\n | undefined;\n setRequestHandler?:\n | ((\n method: 'elicitation/create',\n handler: (request: {\n readonly params: McpElicitationRequest;\n }) => Promise<McpElicitationResult>,\n ) => void)\n | undefined;\n}\n\nexport function registerElicitationHandlers(\n client: McpClientRequestHandler,\n handlers: McpElicitationHandlers | undefined,\n): void {\n if (handlers === undefined) return;\n\n const supportsForm = handlers.form !== undefined;\n const supportsUrl = handlers.url !== undefined;\n if (!supportsForm && !supportsUrl) {\n throw new TypeError('At least one MCP elicitation handler must be provided');\n }\n if (client.registerCapabilities === undefined || client.setRequestHandler === undefined) {\n throw new TypeError(\n 'The MCP client does not support elicitation capabilities and request handlers',\n );\n }\n\n client.registerCapabilities({\n elicitation: {\n ...(supportsForm ? { form: {} } : {}),\n ...(supportsUrl ? { url: {} } : {}),\n },\n });\n client.setRequestHandler('elicitation/create', async ({ params }) => {\n if (params.mode === 'url') {\n const request = params as McpElicitationUrlRequest;\n if (handlers.url === undefined) {\n throw new Error('MCP server requested URL elicitation, but no URL handler is configured');\n }\n return handlers.url(request);\n }\n\n const request = params as McpElicitationFormRequest;\n if (handlers.form === undefined) {\n throw new Error('MCP server requested form elicitation, but no form handler is configured');\n }\n return handlers.form(request);\n });\n}\n","/**\n * Optional Node.js MCP stdio connector.\n *\n * This subpath uses the official @modelcontextprotocol/client v2 package dynamically so\n * the root SDK entrypoint remains transport-agnostic and Edge-runtime compatible.\n *\n * Install @modelcontextprotocol/client separately when using this adapter.\n */\n\nimport { registerElicitationHandlers, type McpClientRequestHandler } from './client-options.js';\nimport type { McpClientLike, McpElicitationHandlers } from './types.js';\n\nconst MCP_CLIENT_PACKAGE = '@modelcontextprotocol/client';\nconst MCP_STDIO_PACKAGE = '@modelcontextprotocol/client/stdio';\n\nexport interface StdioMcpServerParameters {\n readonly command: string;\n readonly args?: readonly string[] | undefined;\n readonly cwd?: string | undefined;\n readonly env?: Record<string, string> | undefined;\n readonly maxBufferSize?: number | undefined;\n readonly stderr?: 'inherit' | 'pipe' | 'ignore' | undefined;\n}\n\nexport interface StdioMcpClientOptions {\n readonly name?: string | undefined;\n readonly version?: string | undefined;\n readonly elicitation?: McpElicitationHandlers | undefined;\n /** Defaults to manual so input_required responses are returned to the caller. */\n readonly inputRequiredMode?: 'manual' | 'automatic' | undefined;\n}\n\nexport interface StdioMcpConnection {\n readonly client: McpClientLike;\n readonly close: () => Promise<void>;\n}\n\ninterface DynamicMcpClientModule {\n readonly Client: new (\n metadata: { name: string; version: string },\n options?: { readonly inputRequired?: { readonly autoFulfill: boolean } },\n ) => {\n connect: (transport: unknown) => Promise<void>;\n close: () => Promise<void>;\n listTools: McpClientLike['listTools'];\n callTool: McpClientLike['callTool'];\n } & McpClientRequestHandler;\n}\n\ninterface DynamicMcpStdioModule {\n readonly StdioClientTransport: new (server: StdioMcpServerParameters) => unknown;\n}\n\nasync function loadStdioModules(): Promise<{\n readonly clientModule: DynamicMcpClientModule;\n readonly stdioModule: DynamicMcpStdioModule;\n}> {\n try {\n const [clientModule, stdioModule] = await Promise.all([\n import(MCP_CLIENT_PACKAGE) as Promise<unknown>,\n import(MCP_STDIO_PACKAGE) as Promise<unknown>,\n ]);\n return {\n clientModule: clientModule as DynamicMcpClientModule,\n stdioModule: stdioModule as DynamicMcpStdioModule,\n };\n } catch (error) {\n throw new Error(\n 'MCP stdio support requires @modelcontextprotocol/client >= 2.0.0. ' +\n 'Install it with npm install @modelcontextprotocol/client.',\n { cause: error },\n );\n }\n}\n\n/**\n * Connects to a local MCP server over stdin/stdout using the official MCP TypeScript\n * client's Node-only StdioClientTransport.\n */\nexport async function connectStdioMcpClient(\n server: StdioMcpServerParameters,\n options: StdioMcpClientOptions = {},\n): Promise<StdioMcpConnection> {\n if (!server.command) {\n throw new TypeError('MCP stdio server command must be a non-empty string');\n }\n\n const { clientModule, stdioModule } = await loadStdioModules();\n const client = new clientModule.Client(\n {\n name: options.name ?? '@nemesis-oss/ollama-sdk',\n version: options.version ?? '1.0.0',\n },\n { inputRequired: { autoFulfill: options.inputRequiredMode === 'automatic' } },\n );\n registerElicitationHandlers(client, options.elicitation);\n const transport = new stdioModule.StdioClientTransport({\n command: server.command,\n ...(server.args !== undefined ? { args: [...server.args] } : {}),\n ...(server.cwd !== undefined ? { cwd: server.cwd } : {}),\n ...(server.env !== undefined ? { env: server.env } : {}),\n ...(server.maxBufferSize !== undefined ? { maxBufferSize: server.maxBufferSize } : {}),\n ...(server.stderr !== undefined ? { stderr: server.stderr } : {}),\n });\n\n await client.connect(transport);\n\n return {\n client,\n close: () => client.close(),\n };\n}\n"]}
@@ -1,4 +1,5 @@
1
- import { M as McpClientLike } from './types-MOsWXEE7.cjs';
1
+ import { g as McpElicitationHandlers, M as McpClientLike } from './types-CI-gM2u5.cjs';
2
+ import 'zod';
2
3
 
3
4
  /**
4
5
  * Optional Node.js MCP stdio connector.
@@ -20,6 +21,9 @@ interface StdioMcpServerParameters {
20
21
  interface StdioMcpClientOptions {
21
22
  readonly name?: string | undefined;
22
23
  readonly version?: string | undefined;
24
+ readonly elicitation?: McpElicitationHandlers | undefined;
25
+ /** Defaults to manual so input_required responses are returned to the caller. */
26
+ readonly inputRequiredMode?: 'manual' | 'automatic' | undefined;
23
27
  }
24
28
  interface StdioMcpConnection {
25
29
  readonly client: McpClientLike;
@@ -1,4 +1,5 @@
1
- import { M as McpClientLike } from './types-MOsWXEE7.js';
1
+ import { g as McpElicitationHandlers, M as McpClientLike } from './types-CI-gM2u5.js';
2
+ import 'zod';
2
3
 
3
4
  /**
4
5
  * Optional Node.js MCP stdio connector.
@@ -20,6 +21,9 @@ interface StdioMcpServerParameters {
20
21
  interface StdioMcpClientOptions {
21
22
  readonly name?: string | undefined;
22
23
  readonly version?: string | undefined;
24
+ readonly elicitation?: McpElicitationHandlers | undefined;
25
+ /** Defaults to manual so input_required responses are returned to the caller. */
26
+ readonly inputRequiredMode?: 'manual' | 'automatic' | undefined;
23
27
  }
24
28
  interface StdioMcpConnection {
25
29
  readonly client: McpClientLike;
package/dist/mcp-stdio.js CHANGED
@@ -1,3 +1,38 @@
1
+ // src/mcp/client-options.ts
2
+ function registerElicitationHandlers(client, handlers) {
3
+ if (handlers === void 0) return;
4
+ const supportsForm = handlers.form !== void 0;
5
+ const supportsUrl = handlers.url !== void 0;
6
+ if (!supportsForm && !supportsUrl) {
7
+ throw new TypeError("At least one MCP elicitation handler must be provided");
8
+ }
9
+ if (client.registerCapabilities === void 0 || client.setRequestHandler === void 0) {
10
+ throw new TypeError(
11
+ "The MCP client does not support elicitation capabilities and request handlers"
12
+ );
13
+ }
14
+ client.registerCapabilities({
15
+ elicitation: {
16
+ ...supportsForm ? { form: {} } : {},
17
+ ...supportsUrl ? { url: {} } : {}
18
+ }
19
+ });
20
+ client.setRequestHandler("elicitation/create", async ({ params }) => {
21
+ if (params.mode === "url") {
22
+ const request2 = params;
23
+ if (handlers.url === void 0) {
24
+ throw new Error("MCP server requested URL elicitation, but no URL handler is configured");
25
+ }
26
+ return handlers.url(request2);
27
+ }
28
+ const request = params;
29
+ if (handlers.form === void 0) {
30
+ throw new Error("MCP server requested form elicitation, but no form handler is configured");
31
+ }
32
+ return handlers.form(request);
33
+ });
34
+ }
35
+
1
36
  // src/mcp/stdio.ts
2
37
  var MCP_CLIENT_PACKAGE = "@modelcontextprotocol/client";
3
38
  var MCP_STDIO_PACKAGE = "@modelcontextprotocol/client/stdio";
@@ -23,10 +58,14 @@ async function connectStdioMcpClient(server, options = {}) {
23
58
  throw new TypeError("MCP stdio server command must be a non-empty string");
24
59
  }
25
60
  const { clientModule, stdioModule } = await loadStdioModules();
26
- const client = new clientModule.Client({
27
- name: options.name ?? "@nemesis-oss/ollama-sdk",
28
- version: options.version ?? "1.0.0"
29
- });
61
+ const client = new clientModule.Client(
62
+ {
63
+ name: options.name ?? "@nemesis-oss/ollama-sdk",
64
+ version: options.version ?? "1.0.0"
65
+ },
66
+ { inputRequired: { autoFulfill: options.inputRequiredMode === "automatic" } }
67
+ );
68
+ registerElicitationHandlers(client, options.elicitation);
30
69
  const transport = new stdioModule.StdioClientTransport({
31
70
  command: server.command,
32
71
  ...server.args !== void 0 ? { args: [...server.args] } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mcp/stdio.ts"],"names":[],"mappings":";AAWA,IAAM,kBAAA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GAAA,EAAK,MAAA,CAAO,GAAA,EAAI,GAAI,EAAC;AAAA,IACtD,GAAI,OAAO,aAAA,KAAkB,MAAA,GAAY,EAAE,aAAA,EAAe,MAAA,CAAO,aAAA,EAAc,GAAI,EAAC;AAAA,IACpF,GAAI,OAAO,MAAA,KAAW,MAAA,GAAY,EAAE,MAAA,EAAQ,MAAA,CAAO,MAAA,EAAO,GAAI;AAAC,GAChE,CAAA;AAED,EAAA,MAAM,MAAA,CAAO,QAAQ,SAAS,CAAA;AAE9B,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,KAAA,EAAO,MAAM,MAAA,CAAO,KAAA;AAAM,GAC5B;AACF","file":"mcp-stdio.js","sourcesContent":["/**\n * Optional Node.js MCP stdio connector.\n *\n * This subpath uses the official @modelcontextprotocol/client v2 package dynamically so\n * the root SDK entrypoint remains transport-agnostic and Edge-runtime compatible.\n *\n * Install @modelcontextprotocol/client separately when using this adapter.\n */\n\nimport type { McpClientLike } from './types.js';\n\nconst MCP_CLIENT_PACKAGE = '@modelcontextprotocol/client';\nconst MCP_STDIO_PACKAGE = '@modelcontextprotocol/client/stdio';\n\nexport interface StdioMcpServerParameters {\n readonly command: string;\n readonly args?: readonly string[] | undefined;\n readonly cwd?: string | undefined;\n readonly env?: Record<string, string> | undefined;\n readonly maxBufferSize?: number | undefined;\n readonly stderr?: 'inherit' | 'pipe' | 'ignore' | undefined;\n}\n\nexport interface StdioMcpClientOptions {\n readonly name?: string | undefined;\n readonly version?: string | undefined;\n}\n\nexport interface StdioMcpConnection {\n readonly client: McpClientLike;\n readonly close: () => Promise<void>;\n}\n\ninterface DynamicMcpClientModule {\n readonly Client: new (metadata: { name: string; version: string }) => {\n connect: (transport: unknown) => Promise<void>;\n close: () => Promise<void>;\n listTools: McpClientLike['listTools'];\n callTool: McpClientLike['callTool'];\n };\n}\n\ninterface DynamicMcpStdioModule {\n readonly StdioClientTransport: new (server: StdioMcpServerParameters) => unknown;\n}\n\nasync function loadStdioModules(): Promise<{\n readonly clientModule: DynamicMcpClientModule;\n readonly stdioModule: DynamicMcpStdioModule;\n}> {\n try {\n const [clientModule, stdioModule] = await Promise.all([\n import(MCP_CLIENT_PACKAGE) as Promise<unknown>,\n import(MCP_STDIO_PACKAGE) as Promise<unknown>,\n ]);\n return {\n clientModule: clientModule as DynamicMcpClientModule,\n stdioModule: stdioModule as DynamicMcpStdioModule,\n };\n } catch (error) {\n throw new Error(\n 'MCP stdio support requires @modelcontextprotocol/client >= 2.0.0. ' +\n 'Install it with npm install @modelcontextprotocol/client.',\n { cause: error },\n );\n }\n}\n\n/**\n * Connects to a local MCP server over stdin/stdout using the official MCP TypeScript\n * client's Node-only StdioClientTransport.\n */\nexport async function connectStdioMcpClient(\n server: StdioMcpServerParameters,\n options: StdioMcpClientOptions = {},\n): Promise<StdioMcpConnection> {\n if (!server.command) {\n throw new TypeError('MCP stdio server command must be a non-empty string');\n }\n\n const { clientModule, stdioModule } = await loadStdioModules();\n const client = new clientModule.Client({\n name: options.name ?? '@nemesis-oss/ollama-sdk',\n version: options.version ?? '1.0.0',\n });\n const transport = new stdioModule.StdioClientTransport({\n command: server.command,\n ...(server.args !== undefined ? { args: [...server.args] } : {}),\n ...(server.cwd !== undefined ? { cwd: server.cwd } : {}),\n ...(server.env !== undefined ? { env: server.env } : {}),\n ...(server.maxBufferSize !== undefined ? { maxBufferSize: server.maxBufferSize } : {}),\n ...(server.stderr !== undefined ? { stderr: server.stderr } : {}),\n });\n\n await client.connect(transport);\n\n return {\n client,\n close: () => client.close(),\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/mcp/client-options.ts","../src/mcp/stdio.ts"],"names":["request"],"mappings":";AA2BO,SAAS,2BAAA,CACd,QACA,QAAA,EACM;AACN,EAAA,IAAI,aAAa,MAAA,EAAW;AAE5B,EAAA,MAAM,YAAA,GAAe,SAAS,IAAA,KAAS,MAAA;AACvC,EAAA,MAAM,WAAA,GAAc,SAAS,GAAA,KAAQ,MAAA;AACrC,EAAA,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GAAI,OAAO,aAAA,KAAkB,MAAA,GAAY,EAAE,aAAA,EAAe,MAAA,CAAO,aAAA,EAAc,GAAI,EAAC;AAAA,IACpF,GAAI,OAAO,MAAA,KAAW,MAAA,GAAY,EAAE,MAAA,EAAQ,MAAA,CAAO,MAAA,EAAO,GAAI;AAAC,GAChE,CAAA;AAED,EAAA,MAAM,MAAA,CAAO,QAAQ,SAAS,CAAA;AAE9B,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,KAAA,EAAO,MAAM,MAAA,CAAO,KAAA;AAAM,GAC5B;AACF","file":"mcp-stdio.js","sourcesContent":["import type {\n McpElicitationFormRequest,\n McpElicitationHandlers,\n McpElicitationRequest,\n McpElicitationResult,\n McpElicitationUrlRequest,\n} from './types.js';\n\nexport interface McpClientRequestHandler {\n registerCapabilities?:\n | ((capabilities: {\n readonly elicitation: {\n readonly form?: Record<string, never> | undefined;\n readonly url?: Record<string, never> | undefined;\n };\n }) => void)\n | undefined;\n setRequestHandler?:\n | ((\n method: 'elicitation/create',\n handler: (request: {\n readonly params: McpElicitationRequest;\n }) => Promise<McpElicitationResult>,\n ) => void)\n | undefined;\n}\n\nexport function registerElicitationHandlers(\n client: McpClientRequestHandler,\n handlers: McpElicitationHandlers | undefined,\n): void {\n if (handlers === undefined) return;\n\n const supportsForm = handlers.form !== undefined;\n const supportsUrl = handlers.url !== undefined;\n if (!supportsForm && !supportsUrl) {\n throw new TypeError('At least one MCP elicitation handler must be provided');\n }\n if (client.registerCapabilities === undefined || client.setRequestHandler === undefined) {\n throw new TypeError(\n 'The MCP client does not support elicitation capabilities and request handlers',\n );\n }\n\n client.registerCapabilities({\n elicitation: {\n ...(supportsForm ? { form: {} } : {}),\n ...(supportsUrl ? { url: {} } : {}),\n },\n });\n client.setRequestHandler('elicitation/create', async ({ params }) => {\n if (params.mode === 'url') {\n const request = params as McpElicitationUrlRequest;\n if (handlers.url === undefined) {\n throw new Error('MCP server requested URL elicitation, but no URL handler is configured');\n }\n return handlers.url(request);\n }\n\n const request = params as McpElicitationFormRequest;\n if (handlers.form === undefined) {\n throw new Error('MCP server requested form elicitation, but no form handler is configured');\n }\n return handlers.form(request);\n });\n}\n","/**\n * Optional Node.js MCP stdio connector.\n *\n * This subpath uses the official @modelcontextprotocol/client v2 package dynamically so\n * the root SDK entrypoint remains transport-agnostic and Edge-runtime compatible.\n *\n * Install @modelcontextprotocol/client separately when using this adapter.\n */\n\nimport { registerElicitationHandlers, type McpClientRequestHandler } from './client-options.js';\nimport type { McpClientLike, McpElicitationHandlers } from './types.js';\n\nconst MCP_CLIENT_PACKAGE = '@modelcontextprotocol/client';\nconst MCP_STDIO_PACKAGE = '@modelcontextprotocol/client/stdio';\n\nexport interface StdioMcpServerParameters {\n readonly command: string;\n readonly args?: readonly string[] | undefined;\n readonly cwd?: string | undefined;\n readonly env?: Record<string, string> | undefined;\n readonly maxBufferSize?: number | undefined;\n readonly stderr?: 'inherit' | 'pipe' | 'ignore' | undefined;\n}\n\nexport interface StdioMcpClientOptions {\n readonly name?: string | undefined;\n readonly version?: string | undefined;\n readonly elicitation?: McpElicitationHandlers | undefined;\n /** Defaults to manual so input_required responses are returned to the caller. */\n readonly inputRequiredMode?: 'manual' | 'automatic' | undefined;\n}\n\nexport interface StdioMcpConnection {\n readonly client: McpClientLike;\n readonly close: () => Promise<void>;\n}\n\ninterface DynamicMcpClientModule {\n readonly Client: new (\n metadata: { name: string; version: string },\n options?: { readonly inputRequired?: { readonly autoFulfill: boolean } },\n ) => {\n connect: (transport: unknown) => Promise<void>;\n close: () => Promise<void>;\n listTools: McpClientLike['listTools'];\n callTool: McpClientLike['callTool'];\n } & McpClientRequestHandler;\n}\n\ninterface DynamicMcpStdioModule {\n readonly StdioClientTransport: new (server: StdioMcpServerParameters) => unknown;\n}\n\nasync function loadStdioModules(): Promise<{\n readonly clientModule: DynamicMcpClientModule;\n readonly stdioModule: DynamicMcpStdioModule;\n}> {\n try {\n const [clientModule, stdioModule] = await Promise.all([\n import(MCP_CLIENT_PACKAGE) as Promise<unknown>,\n import(MCP_STDIO_PACKAGE) as Promise<unknown>,\n ]);\n return {\n clientModule: clientModule as DynamicMcpClientModule,\n stdioModule: stdioModule as DynamicMcpStdioModule,\n };\n } catch (error) {\n throw new Error(\n 'MCP stdio support requires @modelcontextprotocol/client >= 2.0.0. ' +\n 'Install it with npm install @modelcontextprotocol/client.',\n { cause: error },\n );\n }\n}\n\n/**\n * Connects to a local MCP server over stdin/stdout using the official MCP TypeScript\n * client's Node-only StdioClientTransport.\n */\nexport async function connectStdioMcpClient(\n server: StdioMcpServerParameters,\n options: StdioMcpClientOptions = {},\n): Promise<StdioMcpConnection> {\n if (!server.command) {\n throw new TypeError('MCP stdio server command must be a non-empty string');\n }\n\n const { clientModule, stdioModule } = await loadStdioModules();\n const client = new clientModule.Client(\n {\n name: options.name ?? '@nemesis-oss/ollama-sdk',\n version: options.version ?? '1.0.0',\n },\n { inputRequired: { autoFulfill: options.inputRequiredMode === 'automatic' } },\n );\n registerElicitationHandlers(client, options.elicitation);\n const transport = new stdioModule.StdioClientTransport({\n command: server.command,\n ...(server.args !== undefined ? { args: [...server.args] } : {}),\n ...(server.cwd !== undefined ? { cwd: server.cwd } : {}),\n ...(server.env !== undefined ? { env: server.env } : {}),\n ...(server.maxBufferSize !== undefined ? { maxBufferSize: server.maxBufferSize } : {}),\n ...(server.stderr !== undefined ? { stderr: server.stderr } : {}),\n });\n\n await client.connect(transport);\n\n return {\n client,\n close: () => client.close(),\n };\n}\n"]}