Debian Codegraph @

src/anthropic/resources/beta/tunnels/tunnels.py

raw
1 from __future__ import annotations
2
3 from typing import List, Optional
4 from itertools import chain
5
6 import httpx2
7
8 from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
9 from ...._utils import is_given, path_template, strip_not_given
10 from ...._compat import cached_property
11 from ...._resource import SyncAPIResource, AsyncAPIResource
12 from ...._response import (
13 to_raw_response_wrapper,
14 to_streamed_response_wrapper,
15 async_to_raw_response_wrapper,
16 async_to_streamed_response_wrapper,
17 )
18 from .certificates import (
19 Certificates,
20 AsyncCertificates,
21 CertificatesWithRawResponse,
22 AsyncCertificatesWithRawResponse,
23 CertificatesWithStreamingResponse,
24 AsyncCertificatesWithStreamingResponse,
25 )
26 from ....pagination import SyncPageCursor, AsyncPageCursor
27 from ...._base_client import AsyncPaginator, make_request_options
28 from ....types.beta.beta_tunnel import BetaTunnel
29 from ....types.anthropic_beta_param import AnthropicBetaParam
30 from ....types.beta.beta_tunnel_token import BetaTunnelToken
31
32 __all__ = ["Tunnels", "AsyncTunnels"]
33
34
35 class Tunnels(SyncAPIResource):
36 @cached_property
37 def certificates(self) -> Certificates:
38 return Certificates(self._client)
39
40 @cached_property
41 def with_raw_response(self) -> TunnelsWithRawResponse:
42 """
43 This property can be used as a prefix for any HTTP method call to return
44 the raw response object instead of the parsed content.
45
46 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
47 """
48 return TunnelsWithRawResponse(self)
49
50 @cached_property
51 def with_streaming_response(self) -> TunnelsWithStreamingResponse:
52 """
53 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
54
55 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
56 """
57 return TunnelsWithStreamingResponse(self)
58
59 def create(
60 self,
61 *,
62 display_name: Optional[str] | Omit = omit,
63 betas: List[AnthropicBetaParam] | Omit = omit,
64 workspace_id: str | Omit = omit,
65 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
66 # The extra values given here take precedence over values defined on the client or passed to this method.
67 extra_headers: Headers | None = None,
68 extra_query: Query | None = None,
69 extra_body: Body | None = None,
70 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
71 ) -> BetaTunnel:
72 """The Tunnels API is in research preview.
73
74 It requires the
75 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
76 deprecation period. It supersedes the Admin API endpoints at
77 `/v1/organizations/tunnels`, which remain available during a migration window.
78
79 Creates a tunnel. Creation allocates a fresh hostname and provisions the tunnel;
80 it is not idempotent. The new tunnel rejects MCP traffic until at least one CA
81 certificate is added.
82
83 Args:
84 display_name: Optional human-readable name for the tunnel (1-255 characters).
85
86 betas: Optional header to specify the beta version(s) you want to use.
87
88 workspace_id: Optional header to select the Workspace for this request. The value is a
89 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
90
91 Only needed for credentials that can act on more than one Workspace. A
92 credential that belongs to a specific Workspace may omit it; if sent, it must
93 match that Workspace.
94
95 extra_headers: Send extra headers
96
97 extra_query: Add additional query parameters to the request
98
99 extra_body: Add additional JSON properties to the request
100
101 timeout: Override the client-level default timeout for this request, in seconds
102 """
103 extra_headers = {
104 **strip_not_given(
105 {
106 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
107 if is_given(betas)
108 else not_given,
109 "anthropic-workspace-id": workspace_id,
110 }
111 ),
112 **(extra_headers or {}),
113 }
114 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
115 return self._post(
116 "/v1/tunnels?beta=true",
117 body={"display_name": display_name},
118 options=make_request_options(
119 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
120 ),
121 cast_to=BetaTunnel,
122 )
123
124 def retrieve(
125 self,
126 tunnel_id: str,
127 *,
128 betas: List[AnthropicBetaParam] | Omit = omit,
129 workspace_id: str | Omit = omit,
130 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
131 # The extra values given here take precedence over values defined on the client or passed to this method.
132 extra_headers: Headers | None = None,
133 extra_query: Query | None = None,
134 extra_body: Body | None = None,
135 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
136 ) -> BetaTunnel:
137 """The Tunnels API is in research preview.
138
139 It requires the
140 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
141 deprecation period. It supersedes the Admin API endpoints at
142 `/v1/organizations/tunnels`, which remain available during a migration window.
143
144 Fetches a tunnel by ID.
145
146 Args:
147 tunnel_id: ID of the tunnel (`tnl_...`).
148
149 betas: Optional header to specify the beta version(s) you want to use.
150
151 workspace_id: Optional header to select the Workspace for this request. The value is a
152 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
153
154 Only needed for credentials that can act on more than one Workspace. A
155 credential that belongs to a specific Workspace may omit it; if sent, it must
156 match that Workspace.
157
158 extra_headers: Send extra headers
159
160 extra_query: Add additional query parameters to the request
161
162 extra_body: Add additional JSON properties to the request
163
164 timeout: Override the client-level default timeout for this request, in seconds
165 """
166 if not tunnel_id:
167 raise ValueError(f"Expected a non-empty value for `tunnel_id` but received {tunnel_id!r}")
168 extra_headers = {
169 **strip_not_given(
170 {
171 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
172 if is_given(betas)
173 else not_given,
174 "anthropic-workspace-id": workspace_id,
175 }
176 ),
177 **(extra_headers or {}),
178 }
179 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
180 return self._get(
181 path_template("/v1/tunnels/{tunnel_id}?beta=true", tunnel_id=tunnel_id),
182 options=make_request_options(
183 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
184 ),
185 cast_to=BetaTunnel,
186 )
187
188 def list(
189 self,
190 *,
191 include_archived: bool | Omit = omit,
192 limit: int | Omit = omit,
193 page: str | Omit = omit,
194 betas: List[AnthropicBetaParam] | Omit = omit,
195 workspace_id: str | Omit = omit,
196 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
197 # The extra values given here take precedence over values defined on the client or passed to this method.
198 extra_headers: Headers | None = None,
199 extra_query: Query | None = None,
200 extra_body: Body | None = None,
201 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
202 ) -> SyncPageCursor[BetaTunnel]:
203 """The Tunnels API is in research preview.
204
205 It requires the
206 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
207 deprecation period. It supersedes the Admin API endpoints at
208 `/v1/organizations/tunnels`, which remain available during a migration window.
209
210 Lists tunnels. Results are ordered by creation time, newest first; archived
211 tunnels are excluded unless include_archived is set.
212
213 Args:
214 include_archived: Whether to include archived tunnels in the results. Defaults to false.
215
216 limit: Maximum number of tunnels to return per page. Defaults to 20, maximum 1000.
217
218 page: Opaque pagination cursor from a previous `list_tunnels` response.
219
220 betas: Optional header to specify the beta version(s) you want to use.
221
222 workspace_id: Optional header to select the Workspace for this request. The value is a
223 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
224
225 Only needed for credentials that can act on more than one Workspace. A
226 credential that belongs to a specific Workspace may omit it; if sent, it must
227 match that Workspace.
228
229 extra_headers: Send extra headers
230
231 extra_query: Add additional query parameters to the request
232
233 extra_body: Add additional JSON properties to the request
234
235 timeout: Override the client-level default timeout for this request, in seconds
236 """
237 extra_headers = {
238 **strip_not_given(
239 {
240 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
241 if is_given(betas)
242 else not_given,
243 "anthropic-workspace-id": workspace_id,
244 }
245 ),
246 **(extra_headers or {}),
247 }
248 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
249 return self._get_api_list(
250 "/v1/tunnels?beta=true",
251 page=SyncPageCursor[BetaTunnel],
252 options=make_request_options(
253 extra_headers=extra_headers,
254 extra_query=extra_query,
255 extra_body=extra_body,
256 timeout=timeout,
257 query={
258 "include_archived": include_archived,
259 "limit": limit,
260 "page": page,
261 },
262 ),
263 model=BetaTunnel,
264 )
265
266 def archive(
267 self,
268 tunnel_id: str,
269 *,
270 betas: List[AnthropicBetaParam] | Omit = omit,
271 workspace_id: str | Omit = omit,
272 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
273 # The extra values given here take precedence over values defined on the client or passed to this method.
274 extra_headers: Headers | None = None,
275 extra_query: Query | None = None,
276 extra_body: Body | None = None,
277 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
278 ) -> BetaTunnel:
279 """The Tunnels API is in research preview.
280
281 It requires the
282 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
283 deprecation period. It supersedes the Admin API endpoints at
284 `/v1/organizations/tunnels`, which remain available during a migration window.
285
286 Archives a tunnel. Archival is irreversible: every non-archived certificate on
287 the tunnel is archived in the same operation, the hostname is retired and never
288 re-allocated, and the tunnel token is invalidated. Retrying against an
289 already-archived tunnel returns the existing record unchanged.
290
291 Args:
292 tunnel_id: ID of the tunnel (`tnl_...`).
293
294 betas: Optional header to specify the beta version(s) you want to use.
295
296 workspace_id: Optional header to select the Workspace for this request. The value is a
297 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
298
299 Only needed for credentials that can act on more than one Workspace. A
300 credential that belongs to a specific Workspace may omit it; if sent, it must
301 match that Workspace.
302
303 extra_headers: Send extra headers
304
305 extra_query: Add additional query parameters to the request
306
307 extra_body: Add additional JSON properties to the request
308
309 timeout: Override the client-level default timeout for this request, in seconds
310 """
311 if not tunnel_id:
312 raise ValueError(f"Expected a non-empty value for `tunnel_id` but received {tunnel_id!r}")
313 extra_headers = {
314 **strip_not_given(
315 {
316 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
317 if is_given(betas)
318 else not_given,
319 "anthropic-workspace-id": workspace_id,
320 }
321 ),
322 **(extra_headers or {}),
323 }
324 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
325 return self._post(
326 path_template("/v1/tunnels/{tunnel_id}/archive?beta=true", tunnel_id=tunnel_id),
327 options=make_request_options(
328 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
329 ),
330 cast_to=BetaTunnel,
331 )
332
333 def reveal_token(
334 self,
335 tunnel_id: str,
336 *,
337 betas: List[AnthropicBetaParam] | Omit = omit,
338 workspace_id: str | Omit = omit,
339 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
340 # The extra values given here take precedence over values defined on the client or passed to this method.
341 extra_headers: Headers | None = None,
342 extra_query: Query | None = None,
343 extra_body: Body | None = None,
344 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
345 ) -> BetaTunnelToken:
346 """The Tunnels API is in research preview.
347
348 It requires the
349 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
350 deprecation period. It supersedes the Admin API endpoints at
351 `/v1/organizations/tunnels`, which remain available during a migration window.
352
353 Reveals a tunnel's connector token. The value is fetched live on each call;
354 Anthropic does not store it. Repeated calls return the same value until the
355 token is rotated. Exposed as POST so the token does not appear in intermediary
356 access logs.
357
358 Args:
359 tunnel_id: ID of the tunnel (`tnl_...`).
360
361 betas: Optional header to specify the beta version(s) you want to use.
362
363 workspace_id: Optional header to select the Workspace for this request. The value is a
364 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
365
366 Only needed for credentials that can act on more than one Workspace. A
367 credential that belongs to a specific Workspace may omit it; if sent, it must
368 match that Workspace.
369
370 extra_headers: Send extra headers
371
372 extra_query: Add additional query parameters to the request
373
374 extra_body: Add additional JSON properties to the request
375
376 timeout: Override the client-level default timeout for this request, in seconds
377 """
378 if not tunnel_id:
379 raise ValueError(f"Expected a non-empty value for `tunnel_id` but received {tunnel_id!r}")
380 extra_headers = {
381 **strip_not_given(
382 {
383 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
384 if is_given(betas)
385 else not_given,
386 "anthropic-workspace-id": workspace_id,
387 }
388 ),
389 **(extra_headers or {}),
390 }
391 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
392 return self._post(
393 path_template("/v1/tunnels/{tunnel_id}/reveal_token?beta=true", tunnel_id=tunnel_id),
394 options=make_request_options(
395 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
396 ),
397 cast_to=BetaTunnelToken,
398 )
399
400 def rotate_token(
401 self,
402 tunnel_id: str,
403 *,
404 reason: Optional[str] | Omit = omit,
405 betas: List[AnthropicBetaParam] | Omit = omit,
406 workspace_id: str | Omit = omit,
407 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
408 # The extra values given here take precedence over values defined on the client or passed to this method.
409 extra_headers: Headers | None = None,
410 extra_query: Query | None = None,
411 extra_body: Body | None = None,
412 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
413 ) -> BetaTunnelToken:
414 """The Tunnels API is in research preview.
415
416 It requires the
417 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
418 deprecation period. It supersedes the Admin API endpoints at
419 `/v1/organizations/tunnels`, which remain available during a migration window.
420
421 Rotates a tunnel's connector token. Rotation invalidates the current token for
422 new connections and returns a fresh value; established connections are not
423 severed. A connector restarted after rotation must use the new value.
424
425 Args:
426 tunnel_id: ID of the tunnel (`tnl_...`).
427
428 reason: Optional free-text reason for the rotation, recorded for audit.
429
430 betas: Optional header to specify the beta version(s) you want to use.
431
432 workspace_id: Optional header to select the Workspace for this request. The value is a
433 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
434
435 Only needed for credentials that can act on more than one Workspace. A
436 credential that belongs to a specific Workspace may omit it; if sent, it must
437 match that Workspace.
438
439 extra_headers: Send extra headers
440
441 extra_query: Add additional query parameters to the request
442
443 extra_body: Add additional JSON properties to the request
444
445 timeout: Override the client-level default timeout for this request, in seconds
446 """
447 if not tunnel_id:
448 raise ValueError(f"Expected a non-empty value for `tunnel_id` but received {tunnel_id!r}")
449 extra_headers = {
450 **strip_not_given(
451 {
452 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
453 if is_given(betas)
454 else not_given,
455 "anthropic-workspace-id": workspace_id,
456 }
457 ),
458 **(extra_headers or {}),
459 }
460 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
461 return self._post(
462 path_template("/v1/tunnels/{tunnel_id}/rotate_token?beta=true", tunnel_id=tunnel_id),
463 body={"reason": reason},
464 options=make_request_options(
465 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
466 ),
467 cast_to=BetaTunnelToken,
468 )
469
470
471 class AsyncTunnels(AsyncAPIResource):
472 @cached_property
473 def certificates(self) -> AsyncCertificates:
474 return AsyncCertificates(self._client)
475
476 @cached_property
477 def with_raw_response(self) -> AsyncTunnelsWithRawResponse:
478 """
479 This property can be used as a prefix for any HTTP method call to return
480 the raw response object instead of the parsed content.
481
482 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
483 """
484 return AsyncTunnelsWithRawResponse(self)
485
486 @cached_property
487 def with_streaming_response(self) -> AsyncTunnelsWithStreamingResponse:
488 """
489 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
490
491 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
492 """
493 return AsyncTunnelsWithStreamingResponse(self)
494
495 async def create(
496 self,
497 *,
498 display_name: Optional[str] | Omit = omit,
499 betas: List[AnthropicBetaParam] | Omit = omit,
500 workspace_id: str | Omit = omit,
501 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
502 # The extra values given here take precedence over values defined on the client or passed to this method.
503 extra_headers: Headers | None = None,
504 extra_query: Query | None = None,
505 extra_body: Body | None = None,
506 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
507 ) -> BetaTunnel:
508 """The Tunnels API is in research preview.
509
510 It requires the
511 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
512 deprecation period. It supersedes the Admin API endpoints at
513 `/v1/organizations/tunnels`, which remain available during a migration window.
514
515 Creates a tunnel. Creation allocates a fresh hostname and provisions the tunnel;
516 it is not idempotent. The new tunnel rejects MCP traffic until at least one CA
517 certificate is added.
518
519 Args:
520 display_name: Optional human-readable name for the tunnel (1-255 characters).
521
522 betas: Optional header to specify the beta version(s) you want to use.
523
524 workspace_id: Optional header to select the Workspace for this request. The value is a
525 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
526
527 Only needed for credentials that can act on more than one Workspace. A
528 credential that belongs to a specific Workspace may omit it; if sent, it must
529 match that Workspace.
530
531 extra_headers: Send extra headers
532
533 extra_query: Add additional query parameters to the request
534
535 extra_body: Add additional JSON properties to the request
536
537 timeout: Override the client-level default timeout for this request, in seconds
538 """
539 extra_headers = {
540 **strip_not_given(
541 {
542 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
543 if is_given(betas)
544 else not_given,
545 "anthropic-workspace-id": workspace_id,
546 }
547 ),
548 **(extra_headers or {}),
549 }
550 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
551 return await self._post(
552 "/v1/tunnels?beta=true",
553 body={"display_name": display_name},
554 options=make_request_options(
555 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
556 ),
557 cast_to=BetaTunnel,
558 )
559
560 async def retrieve(
561 self,
562 tunnel_id: str,
563 *,
564 betas: List[AnthropicBetaParam] | Omit = omit,
565 workspace_id: str | Omit = omit,
566 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
567 # The extra values given here take precedence over values defined on the client or passed to this method.
568 extra_headers: Headers | None = None,
569 extra_query: Query | None = None,
570 extra_body: Body | None = None,
571 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
572 ) -> BetaTunnel:
573 """The Tunnels API is in research preview.
574
575 It requires the
576 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
577 deprecation period. It supersedes the Admin API endpoints at
578 `/v1/organizations/tunnels`, which remain available during a migration window.
579
580 Fetches a tunnel by ID.
581
582 Args:
583 tunnel_id: ID of the tunnel (`tnl_...`).
584
585 betas: Optional header to specify the beta version(s) you want to use.
586
587 workspace_id: Optional header to select the Workspace for this request. The value is a
588 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
589
590 Only needed for credentials that can act on more than one Workspace. A
591 credential that belongs to a specific Workspace may omit it; if sent, it must
592 match that Workspace.
593
594 extra_headers: Send extra headers
595
596 extra_query: Add additional query parameters to the request
597
598 extra_body: Add additional JSON properties to the request
599
600 timeout: Override the client-level default timeout for this request, in seconds
601 """
602 if not tunnel_id:
603 raise ValueError(f"Expected a non-empty value for `tunnel_id` but received {tunnel_id!r}")
604 extra_headers = {
605 **strip_not_given(
606 {
607 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
608 if is_given(betas)
609 else not_given,
610 "anthropic-workspace-id": workspace_id,
611 }
612 ),
613 **(extra_headers or {}),
614 }
615 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
616 return await self._get(
617 path_template("/v1/tunnels/{tunnel_id}?beta=true", tunnel_id=tunnel_id),
618 options=make_request_options(
619 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
620 ),
621 cast_to=BetaTunnel,
622 )
623
624 def list(
625 self,
626 *,
627 include_archived: bool | Omit = omit,
628 limit: int | Omit = omit,
629 page: str | Omit = omit,
630 betas: List[AnthropicBetaParam] | Omit = omit,
631 workspace_id: str | Omit = omit,
632 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
633 # The extra values given here take precedence over values defined on the client or passed to this method.
634 extra_headers: Headers | None = None,
635 extra_query: Query | None = None,
636 extra_body: Body | None = None,
637 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
638 ) -> AsyncPaginator[BetaTunnel, AsyncPageCursor[BetaTunnel]]:
639 """The Tunnels API is in research preview.
640
641 It requires the
642 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
643 deprecation period. It supersedes the Admin API endpoints at
644 `/v1/organizations/tunnels`, which remain available during a migration window.
645
646 Lists tunnels. Results are ordered by creation time, newest first; archived
647 tunnels are excluded unless include_archived is set.
648
649 Args:
650 include_archived: Whether to include archived tunnels in the results. Defaults to false.
651
652 limit: Maximum number of tunnels to return per page. Defaults to 20, maximum 1000.
653
654 page: Opaque pagination cursor from a previous `list_tunnels` response.
655
656 betas: Optional header to specify the beta version(s) you want to use.
657
658 workspace_id: Optional header to select the Workspace for this request. The value is a
659 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
660
661 Only needed for credentials that can act on more than one Workspace. A
662 credential that belongs to a specific Workspace may omit it; if sent, it must
663 match that Workspace.
664
665 extra_headers: Send extra headers
666
667 extra_query: Add additional query parameters to the request
668
669 extra_body: Add additional JSON properties to the request
670
671 timeout: Override the client-level default timeout for this request, in seconds
672 """
673 extra_headers = {
674 **strip_not_given(
675 {
676 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
677 if is_given(betas)
678 else not_given,
679 "anthropic-workspace-id": workspace_id,
680 }
681 ),
682 **(extra_headers or {}),
683 }
684 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
685 return self._get_api_list(
686 "/v1/tunnels?beta=true",
687 page=AsyncPageCursor[BetaTunnel],
688 options=make_request_options(
689 extra_headers=extra_headers,
690 extra_query=extra_query,
691 extra_body=extra_body,
692 timeout=timeout,
693 query={
694 "include_archived": include_archived,
695 "limit": limit,
696 "page": page,
697 },
698 ),
699 model=BetaTunnel,
700 )
701
702 async def archive(
703 self,
704 tunnel_id: str,
705 *,
706 betas: List[AnthropicBetaParam] | Omit = omit,
707 workspace_id: str | Omit = omit,
708 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
709 # The extra values given here take precedence over values defined on the client or passed to this method.
710 extra_headers: Headers | None = None,
711 extra_query: Query | None = None,
712 extra_body: Body | None = None,
713 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
714 ) -> BetaTunnel:
715 """The Tunnels API is in research preview.
716
717 It requires the
718 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
719 deprecation period. It supersedes the Admin API endpoints at
720 `/v1/organizations/tunnels`, which remain available during a migration window.
721
722 Archives a tunnel. Archival is irreversible: every non-archived certificate on
723 the tunnel is archived in the same operation, the hostname is retired and never
724 re-allocated, and the tunnel token is invalidated. Retrying against an
725 already-archived tunnel returns the existing record unchanged.
726
727 Args:
728 tunnel_id: ID of the tunnel (`tnl_...`).
729
730 betas: Optional header to specify the beta version(s) you want to use.
731
732 workspace_id: Optional header to select the Workspace for this request. The value is a
733 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
734
735 Only needed for credentials that can act on more than one Workspace. A
736 credential that belongs to a specific Workspace may omit it; if sent, it must
737 match that Workspace.
738
739 extra_headers: Send extra headers
740
741 extra_query: Add additional query parameters to the request
742
743 extra_body: Add additional JSON properties to the request
744
745 timeout: Override the client-level default timeout for this request, in seconds
746 """
747 if not tunnel_id:
748 raise ValueError(f"Expected a non-empty value for `tunnel_id` but received {tunnel_id!r}")
749 extra_headers = {
750 **strip_not_given(
751 {
752 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
753 if is_given(betas)
754 else not_given,
755 "anthropic-workspace-id": workspace_id,
756 }
757 ),
758 **(extra_headers or {}),
759 }
760 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
761 return await self._post(
762 path_template("/v1/tunnels/{tunnel_id}/archive?beta=true", tunnel_id=tunnel_id),
763 options=make_request_options(
764 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
765 ),
766 cast_to=BetaTunnel,
767 )
768
769 async def reveal_token(
770 self,
771 tunnel_id: str,
772 *,
773 betas: List[AnthropicBetaParam] | Omit = omit,
774 workspace_id: str | Omit = omit,
775 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
776 # The extra values given here take precedence over values defined on the client or passed to this method.
777 extra_headers: Headers | None = None,
778 extra_query: Query | None = None,
779 extra_body: Body | None = None,
780 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
781 ) -> BetaTunnelToken:
782 """The Tunnels API is in research preview.
783
784 It requires the
785 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
786 deprecation period. It supersedes the Admin API endpoints at
787 `/v1/organizations/tunnels`, which remain available during a migration window.
788
789 Reveals a tunnel's connector token. The value is fetched live on each call;
790 Anthropic does not store it. Repeated calls return the same value until the
791 token is rotated. Exposed as POST so the token does not appear in intermediary
792 access logs.
793
794 Args:
795 tunnel_id: ID of the tunnel (`tnl_...`).
796
797 betas: Optional header to specify the beta version(s) you want to use.
798
799 workspace_id: Optional header to select the Workspace for this request. The value is a
800 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
801
802 Only needed for credentials that can act on more than one Workspace. A
803 credential that belongs to a specific Workspace may omit it; if sent, it must
804 match that Workspace.
805
806 extra_headers: Send extra headers
807
808 extra_query: Add additional query parameters to the request
809
810 extra_body: Add additional JSON properties to the request
811
812 timeout: Override the client-level default timeout for this request, in seconds
813 """
814 if not tunnel_id:
815 raise ValueError(f"Expected a non-empty value for `tunnel_id` but received {tunnel_id!r}")
816 extra_headers = {
817 **strip_not_given(
818 {
819 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
820 if is_given(betas)
821 else not_given,
822 "anthropic-workspace-id": workspace_id,
823 }
824 ),
825 **(extra_headers or {}),
826 }
827 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
828 return await self._post(
829 path_template("/v1/tunnels/{tunnel_id}/reveal_token?beta=true", tunnel_id=tunnel_id),
830 options=make_request_options(
831 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
832 ),
833 cast_to=BetaTunnelToken,
834 )
835
836 async def rotate_token(
837 self,
838 tunnel_id: str,
839 *,
840 reason: Optional[str] | Omit = omit,
841 betas: List[AnthropicBetaParam] | Omit = omit,
842 workspace_id: str | Omit = omit,
843 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
844 # The extra values given here take precedence over values defined on the client or passed to this method.
845 extra_headers: Headers | None = None,
846 extra_query: Query | None = None,
847 extra_body: Body | None = None,
848 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
849 ) -> BetaTunnelToken:
850 """The Tunnels API is in research preview.
851
852 It requires the
853 `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
854 deprecation period. It supersedes the Admin API endpoints at
855 `/v1/organizations/tunnels`, which remain available during a migration window.
856
857 Rotates a tunnel's connector token. Rotation invalidates the current token for
858 new connections and returns a fresh value; established connections are not
859 severed. A connector restarted after rotation must use the new value.
860
861 Args:
862 tunnel_id: ID of the tunnel (`tnl_...`).
863
864 reason: Optional free-text reason for the rotation, recorded for audit.
865
866 betas: Optional header to specify the beta version(s) you want to use.
867
868 workspace_id: Optional header to select the Workspace for this request. The value is a
869 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
870
871 Only needed for credentials that can act on more than one Workspace. A
872 credential that belongs to a specific Workspace may omit it; if sent, it must
873 match that Workspace.
874
875 extra_headers: Send extra headers
876
877 extra_query: Add additional query parameters to the request
878
879 extra_body: Add additional JSON properties to the request
880
881 timeout: Override the client-level default timeout for this request, in seconds
882 """
883 if not tunnel_id:
884 raise ValueError(f"Expected a non-empty value for `tunnel_id` but received {tunnel_id!r}")
885 extra_headers = {
886 **strip_not_given(
887 {
888 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["mcp-tunnels-2026-06-22"]))
889 if is_given(betas)
890 else not_given,
891 "anthropic-workspace-id": workspace_id,
892 }
893 ),
894 **(extra_headers or {}),
895 }
896 extra_headers = {"anthropic-beta": "mcp-tunnels-2026-06-22", **(extra_headers or {})}
897 return await self._post(
898 path_template("/v1/tunnels/{tunnel_id}/rotate_token?beta=true", tunnel_id=tunnel_id),
899 body={"reason": reason},
900 options=make_request_options(
901 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
902 ),
903 cast_to=BetaTunnelToken,
904 )
905
906
907 class TunnelsWithRawResponse:
908 def __init__(self, tunnels: Tunnels) -> None:
909 self._tunnels = tunnels
910
911 self.create = to_raw_response_wrapper(
912 tunnels.create,
913 )
914 self.retrieve = to_raw_response_wrapper(
915 tunnels.retrieve,
916 )
917 self.list = to_raw_response_wrapper(
918 tunnels.list,
919 )
920 self.archive = to_raw_response_wrapper(
921 tunnels.archive,
922 )
923 self.reveal_token = to_raw_response_wrapper(
924 tunnels.reveal_token,
925 )
926 self.rotate_token = to_raw_response_wrapper(
927 tunnels.rotate_token,
928 )
929
930 @cached_property
931 def certificates(self) -> CertificatesWithRawResponse:
932 return CertificatesWithRawResponse(self._tunnels.certificates)
933
934
935 class AsyncTunnelsWithRawResponse:
936 def __init__(self, tunnels: AsyncTunnels) -> None:
937 self._tunnels = tunnels
938
939 self.create = async_to_raw_response_wrapper(
940 tunnels.create,
941 )
942 self.retrieve = async_to_raw_response_wrapper(
943 tunnels.retrieve,
944 )
945 self.list = async_to_raw_response_wrapper(
946 tunnels.list,
947 )
948 self.archive = async_to_raw_response_wrapper(
949 tunnels.archive,
950 )
951 self.reveal_token = async_to_raw_response_wrapper(
952 tunnels.reveal_token,
953 )
954 self.rotate_token = async_to_raw_response_wrapper(
955 tunnels.rotate_token,
956 )
957
958 @cached_property
959 def certificates(self) -> AsyncCertificatesWithRawResponse:
960 return AsyncCertificatesWithRawResponse(self._tunnels.certificates)
961
962
963 class TunnelsWithStreamingResponse:
964 def __init__(self, tunnels: Tunnels) -> None:
965 self._tunnels = tunnels
966
967 self.create = to_streamed_response_wrapper(
968 tunnels.create,
969 )
970 self.retrieve = to_streamed_response_wrapper(
971 tunnels.retrieve,
972 )
973 self.list = to_streamed_response_wrapper(
974 tunnels.list,
975 )
976 self.archive = to_streamed_response_wrapper(
977 tunnels.archive,
978 )
979 self.reveal_token = to_streamed_response_wrapper(
980 tunnels.reveal_token,
981 )
982 self.rotate_token = to_streamed_response_wrapper(
983 tunnels.rotate_token,
984 )
985
986 @cached_property
987 def certificates(self) -> CertificatesWithStreamingResponse:
988 return CertificatesWithStreamingResponse(self._tunnels.certificates)
989
990
991 class AsyncTunnelsWithStreamingResponse:
992 def __init__(self, tunnels: AsyncTunnels) -> None:
993 self._tunnels = tunnels
994
995 self.create = async_to_streamed_response_wrapper(
996 tunnels.create,
997 )
998 self.retrieve = async_to_streamed_response_wrapper(
999 tunnels.retrieve,
1000 )
1001 self.list = async_to_streamed_response_wrapper(
1002 tunnels.list,
1003 )
1004 self.archive = async_to_streamed_response_wrapper(
1005 tunnels.archive,
1006 )
1007 self.reveal_token = async_to_streamed_response_wrapper(
1008 tunnels.reveal_token,
1009 )
1010 self.rotate_token = async_to_streamed_response_wrapper(
1011 tunnels.rotate_token,
1012 )
1013
1014 @cached_property
1015 def certificates(self) -> AsyncCertificatesWithStreamingResponse:
1016 return AsyncCertificatesWithStreamingResponse(self._tunnels.certificates)