@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
176 lines • 7.06 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import * as CertificatesAPI from "./certificates.mjs";
import { Certificates, } from "./certificates.mjs";
import { PageCursor } from "../../../core/pagination.mjs";
import { buildHeaders } from "../../../internal/headers.mjs";
import { path } from "../../../internal/utils/path.mjs";
export class Tunnels extends APIResource {
constructor() {
super(...arguments);
this.certificates = new CertificatesAPI.Certificates(this._client);
}
/**
* The Tunnels API is in research preview. It requires the
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
* deprecation period. It supersedes the Admin API endpoints at
* `/v1/organizations/tunnels`, which remain available during a migration window.
*
* Creates a tunnel. Creation allocates a fresh hostname and provisions the tunnel;
* it is not idempotent. The new tunnel rejects MCP traffic until at least one CA
* certificate is added.
*
* @example
* ```ts
* const betaTunnel = await client.beta.tunnels.create();
* ```
*/
create(params, options) {
const { betas, ...body } = params;
return this._client.post('/v1/tunnels?beta=true', {
body,
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'mcp-tunnels-2026-06-22'].toString() },
options?.headers,
]),
});
}
/**
* The Tunnels API is in research preview. It requires the
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
* deprecation period. It supersedes the Admin API endpoints at
* `/v1/organizations/tunnels`, which remain available during a migration window.
*
* Fetches a tunnel by ID.
*
* @example
* ```ts
* const betaTunnel = await client.beta.tunnels.retrieve(
* 'tunnel_id',
* );
* ```
*/
retrieve(tunnelID, params = {}, options) {
const { betas } = params ?? {};
return this._client.get(path `/v1/tunnels/${tunnelID}?beta=true`, {
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'mcp-tunnels-2026-06-22'].toString() },
options?.headers,
]),
});
}
/**
* The Tunnels API is in research preview. It requires the
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
* deprecation period. It supersedes the Admin API endpoints at
* `/v1/organizations/tunnels`, which remain available during a migration window.
*
* Lists tunnels. Results are ordered by creation time, newest first; archived
* tunnels are excluded unless include_archived is set.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const betaTunnel of client.beta.tunnels.list()) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { betas, ...query } = params ?? {};
return this._client.getAPIList('/v1/tunnels?beta=true', (PageCursor), {
query,
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'mcp-tunnels-2026-06-22'].toString() },
options?.headers,
]),
});
}
/**
* The Tunnels API is in research preview. It requires the
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
* deprecation period. It supersedes the Admin API endpoints at
* `/v1/organizations/tunnels`, which remain available during a migration window.
*
* Archives a tunnel. Archival is irreversible: every non-archived certificate on
* the tunnel is archived in the same operation, the hostname is retired and never
* re-allocated, and the tunnel token is invalidated. Retrying against an
* already-archived tunnel returns the existing record unchanged.
*
* @example
* ```ts
* const betaTunnel = await client.beta.tunnels.archive(
* 'tunnel_id',
* );
* ```
*/
archive(tunnelID, params = {}, options) {
const { betas } = params ?? {};
return this._client.post(path `/v1/tunnels/${tunnelID}/archive?beta=true`, {
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'mcp-tunnels-2026-06-22'].toString() },
options?.headers,
]),
});
}
/**
* The Tunnels API is in research preview. It requires the
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
* deprecation period. It supersedes the Admin API endpoints at
* `/v1/organizations/tunnels`, which remain available during a migration window.
*
* Reveals a tunnel's connector token. The value is fetched live on each call;
* Anthropic does not store it. Repeated calls return the same value until the
* token is rotated. Exposed as POST so the token does not appear in intermediary
* access logs.
*
* @example
* ```ts
* const betaTunnelToken =
* await client.beta.tunnels.revealToken('tunnel_id');
* ```
*/
revealToken(tunnelID, params = {}, options) {
const { betas } = params ?? {};
return this._client.post(path `/v1/tunnels/${tunnelID}/reveal_token?beta=true`, {
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'mcp-tunnels-2026-06-22'].toString() },
options?.headers,
]),
});
}
/**
* The Tunnels API is in research preview. It requires the
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
* deprecation period. It supersedes the Admin API endpoints at
* `/v1/organizations/tunnels`, which remain available during a migration window.
*
* Rotates a tunnel's connector token. Rotation invalidates the current token for
* new connections and returns a fresh value; established connections are not
* severed. A connector restarted after rotation must use the new value.
*
* @example
* ```ts
* const betaTunnelToken =
* await client.beta.tunnels.rotateToken('tunnel_id');
* ```
*/
rotateToken(tunnelID, params, options) {
const { betas, ...body } = params;
return this._client.post(path `/v1/tunnels/${tunnelID}/rotate_token?beta=true`, {
body,
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'mcp-tunnels-2026-06-22'].toString() },
options?.headers,
]),
});
}
}
Tunnels.Certificates = Certificates;
//# sourceMappingURL=tunnels.mjs.map