@kya-os/mcp-i-core 1.2.3-canary.6 → 1.3.0

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 (231) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.turbo/turbo-test$colon$coverage.log +4514 -0
  4. package/.turbo/turbo-test.log +2973 -0
  5. package/COMPLIANCE_IMPROVEMENT_REPORT.md +483 -0
  6. package/Composer 3.md +615 -0
  7. package/GPT-5.md +1169 -0
  8. package/OPUS-plan.md +352 -0
  9. package/PHASE_3_AND_4.1_SUMMARY.md +585 -0
  10. package/PHASE_3_SUMMARY.md +317 -0
  11. package/PHASE_4.1.3_SUMMARY.md +428 -0
  12. package/PHASE_4.1_COMPLETE.md +525 -0
  13. package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +1240 -0
  14. package/SCHEMA_COMPLIANCE_REPORT.md +275 -0
  15. package/TEST_PLAN.md +571 -0
  16. package/coverage/coverage-final.json +57 -0
  17. package/dist/__tests__/utils/mock-providers.d.ts +1 -2
  18. package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
  19. package/dist/__tests__/utils/mock-providers.js.map +1 -1
  20. package/dist/cache/oauth-config-cache.d.ts +69 -0
  21. package/dist/cache/oauth-config-cache.d.ts.map +1 -0
  22. package/dist/cache/oauth-config-cache.js +76 -0
  23. package/dist/cache/oauth-config-cache.js.map +1 -0
  24. package/dist/identity/idp-token-resolver.d.ts +53 -0
  25. package/dist/identity/idp-token-resolver.d.ts.map +1 -0
  26. package/dist/identity/idp-token-resolver.js +108 -0
  27. package/dist/identity/idp-token-resolver.js.map +1 -0
  28. package/dist/identity/idp-token-storage.interface.d.ts +42 -0
  29. package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
  30. package/dist/identity/idp-token-storage.interface.js +12 -0
  31. package/dist/identity/idp-token-storage.interface.js.map +1 -0
  32. package/dist/identity/user-did-manager.d.ts +39 -1
  33. package/dist/identity/user-did-manager.d.ts.map +1 -1
  34. package/dist/identity/user-did-manager.js +69 -3
  35. package/dist/identity/user-did-manager.js.map +1 -1
  36. package/dist/index.d.ts +22 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +39 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/runtime/audit-logger.d.ts +37 -0
  41. package/dist/runtime/audit-logger.d.ts.map +1 -0
  42. package/dist/runtime/audit-logger.js +9 -0
  43. package/dist/runtime/audit-logger.js.map +1 -0
  44. package/dist/runtime/base.d.ts +58 -2
  45. package/dist/runtime/base.d.ts.map +1 -1
  46. package/dist/runtime/base.js +266 -11
  47. package/dist/runtime/base.js.map +1 -1
  48. package/dist/services/access-control.service.d.ts.map +1 -1
  49. package/dist/services/access-control.service.js +200 -35
  50. package/dist/services/access-control.service.js.map +1 -1
  51. package/dist/services/authorization/authorization-registry.d.ts +29 -0
  52. package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
  53. package/dist/services/authorization/authorization-registry.js +57 -0
  54. package/dist/services/authorization/authorization-registry.js.map +1 -0
  55. package/dist/services/authorization/types.d.ts +53 -0
  56. package/dist/services/authorization/types.d.ts.map +1 -0
  57. package/dist/services/authorization/types.js +10 -0
  58. package/dist/services/authorization/types.js.map +1 -0
  59. package/dist/services/batch-delegation.service.d.ts +53 -0
  60. package/dist/services/batch-delegation.service.d.ts.map +1 -0
  61. package/dist/services/batch-delegation.service.js +95 -0
  62. package/dist/services/batch-delegation.service.js.map +1 -0
  63. package/dist/services/oauth-config.service.d.ts +53 -0
  64. package/dist/services/oauth-config.service.d.ts.map +1 -0
  65. package/dist/services/oauth-config.service.js +117 -0
  66. package/dist/services/oauth-config.service.js.map +1 -0
  67. package/dist/services/oauth-provider-registry.d.ts +77 -0
  68. package/dist/services/oauth-provider-registry.d.ts.map +1 -0
  69. package/dist/services/oauth-provider-registry.js +112 -0
  70. package/dist/services/oauth-provider-registry.js.map +1 -0
  71. package/dist/services/oauth-service.d.ts +77 -0
  72. package/dist/services/oauth-service.d.ts.map +1 -0
  73. package/dist/services/oauth-service.js +348 -0
  74. package/dist/services/oauth-service.js.map +1 -0
  75. package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
  76. package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
  77. package/dist/services/oauth-token-retrieval.service.js +150 -0
  78. package/dist/services/oauth-token-retrieval.service.js.map +1 -0
  79. package/dist/services/provider-resolver.d.ts +48 -0
  80. package/dist/services/provider-resolver.d.ts.map +1 -0
  81. package/dist/services/provider-resolver.js +120 -0
  82. package/dist/services/provider-resolver.js.map +1 -0
  83. package/dist/services/provider-validator.d.ts +55 -0
  84. package/dist/services/provider-validator.d.ts.map +1 -0
  85. package/dist/services/provider-validator.js +135 -0
  86. package/dist/services/provider-validator.js.map +1 -0
  87. package/dist/services/tool-context-builder.d.ts +57 -0
  88. package/dist/services/tool-context-builder.d.ts.map +1 -0
  89. package/dist/services/tool-context-builder.js +125 -0
  90. package/dist/services/tool-context-builder.js.map +1 -0
  91. package/dist/services/tool-protection.service.d.ts +87 -10
  92. package/dist/services/tool-protection.service.d.ts.map +1 -1
  93. package/dist/services/tool-protection.service.js +282 -112
  94. package/dist/services/tool-protection.service.js.map +1 -1
  95. package/dist/types/oauth-required-error.d.ts +40 -0
  96. package/dist/types/oauth-required-error.d.ts.map +1 -0
  97. package/dist/types/oauth-required-error.js +40 -0
  98. package/dist/types/oauth-required-error.js.map +1 -0
  99. package/dist/utils/did-helpers.d.ts +33 -0
  100. package/dist/utils/did-helpers.d.ts.map +1 -1
  101. package/dist/utils/did-helpers.js +40 -0
  102. package/dist/utils/did-helpers.js.map +1 -1
  103. package/dist/utils/index.d.ts +1 -0
  104. package/dist/utils/index.d.ts.map +1 -1
  105. package/dist/utils/index.js +1 -0
  106. package/dist/utils/index.js.map +1 -1
  107. package/docs/API_REFERENCE.md +1362 -0
  108. package/docs/COMPLIANCE_MATRIX.md +691 -0
  109. package/docs/STATUSLIST2021_GUIDE.md +696 -0
  110. package/docs/W3C_VC_DELEGATION_GUIDE.md +710 -0
  111. package/package.json +24 -50
  112. package/scripts/audit-compliance.ts +724 -0
  113. package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
  114. package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
  115. package/src/__tests__/delegation-e2e.test.ts +690 -0
  116. package/src/__tests__/identity/user-did-manager.test.ts +213 -0
  117. package/src/__tests__/index.test.ts +56 -0
  118. package/src/__tests__/integration/full-flow.test.ts +776 -0
  119. package/src/__tests__/integration.test.ts +281 -0
  120. package/src/__tests__/providers/base.test.ts +173 -0
  121. package/src/__tests__/providers/memory.test.ts +319 -0
  122. package/src/__tests__/regression/phase2-regression.test.ts +427 -0
  123. package/src/__tests__/runtime/audit-logger.test.ts +154 -0
  124. package/src/__tests__/runtime/base-extensions.test.ts +593 -0
  125. package/src/__tests__/runtime/base.test.ts +869 -0
  126. package/src/__tests__/runtime/delegation-flow.test.ts +164 -0
  127. package/src/__tests__/runtime/proof-client-did.test.ts +375 -0
  128. package/src/__tests__/runtime/route-interception.test.ts +686 -0
  129. package/src/__tests__/runtime/tool-protection-enforcement.test.ts +908 -0
  130. package/src/__tests__/services/agentshield-integration.test.ts +784 -0
  131. package/src/__tests__/services/provider-resolver-edge-cases.test.ts +487 -0
  132. package/src/__tests__/services/tool-protection-oauth-provider.test.ts +480 -0
  133. package/src/__tests__/services/tool-protection.service.test.ts +1366 -0
  134. package/src/__tests__/utils/mock-providers.ts +340 -0
  135. package/src/cache/oauth-config-cache.d.ts +69 -0
  136. package/src/cache/oauth-config-cache.d.ts.map +1 -0
  137. package/src/cache/oauth-config-cache.js +71 -0
  138. package/src/cache/oauth-config-cache.js.map +1 -0
  139. package/src/cache/oauth-config-cache.ts +123 -0
  140. package/src/cache/tool-protection-cache.ts +171 -0
  141. package/src/compliance/EXAMPLE.md +412 -0
  142. package/src/compliance/__tests__/schema-verifier.test.ts +797 -0
  143. package/src/compliance/index.ts +8 -0
  144. package/src/compliance/schema-registry.ts +460 -0
  145. package/src/compliance/schema-verifier.ts +708 -0
  146. package/src/config/__tests__/remote-config.spec.ts +268 -0
  147. package/src/config/remote-config.ts +174 -0
  148. package/src/config.ts +309 -0
  149. package/src/delegation/__tests__/audience-validator.test.ts +112 -0
  150. package/src/delegation/__tests__/bitstring.test.ts +346 -0
  151. package/src/delegation/__tests__/cascading-revocation.test.ts +628 -0
  152. package/src/delegation/__tests__/delegation-graph.test.ts +584 -0
  153. package/src/delegation/__tests__/utils.test.ts +152 -0
  154. package/src/delegation/__tests__/vc-issuer.test.ts +442 -0
  155. package/src/delegation/__tests__/vc-verifier.test.ts +922 -0
  156. package/src/delegation/audience-validator.ts +52 -0
  157. package/src/delegation/bitstring.ts +278 -0
  158. package/src/delegation/cascading-revocation.ts +370 -0
  159. package/src/delegation/delegation-graph.ts +299 -0
  160. package/src/delegation/index.ts +14 -0
  161. package/src/delegation/statuslist-manager.ts +353 -0
  162. package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +366 -0
  163. package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +228 -0
  164. package/src/delegation/storage/index.ts +9 -0
  165. package/src/delegation/storage/memory-graph-storage.ts +178 -0
  166. package/src/delegation/storage/memory-statuslist-storage.ts +77 -0
  167. package/src/delegation/utils.ts +42 -0
  168. package/src/delegation/vc-issuer.ts +232 -0
  169. package/src/delegation/vc-verifier.ts +568 -0
  170. package/src/identity/idp-token-resolver.ts +147 -0
  171. package/src/identity/idp-token-storage.interface.ts +59 -0
  172. package/src/identity/user-did-manager.ts +370 -0
  173. package/src/index.ts +260 -0
  174. package/src/providers/base.d.ts +91 -0
  175. package/src/providers/base.d.ts.map +1 -0
  176. package/src/providers/base.js +38 -0
  177. package/src/providers/base.js.map +1 -0
  178. package/src/providers/base.ts +96 -0
  179. package/src/providers/memory.ts +142 -0
  180. package/src/runtime/audit-logger.ts +39 -0
  181. package/src/runtime/base.ts +1329 -0
  182. package/src/services/__tests__/access-control.integration.test.ts +443 -0
  183. package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
  184. package/src/services/__tests__/access-control.service.test.ts +970 -0
  185. package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
  186. package/src/services/__tests__/crypto.service.test.ts +531 -0
  187. package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
  188. package/src/services/__tests__/proof-verifier.integration.test.ts +485 -0
  189. package/src/services/__tests__/proof-verifier.test.ts +489 -0
  190. package/src/services/__tests__/provider-resolution.integration.test.ts +198 -0
  191. package/src/services/__tests__/provider-resolver.test.ts +217 -0
  192. package/src/services/__tests__/storage.service.test.ts +358 -0
  193. package/src/services/access-control.service.ts +990 -0
  194. package/src/services/authorization/authorization-registry.ts +66 -0
  195. package/src/services/authorization/types.ts +71 -0
  196. package/src/services/batch-delegation.service.ts +137 -0
  197. package/src/services/crypto.service.ts +302 -0
  198. package/src/services/errors.ts +76 -0
  199. package/src/services/index.ts +9 -0
  200. package/src/services/oauth-config.service.d.ts +53 -0
  201. package/src/services/oauth-config.service.d.ts.map +1 -0
  202. package/src/services/oauth-config.service.js +113 -0
  203. package/src/services/oauth-config.service.js.map +1 -0
  204. package/src/services/oauth-config.service.ts +166 -0
  205. package/src/services/oauth-provider-registry.d.ts +57 -0
  206. package/src/services/oauth-provider-registry.d.ts.map +1 -0
  207. package/src/services/oauth-provider-registry.js +73 -0
  208. package/src/services/oauth-provider-registry.js.map +1 -0
  209. package/src/services/oauth-provider-registry.ts +123 -0
  210. package/src/services/oauth-service.ts +510 -0
  211. package/src/services/oauth-token-retrieval.service.ts +245 -0
  212. package/src/services/proof-verifier.ts +478 -0
  213. package/src/services/provider-resolver.d.ts +48 -0
  214. package/src/services/provider-resolver.d.ts.map +1 -0
  215. package/src/services/provider-resolver.js +106 -0
  216. package/src/services/provider-resolver.js.map +1 -0
  217. package/src/services/provider-resolver.ts +144 -0
  218. package/src/services/provider-validator.ts +170 -0
  219. package/src/services/storage.service.ts +566 -0
  220. package/src/services/tool-context-builder.ts +172 -0
  221. package/src/services/tool-protection.service.ts +958 -0
  222. package/src/types/oauth-required-error.ts +63 -0
  223. package/src/types/tool-protection.ts +155 -0
  224. package/src/utils/__tests__/did-helpers.test.ts +101 -0
  225. package/src/utils/base64.ts +148 -0
  226. package/src/utils/cors.ts +83 -0
  227. package/src/utils/did-helpers.ts +150 -0
  228. package/src/utils/index.ts +8 -0
  229. package/src/utils/storage-keys.ts +278 -0
  230. package/tsconfig.json +21 -0
  231. package/vitest.config.ts +56 -0
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Platform-agnostic cache interface for tool protection configurations
3
+ *
4
+ * This interface allows different runtime adapters to provide their own
5
+ * caching implementations (e.g., in-memory for Node.js, KV for CloudFlare)
6
+ *
7
+ * @package @kya-os/mcp-i-core
8
+ */
9
+
10
+ import type { ToolProtectionConfig } from '../types/tool-protection.js';
11
+
12
+ /**
13
+ * Cache interface for storing and retrieving tool protection configurations
14
+ */
15
+ export interface ToolProtectionCache {
16
+ /**
17
+ * Retrieve a cached tool protection configuration
18
+ * @param key Cache key (typically projectId)
19
+ * @returns Cached config or null if not found/expired
20
+ */
21
+ get(key: string): Promise<ToolProtectionConfig | null>;
22
+
23
+ /**
24
+ * Store a tool protection configuration in cache
25
+ * @param key Cache key (typically projectId)
26
+ * @param value Tool protection configuration to cache
27
+ * @param ttl Time-to-live in milliseconds
28
+ */
29
+ set(key: string, value: ToolProtectionConfig, ttl: number): Promise<void>;
30
+
31
+ /**
32
+ * Clear all cached entries
33
+ */
34
+ clear(): Promise<void>;
35
+
36
+ /**
37
+ * Remove a specific cache entry
38
+ * @param key Cache key to remove
39
+ */
40
+ delete(key: string): Promise<void>;
41
+ }
42
+
43
+ /**
44
+ * In-memory cache implementation
45
+ *
46
+ * Suitable for:
47
+ * - Node.js runtimes
48
+ * - Development/testing
49
+ * - Single-instance deployments
50
+ *
51
+ * NOT suitable for:
52
+ * - Multi-instance deployments (cache not shared)
53
+ * - Serverless environments (state not persisted)
54
+ */
55
+ export class InMemoryToolProtectionCache implements ToolProtectionCache {
56
+ private cache = new Map<
57
+ string,
58
+ { value: ToolProtectionConfig; expiresAt: number }
59
+ >();
60
+
61
+ async get(key: string): Promise<ToolProtectionConfig | null> {
62
+ const entry = this.cache.get(key);
63
+
64
+ if (!entry) {
65
+ return null;
66
+ }
67
+
68
+ // Check if expired
69
+ if (Date.now() > entry.expiresAt) {
70
+ this.cache.delete(key);
71
+ return null;
72
+ }
73
+
74
+ return entry.value;
75
+ }
76
+
77
+ async set(
78
+ key: string,
79
+ value: ToolProtectionConfig,
80
+ ttl: number
81
+ ): Promise<void> {
82
+ // If TTL is <= 0, don't store (entry would be immediately expired)
83
+ if (ttl <= 0) {
84
+ return;
85
+ }
86
+ const expiresAt = Date.now() + ttl;
87
+ this.cache.set(key, { value, expiresAt });
88
+ }
89
+
90
+ async clear(): Promise<void> {
91
+ this.cache.clear();
92
+ }
93
+
94
+ async delete(key: string): Promise<void> {
95
+ this.cache.delete(key);
96
+ }
97
+
98
+ /**
99
+ * Clean up expired entries (call periodically)
100
+ */
101
+ cleanup(): void {
102
+ const now = Date.now();
103
+ for (const [key, entry] of this.cache.entries()) {
104
+ if (now > entry.expiresAt) {
105
+ this.cache.delete(key);
106
+ }
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Get stale cache entry (including expired entries)
112
+ * Used for fail-safe behavior when API is unavailable
113
+ * This method accesses the internal cache map directly to avoid
114
+ * deletion of expired entries that would occur with get()
115
+ * @param key Cache key
116
+ * @returns Cached config or null if not found
117
+ */
118
+ getStale(key: string): ToolProtectionConfig | null {
119
+ // Access internal cache map directly (not through async get() which deletes expired entries)
120
+ const entry = this.cache.get(key);
121
+ if (!entry) {
122
+ return null;
123
+ }
124
+ // Return value even if expired (getStale is meant for fail-safe behavior)
125
+ return entry.value;
126
+ }
127
+
128
+ /**
129
+ * Get expiration timestamp for a cache entry
130
+ * Used to check if stale cache is within maxStaleCacheAge
131
+ * @param key Cache key
132
+ * @returns Expiration timestamp in milliseconds, or null if not found
133
+ */
134
+ getExpiresAt(key: string): number | null {
135
+ // Access internal cache map directly (not through async get() which deletes expired entries)
136
+ const entry = this.cache.get(key);
137
+ if (!entry) {
138
+ return null;
139
+ }
140
+ return entry.expiresAt;
141
+ }
142
+ }
143
+
144
+ /**
145
+ * No-op cache implementation (disables caching)
146
+ *
147
+ * Use when:
148
+ * - You want to disable caching entirely
149
+ * - Testing scenarios that require fresh data
150
+ */
151
+ export class NoOpToolProtectionCache implements ToolProtectionCache {
152
+ async get(_key: string): Promise<ToolProtectionConfig | null> {
153
+ return null;
154
+ }
155
+
156
+ async set(
157
+ _key: string,
158
+ _value: ToolProtectionConfig,
159
+ _ttl: number
160
+ ): Promise<void> {
161
+ // No-op
162
+ }
163
+
164
+ async clear(): Promise<void> {
165
+ // No-op
166
+ }
167
+
168
+ async delete(_key: string): Promise<void> {
169
+ // No-op
170
+ }
171
+ }
@@ -0,0 +1,412 @@
1
+ # Schema Compliance Verification - Usage Examples
2
+
3
+ ## Overview
4
+
5
+ Automated verification tool to ensure 100% compliance with canonical schemas from `schemas.kya-os.ai`.
6
+
7
+ ---
8
+
9
+ ## Quick Start
10
+
11
+ ```typescript
12
+ import {
13
+ createSchemaVerifier,
14
+ getAllSchemas,
15
+ getCriticalSchemas,
16
+ getSchemasByCategory,
17
+ } from '@kya-os/mcp-i-core';
18
+
19
+ // Create verifier
20
+ const verifier = createSchemaVerifier({
21
+ schemasBaseUrl: 'https://schemas.kya-os.ai',
22
+ });
23
+
24
+ // Get all schemas
25
+ const allSchemas = getAllSchemas();
26
+ console.log(`Total schemas: ${allSchemas.length}`); // 41
27
+
28
+ // Get critical schemas (must be 100% compliant)
29
+ const criticalSchemas = getCriticalSchemas();
30
+ console.log(`Critical schemas: ${criticalSchemas.length}`); // 7
31
+ ```
32
+
33
+ ---
34
+
35
+ ## Verify Single Schema
36
+
37
+ ```typescript
38
+ import { createSchemaVerifier, getSchemaById } from '@kya-os/mcp-i-core';
39
+ import { DelegationCredential } from '@kya-os/contracts';
40
+
41
+ // Get the delegation credential schema
42
+ const schema = getSchemaById('delegation-credential')!;
43
+
44
+ // Create a sample delegation credential
45
+ const delegationVC: DelegationCredential = {
46
+ '@context': [
47
+ 'https://www.w3.org/2018/credentials/v1',
48
+ 'https://mcp-i.org/contexts/delegation/v1',
49
+ ],
50
+ id: 'urn:uuid:123',
51
+ type: ['VerifiableCredential', 'DelegationCredential'],
52
+ issuer: 'did:key:z6Mkf...',
53
+ issuanceDate: '2025-10-17T00:00:00Z',
54
+ credentialSubject: {
55
+ id: 'did:key:z6Mkf...',
56
+ delegation: {
57
+ id: 'delegation-123',
58
+ issuerDid: 'did:key:z6Mkf...',
59
+ subjectDid: 'did:key:z6Mkf...',
60
+ // ... rest of delegation
61
+ },
62
+ },
63
+ proof: {
64
+ type: 'Ed25519Signature2020',
65
+ created: '2025-10-17T00:00:00Z',
66
+ verificationMethod: 'did:key:z6Mkf...#keys-1',
67
+ proofPurpose: 'assertionMethod',
68
+ proofValue: 'z58DAdF...',
69
+ },
70
+ };
71
+
72
+ // Verify compliance
73
+ const verifier = createSchemaVerifier();
74
+ const report = await verifier.verifySchema(schema, delegationVC);
75
+
76
+ // Check results
77
+ console.log(verifier.generateReport(report));
78
+
79
+ if (report.compliant) {
80
+ console.log('✅ 100% Compliant!');
81
+ } else {
82
+ console.log('❌ Issues found:');
83
+ report.issues.forEach((issue) => console.log(` - ${issue}`));
84
+ }
85
+ ```
86
+
87
+ **Output:**
88
+ ```
89
+ ================================================================================
90
+ SCHEMA COMPLIANCE REPORT: delegation-credential
91
+ ================================================================================
92
+
93
+ Schema: DelegationCredential v1.0.0
94
+ URL: https://schemas.kya-os.ai/xmcp-i/delegation/delegation-credential.v1.0.0.json
95
+ Status: ✅ COMPLIANT
96
+ Compliance: 100.0%
97
+
98
+ 📊 FIELD DETAILS:
99
+
100
+ ✅ Pass: 8
101
+ ❌ Fail: 0
102
+ ⚠️ Warn: 2
103
+ 📝 Total: 10
104
+
105
+ ================================================================================
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Verify All Schemas
111
+
112
+ ```typescript
113
+ import {
114
+ createSchemaVerifier,
115
+ getAllSchemas,
116
+ } from '@kya-os/mcp-i-core';
117
+
118
+ // Import all your implementations
119
+ import * as implementations from '@kya-os/contracts';
120
+
121
+ // Create a map of schema ID to implementation
122
+ const implementationMap = new Map<string, any>([
123
+ ['verifiable-credential', implementations.VerifiableCredential],
124
+ ['delegation-credential', implementations.DelegationCredential],
125
+ ['detached-proof', implementations.DetachedProof],
126
+ // ... add all implementations
127
+ ]);
128
+
129
+ // Verify all schemas
130
+ const verifier = createSchemaVerifier();
131
+ const schemas = getAllSchemas();
132
+ const fullReport = await verifier.verifyAll(schemas, implementationMap);
133
+
134
+ // Print summary
135
+ console.log(verifier.generateFullReport(fullReport));
136
+
137
+ console.log(`\nOverall Compliance: ${fullReport.overallCompliance.toFixed(1)}%`);
138
+ console.log(`Compliant: ${fullReport.compliantSchemas}/${fullReport.totalSchemas}`);
139
+
140
+ if (fullReport.criticalIssues.length > 0) {
141
+ console.log('\n🚨 Critical Issues:');
142
+ fullReport.criticalIssues.forEach((issue) => console.log(` - ${issue}`));
143
+ }
144
+ ```
145
+
146
+ **Output:**
147
+ ```
148
+ ================================================================================
149
+ FULL SCHEMA COMPLIANCE REPORT
150
+ ================================================================================
151
+
152
+ Total Schemas: 41
153
+ Compliant: 38
154
+ Non-Compliant: 3
155
+ Overall Compliance: 92.7%
156
+
157
+ 🚨 CRITICAL ISSUES (3):
158
+ 1. mcp-tool: Missing implementation
159
+ 2. mcp-resource: Missing implementation
160
+ 3. mcp-prompt: Type mismatch in 'arguments' field
161
+
162
+ 📊 SCHEMA BREAKDOWN:
163
+
164
+ ✅ verifiable-credential: 100.0%
165
+ ✅ delegation-credential: 100.0%
166
+ ✅ detached-proof: 100.0%
167
+ ✅ statuslist2021-credential: 100.0%
168
+ ❌ mcp-tool: 0.0%
169
+ ❌ mcp-resource: 0.0%
170
+ ⚠️ mcp-prompt: 85.0%
171
+ ...
172
+
173
+ ================================================================================
174
+ ```
175
+
176
+ ---
177
+
178
+ ## Verify by Category
179
+
180
+ ```typescript
181
+ import {
182
+ createSchemaVerifier,
183
+ getSchemasByCategory,
184
+ } from '@kya-os/mcp-i-core';
185
+
186
+ // Get only W3C VC schemas
187
+ const w3cSchemas = getSchemasByCategory('w3c');
188
+ console.log(`W3C schemas: ${w3cSchemas.length}`); // 5
189
+
190
+ // Get only delegation schemas
191
+ const delegationSchemas = getSchemasByCategory('delegation');
192
+ console.log(`Delegation schemas: ${delegationSchemas.length}`); // 6
193
+
194
+ // Verify just delegation schemas
195
+ const verifier = createSchemaVerifier();
196
+ const delegationImplementations = new Map<string, any>([
197
+ ['delegation-credential', myDelegationCredential],
198
+ ['delegation-record', myDelegationRecord],
199
+ // ... add delegation implementations
200
+ ]);
201
+
202
+ const report = await verifier.verifyAll(
203
+ delegationSchemas,
204
+ delegationImplementations
205
+ );
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Get Statistics
211
+
212
+ ```typescript
213
+ import { getSchemaStats } from '@kya-os/mcp-i-core';
214
+
215
+ const stats = getSchemaStats();
216
+
217
+ console.log(`Total schemas: ${stats.total}`); // 41
218
+
219
+ console.log('\nBy Category:');
220
+ Object.entries(stats.byCategory).forEach(([category, count]) => {
221
+ console.log(` ${category}: ${count}`);
222
+ });
223
+
224
+ console.log('\nBy Version:');
225
+ Object.entries(stats.byVersion).forEach(([version, count]) => {
226
+ console.log(` v${version}: ${count}`);
227
+ });
228
+ ```
229
+
230
+ **Output:**
231
+ ```
232
+ Total schemas: 41
233
+
234
+ By Category:
235
+ w3c: 5
236
+ xmcp-i: 28
237
+ did: 2
238
+ mcp: 3
239
+ tlkrc: 2
240
+ runtime: 1
241
+
242
+ By Version:
243
+ v1.0.0: 38
244
+ v1.1.0: 3
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Integration with Tests
250
+
251
+ ```typescript
252
+ import { describe, test, expect } from 'vitest';
253
+ import {
254
+ createSchemaVerifier,
255
+ getCriticalSchemas,
256
+ } from '@kya-os/mcp-i-core';
257
+
258
+ describe('Schema Compliance', () => {
259
+ test('all critical schemas should be 100% compliant', async () => {
260
+ const verifier = createSchemaVerifier();
261
+ const criticalSchemas = getCriticalSchemas();
262
+
263
+ for (const schema of criticalSchemas) {
264
+ const implementation = getImplementation(schema.id);
265
+ const report = await verifier.verifySchema(schema, implementation);
266
+
267
+ expect(report.compliant).toBe(true);
268
+ expect(report.compliancePercentage).toBe(100);
269
+ expect(report.issues).toHaveLength(0);
270
+ }
271
+ });
272
+
273
+ test('all schemas should be at least 95% compliant', async () => {
274
+ const verifier = createSchemaVerifier();
275
+ const schemas = getAllSchemas();
276
+ const implementations = getAllImplementations();
277
+
278
+ const fullReport = await verifier.verifyAll(schemas, implementations);
279
+
280
+ expect(fullReport.overallCompliance).toBeGreaterThanOrEqual(95);
281
+ });
282
+ });
283
+ ```
284
+
285
+ ---
286
+
287
+ ## Custom Verification Options
288
+
289
+ ```typescript
290
+ import { createSchemaVerifier } from '@kya-os/mcp-i-core';
291
+
292
+ // Use custom schemas endpoint (e.g., for testing)
293
+ const verifier = createSchemaVerifier({
294
+ schemasBaseUrl: 'http://localhost:3000/schemas',
295
+ });
296
+
297
+ // Verify with custom options
298
+ const report = await verifier.verifySchema(schema, implementation);
299
+ ```
300
+
301
+ ---
302
+
303
+ ## Available Schema Categories
304
+
305
+ ```typescript
306
+ const categories = [
307
+ 'w3c', // W3C Verifiable Credentials (5 schemas)
308
+ 'delegation', // Delegation system (6 schemas)
309
+ 'identity', // Agent identity (3 schemas)
310
+ 'protocol', // MCP-I protocol (5 schemas)
311
+ 'tool-protection', // Tool protection (2 schemas)
312
+ 'audit', // Audit logging (2 schemas)
313
+ 'nonce', // Nonce cache (2 schemas)
314
+ 'mcp', // MCP tools/resources (3 schemas)
315
+ 'registry', // Agent registry (2 schemas)
316
+ 'verifier', // Verifier service (3 schemas)
317
+ 'config', // Configuration (4 schemas)
318
+ 'tlkrc', // Tool-level key rotation (2 schemas)
319
+ ];
320
+ ```
321
+
322
+ ---
323
+
324
+ ## Critical Schemas (Must Be 100% Compliant)
325
+
326
+ 1. `verifiable-credential` - W3C VC base
327
+ 2. `delegation-credential` - Delegation VCs
328
+ 3. `detached-proof` - MCP-I proofs
329
+ 4. `proof-meta` - Proof metadata
330
+ 5. `statuslist2021-credential` - Revocation lists
331
+ 6. `handshake-request` - Protocol handshakes
332
+ 7. `handshake-response` - Protocol responses
333
+
334
+ ---
335
+
336
+ ## Field-Level Details
337
+
338
+ ```typescript
339
+ const report = await verifier.verifySchema(schema, implementation);
340
+
341
+ // Inspect field-level compliance
342
+ report.fields.forEach((field) => {
343
+ console.log(`Field: ${field.fieldPath}`);
344
+ console.log(` Present: ${field.present}`);
345
+ console.log(` Expected Type: ${field.expectedType}`);
346
+ console.log(` Actual Type: ${field.actualType}`);
347
+ console.log(` Type Matches: ${field.typeMatches}`);
348
+ console.log(` Required: ${field.required}`);
349
+ console.log(` Status: ${field.status}`);
350
+ if (field.reason) {
351
+ console.log(` Reason: ${field.reason}`);
352
+ }
353
+ });
354
+ ```
355
+
356
+ ---
357
+
358
+ ## CI/CD Integration
359
+
360
+ ```bash
361
+ # Run compliance check in CI
362
+ node scripts/check-compliance.js
363
+
364
+ # Exit with error if not 100% compliant
365
+ if [ $? -ne 0 ]; then
366
+ echo "❌ Schema compliance check failed"
367
+ exit 1
368
+ fi
369
+ ```
370
+
371
+ **scripts/check-compliance.js:**
372
+ ```javascript
373
+ const { createSchemaVerifier, getAllSchemas } = require('@kya-os/mcp-i-core');
374
+
375
+ async function main() {
376
+ const verifier = createSchemaVerifier();
377
+ const schemas = getAllSchemas();
378
+ const implementations = getImplementations();
379
+
380
+ const report = await verifier.verifyAll(schemas, implementations);
381
+
382
+ console.log(verifier.generateFullReport(report));
383
+
384
+ if (report.overallCompliance < 100) {
385
+ process.exit(1);
386
+ }
387
+ }
388
+
389
+ main();
390
+ ```
391
+
392
+ ---
393
+
394
+ ## Next Steps
395
+
396
+ 1. **Implement Schema Fetching**: Add actual HTTP fetching from schemas.kya-os.ai
397
+ 2. **Add JSON Schema Validation**: Use AJV or similar for deep validation
398
+ 3. **Create Mock Schemas**: For offline testing
399
+ 4. **Add Caching**: Cache fetched schemas locally
400
+ 5. **Add Watch Mode**: Auto-verify on file changes
401
+
402
+ ---
403
+
404
+ **Status: Schema Compliance Tool Ready! 🎉**
405
+
406
+ - ✅ 41 schemas cataloged
407
+ - ✅ Automated verification
408
+ - ✅ Field-level checking
409
+ - ✅ Category filtering
410
+ - ✅ Statistics
411
+ - ✅ Report generation
412
+ - ✅ CI/CD ready