cks-runtime 0.2.0__tar.gz → 0.4.1__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 (76) hide show
  1. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/PKG-INFO +28 -16
  2. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/README.md +27 -15
  3. cks_runtime-0.4.1/cks_runtime/__init__.py +21 -0
  4. cks_runtime-0.4.1/cks_runtime/adapters/mcp/__init__.py +17 -0
  5. cks_runtime-0.4.1/cks_runtime/adapters/mcp/adapter.py +68 -0
  6. cks_runtime-0.4.1/cks_runtime/adapters/mcp/contracts.py +256 -0
  7. cks_runtime-0.4.1/cks_runtime/adapters/mcp/errors.py +164 -0
  8. cks_runtime-0.4.1/cks_runtime/adapters/mcp/handlers.py +144 -0
  9. cks_runtime-0.4.1/cks_runtime/adapters/mcp/serializers.py +140 -0
  10. cks_runtime-0.4.1/cks_runtime/adapters/mcp/tool_registry.py +261 -0
  11. cks_runtime-0.4.1/cks_runtime/config.py +51 -0
  12. cks_runtime-0.4.1/cks_runtime/core_api/__init__.py +21 -0
  13. cks_runtime-0.4.1/cks_runtime/core_api/bridge.py +151 -0
  14. cks_runtime-0.4.1/cks_runtime/core_api/interfaces.py +127 -0
  15. cks_runtime-0.4.1/cks_runtime/core_api/validation_result.py +42 -0
  16. cks_runtime-0.4.1/cks_runtime/diagnostics/aggregator.py +148 -0
  17. cks_runtime-0.4.1/cks_runtime/diagnostics/diagnostic.py +139 -0
  18. cks_runtime-0.4.1/cks_runtime/dispatcher/dispatcher.py +135 -0
  19. cks_runtime-0.4.1/cks_runtime/events/event_bus.py +207 -0
  20. cks_runtime-0.4.1/cks_runtime/events/runtime_event.py +135 -0
  21. cks_runtime-0.4.1/cks_runtime/execution/execution_context.py +62 -0
  22. cks_runtime-0.4.1/cks_runtime/execution/operation_executor.py +214 -0
  23. cks_runtime-0.4.1/cks_runtime/operations/operation_registry.py +172 -0
  24. cks_runtime-0.4.1/cks_runtime/operations/operation_types.py +125 -0
  25. cks_runtime-0.4.1/cks_runtime/pipeline/execution_pipeline.py +208 -0
  26. cks_runtime-0.4.1/cks_runtime/runtime.py +391 -0
  27. cks_runtime-0.4.1/cks_runtime/session/session.py +51 -0
  28. cks_runtime-0.4.1/cks_runtime/session/session_manager.py +154 -0
  29. cks_runtime-0.4.1/cks_runtime/storage/memory_storage.py +177 -0
  30. cks_runtime-0.4.1/cks_runtime/storage/storage.py +132 -0
  31. cks_runtime-0.4.1/cks_runtime/transaction/transaction.py +89 -0
  32. cks_runtime-0.4.1/cks_runtime/transaction/transaction_manager.py +195 -0
  33. cks_runtime-0.4.1/cks_runtime/versioning/version.py +110 -0
  34. cks_runtime-0.4.1/cks_runtime/versioning/version_manager.py +155 -0
  35. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime.egg-info/PKG-INFO +28 -16
  36. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime.egg-info/SOURCES.txt +19 -5
  37. cks_runtime-0.4.1/cks_runtime.egg-info/top_level.txt +2 -0
  38. cks_runtime-0.4.1/cks_runtime_plugins/__init__.py +0 -0
  39. {cks_runtime-0.2.0/cks_runtime_core → cks_runtime-0.4.1/cks_runtime_plugins/cks_core}/__init__.py +3 -1
  40. cks_runtime-0.4.1/cks_runtime_plugins/cks_core/adapter.py +110 -0
  41. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/pyproject.toml +16 -3
  42. cks_runtime-0.2.0/cks_runtime/__init__.py +0 -11
  43. cks_runtime-0.2.0/cks_runtime/config.py +0 -26
  44. cks_runtime-0.2.0/cks_runtime/core_api/adapter.py +0 -154
  45. cks_runtime-0.2.0/cks_runtime/core_api/interfaces.py +0 -85
  46. cks_runtime-0.2.0/cks_runtime/core_api/validation_result.py +0 -53
  47. cks_runtime-0.2.0/cks_runtime/diagnostics/aggregator.py +0 -133
  48. cks_runtime-0.2.0/cks_runtime/diagnostics/diagnostic.py +0 -84
  49. cks_runtime-0.2.0/cks_runtime/pipeline/execution_pipeline.py +0 -176
  50. cks_runtime-0.2.0/cks_runtime/runtime.py +0 -229
  51. cks_runtime-0.2.0/cks_runtime/session/session.py +0 -76
  52. cks_runtime-0.2.0/cks_runtime/session/session_manager.py +0 -112
  53. cks_runtime-0.2.0/cks_runtime/storage/exceptions.py +0 -37
  54. cks_runtime-0.2.0/cks_runtime/storage/memory_storage.py +0 -127
  55. cks_runtime-0.2.0/cks_runtime/storage/storage.py +0 -90
  56. cks_runtime-0.2.0/cks_runtime/transaction/transaction.py +0 -120
  57. cks_runtime-0.2.0/cks_runtime/transaction/transaction_manager.py +0 -110
  58. cks_runtime-0.2.0/cks_runtime/versioning/version.py +0 -73
  59. cks_runtime-0.2.0/cks_runtime/versioning/version_manager.py +0 -103
  60. cks_runtime-0.2.0/cks_runtime.egg-info/top_level.txt +0 -2
  61. cks_runtime-0.2.0/cks_runtime_core/adapter.py +0 -78
  62. cks_runtime-0.2.0/tests/test_core_adapter.py +0 -69
  63. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/LICENSE +0 -0
  64. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime/adapters/__init__.py +0 -0
  65. {cks_runtime-0.2.0/cks_runtime/core_api → cks_runtime-0.4.1/cks_runtime/diagnostics}/__init__.py +0 -0
  66. {cks_runtime-0.2.0/cks_runtime/diagnostics → cks_runtime-0.4.1/cks_runtime/execution}/__init__.py +0 -0
  67. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime/explainability/__init__.py +0 -0
  68. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime/explainability/explainability_manager.py +0 -0
  69. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime/pipeline/__init__.py +0 -0
  70. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime/session/__init__.py +0 -0
  71. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime/storage/__init__.py +0 -0
  72. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime/transaction/__init__.py +0 -0
  73. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime/versioning/__init__.py +0 -0
  74. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime.egg-info/dependency_links.txt +0 -0
  75. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/cks_runtime.egg-info/requires.txt +0 -0
  76. {cks_runtime-0.2.0 → cks_runtime-0.4.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cks-runtime
3
- Version: 0.2.0
3
+ Version: 0.4.1
4
4
  Summary: Canonical Runtime for the Canonical Knowledge Structure ecosystem
5
5
  Author: Vladyslav Hruznov
6
6
  License: MIT
@@ -29,7 +29,7 @@ Dynamic: license-file
29
29
 
30
30
  ![Python](https://img.shields.io/badge/python-3.11%2B-blue)
31
31
  ![License](https://img.shields.io/badge/license-MIT-green)
32
- ![Tests](https://img.shields.io/badge/tests-89%20passing-brightgreen)
32
+ ![Tests](https://img.shields.io/badge/tests-147%20passing-brightgreen)
33
33
  ![Status](https://img.shields.io/badge/status-beta-blue)
34
34
 
35
35
  CKS Runtime is the canonical execution environment for
@@ -51,7 +51,7 @@ Canonical Knowledge Structure.
51
51
 
52
52
  | Project | Description | Repository |
53
53
  |---------|-------------|------------|
54
- | **cks-core** | Semantic engine – the single source of canonical truth. | [Deus-corp/CKS](https://github.com/Deus-corp/CKS) |
54
+ | **cks-core** | Semantic engine – the single source of canonical truth. | [Deus-corp/cks-core](https://github.com/Deus-corp/cks-core) |
55
55
  | **cks-runtime** | Operational environment – sessions, transactions, persistence. | [Deus-corp/cks-runtime](https://github.com/Deus-corp/cks-runtime) |
56
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
57
 
@@ -184,7 +184,10 @@ The current Reference Runtime provides:
184
184
  - Canonical Runtime API
185
185
  - Reference Runtime Architecture
186
186
  - Runtime Conformance Model
187
- - **CKS Core Integration** (via `cks_runtime_core`)
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
188
191
 
189
192
  ---
190
193
 
@@ -249,16 +252,18 @@ pip install -e .
249
252
 
250
253
  ```python
251
254
  from cks_runtime import Runtime
252
- from cks_runtime_core import CksCoreAdapter
255
+ from cks_runtime_plugins.cks_core import CksCoreAdapter
256
+ from cks_runtime.operations.operation_types import ValidateOperation
253
257
 
254
- # Create Runtime with real CKS Core attached
258
+ # Create Runtime with real CKS Core
255
259
  runtime = Runtime(core=CksCoreAdapter())
256
260
 
257
- session = runtime.sessions.create(
258
- knowledge_structure=my_structure
259
- )
261
+ session = runtime.create_session({"example": True})
262
+ tx = runtime.begin_transaction(session)
263
+ tx.add_operation(ValidateOperation("v1", knowledge_structure=session.knowledge_structure))
260
264
 
261
- transaction = runtime.transactions.begin(session)
265
+ version = runtime.commit_transaction(tx)
266
+ print(version)
262
267
 
263
268
  # Runtime coordinates execution. CKS Core defines semantics.
264
269
  ```
@@ -289,9 +294,9 @@ Supporting documents include:
289
294
 
290
295
  ---
291
296
 
292
- # Project Status
297
+ ## Project Status
293
298
 
294
- Current implementation status:
299
+ Current implementation status (v0.4.0):
295
300
 
296
301
  | Component | Status |
297
302
  |----------|--------|
@@ -302,10 +307,17 @@ Current implementation status:
302
307
  | Diagnostics | ✅ Complete |
303
308
  | Storage Abstraction | ✅ Complete |
304
309
  | Runtime API | ✅ Complete |
305
- | Runtime Documentation | ✅ Complete |
306
- | Core Integration | ✅ Complete |
307
- | Reference Implementation | ✅ Complete |
308
- | Adapter Infrastructure | 🚧 In Progress |
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).
309
321
 
310
322
  ---
311
323
 
@@ -4,7 +4,7 @@
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
- ![Tests](https://img.shields.io/badge/tests-89%20passing-brightgreen)
7
+ ![Tests](https://img.shields.io/badge/tests-147%20passing-brightgreen)
8
8
  ![Status](https://img.shields.io/badge/status-beta-blue)
9
9
 
10
10
  CKS Runtime is the canonical execution environment for
@@ -26,7 +26,7 @@ Canonical Knowledge Structure.
26
26
 
27
27
  | Project | Description | Repository |
28
28
  |---------|-------------|------------|
29
- | **cks-core** | Semantic engine – the single source of canonical truth. | [Deus-corp/CKS](https://github.com/Deus-corp/CKS) |
29
+ | **cks-core** | Semantic engine – the single source of canonical truth. | [Deus-corp/cks-core](https://github.com/Deus-corp/cks-core) |
30
30
  | **cks-runtime** | Operational environment – sessions, transactions, persistence. | [Deus-corp/cks-runtime](https://github.com/Deus-corp/cks-runtime) |
31
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
32
 
@@ -159,7 +159,10 @@ The current Reference Runtime provides:
159
159
  - Canonical Runtime API
160
160
  - Reference Runtime Architecture
161
161
  - Runtime Conformance Model
162
- - **CKS Core Integration** (via `cks_runtime_core`)
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
163
166
 
164
167
  ---
165
168
 
@@ -224,16 +227,18 @@ pip install -e .
224
227
 
225
228
  ```python
226
229
  from cks_runtime import Runtime
227
- from cks_runtime_core import CksCoreAdapter
230
+ from cks_runtime_plugins.cks_core import CksCoreAdapter
231
+ from cks_runtime.operations.operation_types import ValidateOperation
228
232
 
229
- # Create Runtime with real CKS Core attached
233
+ # Create Runtime with real CKS Core
230
234
  runtime = Runtime(core=CksCoreAdapter())
231
235
 
232
- session = runtime.sessions.create(
233
- knowledge_structure=my_structure
234
- )
236
+ session = runtime.create_session({"example": True})
237
+ tx = runtime.begin_transaction(session)
238
+ tx.add_operation(ValidateOperation("v1", knowledge_structure=session.knowledge_structure))
235
239
 
236
- transaction = runtime.transactions.begin(session)
240
+ version = runtime.commit_transaction(tx)
241
+ print(version)
237
242
 
238
243
  # Runtime coordinates execution. CKS Core defines semantics.
239
244
  ```
@@ -264,9 +269,9 @@ Supporting documents include:
264
269
 
265
270
  ---
266
271
 
267
- # Project Status
272
+ ## Project Status
268
273
 
269
- Current implementation status:
274
+ Current implementation status (v0.4.0):
270
275
 
271
276
  | Component | Status |
272
277
  |----------|--------|
@@ -277,10 +282,17 @@ Current implementation status:
277
282
  | Diagnostics | ✅ Complete |
278
283
  | Storage Abstraction | ✅ Complete |
279
284
  | Runtime API | ✅ Complete |
280
- | Runtime Documentation | ✅ Complete |
281
- | Core Integration | ✅ Complete |
282
- | Reference Implementation | ✅ Complete |
283
- | Adapter Infrastructure | 🚧 In Progress |
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).
284
296
 
285
297
  ---
286
298
 
@@ -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
@@ -0,0 +1,164 @@
1
+ """
2
+ MCP Error Model.
3
+
4
+ Defines Runtime-side JSON-RPC / MCP errors.
5
+
6
+ This module contains no transport logic.
7
+
8
+ It only defines the canonical error objects used by
9
+ the MCP Adapter.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from dataclasses import dataclass
15
+ from enum import IntEnum
16
+ from typing import Any
17
+
18
+
19
+ class MCPErrorCode(IntEnum):
20
+ """
21
+ Standard JSON-RPC / MCP error codes.
22
+ """
23
+
24
+ #
25
+ # JSON parsing
26
+ #
27
+
28
+ PARSE_ERROR = -32700
29
+
30
+ #
31
+ # Request validation
32
+ #
33
+
34
+ INVALID_REQUEST = -32600
35
+
36
+ #
37
+ # Method dispatch
38
+ #
39
+
40
+ METHOD_NOT_FOUND = -32601
41
+
42
+ #
43
+ # Parameter validation
44
+ #
45
+
46
+ INVALID_PARAMS = -32602
47
+
48
+ #
49
+ # Internal execution
50
+ #
51
+
52
+ INTERNAL_ERROR = -32603
53
+
54
+ #
55
+ # Runtime-specific server errors.
56
+ #
57
+
58
+ SERVER_ERROR = -32000
59
+
60
+ RESOURCE_NOT_FOUND = -32002
61
+
62
+ REQUEST_TIMEOUT = -32001
63
+
64
+
65
+ @dataclass(frozen=True, slots=True)
66
+ class MCPError:
67
+ """
68
+ Runtime representation of a JSON-RPC error.
69
+ """
70
+
71
+ code: MCPErrorCode
72
+
73
+ message: str
74
+
75
+ data: Any | None = None
76
+
77
+ def as_dict(self) -> dict[str, Any]:
78
+ """
79
+ Serialize into JSON-RPC error object.
80
+ """
81
+
82
+ payload = {
83
+ "code": int(self.code),
84
+ "message": self.message,
85
+ }
86
+
87
+ if self.data is not None:
88
+ payload["data"] = self.data
89
+
90
+ return payload
91
+
92
+
93
+ #
94
+ # ------------------------------------------------------------------
95
+ # Convenience constructors
96
+ # ------------------------------------------------------------------
97
+ #
98
+
99
+ def parse_error() -> MCPError:
100
+
101
+ return MCPError(
102
+ MCPErrorCode.PARSE_ERROR,
103
+ "Parse error",
104
+ )
105
+
106
+
107
+ def invalid_request(
108
+ message: str = "Invalid request",
109
+ ) -> MCPError:
110
+
111
+ return MCPError(
112
+ MCPErrorCode.INVALID_REQUEST,
113
+ message,
114
+ )
115
+
116
+
117
+ def method_not_found(
118
+ method: str,
119
+ ) -> MCPError:
120
+
121
+ return MCPError(
122
+ MCPErrorCode.METHOD_NOT_FOUND,
123
+ f"Method '{method}' not found.",
124
+ )
125
+
126
+
127
+ def invalid_params(
128
+ message: str,
129
+ ) -> MCPError:
130
+
131
+ return MCPError(
132
+ MCPErrorCode.INVALID_PARAMS,
133
+ message,
134
+ )
135
+
136
+
137
+ def internal_error(
138
+ exc: Exception | str,
139
+ ) -> MCPError:
140
+
141
+ return MCPError(
142
+ MCPErrorCode.INTERNAL_ERROR,
143
+ str(exc),
144
+ )
145
+
146
+
147
+ def resource_not_found(
148
+ resource: str,
149
+ ) -> MCPError:
150
+
151
+ return MCPError(
152
+ MCPErrorCode.RESOURCE_NOT_FOUND,
153
+ f"Resource '{resource}' not found.",
154
+ )
155
+
156
+
157
+ def timeout(
158
+ operation: str,
159
+ ) -> MCPError:
160
+
161
+ return MCPError(
162
+ MCPErrorCode.REQUEST_TIMEOUT,
163
+ f"Operation '{operation}' timed out.",
164
+ )