Skip to main content

Migrating to @nxisai/sdk

Up to version 2.x, the NxisAI JavaScript SDK was published as @nxisai/nxis. That one package held three things: the server SDK (NxisClient), a browser build of the tag script, and a webmcp subpath.

From 3.0.0, the SDK is published as @nxisai/sdk, and it contains the server SDK only. The NxisClient API is unchanged, so for most server code the migration is a package swap and a find-and-replace.

@nxisai/nxis 2.x@nxisai/sdk 3.0
NxisClient (SSR)✅✅ unchanged
ProxyError, ErrorCode, errorCodeToHttp✅✅ unchanged
NxisWarningThrown, but not exported✅ Exported
NxisConfig, NxisIndexConfig types–✅ New type exports
Browser bundle (browser field, build/nxis.js)✅❌ Removed. Use the CDN tag
/webmcp subpath (registerActions, …)✅❌ Moved to @nxisai/webmcp/actions. See step 3
/ssr subpath✅✅ Kept, as an alias of the package root

1. Swap the package​

npm uninstall @nxisai/nxis
npm install @nxisai/sdk

2. Change the imports​

The API is the same, so only the module name changes.

ES modules / TypeScript

- import { NxisClient } from '@nxisai/nxis/ssr';
+ import { NxisClient } from '@nxisai/sdk';

CommonJS

- const { NxisClient } = require('@nxisai/nxis');
+ const { NxisClient } = require('@nxisai/sdk');

@nxisai/sdk/ssr still resolves, as an alias of @nxisai/sdk. Replacing @nxisai/nxis with @nxisai/sdk everywhere works too.

Your configuration doesn't change. Keep the same environment variables (NXIS_API_HOST, NXIS_CLIENT_ID, NXIS_CLIENT_SECRET, NXIS_SITE_ID) and the same constructor options:

import { NxisClient } from '@nxisai/sdk';

const nxis = new NxisClient({
clientId: process.env.NXIS_CLIENT_ID!,
clientSecret: process.env.NXIS_CLIENT_SECRET!,
});

const jsonLd = await nxis.getStructuredData({
uri: 'https://yoursite.com/',
siteId: process.env.NXIS_SITE_ID!,
});

3. WebMCP in the browser​

The @nxisai/nxis/webmcp subpath isn't in @nxisai/sdk. If you used it to register your page's Actions as WebMCP tools from app code, switch to @nxisai/webmcp/actions. The API is the same (registerActions, readActions, buildInputSchema and the contract types), so only the import changes:

npm install @nxisai/webmcp
- import { registerActions } from '@nxisai/nxis/webmcp';
+ import { registerActions } from '@nxisai/webmcp/actions';

const cleanup = registerActions();

Keep calling it from a client-only component, as before. See WebMCP.

If you'd rather not register tools from app code at all, the JS tag registers your page's Action tools itself. If your server already renders the JSON-LD with NxisClient, use a tag token in ssr mode: the tag then registers tools from the JSON-LD already in the page and makes no data request of its own. See The site token.

4. Browser bundle​

If you imported @nxisai/nxis in browser code to get the tag script, stop importing it, and load the script from the CDN instead:

<link rel="preconnect" href="https://cdn.nxis.ai" crossorigin />
<script
type="text/javascript"
async
src="https://cdn.nxis.ai/nxis.js?token=${TOKEN}"
crossorigin="anonymous">
</script>

Nothing needs to be installed for it.

5. Optional: handle "no data" separately​

NxisWarning is now exported, so you can tell "this page has no structured data" apart from a real failure:

import { NxisClient, NxisWarning, ProxyError } from '@nxisai/sdk';

try {
jsonLd = await nxis.getStructuredData({ uri, siteId });
} catch (e) {
if (e instanceof NxisWarning) {
jsonLd = undefined; // render the page without JSON-LD
} else if (e instanceof ProxyError && e.isRetryable) {
// rate limited or a server error: retry later, or render without JSON-LD
} else {
throw e;
}
}

Under 2.x, the same condition threw an error you couldn't import to test against.

Checklist​

  • @nxisai/nxis removed from package.json, and @nxisai/sdk added
  • Every @nxisai/nxis or @nxisai/nxis/ssr import changed to @nxisai/sdk
  • No browser code imports the SDK. The tag is loaded from https://cdn.nxis.ai/nxis.js
  • registerActions imported from @nxisai/webmcp/actions, or replaced by the CDN tag (ssr or browser mode)
  • Environment variables unchanged