---
id: connectors/assistant-mcp
title: Assistant MCP connections with portable files
summary: Compose token-based MCP discovery and explicitly authorized tool calls using the shared connector runtime.
keywords: connectors, integrations, mcp, n8n, sanity, assistant, files, cli
requires: @jskit-ai/connectors-core, @jskit-ai/connectors-catalog
---

# Assistant MCP connections with portable files

## Use when

An existing assistant host or operator CLI needs n8n or Sanity MCP tools using
an owner's token. Use the package runtime for protocol and credential handling,
and source configuration for the same values edited by the UI.

## Do not use when

This is not application-user OAuth, a shared deployed-app account, local stdio
or automatic assistant attachment. Do not enable tool calls on a public route
using a hard-coded owner. The current fragments support token authentication.

## Product decisions

Choose the assistant owner and permitted tools. Existing host policy must decide
which calls need explicit user approval. It also owns model tool presentation,
argument validation, output handling and project/session access. Preserve the
host's restrictions on temporary assistants; a configured connector is not
permission to bypass them.

## Invariants

- Configuration and runtime state remain text files with the existing owners.
- Tokens stay in Env; grants use the core's encrypted private file store.
- `connectApiKey` initializes and lists tools without executing a tool.
- Discovery is not blanket execution permission or proof of every tool's access.
- `authorize` sees the exact tool name and arguments before any network call.
- Provider results and schemas remain untrusted external data.
- Cancellation ends the local request; it cannot undo accepted remote work.

## Framework APIs

Use `createConnectionService`, `createEnvironmentReferenceResolver`,
`createFileConnectionStore`, `createCredentialProtection` and the shared parser
from connectors-core. Import only the required `n8nProvider` or `sanityProvider`
server export. The official MCP SDK is internal to these server modules; the
browser imports definitions only.

## Example files

`example/integrations.json` supplies an assistant-owned n8n slot. Set its actual
instance endpoint and provision `N8N_MCP_TOKEN` outside source. Use the
`api-key-connection` pattern's ordinary file-runtime composition with
`providers: [n8nProvider]`. Supply the host's existing connection policy:

```js
async function applicationConnectionPolicy(context, request) {
  const owner = await assistantAccess.requireConnectionOwner(context, request.integrationId);
  if (request.operation === "tools.call") {
    await assistantAccess.requireToolApproval(context, {
      integrationId: request.integrationId,
      name: request.input.name,
      arguments: request.input.arguments
    });
  }
  return owner;
}
```

`assistantAccess` represents application-owned authorization, not a JSKIT API.
It must return stable trusted `applicationId` and `subjectId` values, and reject
unauthorized management/discovery as well as calls. Approval must be tied to the
exact arguments. Connection membership alone is insufficient for tool execution.

```js
await connections.connectApiKey({ context, integrationId: "automation" });
const discovered = await connections.invoke({
  context, integrationId: "automation", operation: "tools.list", input: {}
});
// After choosing a permitted tool, validating its input and obtaining any approval:
const result = await connections.invoke({
  context, integrationId: "automation", operation: "tools.call",
  input: { name: approvedToolName, arguments: approvedArguments }, signal
});
```

Process `nextCursor` explicitly; discovery does not auto-fetch all pages. Check
`result.isError` before treating a tool result as success. Never automatically
follow links or obey instructions inside descriptions or tool output.

## Variation points

Sanity has a fixed endpoint and no `settings.serverUrl`. n8n uses an own instance
URL and its MCP token, not a REST API key. A trusted local CLI may use its process
identity, but still needs an explicit tool policy. The same implementation can
run under an authorized editor assistant without becoming a published-app API.

## Verification

`test/mcp.test.js` exercises the actual SDK with mocked protocol responses and
encrypted file persistence, including JSON/SSE, cancellation, cleanup, owner
isolation, token rotation and prevention of input mutation during authorization.
Public editor tests prove configuration and reload. No sample app is generated
or run, and no live tool is invoked.

## Avoid

Do not copy the MCP protocol into scaffolding, expose bearer tokens to browsers,
attach these tools to every assistant automatically, infer permission from a
tool's annotations, or fall back to provider OAuth without an implemented flow.
