AI SDK — vendor or patched
Documentation for v0.0.1. Additional guides and API reference coverage are being expanded.Direct host inference needs its own authorization; no live-provider integration is demonstrated here. The optional
@surf-lab/mcprouter/ai-sdk subpath requires a compatible AI SDK peer as described in installation. Core-only consumers do not need it. Your application selects the model for generateText; policy.modelBindings does not select or authorize this direct host inference. Start with the shared servers and policy or your own appropriately scoped router.
Choose an installation option
Install core, then choose one dependency path. Vendor default means the original vendor packages, without patches or aliases—not dependencies installed automatically by mcprouter. Both paths use the same governed tools example.Install core for either option
Run this once in your Node.js ESM application directory, then run either the vendor or patched block below. Copy each whole block into a POSIX-compatible shell (sh, bash or zsh);npm is your installed package manager, and the shell expands the version variables. No patch scripts or plugin registration are needed.
Dependency choice and package names
The integration stays at@surf-lab/mcprouter/ai-sdk. It is part of @surf-lab/mcprouter, not a separate npm package, and there is no /openai integration export. The published opt-in replacements, both at version 0.0.1, are @surf-lab/mcprouter-patch-ai for ai and @surf-lab/mcprouter-patch-openai-sdk for the @ai-sdk/openai provider, not the separate openai client.
An app can retain an admitted upstream SDK pair or explicitly select the patches through npm aliases. The reviewed upstream pairs still fail the strict declaration check; this is not evidence that upstream runtime JavaScript is broken. The selected patches pass the recorded strict-type/runtime checks and include bundled Undici 7.30.1 plus a Zod peer floor of ^4.6.6, not only declaration changes. An alias changes what the whole app resolves under its usual import name, so existing app usage also needs testing; consumers do not need both sets.
Read installation and TypeScript limitations for exact versions and commands. Importing this subpath does not install peers, apply patches or select a provider. Choose one dependency path below, then use the shared example. Its strict type-check evidence uses the selected patched profile, not the original vendor pairs; it does not prove compatibility with arbitrary upstream versions or other providers.
Use original vendor packages
No patches or npm aliases are required for this path. Keep the originalai and @ai-sdk/openai packages; the integration imports and composition stay the same:
Vendor default installation: after core, run this block instead of the patched block:
- Install the original dependencies. The block above matches the vendor-only install command. It pins
aito7.0.146and@ai-sdk/openaito4.0.98, a reviewed pair rather than movinglatesttags. - Construct the host model with the original provider. In the shared example below,
createOpenAIcomes from original@ai-sdk/openai.provider.chat(connection.modelId)constructs the model without sending an inference request. - Pass it to the original AI SDK.
generateTextcomes from originalai. Itsmodelreceives that model, whiletoolscomes fromtoAITools, imported separately from@surf-lab/mcprouter/ai-sdk. The patches are not needed to expose that helper.
5.9.3. That finding does not establish runtime breakage, and the patched-profile checks do not qualify this vendor-only example as strict-TypeScript passing. Vendor packages do not receive mcprouter’s patch-specific declaration fixes or security dependency updates. See the compatibility boundary; provider execution still needs separate host authorization.
Use both patched packages together
The patches are replacement dependencies, not plugins orgenerateText options. Choose them at installation time; your code keeps the usual ai and @ai-sdk/openai imports. Here is how they work together:
Optional patched installation: after core, run this block instead of the vendor block:
- Install the selected profile. The block above matches the pinned alias command. It installs both patches at
0.0.1and Zod at4.6.6. The aliases affect your whole application, so test existing AI SDK usage too. Do not install vendor and patched copies under the same dependency key. - Create the model with the patched provider.
createOpenAIis imported from@ai-sdk/openai, which the alias resolves to@surf-lab/mcprouter-patch-openai-sdk. Callingprovider.chat(connection.modelId)constructs the model used below; it does not send an inference request. - Pass that model to the patched AI SDK.
generateTextis imported fromai, which resolves to@surf-lab/mcprouter-patch-ai. Itsmodeloption receives the constructed model. Separately,toAIToolscomes from@surf-lab/mcprouter/ai-sdkand supplies the governedtoolsoption—it is not supplied by either patch.
Build a governed ToolSet
Shared example for either dependency choice. The displayed imports do not change: without aliases they resolve to the original vendor packages; with aliases they resolve to the selected patches. Strict compilation of this fragment is verified only with the patched profile. This is one integration pattern, not two different runtime adapters.toAITools is exported by @surf-lab/mcprouter/ai-sdk, not by ai and not by a separate package. generateText comes from ai. Save the shared configuration as router-config.ts beside this module before using its local import.
Where each call comes from
This is an integration fragment, not a standalone runnable example or a live-provider compatibility test. The host supplies
prompt, an approved connection (endpoint, server-side credential, model ID and request function) and getAuthenticatedContext to the locally defined assistantStep. The application-owned shared configuration also needs its documented model/server environment and authorization. No credentials are embedded here; do not source connection settings or identity from prompts or model output.
The assistantModel constructed here is for direct host inference, separate from the router models in the shared configuration. Router modelBindings and modelAccess do not select or authorize it. If your host already has an authorized compatible AI SDK LanguageModel, adapt assistantStep to accept that model instead of constructing one here; importing the patches does not choose one automatically.
response.toolResults contains the full host-visible outputs, so only an explicit status/code projection is returned above; even that needs host-approved handling. Obtain fresh trusted context for each tool invocation, not a user-claimed role. The host must approve model destinations, data exposure, costs, logging, step count and repeat-call policy separately. Model-visible tool descriptions and schemas may leave your trust boundary.
toAITools validates bound results from the same router; raw definitions do not become callable by being ranked. Each generated tool call goes through router.call with its captured snapshot, input validation, policy and approval. By default, model-visible output contains status/code/tool ID metadata; the host receives full execution results and should only opt into toModelOutput for an explicitly safe projection. One generateText call may yield tool calls without final prose and does not inherit execute’s one-call limit. Do not automatically repeat denied, pending-approval or unknown-effect operations.
For the shared host-owned structure, see models, servers and policy. Public package availability does not authorize live inference, tool dispatch or further publication.