MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / Server

Class Server

tests/test_tracing.py:99–119  ·  view source on GitHub ↗

Answers a call, after one retry if `retried`. Records each request, and the context of the span that was current while the HTTP client sent it.

Source from the content-addressed store, hash-verified

97
98
99class Server:
100 """Answers a call, after one retry if `retried`.
101
102 Records each request, and the context of the span that was current while the HTTP client sent it.
103 """
104
105 def __init__(self, *, retried: bool = False) -> None:
106 self.retried = retried
107 self.requests: list[httpx2.Request] = []
108 self.current_spans: list[SpanContext] = []
109
110 def __call__(self, request: httpx2.Request) -> httpx2.Response:
111 self.requests.append(request)
112 self.current_spans.append(trace.get_current_span().get_span_context())
113 if self.retried and len(self.requests) == 1:
114 return httpx2.Response(500, headers={"retry-after-ms": "1"}, json={})
115 return httpx2.Response(200, json={})
116
117 @property
118 def traceparents(self) -> list[str | None]:
119 return [request.headers.get("traceparent") for request in self.requests]
120
121
122NewClient = Callable[..., Client]

Calls

no outgoing calls