holon-sh 0.0.1.dev25__tar.gz → 0.0.1.dev27__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/PKG-INFO +3 -1
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/client.py +17 -7
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/serve.py +12 -2
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/pyproject.toml +3 -1
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/tests/test_runtime.py +13 -2
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/tests/test_serve.py +39 -2
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/.gitignore +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/LICENSE +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/README.md +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/context.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/__init__.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/events/__init__.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/events/_client.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/events/_server.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/events/_wire.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/files/__init__.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/files/_client.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/files/_server.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/ext/files/_wire.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/holon/py.typed +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/scripts/verify_distribution.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/tests/fixtures/caller/holon/apps/__init__.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/tests/test_elicit.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/tests/test_events.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/tests/test_files.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev27}/tests/test_package.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: holon-sh
|
|
3
|
-
Version: 0.0.1.
|
|
3
|
+
Version: 0.0.1.dev27
|
|
4
4
|
Summary: Typed MCP clients and the caller of an MCP request
|
|
5
5
|
Project-URL: Repository, https://github.com/holon-sh/sdk-py
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -10,6 +10,8 @@ Requires-Dist: httpx2<3,>=2.10
|
|
|
10
10
|
Requires-Dist: jsonschema<5,>=4.26
|
|
11
11
|
Requires-Dist: mcp<3,>=2.3
|
|
12
12
|
Requires-Dist: opentelemetry-api<2,>=1.28
|
|
13
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http<2,>=1.28
|
|
14
|
+
Requires-Dist: opentelemetry-sdk<2,>=1.28
|
|
13
15
|
Requires-Dist: pydantic<3,>=2.12
|
|
14
16
|
Requires-Dist: starlette<2,>=0.48
|
|
15
17
|
Requires-Dist: uvicorn<1,>=0.31.1
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
import os
|
|
4
5
|
from collections.abc import AsyncIterator, Awaitable, Callable, Mapping, Sequence
|
|
5
6
|
from contextlib import asynccontextmanager
|
|
@@ -110,6 +111,12 @@ class CallOptions(TypedDict, total=False):
|
|
|
110
111
|
elicit: Callable[[ElicitRequestParams], Awaitable[ElicitResult]]
|
|
111
112
|
|
|
112
113
|
|
|
114
|
+
def _text(result: CallToolResult) -> str | None:
|
|
115
|
+
return next(
|
|
116
|
+
(part.text for part in result.content if isinstance(part, TextContent)), None
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
113
120
|
class ToolCallError(RuntimeError):
|
|
114
121
|
"""Raised by ``tools.<name>`` when a tool fails or needs input.
|
|
115
122
|
|
|
@@ -130,10 +137,7 @@ class ToolCallError(RuntimeError):
|
|
|
130
137
|
)
|
|
131
138
|
else:
|
|
132
139
|
message = "tool failed"
|
|
133
|
-
detail =
|
|
134
|
-
(part.text for part in result.content if isinstance(part, TextContent)),
|
|
135
|
-
"",
|
|
136
|
-
)
|
|
140
|
+
detail = _text(result) or ""
|
|
137
141
|
if detail:
|
|
138
142
|
message = f"{message}: {detail}"
|
|
139
143
|
super().__init__(f"{app}.{tool}: {message}")
|
|
@@ -207,9 +211,10 @@ class _App:
|
|
|
207
211
|
if contract is None
|
|
208
212
|
else {tool["name"]: tool for tool in contract["tools"]}
|
|
209
213
|
)
|
|
214
|
+
parsed = set((contract or {}).get("responses", ()))
|
|
210
215
|
self.tools = SimpleNamespace(
|
|
211
216
|
**{
|
|
212
|
-
name: partial(self._call_tool, tool)
|
|
217
|
+
name: partial(self._call_tool, tool, name in parsed)
|
|
213
218
|
for name, tool in self._definitions.items()
|
|
214
219
|
if not name.startswith("_")
|
|
215
220
|
}
|
|
@@ -346,6 +351,7 @@ class _App:
|
|
|
346
351
|
async def _call_tool(
|
|
347
352
|
self,
|
|
348
353
|
tool: dict[str, Any],
|
|
354
|
+
parsed: bool,
|
|
349
355
|
options: CallOptions | None = None,
|
|
350
356
|
/,
|
|
351
357
|
**arguments: object,
|
|
@@ -353,6 +359,9 @@ class _App:
|
|
|
353
359
|
result = await self.call_tool(tool["name"], options, **arguments)
|
|
354
360
|
if isinstance(result, InputRequiredResult) or result.is_error:
|
|
355
361
|
raise ToolCallError(self._name, tool["name"], result)
|
|
362
|
+
if parsed:
|
|
363
|
+
text = _text(result)
|
|
364
|
+
return None if text is None else json.loads(text)
|
|
356
365
|
return result.structured_content if "outputSchema" in tool else result
|
|
357
366
|
|
|
358
367
|
|
|
@@ -360,8 +369,9 @@ class Apps:
|
|
|
360
369
|
"""An application's dependencies, as generated clients use them.
|
|
361
370
|
|
|
362
371
|
Applications use ``apps`` or ``create_apps`` from ``holon.apps``. Each dependency is ``apps.<name>``
|
|
363
|
-
or ``apps[name]``: its ``tools.<name>`` return structured output or
|
|
364
|
-
and its ``call_tool``
|
|
372
|
+
or ``apps[name]``: its ``tools.<name>`` return structured output, or the parsed JSON text of a tool
|
|
373
|
+
the contract lists under ``responses``, or raise :class:`ToolCallError`, and its ``call_tool``
|
|
374
|
+
returns the full result.
|
|
365
375
|
|
|
366
376
|
Args:
|
|
367
377
|
identity: Application name, version, and ``requires``.
|
|
@@ -22,7 +22,10 @@ from mcp.server.auth.provider import AccessToken
|
|
|
22
22
|
from mcp.server.subscriptions import ListenHandler
|
|
23
23
|
from mcp.server.transport_security import TransportSecuritySettings
|
|
24
24
|
from opentelemetry import context as tracing
|
|
25
|
-
from opentelemetry import propagate
|
|
25
|
+
from opentelemetry import propagate, trace
|
|
26
|
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
|
27
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
28
|
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
26
29
|
from pydantic import BaseModel
|
|
27
30
|
from starlette.authentication import AuthCredentials, UnauthenticatedUser
|
|
28
31
|
from starlette.datastructures import Headers
|
|
@@ -74,8 +77,14 @@ def load(entry: str) -> App:
|
|
|
74
77
|
async def serve(app: App) -> None:
|
|
75
78
|
"""Serve ``app`` on ``HOST`` and ``PORT``, or else on 127.0.0.1:3000.
|
|
76
79
|
|
|
77
|
-
The MCP endpoint is at ``/mcp`` and ``/mcp/<app>``, and the frontend's files are everywhere else.
|
|
80
|
+
The MCP endpoint is at ``/mcp`` and ``/mcp/<app>``, and the frontend's files are everywhere else. With
|
|
81
|
+
``OTEL_EXPORTER_OTLP_ENDPOINT`` set, as Holon sets it, the MCP SDK's spans for each request and each call to a
|
|
82
|
+
dependency are exported there, the last of them as the server stops.
|
|
78
83
|
"""
|
|
84
|
+
provider = TracerProvider()
|
|
85
|
+
if os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT"):
|
|
86
|
+
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
|
|
87
|
+
trace.set_tracer_provider(provider)
|
|
79
88
|
config = uvicorn.Config(
|
|
80
89
|
_asgi(app),
|
|
81
90
|
host=os.environ.get("HOST", "127.0.0.1"),
|
|
@@ -99,6 +108,7 @@ async def serve(app: App) -> None:
|
|
|
99
108
|
if isinstance(each, Events):
|
|
100
109
|
each.close()
|
|
101
110
|
await super().shutdown(sockets)
|
|
111
|
+
provider.shutdown()
|
|
102
112
|
|
|
103
113
|
await Server(config).serve()
|
|
104
114
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "holon-sh"
|
|
7
|
-
version = "0.0.1.
|
|
7
|
+
version = "0.0.1.dev27"
|
|
8
8
|
description = "Typed MCP clients and the caller of an MCP request"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -15,6 +15,8 @@ dependencies = [
|
|
|
15
15
|
"jsonschema>=4.26,<5",
|
|
16
16
|
"httpx2>=2.10,<3",
|
|
17
17
|
"opentelemetry-api>=1.28,<2",
|
|
18
|
+
"opentelemetry-exporter-otlp-proto-http>=1.28,<2",
|
|
19
|
+
"opentelemetry-sdk>=1.28,<2",
|
|
18
20
|
"pydantic>=2.12,<3",
|
|
19
21
|
"starlette>=0.48,<2",
|
|
20
22
|
"uvicorn>=0.31.1,<1",
|
|
@@ -58,8 +58,10 @@ def test_clients_preserve_mcp_results_and_validate(monkeypatch):
|
|
|
58
58
|
return InputRequiredResult(
|
|
59
59
|
request_state="opaque", _meta={"preserved": True}
|
|
60
60
|
)
|
|
61
|
+
if id == "empty":
|
|
62
|
+
return CallToolResult(content=[])
|
|
61
63
|
return CallToolResult(
|
|
62
|
-
content=[TextContent(type="text", text="
|
|
64
|
+
content=[TextContent(type="text", text='{"order": "unchecked"}')],
|
|
63
65
|
structured_content={"total": "bad" if id == "bad" else limit},
|
|
64
66
|
)
|
|
65
67
|
|
|
@@ -147,7 +149,16 @@ def test_clients_preserve_mcp_results_and_validate(monkeypatch):
|
|
|
147
149
|
k: v for k, v in CONTRACT["tools"][0].items() if k != "outputSchema"
|
|
148
150
|
}
|
|
149
151
|
plain = Apps(identity, {"orders": {"tools": [tool]}}, bindings)
|
|
150
|
-
assert (await plain.orders.tools.read(id="good")).content[0].text ==
|
|
152
|
+
assert (await plain.orders.tools.read(id="good")).content[0].text == (
|
|
153
|
+
'{"order": "unchecked"}'
|
|
154
|
+
)
|
|
155
|
+
parsed = Apps(
|
|
156
|
+
identity, {"orders": {"tools": [tool], "responses": ["read"]}}, bindings
|
|
157
|
+
)
|
|
158
|
+
assert await parsed.orders.tools.read(id="good") == {"order": "unchecked"}
|
|
159
|
+
assert await parsed.orders.tools.read(id="empty") is None
|
|
160
|
+
with pytest.raises(ToolCallError):
|
|
161
|
+
await parsed.orders.tools.read(id="error")
|
|
151
162
|
with pytest.raises(RuntimeError):
|
|
152
163
|
await Apps(undeclared, {}).missing.call_tool("read")
|
|
153
164
|
script = {**identity, "requires": {}}
|
|
@@ -8,6 +8,9 @@ import subprocess
|
|
|
8
8
|
import sys
|
|
9
9
|
from contextlib import asynccontextmanager
|
|
10
10
|
from functools import wraps
|
|
11
|
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
12
|
+
from threading import Thread
|
|
13
|
+
from typing import ClassVar
|
|
11
14
|
|
|
12
15
|
import httpx2
|
|
13
16
|
import pytest
|
|
@@ -21,6 +24,9 @@ from mcp.types import (
|
|
|
21
24
|
LATEST_PROTOCOL_VERSION,
|
|
22
25
|
)
|
|
23
26
|
from opentelemetry import propagate
|
|
27
|
+
from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import (
|
|
28
|
+
ExportTraceServiceRequest,
|
|
29
|
+
)
|
|
24
30
|
from starlette.datastructures import Headers
|
|
25
31
|
from starlette.responses import RedirectResponse, Response
|
|
26
32
|
from test_events import request
|
|
@@ -285,7 +291,19 @@ async def test_the_frontend_serves_its_files_and_nothing_hidden_or_outside_it(
|
|
|
285
291
|
assert (await http.post("/")).status_code == 404
|
|
286
292
|
|
|
287
293
|
|
|
288
|
-
|
|
294
|
+
class _Collector(BaseHTTPRequestHandler):
|
|
295
|
+
exports: ClassVar[list[bytes]] = []
|
|
296
|
+
|
|
297
|
+
def do_POST(self):
|
|
298
|
+
_Collector.exports.append(self.rfile.read(int(self.headers["content-length"])))
|
|
299
|
+
self.send_response(200)
|
|
300
|
+
self.end_headers()
|
|
301
|
+
|
|
302
|
+
def log_message(self, *args):
|
|
303
|
+
pass
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def test_python_m_holon_serve_runs_an_entry_with_a_16_kib_context_exports_its_spans_and_on_sigterm_closes_its_streams_and_stops(
|
|
289
307
|
tmp_path,
|
|
290
308
|
):
|
|
291
309
|
(tmp_path / "src").mkdir()
|
|
@@ -304,10 +322,18 @@ frontend = "web"
|
|
|
304
322
|
with socket.socket() as reserved:
|
|
305
323
|
reserved.bind(("127.0.0.1", 0))
|
|
306
324
|
port = reserved.getsockname()[1]
|
|
325
|
+
collector = HTTPServer(("127.0.0.1", 0), _Collector)
|
|
326
|
+
Thread(target=collector.serve_forever, daemon=True).start()
|
|
307
327
|
process = subprocess.Popen(
|
|
308
328
|
[sys.executable, "-m", "holon.serve", "src/server.py"],
|
|
309
329
|
cwd=tmp_path,
|
|
310
|
-
env={
|
|
330
|
+
env={
|
|
331
|
+
**os.environ,
|
|
332
|
+
"PORT": str(port),
|
|
333
|
+
"OTEL_EXPORTER_OTLP_ENDPOINT": f"http://127.0.0.1:{collector.server_port}",
|
|
334
|
+
"OTEL_SERVICE_NAME": "large",
|
|
335
|
+
"OTEL_RESOURCE_ATTRIBUTES": "holon.session=production",
|
|
336
|
+
},
|
|
311
337
|
)
|
|
312
338
|
|
|
313
339
|
async def exercise():
|
|
@@ -349,3 +375,14 @@ frontend = "web"
|
|
|
349
375
|
process.wait(timeout=10)
|
|
350
376
|
finally:
|
|
351
377
|
process.kill()
|
|
378
|
+
collector.shutdown()
|
|
379
|
+
exported = {}
|
|
380
|
+
for body in _Collector.exports:
|
|
381
|
+
for spans in ExportTraceServiceRequest.FromString(body).resource_spans:
|
|
382
|
+
resource = {
|
|
383
|
+
each.key: each.value.string_value for each in spans.resource.attributes
|
|
384
|
+
}
|
|
385
|
+
for scoped in spans.scope_spans:
|
|
386
|
+
exported |= {span.name: resource for span in scoped.spans}
|
|
387
|
+
resource = {"service.name": "large", "holon.session": "production"}
|
|
388
|
+
assert resource.items() <= exported["events/stream ticked"].items()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|