@kya-os/contracts 1.5.3-canary.2 → 1.5.3-canary.21
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.
- package/.turbo/turbo-build.log +17 -0
- package/.turbo/turbo-test$colon$coverage.log +85 -0
- package/.turbo/turbo-test.log +32 -0
- package/coverage/coverage-final.json +38 -0
- package/dist/agentshield-api/admin-schemas.d.ts +2 -2
- package/dist/agentshield-api/index.d.ts +1 -1
- package/dist/agentshield-api/schemas.d.ts +150 -48
- package/dist/agentshield-api/schemas.js +32 -4
- package/dist/agentshield-api/types.d.ts +31 -4
- package/dist/audit/index.d.ts +193 -0
- package/dist/audit/index.js +100 -0
- package/dist/config/identity.d.ts +205 -2
- package/dist/config/identity.js +28 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/tool-context.d.ts +34 -0
- package/dist/config/tool-context.js +13 -0
- package/dist/consent/schemas.d.ts +119 -93
- package/dist/consent/schemas.js +111 -64
- package/dist/dashboard-config/schemas.d.ts +2248 -992
- package/dist/handshake.d.ts +14 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/tool-protection/index.d.ts +490 -14
- package/dist/tool-protection/index.js +89 -2
- package/dist/verifier/index.d.ts +1 -0
- package/dist/verifier/index.js +18 -0
- package/dist/well-known/index.d.ts +2 -2
- package/package.json +43 -122
- package/schemas/cli/register-output/v1.0.0.json +69 -0
- package/schemas/identity/v1.0.0.json +46 -0
- package/schemas/proof/v1.0.0.json +80 -0
- package/schemas/registry/receipt-v1.0.0.json +60 -0
- package/schemas/verifier/verify-page/v1.0.0.json +94 -0
- package/schemas/well-known/agent/v1.0.0.json +67 -0
- package/schemas/well-known/did/v1.0.0.json +174 -0
- package/scripts/emit-schemas.js +11 -0
- package/src/agentshield-api/admin-schemas.ts +31 -0
- package/src/agentshield-api/admin-types.ts +47 -0
- package/src/agentshield-api/endpoints.ts +60 -0
- package/src/agentshield-api/index.ts +70 -0
- package/src/agentshield-api/schemas.ts +304 -0
- package/src/agentshield-api/types.ts +317 -0
- package/src/audit/index.ts +128 -0
- package/src/cli.ts +156 -0
- package/src/config/base.ts +107 -0
- package/src/config/builder.ts +97 -0
- package/src/config/delegation.ts +232 -0
- package/src/config/identity.ts +252 -0
- package/src/config/index.ts +78 -0
- package/src/config/proofing.ts +138 -0
- package/src/config/tool-context.ts +41 -0
- package/src/config/tool-protection.ts +174 -0
- package/src/consent/index.ts +32 -0
- package/src/consent/schemas.ts +334 -0
- package/src/consent/types.ts +199 -0
- package/src/dashboard-config/default-config.json +86 -0
- package/src/dashboard-config/default-config.ts +266 -0
- package/src/dashboard-config/index.ts +48 -0
- package/src/dashboard-config/schemas.ts +286 -0
- package/src/dashboard-config/types.ts +404 -0
- package/src/delegation/constraints.ts +267 -0
- package/src/delegation/index.ts +8 -0
- package/src/delegation/schemas.ts +595 -0
- package/src/did/index.ts +9 -0
- package/src/did/resolve-contract.ts +255 -0
- package/src/did/schemas.ts +190 -0
- package/src/did/types.ts +224 -0
- package/src/env/constants.ts +70 -0
- package/src/env/index.ts +5 -0
- package/src/handshake.ts +125 -0
- package/src/index.ts +45 -0
- package/src/proof/index.ts +31 -0
- package/src/proof/proof-record.ts +163 -0
- package/src/proof/signing-spec.ts +146 -0
- package/src/proof.ts +99 -0
- package/src/registry.ts +146 -0
- package/src/runtime/errors.ts +153 -0
- package/src/runtime/headers.ts +136 -0
- package/src/runtime/index.ts +6 -0
- package/src/test.ts +143 -0
- package/src/tlkrc/index.ts +5 -0
- package/src/tlkrc/rotation.ts +153 -0
- package/src/tool-protection/index.ts +406 -0
- package/src/utils/validation.ts +93 -0
- package/src/vc/index.ts +8 -0
- package/src/vc/schemas.ts +277 -0
- package/src/vc/statuslist.ts +279 -0
- package/src/verifier/index.ts +2 -0
- package/src/verifier.ts +92 -0
- package/src/well-known/index.ts +237 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Types and Schemas
|
|
3
|
+
*
|
|
4
|
+
* Types and Zod schemas for audit logging in the MCP-I framework.
|
|
5
|
+
* These types are platform-agnostic and used across all implementations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import type { AgentIdentity } from "../config/identity.js";
|
|
10
|
+
import type { SessionContext } from "../handshake.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Audit context schema for logging audit records
|
|
14
|
+
*
|
|
15
|
+
* Contains all metadata needed to generate an audit record.
|
|
16
|
+
* Privacy Note: Only metadata is extracted from these objects.
|
|
17
|
+
* The identity's private key, session's nonce, and other sensitive
|
|
18
|
+
* fields are NEVER included in the audit log.
|
|
19
|
+
*/
|
|
20
|
+
export const AuditContextSchema = z.object({
|
|
21
|
+
/**
|
|
22
|
+
* Agent identity
|
|
23
|
+
* Only `did` and `keyId` are logged. Private key is NEVER logged.
|
|
24
|
+
*/
|
|
25
|
+
identity: z
|
|
26
|
+
.object({
|
|
27
|
+
did: z.string().min(1),
|
|
28
|
+
kid: z.string().min(1),
|
|
29
|
+
})
|
|
30
|
+
.passthrough(), // Allow additional fields but only did/kid are used
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Session context
|
|
34
|
+
* Only `sessionId` and `audience` are logged. Nonce is NEVER logged.
|
|
35
|
+
*/
|
|
36
|
+
session: z
|
|
37
|
+
.object({
|
|
38
|
+
sessionId: z.string().min(1),
|
|
39
|
+
audience: z.string().min(1),
|
|
40
|
+
})
|
|
41
|
+
.passthrough(), // Allow additional fields but only sessionId/audience are used
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Request hash (SHA-256 with `sha256:` prefix)
|
|
45
|
+
*/
|
|
46
|
+
requestHash: z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Response hash (SHA-256 with `sha256:` prefix)
|
|
50
|
+
*/
|
|
51
|
+
responseHash: z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Verification result
|
|
55
|
+
* - 'yes': Proof was verified successfully
|
|
56
|
+
* - 'no': Proof verification failed
|
|
57
|
+
*/
|
|
58
|
+
verified: z.enum(["yes", "no"]),
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Optional scope identifier
|
|
62
|
+
* Application-level scope (e.g., 'orders.create', 'users.read').
|
|
63
|
+
* If not provided, '-' is used in the audit log.
|
|
64
|
+
*/
|
|
65
|
+
scopeId: z.string().optional(),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export type AuditContext = {
|
|
69
|
+
identity: AgentIdentity;
|
|
70
|
+
session: SessionContext;
|
|
71
|
+
requestHash: string;
|
|
72
|
+
responseHash: string;
|
|
73
|
+
verified: "yes" | "no";
|
|
74
|
+
scopeId?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Event context schema for logging events that bypass session deduplication
|
|
79
|
+
*
|
|
80
|
+
* Used for consent events where multiple events occur in the same session.
|
|
81
|
+
* Unlike AuditContext, this allows multiple events per session.
|
|
82
|
+
*/
|
|
83
|
+
export const AuditEventContextSchema = z.object({
|
|
84
|
+
/**
|
|
85
|
+
* Event type identifier
|
|
86
|
+
* @example "consent:page_viewed", "consent:approved", "runtime:initialized"
|
|
87
|
+
*/
|
|
88
|
+
eventType: z.string().min(1),
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Agent identity
|
|
92
|
+
* Only `did` and `keyId` are logged. Private key is NEVER logged.
|
|
93
|
+
*/
|
|
94
|
+
identity: z
|
|
95
|
+
.object({
|
|
96
|
+
did: z.string().min(1),
|
|
97
|
+
kid: z.string().min(1),
|
|
98
|
+
})
|
|
99
|
+
.passthrough(), // Allow additional fields but only did/kid are used
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Session context
|
|
103
|
+
* Only `sessionId` and `audience` are logged. Nonce is NEVER logged.
|
|
104
|
+
*/
|
|
105
|
+
session: z
|
|
106
|
+
.object({
|
|
107
|
+
sessionId: z.string().min(1),
|
|
108
|
+
audience: z.string().min(1),
|
|
109
|
+
})
|
|
110
|
+
.passthrough(), // Allow additional fields but only sessionId/audience are used
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Optional event-specific data
|
|
114
|
+
* Used for generating event hash. Not logged directly.
|
|
115
|
+
*/
|
|
116
|
+
eventData: z.record(z.unknown()).optional(),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
export type AuditEventContext = {
|
|
120
|
+
eventType: string;
|
|
121
|
+
identity: AgentIdentity;
|
|
122
|
+
session: SessionContext;
|
|
123
|
+
eventData?: Record<string, any>;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// Re-export AuditRecord from proof module
|
|
127
|
+
export type { AuditRecord } from "../proof.js";
|
|
128
|
+
export { AuditRecordSchema } from "../proof.js";
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CLI command schemas and results
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* CLI Identity File Format Schema
|
|
9
|
+
*
|
|
10
|
+
* Format for identity.json files stored on disk.
|
|
11
|
+
* Used by CLI tools for identity management.
|
|
12
|
+
*/
|
|
13
|
+
export const CLIIdentityFileSchema = z.object({
|
|
14
|
+
version: z.literal("1.0"),
|
|
15
|
+
did: z.string().min(1),
|
|
16
|
+
// Accept both kid and keyId for backward compatibility with pre-1.3 identity files
|
|
17
|
+
kid: z.string().min(1).optional(),
|
|
18
|
+
keyId: z.string().min(1).optional(),
|
|
19
|
+
privateKey: z.string().regex(/^[A-Za-z0-9+/]{43}=$/, "Must be a valid base64-encoded Ed25519 private key (44 characters)"),
|
|
20
|
+
publicKey: z.string().regex(/^[A-Za-z0-9+/]{43}=$/, "Must be a valid base64-encoded Ed25519 public key (44 characters)"),
|
|
21
|
+
createdAt: z.string().datetime(),
|
|
22
|
+
lastRotated: z.string().datetime().optional(),
|
|
23
|
+
}).refine(
|
|
24
|
+
(data) => data.kid || data.keyId,
|
|
25
|
+
{
|
|
26
|
+
message: "Either kid or keyId must be provided",
|
|
27
|
+
}
|
|
28
|
+
).transform((data) => ({
|
|
29
|
+
version: data.version,
|
|
30
|
+
did: data.did,
|
|
31
|
+
kid: data.kid || data.keyId!,
|
|
32
|
+
privateKey: data.privateKey,
|
|
33
|
+
publicKey: data.publicKey,
|
|
34
|
+
createdAt: data.createdAt,
|
|
35
|
+
lastRotated: data.lastRotated,
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
export const KeyRotationResultSchema = z.object({
|
|
39
|
+
success: z.boolean(),
|
|
40
|
+
oldKeyId: z.string().min(1),
|
|
41
|
+
newKeyId: z.string().min(1),
|
|
42
|
+
did: z.string().min(1),
|
|
43
|
+
mode: z.enum(["dev", "prod"]),
|
|
44
|
+
delegated: z.boolean(),
|
|
45
|
+
forced: z.boolean(),
|
|
46
|
+
auditLine: z.string().min(1),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const StatusReportSchema = z.object({
|
|
50
|
+
did: z.string().min(1),
|
|
51
|
+
kid: z.string().min(1), // Changed from keyId to kid for spec compliance
|
|
52
|
+
ktaURL: z.string().url(),
|
|
53
|
+
mirrorStatus: z.enum(["pending", "success", "error"]),
|
|
54
|
+
lastHandshake: z.number().int().positive().optional(),
|
|
55
|
+
environment: z.enum(["dev", "prod"]),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const PackageInfoSchema = z.object({
|
|
59
|
+
name: z.string(),
|
|
60
|
+
version: z.string(),
|
|
61
|
+
compatible: z.boolean(),
|
|
62
|
+
issues: z.array(z.string()).optional(),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const XMCPUpstreamInfoSchema = z.object({
|
|
66
|
+
version: z.string(),
|
|
67
|
+
compatible: z.boolean(),
|
|
68
|
+
issues: z.array(z.string()).optional(),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const EnvironmentInfoSchema = z.object({
|
|
72
|
+
valid: z.boolean(),
|
|
73
|
+
missing: z.array(z.string()),
|
|
74
|
+
issues: z.array(z.string()).optional(),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const KTAInfoSchema = z.object({
|
|
78
|
+
reachable: z.boolean(),
|
|
79
|
+
authenticated: z.boolean(),
|
|
80
|
+
issues: z.array(z.string()).optional(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const CacheInfoSchema = z.object({
|
|
84
|
+
type: z.string(),
|
|
85
|
+
functional: z.boolean(),
|
|
86
|
+
issues: z.array(z.string()).optional(),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export const DoctorResultSchema = z.object({
|
|
90
|
+
packages: z.array(PackageInfoSchema),
|
|
91
|
+
xmcpUpstream: XMCPUpstreamInfoSchema,
|
|
92
|
+
environment: EnvironmentInfoSchema,
|
|
93
|
+
kta: KTAInfoSchema,
|
|
94
|
+
cache: CacheInfoSchema,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export const ScaffolderOptionsSchema = z.object({
|
|
98
|
+
projectName: z.string().min(1),
|
|
99
|
+
xmcpVersion: z.string().optional(),
|
|
100
|
+
xmcpChannel: z.enum(["latest", "next"]).optional(),
|
|
101
|
+
noIdentity: z.boolean().default(false),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const ScaffolderResultSchema = z.object({
|
|
105
|
+
success: z.boolean(),
|
|
106
|
+
projectPath: z.string().min(1),
|
|
107
|
+
xmcpVersion: z.string().min(1),
|
|
108
|
+
identityEnabled: z.boolean(),
|
|
109
|
+
warnings: z.array(z.string()).optional(),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Type exports
|
|
113
|
+
export type CLIIdentityFile = z.infer<typeof CLIIdentityFileSchema>;
|
|
114
|
+
export type KeyRotationResult = z.infer<typeof KeyRotationResultSchema>;
|
|
115
|
+
export type StatusReport = z.infer<typeof StatusReportSchema>;
|
|
116
|
+
export type PackageInfo = z.infer<typeof PackageInfoSchema>;
|
|
117
|
+
export type XMCPUpstreamInfo = z.infer<typeof XMCPUpstreamInfoSchema>;
|
|
118
|
+
export type EnvironmentInfo = z.infer<typeof EnvironmentInfoSchema>;
|
|
119
|
+
export type KTAInfo = z.infer<typeof KTAInfoSchema>;
|
|
120
|
+
export type CacheInfo = z.infer<typeof CacheInfoSchema>;
|
|
121
|
+
export type DoctorResult = z.infer<typeof DoctorResultSchema>;
|
|
122
|
+
export type ScaffolderOptions = z.infer<typeof ScaffolderOptionsSchema>;
|
|
123
|
+
export type ScaffolderResult = z.infer<typeof ScaffolderResultSchema>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated Use CLIIdentityFile instead
|
|
127
|
+
* This export is maintained for backward compatibility
|
|
128
|
+
*/
|
|
129
|
+
export type IdentityConfig = CLIIdentityFile;
|
|
130
|
+
|
|
131
|
+
// Error codes as string literal union
|
|
132
|
+
export const ERROR_CODES = {
|
|
133
|
+
XMCP_I_EBADPROOF: "XMCP_I_EBADPROOF",
|
|
134
|
+
XMCP_I_ENOIDENTITY: "XMCP_I_ENOIDENTITY",
|
|
135
|
+
XMCP_I_EMIRRORPENDING: "XMCP_I_EMIRRORPENDING",
|
|
136
|
+
XMCP_I_EHANDSHAKE: "XMCP_I_EHANDSHAKE",
|
|
137
|
+
XMCP_I_ESESSION: "XMCP_I_ESESSION",
|
|
138
|
+
XMCP_I_ECLAIM: "XMCP_I_ECLAIM",
|
|
139
|
+
XMCP_I_ECONFIG: "XMCP_I_ECONFIG",
|
|
140
|
+
XMCP_I_ERUNTIME: "XMCP_I_ERUNTIME",
|
|
141
|
+
} as const;
|
|
142
|
+
|
|
143
|
+
export type ErrorCode = keyof typeof ERROR_CODES;
|
|
144
|
+
|
|
145
|
+
// CLI exit codes
|
|
146
|
+
export const CLI_EXIT_CODES = {
|
|
147
|
+
SUCCESS: 0,
|
|
148
|
+
GENERAL_ERROR: 1,
|
|
149
|
+
BADPROOF: 20,
|
|
150
|
+
NOIDENTITY: 21,
|
|
151
|
+
HANDSHAKE: 22,
|
|
152
|
+
SESSION: 23,
|
|
153
|
+
CLAIM: 24,
|
|
154
|
+
CONFIG: 25,
|
|
155
|
+
RUNTIME: 26,
|
|
156
|
+
} as const;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* Shared configuration interfaces that are platform-agnostic and used
|
|
5
|
+
* across all XMCP-I implementations. These form the foundation of the
|
|
6
|
+
* configuration hierarchy.
|
|
7
|
+
*
|
|
8
|
+
* @module @kya-os/contracts/config
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Base configuration shared across ALL platforms
|
|
13
|
+
*
|
|
14
|
+
* This interface defines the core configuration options that are
|
|
15
|
+
* universally applicable regardless of the runtime platform (Node.js,
|
|
16
|
+
* Cloudflare Workers, etc.).
|
|
17
|
+
*/
|
|
18
|
+
export interface MCPIBaseConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Runtime environment setting
|
|
21
|
+
* - 'development': Enables debug logging, dev identity, relaxed security
|
|
22
|
+
* - 'production': Production security, identity from env vars, minimal logging
|
|
23
|
+
*/
|
|
24
|
+
environment: 'development' | 'production';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Session configuration
|
|
28
|
+
* Controls how sessions are managed and validated
|
|
29
|
+
*/
|
|
30
|
+
session?: {
|
|
31
|
+
/**
|
|
32
|
+
* Maximum time skew allowed for timestamp validation (in seconds)
|
|
33
|
+
* Helps handle clock drift between client and server
|
|
34
|
+
* @default 120
|
|
35
|
+
*/
|
|
36
|
+
timestampSkewSeconds?: number;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Session time-to-live in minutes
|
|
40
|
+
* How long a session remains valid after creation
|
|
41
|
+
* @default 30
|
|
42
|
+
*/
|
|
43
|
+
ttlMinutes?: number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Absolute session lifetime in minutes (optional)
|
|
47
|
+
* Maximum lifetime regardless of activity
|
|
48
|
+
*/
|
|
49
|
+
absoluteLifetime?: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Audit logging configuration
|
|
54
|
+
* Controls what gets logged for security and compliance
|
|
55
|
+
*/
|
|
56
|
+
audit?: {
|
|
57
|
+
/**
|
|
58
|
+
* Enable audit logging
|
|
59
|
+
* @default true in production, false in development
|
|
60
|
+
*/
|
|
61
|
+
enabled: boolean;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Include proof hashes in audit logs
|
|
65
|
+
* Useful for cryptographic verification but increases log size
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
includeProofHashes?: boolean;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Include full payloads in audit logs
|
|
72
|
+
* WARNING: May include sensitive data
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
includePayloads?: boolean;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Custom log function for audit records
|
|
79
|
+
* If not provided, uses console.log
|
|
80
|
+
*/
|
|
81
|
+
logFunction?: (record: string) => void;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Well-known endpoints configuration
|
|
86
|
+
* Controls the /.well-known/* endpoints for identity discovery
|
|
87
|
+
*/
|
|
88
|
+
wellKnown?: {
|
|
89
|
+
/**
|
|
90
|
+
* Enable well-known endpoints
|
|
91
|
+
* @default true
|
|
92
|
+
*/
|
|
93
|
+
enabled: boolean;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Service name advertised in well-known endpoints
|
|
97
|
+
* @default 'MCP-I Service'
|
|
98
|
+
*/
|
|
99
|
+
serviceName?: string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Service endpoint URL
|
|
103
|
+
* @default 'https://example.com'
|
|
104
|
+
*/
|
|
105
|
+
serviceEndpoint?: string;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Builder Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities for building MCP-I configuration objects with sensible defaults.
|
|
5
|
+
* These functions are platform-agnostic and can be used by any adapter/platform.
|
|
6
|
+
*
|
|
7
|
+
* @module @kya-os/contracts/config
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { MCPIBaseConfig } from './base.js';
|
|
11
|
+
import type { RuntimeIdentityConfig } from './identity.js';
|
|
12
|
+
import type { ProofingConfig } from './proofing.js';
|
|
13
|
+
import type { DelegationConfig, DelegationVerifierConfig, AuthorizationConfig } from './delegation.js';
|
|
14
|
+
import type { ToolProtectionSourceConfig } from './tool-protection.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Complete runtime configuration type
|
|
18
|
+
* This can be extended by platform-specific configs
|
|
19
|
+
*/
|
|
20
|
+
export interface MCPIConfig extends MCPIBaseConfig {
|
|
21
|
+
identity?: RuntimeIdentityConfig;
|
|
22
|
+
proofing?: ProofingConfig;
|
|
23
|
+
delegation?: DelegationConfig;
|
|
24
|
+
toolProtection?: ToolProtectionSourceConfig;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Build base MCPIConfig that works across all platforms
|
|
29
|
+
*
|
|
30
|
+
* Creates a platform-agnostic configuration object with sensible defaults
|
|
31
|
+
* for identity, proofing, delegation, audit, and session management.
|
|
32
|
+
*
|
|
33
|
+
* @param env - Environment variables object (works with process.env or Cloudflare env)
|
|
34
|
+
* @returns Complete MCPIConfig object
|
|
35
|
+
*/
|
|
36
|
+
export function buildBaseConfig(env: Record<string, any>): MCPIConfig {
|
|
37
|
+
const environment = (env.MCPI_ENV || env.ENVIRONMENT || 'development') as 'development' | 'production';
|
|
38
|
+
const isDevelopment = environment === 'development';
|
|
39
|
+
|
|
40
|
+
const baseConfig: MCPIConfig = {
|
|
41
|
+
environment,
|
|
42
|
+
|
|
43
|
+
identity: {
|
|
44
|
+
enabled: true,
|
|
45
|
+
environment,
|
|
46
|
+
devIdentityPath: '.mcpi/identity.json'
|
|
47
|
+
} as RuntimeIdentityConfig,
|
|
48
|
+
|
|
49
|
+
proofing: {
|
|
50
|
+
enabled: true,
|
|
51
|
+
batchQueue: {
|
|
52
|
+
destinations: [
|
|
53
|
+
{
|
|
54
|
+
type: 'agentshield' as const,
|
|
55
|
+
apiUrl: env.AGENTSHIELD_API_URL || 'https://kya.vouched.id',
|
|
56
|
+
apiKey: env.AGENTSHIELD_API_KEY
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
maxBatchSize: 10,
|
|
60
|
+
flushIntervalMs: 5000,
|
|
61
|
+
maxRetries: 3,
|
|
62
|
+
debug: isDevelopment
|
|
63
|
+
}
|
|
64
|
+
} as ProofingConfig,
|
|
65
|
+
|
|
66
|
+
delegation: {
|
|
67
|
+
enabled: true,
|
|
68
|
+
enforceDelegations: true,
|
|
69
|
+
verifier: {
|
|
70
|
+
type: 'agentshield' as const,
|
|
71
|
+
apiUrl: env.AGENTSHIELD_API_URL || 'https://kya.vouched.id',
|
|
72
|
+
apiKey: env.AGENTSHIELD_API_KEY || '',
|
|
73
|
+
cacheTtl: 60000, // 1 minute cache
|
|
74
|
+
debug: isDevelopment
|
|
75
|
+
} as DelegationVerifierConfig,
|
|
76
|
+
authorization: {
|
|
77
|
+
authorizationUrl: env.AUTHORIZATION_URL || `${env.AGENTSHIELD_API_URL || 'https://kya.vouched.id'}/authorize`,
|
|
78
|
+
resumeTokenTtl: 600000, // 10 minutes
|
|
79
|
+
minReputationScore: 76
|
|
80
|
+
} as AuthorizationConfig
|
|
81
|
+
} as DelegationConfig,
|
|
82
|
+
|
|
83
|
+
audit: {
|
|
84
|
+
enabled: true,
|
|
85
|
+
includeProofHashes: false,
|
|
86
|
+
includePayloads: false
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
session: {
|
|
90
|
+
timestampSkewSeconds: 120,
|
|
91
|
+
ttlMinutes: 30
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return baseConfig;
|
|
96
|
+
}
|
|
97
|
+
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* Configuration for delegation verification, authorization flows,
|
|
5
|
+
* and consent management in MCP-I.
|
|
6
|
+
*
|
|
7
|
+
* @module @kya-os/contracts/config
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Delegation verifier types
|
|
12
|
+
*/
|
|
13
|
+
export type DelegationVerifierType =
|
|
14
|
+
| 'agentshield' // AgentShield API
|
|
15
|
+
| 'kta' // Know That AI
|
|
16
|
+
| 'memory' // In-memory (development)
|
|
17
|
+
| 'cloudflare-kv' // Cloudflare KV storage
|
|
18
|
+
| 'redis' // Redis cache
|
|
19
|
+
| 'dynamodb' // AWS DynamoDB
|
|
20
|
+
| 'custom'; // Custom implementation
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Delegation verifier configuration
|
|
24
|
+
* Controls how delegations are verified and cached
|
|
25
|
+
*/
|
|
26
|
+
export interface DelegationVerifierConfig {
|
|
27
|
+
/**
|
|
28
|
+
* Type of verifier to use
|
|
29
|
+
*/
|
|
30
|
+
type: DelegationVerifierType;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* API URL for remote verifiers (agentshield, kta)
|
|
34
|
+
* @example 'https://kya.vouched.id'
|
|
35
|
+
*/
|
|
36
|
+
apiUrl?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* API key for authentication with remote verifiers
|
|
40
|
+
*/
|
|
41
|
+
apiKey?: string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Cache time-to-live in milliseconds
|
|
45
|
+
* How long to cache delegation verification results
|
|
46
|
+
* @default 300000 (5 minutes)
|
|
47
|
+
*/
|
|
48
|
+
cacheTtl?: number;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Custom verifier implementation
|
|
52
|
+
* Required when type is 'custom'
|
|
53
|
+
*/
|
|
54
|
+
customVerifier?: {
|
|
55
|
+
verify: (agentDid: string, scopes: string[]) => Promise<boolean>;
|
|
56
|
+
invalidate?: (agentDid: string) => Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Additional verifier-specific options
|
|
61
|
+
*/
|
|
62
|
+
options?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Authorization configuration
|
|
67
|
+
* Controls consent flows and authorization requirements
|
|
68
|
+
*/
|
|
69
|
+
export interface AuthorizationConfig {
|
|
70
|
+
/**
|
|
71
|
+
* Base URL for authorization/consent flow
|
|
72
|
+
* Users are redirected here when delegation is required
|
|
73
|
+
* @example 'https://kya.vouched.id/bouncer/consent'
|
|
74
|
+
*/
|
|
75
|
+
authorizationUrl?: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* KTA (Know That AI) configuration for reputation checks
|
|
79
|
+
*/
|
|
80
|
+
kta?: {
|
|
81
|
+
/**
|
|
82
|
+
* KTA API base URL
|
|
83
|
+
*/
|
|
84
|
+
apiUrl: string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* API key for KTA
|
|
88
|
+
*/
|
|
89
|
+
apiKey?: string;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Minimum reputation score to bypass authorization
|
|
94
|
+
* Agents with reputation above this threshold don't need explicit consent
|
|
95
|
+
* Range: 0-100
|
|
96
|
+
* @default 80
|
|
97
|
+
*/
|
|
98
|
+
minReputationScore?: number;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Resume token TTL in milliseconds
|
|
102
|
+
* How long a resume token remains valid
|
|
103
|
+
* @default 3600000 (1 hour)
|
|
104
|
+
*/
|
|
105
|
+
resumeTokenTtl?: number;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Require authorization for unknown agents
|
|
109
|
+
* If false, unknown agents are allowed by default
|
|
110
|
+
* @default true
|
|
111
|
+
*/
|
|
112
|
+
requireAuthForUnknown?: boolean;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Custom authorization URL builder
|
|
116
|
+
* Allows customization of consent URL generation
|
|
117
|
+
*/
|
|
118
|
+
buildAuthUrl?: (toolName: string, scopes: string[], context: any) => string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Delegation configuration (platform-agnostic)
|
|
123
|
+
*
|
|
124
|
+
* Controls delegation verification, authorization flows, and
|
|
125
|
+
* tool protection enforcement.
|
|
126
|
+
*/
|
|
127
|
+
export interface DelegationConfig {
|
|
128
|
+
/**
|
|
129
|
+
* Enable delegation features
|
|
130
|
+
* When false, all tools are accessible without delegation
|
|
131
|
+
* @default false (for backward compatibility)
|
|
132
|
+
*/
|
|
133
|
+
enabled: boolean;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Enforce delegation requirements strictly
|
|
137
|
+
* When true, tools requiring delegation will fail without valid delegation
|
|
138
|
+
* When false, logs warnings but allows execution
|
|
139
|
+
* @default true in production, false in development
|
|
140
|
+
*/
|
|
141
|
+
enforceDelegations?: boolean;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Delegation verifier configuration
|
|
145
|
+
* Controls how delegations are verified
|
|
146
|
+
*/
|
|
147
|
+
verifier: DelegationVerifierConfig;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Authorization configuration
|
|
151
|
+
* Controls consent flows and reputation checks
|
|
152
|
+
*/
|
|
153
|
+
authorization?: AuthorizationConfig;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Enable debug logging for delegation operations
|
|
157
|
+
* @default false
|
|
158
|
+
*/
|
|
159
|
+
debug?: boolean;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Delegation record structure
|
|
164
|
+
* Represents a delegation from a user to an agent
|
|
165
|
+
*/
|
|
166
|
+
export interface DelegationRecord {
|
|
167
|
+
/**
|
|
168
|
+
* Unique identifier for this delegation
|
|
169
|
+
*/
|
|
170
|
+
id: string;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* User who granted the delegation
|
|
174
|
+
*/
|
|
175
|
+
userId: string;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Agent DID receiving the delegation
|
|
179
|
+
*/
|
|
180
|
+
agentDid: string;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Scopes granted in this delegation
|
|
184
|
+
* @example ['files:read', 'files:write']
|
|
185
|
+
*/
|
|
186
|
+
scopes: string[];
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* ISO 8601 timestamp when delegation was created
|
|
190
|
+
*/
|
|
191
|
+
createdAt: string;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* ISO 8601 timestamp when delegation expires
|
|
195
|
+
*/
|
|
196
|
+
expiresAt?: string;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Whether this delegation has been revoked
|
|
200
|
+
*/
|
|
201
|
+
revoked?: boolean;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Additional constraints on the delegation
|
|
205
|
+
*/
|
|
206
|
+
constraints?: {
|
|
207
|
+
/**
|
|
208
|
+
* IP addresses allowed to use this delegation
|
|
209
|
+
*/
|
|
210
|
+
allowedIps?: string[];
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Origins allowed to use this delegation
|
|
214
|
+
*/
|
|
215
|
+
allowedOrigins?: string[];
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Maximum number of uses
|
|
219
|
+
*/
|
|
220
|
+
maxUses?: number;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Current number of uses
|
|
224
|
+
*/
|
|
225
|
+
currentUses?: number;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Additional custom constraints
|
|
229
|
+
*/
|
|
230
|
+
[key: string]: unknown;
|
|
231
|
+
};
|
|
232
|
+
}
|