@kya-os/mcp-i 0.1.0 → 1.2.1
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/README.md +406 -71
- package/dist/149.js +1 -0
- package/dist/189.js +1 -0
- package/dist/261.js +1 -0
- package/dist/28.js +1 -0
- package/dist/295.js +1 -0
- package/dist/460.js +1 -0
- package/dist/570.js +1 -0
- package/dist/634.js +1 -0
- package/dist/647.js +1 -0
- package/dist/67.js +1 -0
- package/dist/739.js +1 -0
- package/dist/742.js +1 -0
- package/dist/904.js +1 -0
- package/dist/938.js +1 -0
- package/dist/auth/api-key.d.ts +16 -0
- package/dist/auth/api-key.js +82 -0
- package/dist/auth/jwt.d.ts +43 -0
- package/dist/auth/jwt.js +51 -0
- package/dist/auth/oauth/factory.d.ts +12 -0
- package/dist/auth/oauth/factory.js +36 -0
- package/dist/auth/oauth/index.d.ts +5 -0
- package/dist/auth/oauth/index.js +27 -0
- package/dist/auth/oauth/providers/proxy-provider.d.ts +13 -0
- package/dist/auth/oauth/providers/proxy-provider.js +159 -0
- package/dist/auth/oauth/router.d.ts +4 -0
- package/dist/auth/oauth/router.js +294 -0
- package/dist/auth/oauth/storage/memory-storage.d.ts +12 -0
- package/dist/auth/oauth/storage/memory-storage.js +40 -0
- package/dist/auth/oauth/types.d.ts +112 -0
- package/dist/auth/oauth/types.js +2 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/concurrency.test.d.ts +5 -0
- package/dist/cache/__tests__/concurrency.test.js +300 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.js +132 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +133 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.js +252 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.js +95 -0
- package/dist/cache/cloudflare-kv-nonce-cache.d.ts +14 -0
- package/dist/cache/cloudflare-kv-nonce-cache.js +93 -0
- package/dist/cache/dynamodb-nonce-cache.d.ts +15 -0
- package/dist/cache/dynamodb-nonce-cache.js +92 -0
- package/dist/cache/index.d.ts +16 -0
- package/dist/cache/index.js +32 -0
- package/dist/cache/memory-nonce-cache.d.ts +44 -0
- package/dist/cache/memory-nonce-cache.js +105 -0
- package/dist/cache/nonce-cache-factory.d.ts +20 -0
- package/dist/cache/nonce-cache-factory.js +208 -0
- package/dist/cache/redis-nonce-cache.d.ts +14 -0
- package/dist/cache/redis-nonce-cache.js +53 -0
- package/dist/compiler/compiler-context.d.ts +23 -0
- package/dist/compiler/compiler-context.js +24 -0
- package/dist/compiler/config/constants.d.ts +41 -0
- package/dist/compiler/config/constants.js +45 -0
- package/dist/compiler/config/index.d.ts +252 -0
- package/dist/compiler/config/index.js +15 -0
- package/dist/compiler/config/injection.d.ts +26 -0
- package/dist/compiler/config/injection.js +58 -0
- package/dist/compiler/config/schemas/experimental/index.d.ts +91 -0
- package/dist/compiler/config/schemas/experimental/index.js +16 -0
- package/dist/compiler/config/schemas/experimental/oauth.d.ts +74 -0
- package/dist/compiler/config/schemas/experimental/oauth.js +25 -0
- package/dist/compiler/config/schemas/index.d.ts +6 -0
- package/dist/compiler/config/schemas/index.js +17 -0
- package/dist/compiler/config/schemas/paths.d.ts +9 -0
- package/dist/compiler/config/schemas/paths.js +12 -0
- package/dist/compiler/config/schemas/transport/http.d.ts +82 -0
- package/dist/compiler/config/schemas/transport/http.js +33 -0
- package/dist/compiler/config/schemas/transport/stdio.d.ts +9 -0
- package/dist/compiler/config/schemas/transport/stdio.js +15 -0
- package/dist/compiler/config/schemas/webpack.d.ts +3 -0
- package/dist/compiler/config/schemas/webpack.js +15 -0
- package/dist/compiler/config/types.d.ts +1 -0
- package/dist/compiler/config/types.js +2 -0
- package/dist/compiler/config/utils.d.ts +20 -0
- package/dist/compiler/config/utils.js +36 -0
- package/dist/compiler/generate-env-code.d.ts +1 -0
- package/dist/compiler/generate-env-code.js +8 -0
- package/dist/compiler/generate-import-code.d.ts +1 -0
- package/dist/compiler/generate-import-code.js +24 -0
- package/dist/compiler/get-webpack-config/get-entries.d.ts +3 -0
- package/dist/compiler/get-webpack-config/get-entries.js +29 -0
- package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
- package/dist/compiler/get-webpack-config/get-externals.js +88 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.d.ts +8 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.js +25 -0
- package/dist/compiler/get-webpack-config/index.d.ts +4 -0
- package/dist/compiler/get-webpack-config/index.js +101 -0
- package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
- package/dist/compiler/get-webpack-config/plugins.js +132 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.d.ts +9 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.js +40 -0
- package/dist/compiler/index.d.ts +6 -0
- package/dist/compiler/index.js +194 -0
- package/dist/compiler/on-first-build.d.ts +3 -0
- package/dist/compiler/on-first-build.js +58 -0
- package/dist/compiler/parse-xmcp-config.d.ts +9 -0
- package/dist/compiler/parse-xmcp-config.js +155 -0
- package/dist/compiler/start-http-server.d.ts +1 -0
- package/dist/compiler/start-http-server.js +34 -0
- package/dist/index.d.ts +12 -54
- package/dist/index.js +22 -190
- package/dist/index.js.LICENSE.txt +49 -0
- package/dist/runtime/__tests__/audit.test.d.ts +4 -0
- package/dist/runtime/__tests__/audit.test.js +328 -0
- package/dist/runtime/__tests__/identity.test.d.ts +4 -0
- package/dist/runtime/__tests__/identity.test.js +164 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +4 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.js +372 -0
- package/dist/runtime/__tests__/proof.test.d.ts +4 -0
- package/dist/runtime/__tests__/proof.test.js +302 -0
- package/dist/runtime/__tests__/session.test.d.ts +4 -0
- package/dist/runtime/__tests__/session.test.js +254 -0
- package/dist/runtime/__tests__/well-known.test.d.ts +4 -0
- package/dist/runtime/__tests__/well-known.test.js +312 -0
- package/dist/runtime/adapter-express.js +2 -0
- package/dist/runtime/adapter-express.js.LICENSE.txt +252 -0
- package/dist/runtime/adapter-nextjs.js +2 -0
- package/dist/runtime/adapter-nextjs.js.LICENSE.txt +53 -0
- package/dist/runtime/adapters/express/index.d.ts +2 -0
- package/dist/runtime/adapters/express/index.js +48 -0
- package/dist/runtime/adapters/nextjs/index.d.ts +8 -0
- package/dist/runtime/adapters/nextjs/index.js +18 -0
- package/dist/runtime/audit.d.ts +93 -0
- package/dist/runtime/audit.js +212 -0
- package/dist/runtime/debug.d.ts +118 -0
- package/dist/runtime/debug.js +612 -0
- package/dist/runtime/delegation-hooks.d.ts +85 -0
- package/dist/runtime/delegation-hooks.js +116 -0
- package/dist/runtime/demo.d.ts +71 -0
- package/dist/runtime/demo.js +135 -0
- package/dist/runtime/headers.d.ts +1 -0
- package/dist/runtime/headers.js +9 -0
- package/dist/runtime/http.js +2 -0
- package/dist/runtime/http.js.LICENSE.txt +252 -0
- package/dist/runtime/identity.d.ts +105 -0
- package/dist/runtime/identity.js +232 -0
- package/dist/runtime/index.d.ts +16 -0
- package/dist/runtime/index.js +56 -0
- package/dist/runtime/mcpi-runtime.d.ts +164 -0
- package/dist/runtime/mcpi-runtime.js +352 -0
- package/dist/runtime/proof.d.ts +87 -0
- package/dist/runtime/proof.js +223 -0
- package/dist/runtime/session.d.ts +88 -0
- package/dist/runtime/session.js +216 -0
- package/dist/runtime/stdio.js +2 -0
- package/dist/runtime/stdio.js.LICENSE.txt +1 -0
- package/dist/runtime/templates/home.d.ts +2 -0
- package/dist/runtime/templates/home.js +50 -0
- package/dist/runtime/transports/http/base-streamable-http.d.ts +25 -0
- package/dist/runtime/transports/http/base-streamable-http.js +16 -0
- package/dist/runtime/transports/http/http-context.d.ts +9 -0
- package/dist/runtime/transports/http/http-context.js +8 -0
- package/dist/runtime/transports/http/index.d.ts +1 -0
- package/dist/runtime/transports/http/index.js +55 -0
- package/dist/runtime/transports/http/setup-cors.d.ts +4 -0
- package/dist/runtime/transports/http/setup-cors.js +24 -0
- package/dist/runtime/transports/http/stateless-streamable-http.d.ts +39 -0
- package/dist/runtime/transports/http/stateless-streamable-http.js +331 -0
- package/dist/runtime/transports/stdio/index.d.ts +1 -0
- package/dist/runtime/transports/stdio/index.js +51 -0
- package/dist/runtime/utils/server.d.ts +42 -0
- package/dist/runtime/utils/server.js +39 -0
- package/dist/runtime/utils/tools.d.ts +8 -0
- package/dist/runtime/utils/tools.js +115 -0
- package/dist/runtime/verifier-middleware.d.ts +76 -0
- package/dist/runtime/verifier-middleware.js +322 -0
- package/dist/runtime/well-known.d.ts +151 -0
- package/dist/runtime/well-known.js +258 -0
- package/dist/storage/config.d.ts +28 -0
- package/dist/storage/config.js +79 -0
- package/dist/storage/delegation.d.ts +59 -0
- package/dist/storage/delegation.js +130 -0
- package/dist/storage/merkle-verifier.d.ts +84 -0
- package/dist/storage/merkle-verifier.js +261 -0
- package/dist/test/__tests__/nonce-cache-integration.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache-integration.test.js +116 -0
- package/dist/test/__tests__/nonce-cache.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache.test.js +122 -0
- package/dist/test/__tests__/runtime-integration.test.d.ts +4 -0
- package/dist/test/__tests__/runtime-integration.test.js +192 -0
- package/dist/test/__tests__/test-infrastructure.test.d.ts +4 -0
- package/dist/test/__tests__/test-infrastructure.test.js +178 -0
- package/dist/test/deterministic-keys.d.ts +31 -0
- package/dist/test/deterministic-keys.js +108 -0
- package/dist/test/examples/test-usage-example.d.ts +140 -0
- package/dist/test/examples/test-usage-example.js +175 -0
- package/dist/test/index.d.ts +11 -0
- package/dist/test/index.js +27 -0
- package/dist/test/local-verification.d.ts +28 -0
- package/dist/test/local-verification.js +342 -0
- package/dist/test/mock-identity-provider.d.ts +96 -0
- package/dist/test/mock-identity-provider.js +243 -0
- package/dist/test/runtime-integration.d.ts +63 -0
- package/dist/test/runtime-integration.js +140 -0
- package/dist/test/test-environment.d.ts +26 -0
- package/dist/test/test-environment.js +50 -0
- package/dist/types/declarations.d.ts +1 -0
- package/dist/types/declarations.js +6 -0
- package/dist/types/middleware.d.ts +2 -0
- package/dist/types/middleware.js +2 -0
- package/dist/types/tool.d.ts +80 -0
- package/dist/types/tool.js +2 -0
- package/dist/utils/cli-icons.d.ts +3 -0
- package/dist/utils/cli-icons.js +7 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +13 -0
- package/dist/utils/context.d.ts +33 -0
- package/dist/utils/context.js +58 -0
- package/dist/utils/file-watcher.d.ts +19 -0
- package/dist/utils/file-watcher.js +49 -0
- package/dist/utils/fs-utils.d.ts +2 -0
- package/dist/utils/fs-utils.js +22 -0
- package/dist/utils/path-validation.d.ts +3 -0
- package/dist/utils/path-validation.js +56 -0
- package/dist/utils/spawn-process.d.ts +9 -0
- package/dist/utils/spawn-process.js +50 -0
- package/dist/utils/subscribable.d.ts +12 -0
- package/dist/utils/subscribable.js +44 -0
- package/package.json +99 -21
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* bytes
|
|
3
|
+
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
4
|
+
* Copyright(c) 2015 Jed Watson
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*!
|
|
9
|
+
* content-type
|
|
10
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
11
|
+
* MIT Licensed
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/*!
|
|
15
|
+
* depd
|
|
16
|
+
* Copyright(c) 2014-2018 Douglas Christopher Wilson
|
|
17
|
+
* MIT Licensed
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/*!
|
|
21
|
+
* http-errors
|
|
22
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
23
|
+
* Copyright(c) 2016 Douglas Christopher Wilson
|
|
24
|
+
* MIT Licensed
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/*!
|
|
28
|
+
* raw-body
|
|
29
|
+
* Copyright(c) 2013-2014 Jonathan Ong
|
|
30
|
+
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
|
31
|
+
* MIT Licensed
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/*!
|
|
35
|
+
* statuses
|
|
36
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
37
|
+
* Copyright(c) 2016 Douglas Christopher Wilson
|
|
38
|
+
* MIT Licensed
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/*!
|
|
42
|
+
* toidentifier
|
|
43
|
+
* Copyright(c) 2016 Douglas Christopher Wilson
|
|
44
|
+
* MIT Licensed
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/*!
|
|
48
|
+
* unpipe
|
|
49
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
50
|
+
* MIT Licensed
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.xmcpHandler = xmcpHandler;
|
|
4
|
+
const server_1 = require("../../utils/server");
|
|
5
|
+
const stateless_streamable_http_1 = require("../../transports/http/stateless-streamable-http");
|
|
6
|
+
const setup_cors_1 = require("../../transports/http/setup-cors");
|
|
7
|
+
const http_context_1 = require("../../transports/http/http-context");
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
// HTTP config injected by compiler
|
|
10
|
+
// @ts-expect-error: injected by compiler
|
|
11
|
+
const httpConfig = HTTP_CONFIG;
|
|
12
|
+
// CORS config injected by compiler
|
|
13
|
+
// @ts-expect-error: injected by compiler
|
|
14
|
+
const corsConfig = HTTP_CORS_CONFIG;
|
|
15
|
+
async function xmcpHandler(req, res) {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
const id = (0, node_crypto_1.randomUUID)();
|
|
18
|
+
(0, http_context_1.httpContextProvider)({ id, headers: req.headers }, async () => {
|
|
19
|
+
try {
|
|
20
|
+
(0, setup_cors_1.setResponseCorsHeaders)(corsConfig, res);
|
|
21
|
+
const server = await (0, server_1.createServer)();
|
|
22
|
+
const transport = new stateless_streamable_http_1.StatelessHttpServerTransport(httpConfig.debug, httpConfig.bodySizeLimit || "10mb");
|
|
23
|
+
// cleanup when request/connection closes
|
|
24
|
+
res.on("close", () => {
|
|
25
|
+
transport.close();
|
|
26
|
+
server.close();
|
|
27
|
+
});
|
|
28
|
+
await server.connect(transport);
|
|
29
|
+
await transport.handleRequest(req, res, req.body).then(() => {
|
|
30
|
+
resolve(res);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error("[HTTP-server] Error handling MCP request:", error);
|
|
35
|
+
if (!res.headersSent) {
|
|
36
|
+
res.status(500).json({
|
|
37
|
+
jsonrpc: "2.0",
|
|
38
|
+
error: {
|
|
39
|
+
code: -32603,
|
|
40
|
+
message: "Internal server error",
|
|
41
|
+
},
|
|
42
|
+
id: null,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { experimental_withMcpAuth as withMcpAuth } from "@vercel/mcp-adapter";
|
|
2
|
+
export declare function xmcpHandler(request: Request): Promise<Response>;
|
|
3
|
+
export type VerifyToken = Parameters<typeof withMcpAuth>[1];
|
|
4
|
+
export type Options = Parameters<typeof withMcpAuth>[2];
|
|
5
|
+
export type AuthConfig = Options & {
|
|
6
|
+
verifyToken: VerifyToken;
|
|
7
|
+
};
|
|
8
|
+
export declare function withAuth(handler: (request: Request) => Promise<Response>, config: AuthConfig): (request: Request) => Promise<Response>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.xmcpHandler = xmcpHandler;
|
|
4
|
+
exports.withAuth = withAuth;
|
|
5
|
+
const mcp_adapter_1 = require("@vercel/mcp-adapter");
|
|
6
|
+
const server_1 = require("../../utils/server");
|
|
7
|
+
async function xmcpHandler(request) {
|
|
8
|
+
const [toolPromises, toolModules] = (0, server_1.loadTools)();
|
|
9
|
+
await Promise.all(toolPromises);
|
|
10
|
+
const requestHandler = (0, mcp_adapter_1.createMcpHandler)((server) => {
|
|
11
|
+
(0, server_1.configureServer)(server, toolModules);
|
|
12
|
+
}, server_1.INJECTED_CONFIG);
|
|
13
|
+
return requestHandler(request);
|
|
14
|
+
}
|
|
15
|
+
function withAuth(handler, config) {
|
|
16
|
+
const { verifyToken, ...options } = config;
|
|
17
|
+
return (0, mcp_adapter_1.experimental_withMcpAuth)(handler, verifyToken, options);
|
|
18
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Logging System for XMCP-I Runtime
|
|
3
|
+
*
|
|
4
|
+
* Handles audit record generation and logging with frozen format
|
|
5
|
+
* according to requirements 5.4, 5.5.
|
|
6
|
+
*/
|
|
7
|
+
import { AuditRecord } from "@kya-os/contracts/proof";
|
|
8
|
+
import { SessionContext } from "@kya-os/contracts/handshake";
|
|
9
|
+
import { AgentIdentity } from "./identity";
|
|
10
|
+
/**
|
|
11
|
+
* Audit logging configuration
|
|
12
|
+
*/
|
|
13
|
+
export interface AuditConfig {
|
|
14
|
+
enabled?: boolean;
|
|
15
|
+
logFunction?: (record: string) => void;
|
|
16
|
+
includePayloads?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Audit context for logging
|
|
20
|
+
*/
|
|
21
|
+
export interface AuditContext {
|
|
22
|
+
identity: AgentIdentity;
|
|
23
|
+
session: SessionContext;
|
|
24
|
+
requestHash: string;
|
|
25
|
+
responseHash: string;
|
|
26
|
+
verified: "yes" | "no";
|
|
27
|
+
scopeId?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Audit logger class
|
|
31
|
+
*/
|
|
32
|
+
export declare class AuditLogger {
|
|
33
|
+
private config;
|
|
34
|
+
private sessionAuditLog;
|
|
35
|
+
constructor(config?: AuditConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Emit audit record on first call per session
|
|
38
|
+
* Requirements: 5.4, 5.5
|
|
39
|
+
*/
|
|
40
|
+
logAuditRecord(context: AuditContext): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Format audit record as frozen audit line
|
|
43
|
+
* Format: audit.v1 ts=<unix> session=<id> audience=<host> did=<did> kid=<kid> reqHash=<sha256:..> resHash=<sha256:..> verified=yes|no scope=<scopeId|->
|
|
44
|
+
*/
|
|
45
|
+
private formatAuditLine;
|
|
46
|
+
/**
|
|
47
|
+
* Clear session audit log (useful for testing)
|
|
48
|
+
*/
|
|
49
|
+
clearSessionLog(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get audit statistics
|
|
52
|
+
*/
|
|
53
|
+
getStats(): {
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
sessionsLogged: number;
|
|
56
|
+
includePayloads: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Update configuration
|
|
60
|
+
*/
|
|
61
|
+
updateConfig(config: Partial<AuditConfig>): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Key rotation audit logging
|
|
65
|
+
*/
|
|
66
|
+
export interface KeyRotationAuditContext {
|
|
67
|
+
identity: AgentIdentity;
|
|
68
|
+
oldKeyId: string;
|
|
69
|
+
newKeyId: string;
|
|
70
|
+
mode: "dev" | "prod";
|
|
71
|
+
delegated: "yes" | "no";
|
|
72
|
+
force: "yes" | "no";
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Log key rotation audit record
|
|
76
|
+
* Format: keys.rotate.v1 ts=<unix> did=<did> oldKid=<kid> newKid=<kid> mode=dev|prod delegated=yes|no force=yes|no
|
|
77
|
+
*/
|
|
78
|
+
export declare function logKeyRotationAudit(context: KeyRotationAuditContext, logFunction?: (record: string) => void): void;
|
|
79
|
+
/**
|
|
80
|
+
* Default audit logger instance
|
|
81
|
+
*/
|
|
82
|
+
export declare const defaultAuditLogger: AuditLogger;
|
|
83
|
+
/**
|
|
84
|
+
* Utility functions
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Parse audit line back to record (for testing/analysis)
|
|
88
|
+
*/
|
|
89
|
+
export declare function parseAuditLine(line: string): AuditRecord | null;
|
|
90
|
+
/**
|
|
91
|
+
* Validate audit record format
|
|
92
|
+
*/
|
|
93
|
+
export declare function validateAuditRecord(record: any): record is AuditRecord;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Audit Logging System for XMCP-I Runtime
|
|
4
|
+
*
|
|
5
|
+
* Handles audit record generation and logging with frozen format
|
|
6
|
+
* according to requirements 5.4, 5.5.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.defaultAuditLogger = exports.AuditLogger = void 0;
|
|
10
|
+
exports.logKeyRotationAudit = logKeyRotationAudit;
|
|
11
|
+
exports.parseAuditLine = parseAuditLine;
|
|
12
|
+
exports.validateAuditRecord = validateAuditRecord;
|
|
13
|
+
/**
|
|
14
|
+
* Audit logger class
|
|
15
|
+
*/
|
|
16
|
+
class AuditLogger {
|
|
17
|
+
config;
|
|
18
|
+
sessionAuditLog = new Set(); // Track first call per session
|
|
19
|
+
constructor(config = {}) {
|
|
20
|
+
this.config = {
|
|
21
|
+
enabled: true,
|
|
22
|
+
logFunction: console.log,
|
|
23
|
+
includePayloads: false, // Keep identity/proof data out by default
|
|
24
|
+
...config,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Emit audit record on first call per session
|
|
29
|
+
* Requirements: 5.4, 5.5
|
|
30
|
+
*/
|
|
31
|
+
async logAuditRecord(context) {
|
|
32
|
+
if (!this.config.enabled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// Check if this is the first call for this session
|
|
36
|
+
const sessionKey = `${context.session.sessionId}:${context.session.audience}`;
|
|
37
|
+
if (this.sessionAuditLog.has(sessionKey)) {
|
|
38
|
+
return; // Already logged for this session
|
|
39
|
+
}
|
|
40
|
+
// Mark session as logged
|
|
41
|
+
this.sessionAuditLog.add(sessionKey);
|
|
42
|
+
// Create audit record
|
|
43
|
+
const auditRecord = {
|
|
44
|
+
version: "audit.v1",
|
|
45
|
+
ts: Math.floor(Date.now() / 1000),
|
|
46
|
+
session: context.session.sessionId,
|
|
47
|
+
audience: context.session.audience,
|
|
48
|
+
did: context.identity.did,
|
|
49
|
+
kid: context.identity.keyId,
|
|
50
|
+
reqHash: context.requestHash,
|
|
51
|
+
resHash: context.responseHash,
|
|
52
|
+
verified: context.verified,
|
|
53
|
+
scope: context.scopeId || "-", // Use "-" for no scope
|
|
54
|
+
};
|
|
55
|
+
// Format as frozen audit line
|
|
56
|
+
const auditLine = this.formatAuditLine(auditRecord);
|
|
57
|
+
// Emit audit record
|
|
58
|
+
this.config.logFunction(auditLine);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Format audit record as frozen audit line
|
|
62
|
+
* Format: audit.v1 ts=<unix> session=<id> audience=<host> did=<did> kid=<kid> reqHash=<sha256:..> resHash=<sha256:..> verified=yes|no scope=<scopeId|->
|
|
63
|
+
*/
|
|
64
|
+
formatAuditLine(record) {
|
|
65
|
+
const fields = [
|
|
66
|
+
`${record.version}`,
|
|
67
|
+
`ts=${record.ts}`,
|
|
68
|
+
`session=${record.session}`,
|
|
69
|
+
`audience=${record.audience}`,
|
|
70
|
+
`did=${record.did}`,
|
|
71
|
+
`kid=${record.kid}`,
|
|
72
|
+
`reqHash=${record.reqHash}`,
|
|
73
|
+
`resHash=${record.resHash}`,
|
|
74
|
+
`verified=${record.verified}`,
|
|
75
|
+
`scope=${record.scope}`,
|
|
76
|
+
];
|
|
77
|
+
return fields.join(" ");
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Clear session audit log (useful for testing)
|
|
81
|
+
*/
|
|
82
|
+
clearSessionLog() {
|
|
83
|
+
this.sessionAuditLog.clear();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get audit statistics
|
|
87
|
+
*/
|
|
88
|
+
getStats() {
|
|
89
|
+
return {
|
|
90
|
+
enabled: this.config.enabled,
|
|
91
|
+
sessionsLogged: this.sessionAuditLog.size,
|
|
92
|
+
includePayloads: this.config.includePayloads,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Update configuration
|
|
97
|
+
*/
|
|
98
|
+
updateConfig(config) {
|
|
99
|
+
this.config = { ...this.config, ...config };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.AuditLogger = AuditLogger;
|
|
103
|
+
/**
|
|
104
|
+
* Log key rotation audit record
|
|
105
|
+
* Format: keys.rotate.v1 ts=<unix> did=<did> oldKid=<kid> newKid=<kid> mode=dev|prod delegated=yes|no force=yes|no
|
|
106
|
+
*/
|
|
107
|
+
function logKeyRotationAudit(context, logFunction = console.log) {
|
|
108
|
+
const fields = [
|
|
109
|
+
"keys.rotate.v1",
|
|
110
|
+
`ts=${Math.floor(Date.now() / 1000)}`,
|
|
111
|
+
`did=${context.identity.did}`,
|
|
112
|
+
`oldKid=${context.oldKeyId}`,
|
|
113
|
+
`newKid=${context.newKeyId}`,
|
|
114
|
+
`mode=${context.mode}`,
|
|
115
|
+
`delegated=${context.delegated}`,
|
|
116
|
+
`force=${context.force}`,
|
|
117
|
+
];
|
|
118
|
+
const auditLine = fields.join(" ");
|
|
119
|
+
logFunction(auditLine);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Default audit logger instance
|
|
123
|
+
*/
|
|
124
|
+
exports.defaultAuditLogger = new AuditLogger();
|
|
125
|
+
/**
|
|
126
|
+
* Utility functions
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* Parse audit line back to record (for testing/analysis)
|
|
130
|
+
*/
|
|
131
|
+
function parseAuditLine(line) {
|
|
132
|
+
try {
|
|
133
|
+
const parts = line.split(" ");
|
|
134
|
+
if (parts.length < 10 || !parts[0].startsWith("audit.v")) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const record = {
|
|
138
|
+
version: parts[0],
|
|
139
|
+
};
|
|
140
|
+
// Parse key=value pairs
|
|
141
|
+
for (let i = 1; i < parts.length; i++) {
|
|
142
|
+
const [key, value] = parts[i].split("=", 2);
|
|
143
|
+
if (!key || value === undefined)
|
|
144
|
+
continue;
|
|
145
|
+
switch (key) {
|
|
146
|
+
case "ts":
|
|
147
|
+
record.ts = parseInt(value, 10);
|
|
148
|
+
break;
|
|
149
|
+
case "session":
|
|
150
|
+
record.session = value;
|
|
151
|
+
break;
|
|
152
|
+
case "audience":
|
|
153
|
+
record.audience = value;
|
|
154
|
+
break;
|
|
155
|
+
case "did":
|
|
156
|
+
record.did = value;
|
|
157
|
+
break;
|
|
158
|
+
case "kid":
|
|
159
|
+
record.kid = value;
|
|
160
|
+
break;
|
|
161
|
+
case "reqHash":
|
|
162
|
+
record.reqHash = value;
|
|
163
|
+
break;
|
|
164
|
+
case "resHash":
|
|
165
|
+
record.resHash = value;
|
|
166
|
+
break;
|
|
167
|
+
case "verified":
|
|
168
|
+
record.verified = value;
|
|
169
|
+
break;
|
|
170
|
+
case "scope":
|
|
171
|
+
record.scope = value;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Validate required fields
|
|
176
|
+
if (record.version &&
|
|
177
|
+
record.ts &&
|
|
178
|
+
record.session &&
|
|
179
|
+
record.audience &&
|
|
180
|
+
record.did &&
|
|
181
|
+
record.kid &&
|
|
182
|
+
record.reqHash &&
|
|
183
|
+
record.resHash &&
|
|
184
|
+
record.verified &&
|
|
185
|
+
record.scope !== undefined) {
|
|
186
|
+
return record;
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Validate audit record format
|
|
196
|
+
*/
|
|
197
|
+
function validateAuditRecord(record) {
|
|
198
|
+
return (typeof record === "object" &&
|
|
199
|
+
record !== null &&
|
|
200
|
+
record.version === "audit.v1" &&
|
|
201
|
+
typeof record.ts === "number" &&
|
|
202
|
+
typeof record.session === "string" &&
|
|
203
|
+
typeof record.audience === "string" &&
|
|
204
|
+
typeof record.did === "string" &&
|
|
205
|
+
typeof record.kid === "string" &&
|
|
206
|
+
typeof record.reqHash === "string" &&
|
|
207
|
+
record.reqHash.startsWith("sha256:") &&
|
|
208
|
+
typeof record.resHash === "string" &&
|
|
209
|
+
record.resHash.startsWith("sha256:") &&
|
|
210
|
+
(record.verified === "yes" || record.verified === "no") &&
|
|
211
|
+
typeof record.scope === "string");
|
|
212
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XMCP-I Debug Tools - Development-only debug endpoints
|
|
3
|
+
*
|
|
4
|
+
* Provides /verify endpoint for proof inspection and debugging
|
|
5
|
+
* in development environments only.
|
|
6
|
+
*/
|
|
7
|
+
import { AgentIdentity } from "./identity";
|
|
8
|
+
import { SessionContext } from "@kya-os/contracts/handshake";
|
|
9
|
+
import { DetachedProof, ProofMeta } from "@kya-os/contracts/proof";
|
|
10
|
+
import { DIDDocument, AgentDocument } from "./well-known";
|
|
11
|
+
/**
|
|
12
|
+
* Debug verification result
|
|
13
|
+
*/
|
|
14
|
+
export interface DebugVerificationResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
signature: {
|
|
17
|
+
valid: boolean;
|
|
18
|
+
algorithm: string;
|
|
19
|
+
keyId: string;
|
|
20
|
+
};
|
|
21
|
+
proof: {
|
|
22
|
+
valid: boolean;
|
|
23
|
+
timestamp: {
|
|
24
|
+
valid: boolean;
|
|
25
|
+
skew: number;
|
|
26
|
+
remediation?: string;
|
|
27
|
+
};
|
|
28
|
+
hashes: {
|
|
29
|
+
requestValid: boolean;
|
|
30
|
+
responseValid: boolean;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
session: {
|
|
34
|
+
valid: boolean;
|
|
35
|
+
expired: boolean;
|
|
36
|
+
ttl: number;
|
|
37
|
+
};
|
|
38
|
+
errors?: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Debug page data structure
|
|
42
|
+
*/
|
|
43
|
+
export interface DebugPageData {
|
|
44
|
+
identity: {
|
|
45
|
+
did: string;
|
|
46
|
+
keyId: string;
|
|
47
|
+
didDocumentUrl: string;
|
|
48
|
+
};
|
|
49
|
+
registry: {
|
|
50
|
+
ktaUrl: string;
|
|
51
|
+
mcpMirrorStatus: "pending" | "success" | "error" | "unknown";
|
|
52
|
+
mcpMirrorUrl?: string;
|
|
53
|
+
};
|
|
54
|
+
capabilities: {
|
|
55
|
+
protocol: string[];
|
|
56
|
+
identity: string[];
|
|
57
|
+
source: "well-known" | "handshake";
|
|
58
|
+
};
|
|
59
|
+
proof?: {
|
|
60
|
+
jws: string;
|
|
61
|
+
meta: ProofMeta;
|
|
62
|
+
canonicalHashes: {
|
|
63
|
+
requestHash: string;
|
|
64
|
+
responseHash: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
verification?: DebugVerificationResult;
|
|
68
|
+
logRoot?: string;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
environment: "development" | "production";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Debug endpoint manager
|
|
74
|
+
*/
|
|
75
|
+
export declare class DebugManager {
|
|
76
|
+
private identity;
|
|
77
|
+
private environment;
|
|
78
|
+
private lastProof?;
|
|
79
|
+
private lastSession?;
|
|
80
|
+
private logRoot?;
|
|
81
|
+
constructor(identity: AgentIdentity, environment?: "development" | "production");
|
|
82
|
+
/**
|
|
83
|
+
* Update debug state with latest proof and session
|
|
84
|
+
*/
|
|
85
|
+
updateDebugState(proof: DetachedProof, session: SessionContext): void;
|
|
86
|
+
/**
|
|
87
|
+
* Set log root for receipt verification
|
|
88
|
+
*/
|
|
89
|
+
setLogRoot(logRoot: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Generate debug page data
|
|
92
|
+
*/
|
|
93
|
+
generateDebugPageData(_didDocument?: DIDDocument, agentDocument?: AgentDocument, logRoot?: string): Promise<DebugPageData>;
|
|
94
|
+
/**
|
|
95
|
+
* Create debug endpoint handler
|
|
96
|
+
*/
|
|
97
|
+
createDebugHandler(): (_request: any) => Promise<Response>;
|
|
98
|
+
/**
|
|
99
|
+
* Perform local verification of proof
|
|
100
|
+
*/
|
|
101
|
+
private performLocalVerification;
|
|
102
|
+
/**
|
|
103
|
+
* Generate DID document URL
|
|
104
|
+
*/
|
|
105
|
+
private generateDIDDocumentUrl;
|
|
106
|
+
/**
|
|
107
|
+
* Generate KTA URL
|
|
108
|
+
*/
|
|
109
|
+
private generateKTAUrl;
|
|
110
|
+
/**
|
|
111
|
+
* Generate debug HTML page
|
|
112
|
+
*/
|
|
113
|
+
private generateDebugHTML;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create debug endpoint handler for development
|
|
117
|
+
*/
|
|
118
|
+
export declare function createDebugEndpoint(identity: AgentIdentity, environment?: "development" | "production"): DebugManager;
|