igloo-connectors
v0.1.0
Published
Browser SDK for Igloo MCP Gateway connectors: connect sessions, list, connect, disconnect, and a React connector picker.
Maintainers
Readme
igloo-connectors
Browser client for Igloo connectors, with an optional React connector picker. The core client has no React dependency. The picker requires React and React DOM 18 or later.
Install
npm install igloo-connectors
# For the React picker, also install react and react-dom in your app.Client
Configure your gateway to allow your page's origin. Your backend must create a
short-lived connect session for the signed-in user and return { connect_token }.
Keep application credentials on your backend; never embed them in browser code.
import { createIglooConnectors } from 'igloo-connectors'
export const connectors = createIglooConnectors({
baseUrl: 'https://connectors.example.com',
getConnectToken: async () => {
const response = await fetch('/api/connect-session', { method: 'POST' })
if (!response.ok) throw new Error('Could not create a connect session')
const session = await response.json()
return session.connect_token
},
})
const available = await connectors.list()
// Call connect directly from a click handler so the browser allows its popup:
document.querySelector('#connect')?.addEventListener('click', () => {
void connectors.connect('google-drive').catch(console.error)
})
// await connectors.disconnect('google-drive')The client caches the connect token and refreshes it once on token expiry.
Call connectors.signOut() when the signed-in user changes.
React picker
Reuse the client above; keep it stable across renders.
import { useState } from 'react'
import type { Selection } from 'igloo-connectors'
import { ConnectorPicker } from 'igloo-connectors/react'
import { connectors } from './connectors'
export function ChatConnectors() {
const [selection, setSelection] = useState<Selection>([])
return (
<ConnectorPicker
client={connectors}
value={selection}
onChange={setSelection}
onError={console.error}
/>
)
}Styles are injected automatically. [] selects none, an array of slugs selects
those connectors, and null selects all (partner pickers leave Igloo connectors
off by default). For partner apps, use defaultSelection(rows, app.kind) from
igloo-connectors/react after client.listWithApp() to initialize an explicit
selection with the same defaults before sending a chat request.
Use selectionHeaders(selection) from igloo-connectors when sending chat to
your backend. Forward that selection when your backend calls the gateway.
hideToggles hides selection controls without changing access or the value.
Maintainer release
From the repository root, install workspace dependencies with pnpm install.
Then, from web/, authenticate to npmjs.org with a maintainer account and run:
npm run build
npm pack --dry-run
npm run releaseThe release script runs npm publish. Its prepublishOnly hook typechecks,
tests and builds before publishing publicly to npmjs.org. The package version
is currently 0.1.0; use a new version for later releases.
License
MIT, copyright Igloo. See LICENSE.
