Services and API imports · Session cookies
Services and API imports · Session cookies from the built-in skills in Executor 2.0.0-beta.79.
This page covers Session cookies from the built-in skills shipped with Executor 2.0.0-beta.79. It contains app-authoring/integrations.md.
Previous: Services and API imports · OpenAPI APIs
Session cookies
For a service that exchanges a username and password for a session cookie,
declare both as secrets fields with the service’s hosts. Sign in from a
cache loader, then pass liveOpenapiRouter a fetch that adds the cookie.
Clear the definition’s security so operations need no declared scheme:
async (account) => {
const sessions = cache.forAccount(account);
const session = () =>
sessions.get({
key: ["session"],
schema: string(),
freshFor: "20 minutes", // shorter than the service's session lifetime
load: async ({ fetch, signal }) => {
const response = await fetch("https://app.example.com/api/login", {
method: "POST",
signal,
headers: { "content-type": "application/json" },
body: JSON.stringify({
username: account.fields.username,
password: account.fields.password,
}),
});
if (!response.ok) throw new Error(`Sign-in failed with status ${response.status}.`);
const cookies = response.headers.getSetCookie().map((cookie) => cookie.split(";")[0]);
if (cookies.length === 0) throw new Error("Sign-in returned no session cookie.");
return cookies.join("; ");
},
});
return liveOpenapiRouter({
source: { url: "https://app.example.com/openapi.json" },
allowedOrigin: "https://app.example.com",
securitySchemes: {},
methods: {},
oauth: [],
patches: [{ op: "add", path: "/security", value: [] }],
cache,
signal,
account,
fetch: async (input, init) => {
const headers = new Headers(init?.headers);
headers.set("cookie", await session());
const response = await fetch(input, { ...init, headers });
// An expired session signs in again on the next call.
if (response.status === 401) await sessions.invalidate(["session"]);
return response;
},
});
};
The patch replaces only the document’s top-level security; patch any
operation that declares its own. Give the provider a health check that signs
in the same way, so the account form reports refused credentials.
GraphQL APIs
Use graphqlRouter from apps/graphql with the endpoint, an account and its
headers, and optional cancellation signal. Declare graphql (currently
16.11.0) in the app’s dependencies. Authenticated apps use a provider.many()
user requirement and accountRouter as above, or a plain app requirement for
one account every caller uses; public endpoints need no account.
Helpers are separate subpath imports. Importing apps alone does not load
MCP or GraphQL. Optional dependencies must appear in the app’s manifest and
resolve from its own installation. A missing peer fails the deploy with
the package to add. A declared apps version owns its framework dependencies;
otherwise the host supplies them.
Pass cache: ctx.cache to mcpRouter. With an account, the helper keeps the
catalog in that account’s cache scope, so a token renewal keeps it and a
reconnected account starts fresh. The helper returns a dynamic router; it lists
metadata without compiling every tool, and resolves one executable for each
call. Cached identity is the server URL within that scope; headers and
credentials never enter it. Defaults are five minutes fresh plus five minutes
stale.
Set revalidate: true on a specific mcpRouter call to await a new catalog
at a logical connection or explicit refresh boundary. Do not set it on every
app evaluation unless every request must reload discovery. Each HTTP transport
session is short-lived; opening that transport does not force a catalog refresh.
A received notifications/tools/list_changed invalidates the retained manifest.
There is no idle background connection, so TTL or explicit refresh covers changes
made while disconnected. A failed explicit refresh retains the previous catalog.
Only metadata is cached; credentials and executable handlers remain invocation-owned.
GraphQL apps use the same cache policy through graphqlRouter:
await graphqlRouter({
url,
account,
headers: { Authorization: "Bearer " + account.fields.token },
cache: ctx.cache,
signal: ctx.signal,
});
The helper returns a dynamic router. One introspection request creates a revision of per-tool definitions. Listing reads those definitions; execution loads and compiles only the selected query or mutation, without reading the full introspection schema. The current account supplies execution credentials. Public endpoints take no account or headers. Omitting the cache keeps discovery local to the current evaluation. Keys are the URL within the account’s scope.
freshFor, staleFor, and revalidate: true have the same meanings as MCP.
GraphQL has no standard schema-change notification, so TTL or an explicit
refresh discovers changed fields and input types. Failed refreshes retain the
previous revision. Cached introspection never caches query or mutation results.