cks-runtime 0.1.2__tar.gz → 0.4.0__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.
Files changed (71) hide show
  1. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/PKG-INFO +47 -17
  2. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/README.md +44 -15
  3. cks_runtime-0.4.0/cks_runtime/__init__.py +21 -0
  4. cks_runtime-0.4.0/cks_runtime/adapters/mcp/__init__.py +17 -0
  5. cks_runtime-0.4.0/cks_runtime/adapters/mcp/adapter.py +68 -0
  6. cks_runtime-0.4.0/cks_runtime/adapters/mcp/contracts.py +256 -0
  7. cks_runtime-0.4.0/cks_runtime/adapters/mcp/errors.py +164 -0
  8. cks_runtime-0.4.0/cks_runtime/adapters/mcp/handlers.py +144 -0
  9. cks_runtime-0.4.0/cks_runtime/adapters/mcp/serializers.py +140 -0
  10. cks_runtime-0.4.0/cks_runtime/adapters/mcp/tool_registry.py +261 -0
  11. cks_runtime-0.4.0/cks_runtime/config.py +51 -0
  12. cks_runtime-0.4.0/cks_runtime/core_api/__init__.py +21 -0
  13. cks_runtime-0.4.0/cks_runtime/core_api/bridge.py +151 -0
  14. cks_runtime-0.4.0/cks_runtime/core_api/interfaces.py +127 -0
  15. cks_runtime-0.4.0/cks_runtime/core_api/validation_result.py +157 -0
  16. cks_runtime-0.4.0/cks_runtime/diagnostics/aggregator.py +148 -0
  17. cks_runtime-0.4.0/cks_runtime/diagnostics/diagnostic.py +139 -0
  18. cks_runtime-0.4.0/cks_runtime/dispatcher/dispatcher.py +135 -0
  19. cks_runtime-0.4.0/cks_runtime/events/event_bus.py +207 -0
  20. cks_runtime-0.4.0/cks_runtime/events/runtime_event.py +135 -0
  21. cks_runtime-0.4.0/cks_runtime/execution/execution_context.py +62 -0
  22. cks_runtime-0.4.0/cks_runtime/execution/operation_executor.py +214 -0
  23. cks_runtime-0.4.0/cks_runtime/explainability/explainability_manager.py +13 -0
  24. cks_runtime-0.4.0/cks_runtime/operations/operation_registry.py +172 -0
  25. cks_runtime-0.4.0/cks_runtime/operations/operation_types.py +125 -0
  26. cks_runtime-0.4.0/cks_runtime/pipeline/execution_pipeline.py +208 -0
  27. cks_runtime-0.4.0/cks_runtime/runtime.py +391 -0
  28. cks_runtime-0.4.0/cks_runtime/session/session.py +51 -0
  29. cks_runtime-0.4.0/cks_runtime/session/session_manager.py +154 -0
  30. cks_runtime-0.4.0/cks_runtime/storage/memory_storage.py +177 -0
  31. cks_runtime-0.4.0/cks_runtime/storage/storage.py +132 -0
  32. cks_runtime-0.4.0/cks_runtime/transaction/transaction.py +89 -0
  33. cks_runtime-0.4.0/cks_runtime/transaction/transaction_manager.py +195 -0
  34. cks_runtime-0.4.0/cks_runtime/versioning/version.py +110 -0
  35. cks_runtime-0.4.0/cks_runtime/versioning/version_manager.py +155 -0
  36. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/cks_runtime.egg-info/PKG-INFO +47 -17
  37. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/cks_runtime.egg-info/SOURCES.txt +23 -2
  38. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/cks_runtime.egg-info/requires.txt +1 -0
  39. cks_runtime-0.4.0/cks_runtime.egg-info/top_level.txt +2 -0
  40. cks_runtime-0.4.0/cks_runtime_plugins/__init__.py +0 -0
  41. cks_runtime-0.4.0/cks_runtime_plugins/cks_core/__init__.py +16 -0
  42. cks_runtime-0.4.0/cks_runtime_plugins/cks_core/adapter.py +110 -0
  43. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/pyproject.toml +10 -5
  44. cks_runtime-0.1.2/cks_runtime/__init__.py +0 -11
  45. cks_runtime-0.1.2/cks_runtime/config.py +0 -22
  46. cks_runtime-0.1.2/cks_runtime/core_api/interfaces.py +0 -78
  47. cks_runtime-0.1.2/cks_runtime/diagnostics/aggregator.py +0 -115
  48. cks_runtime-0.1.2/cks_runtime/diagnostics/diagnostic.py +0 -68
  49. cks_runtime-0.1.2/cks_runtime/runtime.py +0 -85
  50. cks_runtime-0.1.2/cks_runtime/session/session.py +0 -72
  51. cks_runtime-0.1.2/cks_runtime/session/session_manager.py +0 -98
  52. cks_runtime-0.1.2/cks_runtime/storage/exceptions.py +0 -37
  53. cks_runtime-0.1.2/cks_runtime/storage/memory_storage.py +0 -127
  54. cks_runtime-0.1.2/cks_runtime/storage/storage.py +0 -90
  55. cks_runtime-0.1.2/cks_runtime/transaction/transaction.py +0 -149
  56. cks_runtime-0.1.2/cks_runtime/transaction/transaction_manager.py +0 -125
  57. cks_runtime-0.1.2/cks_runtime/versioning/version.py +0 -44
  58. cks_runtime-0.1.2/cks_runtime/versioning/version_manager.py +0 -81
  59. cks_runtime-0.1.2/cks_runtime.egg-info/top_level.txt +0 -1
  60. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/LICENSE +0 -0
  61. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/cks_runtime/adapters/__init__.py +0 -0
  62. {cks_runtime-0.1.2/cks_runtime/core_api → cks_runtime-0.4.0/cks_runtime/diagnostics}/__init__.py +0 -0
  63. {cks_runtime-0.1.2/cks_runtime/diagnostics → cks_runtime-0.4.0/cks_runtime/execution}/__init__.py +0 -0
  64. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/cks_runtime/explainability/__init__.py +0 -0
  65. {cks_runtime-0.1.2/cks_runtime/session → cks_runtime-0.4.0/cks_runtime/pipeline}/__init__.py +0 -0
  66. {cks_runtime-0.1.2/cks_runtime/storage → cks_runtime-0.4.0/cks_runtime/session}/__init__.py +0 -0
  67. {cks_runtime-0.1.2/cks_runtime/transaction → cks_runtime-0.4.0/cks_runtime/storage}/__init__.py +0 -0
  68. {cks_runtime-0.1.2/cks_runtime/versioning → cks_runtime-0.4.0/cks_runtime/transaction}/__init__.py +0 -0
  69. /cks_runtime-0.1.2/cks_runtime/explainability/explainability_manager.py → /cks_runtime-0.4.0/cks_runtime/versioning/__init__.py +0 -0
  70. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/cks_runtime.egg-info/dependency_links.txt +0 -0
  71. {cks_runtime-0.1.2 → cks_runtime-0.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cks-runtime
3
- Version: 0.1.2
3
+ Version: 0.4.0
4
4
  Summary: Canonical Runtime for the Canonical Knowledge Structure ecosystem
5
5
  Author: Vladyslav Hruznov
6
6
  License: MIT
@@ -11,12 +11,13 @@ Keywords: canonical-knowledge-structure,runtime,knowledge-runtime,transactions,s
11
11
  Classifier: Development Status :: 3 - Alpha
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Topic :: Software Development :: Libraries
16
16
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
- Requires-Python: >=3.11
17
+ Requires-Python: >=3.12
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
+ Requires-Dist: cks-core>=1.1.1
20
21
  Provides-Extra: dev
21
22
  Requires-Dist: pytest>=8.0; extra == "dev"
22
23
  Requires-Dist: mypy>=1.0; extra == "dev"
@@ -28,7 +29,8 @@ Dynamic: license-file
28
29
 
29
30
  ![Python](https://img.shields.io/badge/python-3.11%2B-blue)
30
31
  ![License](https://img.shields.io/badge/license-MIT-green)
31
- ![Status](https://img.shields.io/badge/status-alpha-orange)
32
+ ![Tests](https://img.shields.io/badge/tests-147%20passing-brightgreen)
33
+ ![Status](https://img.shields.io/badge/status-beta-blue)
32
34
 
33
35
  CKS Runtime is the canonical execution environment for
34
36
  Canonical Knowledge Structures (CKS).
@@ -40,6 +42,20 @@ Runtime provides the infrastructure required to execute,
40
42
  manage, version, persist and expose Canonical Knowledge Structures
41
43
  without becoming a semantic authority itself.
42
44
 
45
+ ---
46
+
47
+ # Ecosystem
48
+
49
+ CKS Runtime is part of a family of interoperable projects built on the
50
+ Canonical Knowledge Structure.
51
+
52
+ | Project | Description | Repository |
53
+ |---------|-------------|------------|
54
+ | **cks-core** | Semantic engine – the single source of canonical truth. | [Deus-corp/cks-core](https://github.com/Deus-corp/cks-core) |
55
+ | **cks-runtime** | Operational environment – sessions, transactions, persistence. | [Deus-corp/cks-runtime](https://github.com/Deus-corp/cks-runtime) |
56
+ | **cks-mcp** | MCP server – exposes CKS to LLMs via the Model Context Protocol. | [Deus-corp/cks-mcp](https://github.com/Deus-corp/cks-mcp) |
57
+
58
+
43
59
  ---
44
60
 
45
61
  # Why Runtime?
@@ -168,6 +184,10 @@ The current Reference Runtime provides:
168
184
  - Canonical Runtime API
169
185
  - Reference Runtime Architecture
170
186
  - Runtime Conformance Model
187
+ - **CKS Core Integration** (via `CksCoreAdapter`)
188
+ - **Execution Engine** – canonical operations (Validate, Serialize, Explain, Evolve) via `CoreBridge`
189
+ - **Operation Dispatcher** – registry-based operation resolution
190
+ - **DispatchRequest** support – decoupled operation execution
171
191
 
172
192
  ---
173
193
 
@@ -213,7 +233,6 @@ Runtime communicates exclusively through the public CKS Core API.
213
233
  From PyPI:
214
234
 
215
235
  ```bash
216
- pip install cks-core
217
236
  pip install cks-runtime
218
237
  ```
219
238
 
@@ -233,17 +252,20 @@ pip install -e .
233
252
 
234
253
  ```python
235
254
  from cks_runtime import Runtime
255
+ from cks_runtime_plugins.cks_core import CksCoreAdapter
256
+ from cks_runtime.operations.operation_types import ValidateOperation
236
257
 
237
- runtime = Runtime()
258
+ # Create Runtime with real CKS Core
259
+ runtime = Runtime(core=CksCoreAdapter())
238
260
 
239
- session = runtime.sessions.create(
240
- knowledge_structure=my_structure
241
- )
261
+ session = runtime.create_session({"example": True})
262
+ tx = runtime.begin_transaction(session)
263
+ tx.add_operation(ValidateOperation("v1", knowledge_structure=session.knowledge_structure))
242
264
 
243
- transaction = runtime.transactions.begin(session)
265
+ version = runtime.commit_transaction(tx)
266
+ print(version)
244
267
 
245
- # Runtime coordinates execution.
246
- # CKS Core defines semantics.
268
+ # Runtime coordinates execution. CKS Core defines semantics.
247
269
  ```
248
270
 
249
271
  ---
@@ -272,9 +294,9 @@ Supporting documents include:
272
294
 
273
295
  ---
274
296
 
275
- # Project Status
297
+ ## Project Status
276
298
 
277
- Current implementation status:
299
+ Current implementation status (v0.4.0):
278
300
 
279
301
  | Component | Status |
280
302
  |----------|--------|
@@ -285,9 +307,17 @@ Current implementation status:
285
307
  | Diagnostics | ✅ Complete |
286
308
  | Storage Abstraction | ✅ Complete |
287
309
  | Runtime API | ✅ Complete |
288
- | Runtime Documentation | ✅ Complete |
289
- | Reference Implementation | 🚧 In Progress |
290
- | Adapter Integration | Planned |
310
+ | Core Integration (CoreBridge) | ✅ Complete |
311
+ | Execution Engine (Operations + Dispatcher) | Complete |
312
+ | Test Suite | 147 tests passing |
313
+ | CLI / MCP Adapters | ✅ Experimental |
314
+ | Event System | 🚧 Planned (Phase 3) |
315
+
316
+ The current implementation serves as the reference implementation of the
317
+ CKS Runtime Standard (SPEC-001 … SPEC-008).
318
+
319
+ Future work focuses on Phase 3 (Event System) as outlined in the
320
+ [Roadmap](ROADMAP.md).
291
321
 
292
322
  ---
293
323
 
@@ -4,7 +4,8 @@
4
4
 
5
5
  ![Python](https://img.shields.io/badge/python-3.11%2B-blue)
6
6
  ![License](https://img.shields.io/badge/license-MIT-green)
7
- ![Status](https://img.shields.io/badge/status-alpha-orange)
7
+ ![Tests](https://img.shields.io/badge/tests-147%20passing-brightgreen)
8
+ ![Status](https://img.shields.io/badge/status-beta-blue)
8
9
 
9
10
  CKS Runtime is the canonical execution environment for
10
11
  Canonical Knowledge Structures (CKS).
@@ -16,6 +17,20 @@ Runtime provides the infrastructure required to execute,
16
17
  manage, version, persist and expose Canonical Knowledge Structures
17
18
  without becoming a semantic authority itself.
18
19
 
20
+ ---
21
+
22
+ # Ecosystem
23
+
24
+ CKS Runtime is part of a family of interoperable projects built on the
25
+ Canonical Knowledge Structure.
26
+
27
+ | Project | Description | Repository |
28
+ |---------|-------------|------------|
29
+ | **cks-core** | Semantic engine – the single source of canonical truth. | [Deus-corp/cks-core](https://github.com/Deus-corp/cks-core) |
30
+ | **cks-runtime** | Operational environment – sessions, transactions, persistence. | [Deus-corp/cks-runtime](https://github.com/Deus-corp/cks-runtime) |
31
+ | **cks-mcp** | MCP server – exposes CKS to LLMs via the Model Context Protocol. | [Deus-corp/cks-mcp](https://github.com/Deus-corp/cks-mcp) |
32
+
33
+
19
34
  ---
20
35
 
21
36
  # Why Runtime?
@@ -144,6 +159,10 @@ The current Reference Runtime provides:
144
159
  - Canonical Runtime API
145
160
  - Reference Runtime Architecture
146
161
  - Runtime Conformance Model
162
+ - **CKS Core Integration** (via `CksCoreAdapter`)
163
+ - **Execution Engine** – canonical operations (Validate, Serialize, Explain, Evolve) via `CoreBridge`
164
+ - **Operation Dispatcher** – registry-based operation resolution
165
+ - **DispatchRequest** support – decoupled operation execution
147
166
 
148
167
  ---
149
168
 
@@ -189,7 +208,6 @@ Runtime communicates exclusively through the public CKS Core API.
189
208
  From PyPI:
190
209
 
191
210
  ```bash
192
- pip install cks-core
193
211
  pip install cks-runtime
194
212
  ```
195
213
 
@@ -209,17 +227,20 @@ pip install -e .
209
227
 
210
228
  ```python
211
229
  from cks_runtime import Runtime
230
+ from cks_runtime_plugins.cks_core import CksCoreAdapter
231
+ from cks_runtime.operations.operation_types import ValidateOperation
212
232
 
213
- runtime = Runtime()
233
+ # Create Runtime with real CKS Core
234
+ runtime = Runtime(core=CksCoreAdapter())
214
235
 
215
- session = runtime.sessions.create(
216
- knowledge_structure=my_structure
217
- )
236
+ session = runtime.create_session({"example": True})
237
+ tx = runtime.begin_transaction(session)
238
+ tx.add_operation(ValidateOperation("v1", knowledge_structure=session.knowledge_structure))
218
239
 
219
- transaction = runtime.transactions.begin(session)
240
+ version = runtime.commit_transaction(tx)
241
+ print(version)
220
242
 
221
- # Runtime coordinates execution.
222
- # CKS Core defines semantics.
243
+ # Runtime coordinates execution. CKS Core defines semantics.
223
244
  ```
224
245
 
225
246
  ---
@@ -248,9 +269,9 @@ Supporting documents include:
248
269
 
249
270
  ---
250
271
 
251
- # Project Status
272
+ ## Project Status
252
273
 
253
- Current implementation status:
274
+ Current implementation status (v0.4.0):
254
275
 
255
276
  | Component | Status |
256
277
  |----------|--------|
@@ -261,9 +282,17 @@ Current implementation status:
261
282
  | Diagnostics | ✅ Complete |
262
283
  | Storage Abstraction | ✅ Complete |
263
284
  | Runtime API | ✅ Complete |
264
- | Runtime Documentation | ✅ Complete |
265
- | Reference Implementation | 🚧 In Progress |
266
- | Adapter Integration | Planned |
285
+ | Core Integration (CoreBridge) | ✅ Complete |
286
+ | Execution Engine (Operations + Dispatcher) | Complete |
287
+ | Test Suite | 147 tests passing |
288
+ | CLI / MCP Adapters | ✅ Experimental |
289
+ | Event System | 🚧 Planned (Phase 3) |
290
+
291
+ The current implementation serves as the reference implementation of the
292
+ CKS Runtime Standard (SPEC-001 … SPEC-008).
293
+
294
+ Future work focuses on Phase 3 (Event System) as outlined in the
295
+ [Roadmap](ROADMAP.md).
267
296
 
268
297
  ---
269
298
 
@@ -279,4 +308,4 @@ This preserves a single semantic authority while allowing unlimited operational
279
308
 
280
309
  # License
281
310
 
282
- MIT
311
+ MIT
@@ -0,0 +1,21 @@
1
+ """
2
+ CKS Runtime.
3
+
4
+ Canonical Runtime for the Canonical Knowledge Structure ecosystem.
5
+
6
+ The public package API intentionally exposes only the
7
+ high-level Runtime façade and its configuration object.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from .config import RuntimeConfig
13
+ from .runtime import Runtime
14
+
15
+ __version__ = RuntimeConfig().runtime_version
16
+
17
+ __all__ = (
18
+ "Runtime",
19
+ "RuntimeConfig",
20
+ "__version__",
21
+ )
@@ -0,0 +1,17 @@
1
+ """
2
+ MCP Adapter.
3
+
4
+ Public Runtime interface for Model Context Protocol support.
5
+ """
6
+
7
+ from .adapter import MCPAdapter
8
+ from .handlers import MCPHandler
9
+ from .tool_registry import ToolRegistry
10
+ from .serializers import MCPSerializer
11
+
12
+ __all__ = [
13
+ "MCPAdapter",
14
+ "MCPHandler",
15
+ "MCPToolRegistry",
16
+ "MCPSerializer",
17
+ ]
@@ -0,0 +1,68 @@
1
+ """
2
+ Runtime MCP Adapter.
3
+
4
+ Bridges the Model Context Protocol (MCP)
5
+ and the Runtime public API.
6
+
7
+ The adapter owns only transport translation.
8
+
9
+ Semantic behaviour belongs to Runtime and
10
+ CKS Core plugins.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from typing import Any
16
+
17
+ from cks_runtime.runtime import Runtime
18
+
19
+ from .tool_registry import ToolRegistry
20
+
21
+
22
+ class MCPAdapter:
23
+ """
24
+ Runtime MCP adapter.
25
+
26
+ Responsible only for translating
27
+ MCP requests into Runtime API calls.
28
+ """
29
+
30
+ def __init__(
31
+ self,
32
+ runtime: Runtime,
33
+ ) -> None:
34
+
35
+ self._runtime = runtime
36
+
37
+ self._tools = ToolRegistry()
38
+
39
+ #
40
+ # Public API
41
+ #
42
+
43
+ def list_tools(
44
+ self,
45
+ ) -> list[dict[str, Any]]:
46
+ """
47
+ Return MCP tool descriptions.
48
+ """
49
+
50
+ return self._tools.list()
51
+
52
+ def call_tool(
53
+ self,
54
+ name: str,
55
+ arguments: dict[str, Any],
56
+ ) -> Any:
57
+ """
58
+ Execute an MCP tool.
59
+ """
60
+
61
+ handler = self._tools.resolve(
62
+ name,
63
+ )
64
+
65
+ return handler(
66
+ runtime=self._runtime,
67
+ arguments=arguments,
68
+ )
@@ -0,0 +1,256 @@
1
+ """
2
+ MCP Contracts.
3
+
4
+ Canonical Runtime representation of JSON-RPC / MCP messages.
5
+
6
+ The Runtime never manipulates raw JSON dictionaries directly.
7
+
8
+ Transport layers convert JSON <-> contract objects.
9
+
10
+ The Adapter operates exclusively on these contracts.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from dataclasses import dataclass, field
16
+ from typing import Any
17
+
18
+
19
+ #
20
+ # ----------------------------------------------------------------------
21
+ # Base
22
+ # ----------------------------------------------------------------------
23
+ #
24
+
25
+
26
+ JSONRPC_VERSION = "2.0"
27
+
28
+
29
+ RequestId = str | int
30
+
31
+
32
+ #
33
+ # ----------------------------------------------------------------------
34
+ # Requests
35
+ # ----------------------------------------------------------------------
36
+ #
37
+
38
+
39
+ @dataclass(frozen=True, slots=True)
40
+ class MCPRequest:
41
+ """
42
+ JSON-RPC request.
43
+
44
+ Represents a tool invocation coming from an MCP client.
45
+ """
46
+
47
+ id: RequestId
48
+
49
+ method: str
50
+
51
+ params: dict[str, Any] = field(
52
+ default_factory=dict,
53
+ )
54
+
55
+ jsonrpc: str = JSONRPC_VERSION
56
+
57
+
58
+ #
59
+ # ----------------------------------------------------------------------
60
+ # Notifications
61
+ # ----------------------------------------------------------------------
62
+ #
63
+
64
+
65
+ @dataclass(frozen=True, slots=True)
66
+ class MCPNotification:
67
+ """
68
+ JSON-RPC notification.
69
+
70
+ Notifications never expect a response.
71
+ """
72
+
73
+ method: str
74
+
75
+ params: dict[str, Any] = field(
76
+ default_factory=dict,
77
+ )
78
+
79
+ jsonrpc: str = JSONRPC_VERSION
80
+
81
+
82
+ #
83
+ # ----------------------------------------------------------------------
84
+ # Responses
85
+ # ----------------------------------------------------------------------
86
+ #
87
+
88
+
89
+ @dataclass(frozen=True, slots=True)
90
+ class MCPResponse:
91
+ """
92
+ Successful JSON-RPC response.
93
+ """
94
+
95
+ id: RequestId
96
+
97
+ result: dict[str, Any] = field(
98
+ default_factory=dict,
99
+ )
100
+
101
+ jsonrpc: str = JSONRPC_VERSION
102
+
103
+
104
+ #
105
+ # ----------------------------------------------------------------------
106
+ # Error Responses
107
+ # ----------------------------------------------------------------------
108
+ #
109
+
110
+
111
+ @dataclass(frozen=True, slots=True)
112
+ class MCPErrorResponse:
113
+ """
114
+ JSON-RPC error response.
115
+ """
116
+
117
+ id: RequestId | None
118
+
119
+ error: dict[str, Any]
120
+
121
+ jsonrpc: str = JSONRPC_VERSION
122
+
123
+
124
+ #
125
+ # ----------------------------------------------------------------------
126
+ # Tool Contracts
127
+ # ----------------------------------------------------------------------
128
+ #
129
+
130
+
131
+ @dataclass(frozen=True, slots=True)
132
+ class MCPToolCall:
133
+ """
134
+ Runtime representation of a tool invocation.
135
+ """
136
+
137
+ tool: str
138
+
139
+ arguments: dict[str, Any] = field(
140
+ default_factory=dict,
141
+ )
142
+
143
+
144
+ @dataclass(frozen=True, slots=True)
145
+ class MCPToolResult:
146
+ """
147
+ Result produced by a Runtime tool.
148
+ """
149
+
150
+ content: Any
151
+
152
+ is_error: bool = False
153
+
154
+
155
+ #
156
+ # ----------------------------------------------------------------------
157
+ # Lifecycle
158
+ # ----------------------------------------------------------------------
159
+ #
160
+
161
+
162
+ @dataclass(frozen=True, slots=True)
163
+ class MCPInitializeRequest:
164
+ """
165
+ MCP initialize request.
166
+ """
167
+
168
+ protocol_version: str
169
+
170
+ client_info: dict[str, Any]
171
+
172
+ capabilities: dict[str, Any] = field(
173
+ default_factory=dict,
174
+ )
175
+
176
+
177
+ @dataclass(frozen=True, slots=True)
178
+ class MCPInitializeResponse:
179
+ """
180
+ MCP initialize response.
181
+ """
182
+
183
+ protocol_version: str
184
+
185
+ server_info: dict[str, Any]
186
+
187
+ capabilities: dict[str, Any] = field(
188
+ default_factory=dict,
189
+ )
190
+
191
+
192
+ #
193
+ # ----------------------------------------------------------------------
194
+ # Capabilities
195
+ # ----------------------------------------------------------------------
196
+ #
197
+
198
+
199
+ @dataclass(frozen=True, slots=True)
200
+ class MCPServerCapabilities:
201
+ """
202
+ Runtime capabilities exposed through MCP.
203
+ """
204
+
205
+ tools: bool = True
206
+
207
+ resources: bool = False
208
+
209
+ prompts: bool = False
210
+
211
+ logging: bool = False
212
+
213
+ completion: bool = False
214
+
215
+ sampling: bool = False
216
+
217
+ roots: bool = False
218
+
219
+ experimental: dict[str, Any] = field(
220
+ default_factory=dict,
221
+ )
222
+
223
+ def as_dict(self) -> dict[str, Any]:
224
+ """
225
+ Convert capabilities into MCP payload.
226
+ """
227
+
228
+ payload: dict[str, Any] = {}
229
+
230
+ if self.tools:
231
+ payload["tools"] = {}
232
+
233
+ if self.resources:
234
+ payload["resources"] = {}
235
+
236
+ if self.prompts:
237
+ payload["prompts"] = {}
238
+
239
+ if self.logging:
240
+ payload["logging"] = {}
241
+
242
+ if self.completion:
243
+ payload["completion"] = {}
244
+
245
+ if self.sampling:
246
+ payload["sampling"] = {}
247
+
248
+ if self.roots:
249
+ payload["roots"] = {}
250
+
251
+ if self.experimental:
252
+ payload["experimental"] = dict(
253
+ self.experimental,
254
+ )
255
+
256
+ return payload