@nexart/mcp-server 0.0.0-stage → 0.2.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.
- package/CHANGELOG.md +108 -0
- package/CONTRIBUTING.md +58 -0
- package/LICENSE +202 -0
- package/NOTICE +14 -0
- package/README.md +356 -2
- package/SECURITY.md +77 -0
- package/THIRD_PARTY_NOTICES.md +111 -0
- package/dist/adapters.d.ts +16 -0
- package/dist/adapters.js +48 -0
- package/dist/approve-public.d.ts +2 -0
- package/dist/approve-public.js +65 -0
- package/dist/contracts.d.ts +48 -0
- package/dist/contracts.js +35 -0
- package/dist/create-confidential.d.ts +2 -0
- package/dist/create-confidential.js +34 -0
- package/dist/instrumentation/openai-worker.d.ts +1 -0
- package/dist/instrumentation/openai-worker.js +26 -0
- package/dist/instrumentation/openai.d.ts +51 -0
- package/dist/instrumentation/openai.js +197 -0
- package/dist/json-schema.d.ts +9 -0
- package/dist/json-schema.js +20 -0
- package/dist/limits.d.ts +15 -0
- package/dist/limits.js +62 -0
- package/dist/lookup/contracts.d.ts +38 -0
- package/dist/lookup/contracts.js +23 -0
- package/dist/lookup/verify.d.ts +54 -0
- package/dist/lookup/verify.js +110 -0
- package/dist/network/client.d.ts +26 -0
- package/dist/network/client.js +188 -0
- package/dist/network/contracts.d.ts +104 -0
- package/dist/network/contracts.js +54 -0
- package/dist/network-tools.d.ts +5 -0
- package/dist/network-tools.js +32 -0
- package/dist/owner/create.d.ts +52 -0
- package/dist/owner/create.js +117 -0
- package/dist/owner/custody.d.ts +36 -0
- package/dist/owner/custody.js +210 -0
- package/dist/owner/host.d.ts +10 -0
- package/dist/owner/host.js +70 -0
- package/dist/owner/publisher.d.ts +21 -0
- package/dist/owner/publisher.js +27 -0
- package/dist/owner/reconcile.d.ts +16 -0
- package/dist/owner/reconcile.js +109 -0
- package/dist/protocol-safety.d.ts +3 -0
- package/dist/protocol-safety.js +16 -0
- package/dist/receipts/contracts.d.ts +72 -0
- package/dist/receipts/contracts.js +34 -0
- package/dist/receipts/verify.d.ts +4 -0
- package/dist/receipts/verify.js +104 -0
- package/dist/record/contracts.d.ts +323 -0
- package/dist/record/contracts.js +75 -0
- package/dist/record/customer.d.ts +40 -0
- package/dist/record/customer.js +99 -0
- package/dist/record/policy.d.ts +46 -0
- package/dist/record/policy.js +67 -0
- package/dist/record/publication.d.ts +23 -0
- package/dist/record/publication.js +148 -0
- package/dist/record/record.d.ts +15 -0
- package/dist/record/record.js +97 -0
- package/dist/record/state.d.ts +44 -0
- package/dist/record/state.js +84 -0
- package/dist/record-tools.d.ts +13 -0
- package/dist/record-tools.js +95 -0
- package/dist/recover-confidential.d.ts +2 -0
- package/dist/recover-confidential.js +13 -0
- package/dist/results.d.ts +8 -0
- package/dist/results.js +83 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +39 -0
- package/dist/stdio.d.ts +2 -0
- package/dist/stdio.js +88 -0
- package/dist/trust/lifecycle.d.ts +13 -0
- package/dist/trust/lifecycle.js +42 -0
- package/dist/trust/policy.d.ts +14 -0
- package/dist/trust/policy.js +6 -0
- package/dist/verify.d.ts +3 -0
- package/dist/verify.js +56 -0
- package/dist/write/approval.d.ts +5 -0
- package/dist/write/approval.js +95 -0
- package/dist/write/attest.d.ts +17 -0
- package/dist/write/attest.js +141 -0
- package/dist/write/config.d.ts +11 -0
- package/dist/write/config.js +12 -0
- package/dist/write/contracts.d.ts +229 -0
- package/dist/write/contracts.js +61 -0
- package/dist/write/post.d.ts +11 -0
- package/dist/write/post.js +105 -0
- package/dist/write/profile.d.ts +19 -0
- package/dist/write/profile.js +114 -0
- package/dist/write/seal.d.ts +3 -0
- package/dist/write/seal.js +49 -0
- package/dist/write-tools.d.ts +4 -0
- package/dist/write-tools.js +36 -0
- package/docs/consumer-guide.md +133 -0
- package/docs/examples/customer-claude-desktop.json +14 -0
- package/docs/examples/customer-consent.json +15 -0
- package/docs/examples/customer-custody.json +8 -0
- package/docs/examples/customer-policy.json +43 -0
- package/package.json +58 -4
- package/server.json +20 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { ownerDirectory, readOwnerInput } from './owner/create.js';
|
|
4
|
+
import {} from './owner/custody.js';
|
|
5
|
+
import { mcpRecordInput, recordDiscoveryInput, recordOutput } from './record/contracts.js';
|
|
6
|
+
import { recordExecution } from './record/record.js';
|
|
7
|
+
import { createCustomerPublisher } from './record/customer.js';
|
|
8
|
+
import { writeConfig } from './write/config.js';
|
|
9
|
+
const custodyConfig = z.strictObject({
|
|
10
|
+
version: z.literal(1), directory: z.string().min(1), ageExecutable: z.string().min(1),
|
|
11
|
+
recipient: z.string().min(1), ownerApproved: z.literal(true), decryptionIdentityExcluded: z.literal(true),
|
|
12
|
+
});
|
|
13
|
+
const hostedDiscovery = recordDiscoveryInput.omit({ bundle: true }).extend({
|
|
14
|
+
kind: z.literal('execution'),
|
|
15
|
+
execution: recordDiscoveryInput.shape.execution.unwrap(),
|
|
16
|
+
createdAt: recordDiscoveryInput.shape.createdAt.unwrap(),
|
|
17
|
+
certification: z.strictObject({
|
|
18
|
+
mode: z.literal('node').default('node'), visibility: z.enum(['public', 'private']).optional(),
|
|
19
|
+
}).optional(),
|
|
20
|
+
});
|
|
21
|
+
// Constant guidance only: never interpolate credentials, arguments or paths.
|
|
22
|
+
const SETUP_MESSAGES = Object.freeze({
|
|
23
|
+
CUSTODY_CONFIG_MISSING: 'Configure the owner-only NEXART_RECORD_CUSTODY_CONFIG JSON before execution recording.',
|
|
24
|
+
CUSTODY_CONFIG_INVALID: 'Check custody JSON, recipient, executable real path and owner-only file/directory permissions.',
|
|
25
|
+
ENCRYPTED_CUSTODY_CONFIGURATION_REQUIRED: 'Check the custody recipient, executable real path and owner-only directory permissions.',
|
|
26
|
+
AGE_VERSION_UNSUPPORTED: 'Use a stable age release at least 1.2.1 and below 2.0.0, with an optional leading v in version output.',
|
|
27
|
+
AGE_VERSION_CHECK_FAILED: 'The age version command failed or timed out. Check the locally configured executable.',
|
|
28
|
+
OWNER_PUBLISHER_SETUP_REQUIRED: 'Configure NEXART_RECORD_CERTIFICATION_CONFIG and explicitly approve customer delegation. A key alone does not enable certification.',
|
|
29
|
+
CUSTOMER_CERTIFICATION_CONFIG_INVALID: 'Check the versioned customer consent JSON, absolute paths and owner-only file/directory permissions.',
|
|
30
|
+
CUSTOMER_CONSENT_REQUIRED: 'The owner must review and enable automatic submissions, public disclosure and quota acknowledgements in local configuration.',
|
|
31
|
+
CUSTOMER_CONSENT_EXPIRED_OR_REVOKED: 'Customer consent is expired or revoked. Only the owner should decide whether to renew it.',
|
|
32
|
+
CUSTOMER_CONSENT_CHANGED: 'Consent changed during this transaction. Inspect the retained attempt before taking further action; do not retry automatically.',
|
|
33
|
+
NODE_CREDENTIAL_UNAVAILABLE: 'Configure the customer-owned NEXART_NODE_API_KEY locally. Never paste a key into chat or tool arguments.',
|
|
34
|
+
NODE_AUTH_REJECTED: 'The Node rejected authentication. Check or rotate the customer key locally and update the policy fingerprint. Do not repeat this attempted CER.',
|
|
35
|
+
POLICY_AUTHORIZATION_DENIED: 'Check owner policy expiry, revocation, context and credential fingerprint. Do not broaden policy automatically.',
|
|
36
|
+
POLICY_PROFILE_DENIED: 'Evidence is not eligible under the approved disclosure profile. Do not strip or reseal fields to force submission.',
|
|
37
|
+
POLICY_DISCLOSURE_DENIED: 'Readable fields exceed the owner-approved disclosure allowlist. The owner must review the disclosure.',
|
|
38
|
+
POLICY_IDENTITY_DENIED: 'Producer identity disclosure has not been approved by the owner.',
|
|
39
|
+
POLICY_PROTECTION_REQUIRED: 'Required confidential content protection is missing. No submission was authorized.',
|
|
40
|
+
PUBLISHER_LOCAL_BUDGET_EXHAUSTED: 'The local attempt allowance is exhausted. Stop for owner review; this is not a Node account-wide quota measurement.',
|
|
41
|
+
ATTEMPT_RESERVATION_BUSY: 'A concurrent or stale attempt lock blocks submission. Owner inspection is required; do not clear it automatically.',
|
|
42
|
+
ATTEMPT_REQUIRES_OWNER_RECONCILIATION: 'An attempt already exists or its outcome is uncertain. Use owner-authorized GET reconciliation; do not repeat POST.',
|
|
43
|
+
NODE_QUOTA_OR_RATE_LIMITED: 'The Node returned a quota or rate-limit response. No remaining balance is known and no automatic retry will occur.',
|
|
44
|
+
});
|
|
45
|
+
// Keep only constant classifications, never the underlying filesystem error.
|
|
46
|
+
const custodySetupDiagnostics = new WeakMap();
|
|
47
|
+
export function recordingConfig(env = process.env) {
|
|
48
|
+
const result = { enabled: env.NEXART_ENABLE_RECORD === 'true' };
|
|
49
|
+
if (result.enabled && env.NEXART_RECORD_CERTIFICATION_CONFIG) {
|
|
50
|
+
result.publish = createCustomerPublisher(env.NEXART_RECORD_CERTIFICATION_CONFIG, writeConfig(env).apiKey).publish;
|
|
51
|
+
}
|
|
52
|
+
if (result.enabled && env.NEXART_RECORD_CUSTODY_CONFIG) {
|
|
53
|
+
try {
|
|
54
|
+
ownerDirectory(dirname(env.NEXART_RECORD_CUSTODY_CONFIG));
|
|
55
|
+
const { version: _, ...custody } = custodyConfig.parse(readOwnerInput(env.NEXART_RECORD_CUSTODY_CONFIG));
|
|
56
|
+
result.custody = custody;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
custodySetupDiagnostics.set(result, error?.code === 'ENOENT' ? 'CUSTODY_CONFIG_MISSING' : 'CUSTODY_CONFIG_INVALID');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
export function registerRecordingTool(server, config = recordingConfig()) {
|
|
65
|
+
if (!config.enabled)
|
|
66
|
+
return;
|
|
67
|
+
server.registerTool('nexart_record_execution', {
|
|
68
|
+
description: config.execute
|
|
69
|
+
? 'Create and certify a new confidential AI V2 execution using the customer API key in the HTTP Authorization header and the approved NexArt dashboard policy. May consume the customer account allowance. Existing CERs and local-only mode are unsupported on hosted HTTP. Model/provider require policy approval; other optional readable metadata is rejected. Structural IDs, timestamps, parameters, roles, SDK version, hashes and commitment descriptors remain readable. Input/output, instructions and decision references receive confidential commitments and durable age-encrypted recovery custody before submission. Producer-supplied data is not an authenticated provider observation. No plaintext/openings returned. Keep a stable executionId on retries; uncertain submissions are never automatically repeated.'
|
|
70
|
+
: 'Record producer-supplied execution data as confidential AI V2 with encrypted recovery custody, or verify an unchanged existing confidential AI V2 CER. Node/public is the default intent. Automatic submission requires customer-configured API key, explicit delegation consent and disclosure policy; may consume quota. Missing setup is reported, never silently falls back. Explicit private and local-only supported. Does not observe all host interactions or authenticate a provider call. No openings or plaintext returned. No automatic POST retries.',
|
|
71
|
+
inputSchema: config.execute ? hostedDiscovery : recordDiscoveryInput, outputSchema: recordOutput,
|
|
72
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: Boolean(config.execute || config.publish) },
|
|
73
|
+
}, async (args) => {
|
|
74
|
+
// Discovery optionality never authorizes a partial or mixed branch.
|
|
75
|
+
// Validate before reading runtime custody or calling any recording path.
|
|
76
|
+
const parsed = mcpRecordInput.safeParse(args);
|
|
77
|
+
if (!parsed.success)
|
|
78
|
+
return {
|
|
79
|
+
isError: true, content: [{ type: 'text', text: 'INVALID_RECORDING_ARGUMENTS' }],
|
|
80
|
+
};
|
|
81
|
+
// Only explicitly configured customer delegation; never tool-controlled policy.
|
|
82
|
+
const result = config.execute ? await config.execute(parsed.data) : await recordExecution(parsed.data, {
|
|
83
|
+
captureSource: 'producer_supplied', ...(config.custody ? { encryptedCustody: config.custody } : {}),
|
|
84
|
+
...(config.publish ? { publish: config.publish } : {}),
|
|
85
|
+
});
|
|
86
|
+
const diagnostic = result.reasonCode === 'APPROVED_CUSTODY_REQUIRED'
|
|
87
|
+
? custodySetupDiagnostics.get(config) ?? 'CUSTODY_CONFIG_MISSING' : result.reasonCode;
|
|
88
|
+
const guidance = SETUP_MESSAGES[diagnostic];
|
|
89
|
+
return { ...(config.execute && result.submission !== 'node_reported_accepted' ? { isError: true } : {}), content: [
|
|
90
|
+
{ type: 'text', text: JSON.stringify(result) },
|
|
91
|
+
...(guidance ? [{ type: 'text', text: `${diagnostic}: ${guidance}` }] : []),
|
|
92
|
+
], structuredContent: result };
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=record-tools.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { recoverEncrypted } from './owner/custody.js';
|
|
3
|
+
try {
|
|
4
|
+
const [directory, identityFile, ageExecutable, ...extra] = process.argv.slice(2);
|
|
5
|
+
if (!directory || !identityFile || !ageExecutable || extra.length)
|
|
6
|
+
throw Error('USAGE');
|
|
7
|
+
process.stdout.write(JSON.stringify(recoverEncrypted(directory, identityFile, ageExecutable)) + '\n');
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
process.stderr.write('OWNER_RECOVERY_FAILED: use an isolated owner session, original committed custody directory, private identity and absolute age executable. No decrypted content returned.\n');
|
|
11
|
+
process.exitCode = 1;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=recover-confidential.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolName, VerificationOutput } from './contracts.js';
|
|
2
|
+
import type { SdkOutcome } from './adapters.js';
|
|
3
|
+
export declare function baseOutput(tool: ToolName, bundle: unknown): VerificationOutput;
|
|
4
|
+
/**
|
|
5
|
+
* Deliberate disclosure allowlist, not an arbitrary result serializer.
|
|
6
|
+
* The scoped SDK `ok` remains exact; it is not Node authenticity or completeness.
|
|
7
|
+
*/
|
|
8
|
+
export declare function projectSdkResult(raw: SdkOutcome): Record<string, unknown>;
|
package/dist/results.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { isObject } from './limits.js';
|
|
2
|
+
const FAMILIES = new Set([
|
|
3
|
+
'cer.ai.execution.v1', 'cer.ai.execution.v2', 'cer.consequential.execution.v1',
|
|
4
|
+
'cer.governed.execution.v1', 'cer.project.bundle.v1',
|
|
5
|
+
]);
|
|
6
|
+
const PROTOCOLS = new Set(['1.2.0', '1.3.0', '1.3.1', 'jcs-v1']);
|
|
7
|
+
const LIMITATIONS = [
|
|
8
|
+
'Integrity verification is not proof that a reported action, model response, state or outcome occurred.',
|
|
9
|
+
'Node signatures, signer trust and cryptographic timestamps are not checked.',
|
|
10
|
+
'Completeness and automatic capture of agent actions are not established.',
|
|
11
|
+
'Confidential openings are not accepted or checked; committed plaintext is not verified.',
|
|
12
|
+
'SDK diagnostic text and evidence identifiers are redacted; reason codes and check outcomes are preserved.',
|
|
13
|
+
];
|
|
14
|
+
export function baseOutput(tool, bundle) {
|
|
15
|
+
const b = isObject(bundle) ? bundle : {};
|
|
16
|
+
const snapshot = isObject(b.snapshot) ? b.snapshot : {};
|
|
17
|
+
const protocol = snapshot.protocolVersion ?? b.protocolVersion;
|
|
18
|
+
return {
|
|
19
|
+
contractVersion: '1',
|
|
20
|
+
tool,
|
|
21
|
+
family: typeof b.bundleType === 'string' && FAMILIES.has(b.bundleType)
|
|
22
|
+
? b.bundleType : null,
|
|
23
|
+
recordVersion: b.version === '0.1' || b.version === '0.2' ? b.version : null,
|
|
24
|
+
// Governed envelopes bind JCS but do not carry snapshot.protocolVersion.
|
|
25
|
+
protocol: typeof protocol === 'string' && PROTOCOLS.has(protocol)
|
|
26
|
+
? protocol
|
|
27
|
+
: b.bundleType === 'cer.governed.execution.v1' ? 'jcs-v1' : null,
|
|
28
|
+
artifactIntegrity: 'not_performed',
|
|
29
|
+
reasonCode: 'NOT_PERFORMED',
|
|
30
|
+
sdk: null,
|
|
31
|
+
checks: {
|
|
32
|
+
nodeSignature: 'not_performed', signerTrust: 'not_established',
|
|
33
|
+
timestampCryptography: 'not_performed', confidentialOpenings: 'not_performed',
|
|
34
|
+
completeness: 'not_established',
|
|
35
|
+
},
|
|
36
|
+
limitations: [...LIMITATIONS],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Never echo SDK error text: it can contain attacker-controlled evidence. */
|
|
40
|
+
function diagnostics(value) {
|
|
41
|
+
return Array.isArray(value) ? value.map(() => 'REDACTED_DIAGNOSTIC') : [];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Deliberate disclosure allowlist, not an arbitrary result serializer.
|
|
45
|
+
* The scoped SDK `ok` remains exact; it is not Node authenticity or completeness.
|
|
46
|
+
*/
|
|
47
|
+
export function projectSdkResult(raw) {
|
|
48
|
+
const safe = {
|
|
49
|
+
ok: raw.ok, code: raw.code, errors: diagnostics(raw.errors),
|
|
50
|
+
};
|
|
51
|
+
for (const field of [
|
|
52
|
+
'assurance', 'verdict', 'projectHashValid', 'structuralValid', 'totalSteps',
|
|
53
|
+
'passedSteps', 'failedSteps', 'certificateIntegrity', 'cageSchemaValidity',
|
|
54
|
+
'causalGraphValidity', 'topologyValidation', 'resourceSafety',
|
|
55
|
+
'stateHashVerification', 'producerAuthentication', 'completeness',
|
|
56
|
+
]) {
|
|
57
|
+
if (raw[field] !== undefined)
|
|
58
|
+
safe[field] = raw[field];
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(raw.details))
|
|
61
|
+
safe.details = diagnostics(raw.details);
|
|
62
|
+
if (Array.isArray(raw.warnings))
|
|
63
|
+
safe.warnings = diagnostics(raw.warnings);
|
|
64
|
+
if (Array.isArray(raw.relaxations))
|
|
65
|
+
safe.relaxations = raw.relaxations;
|
|
66
|
+
if (isObject(raw.verifiedUnder)) {
|
|
67
|
+
safe.verifiedUnder = {
|
|
68
|
+
protocolVersion: raw.verifiedUnder.protocolVersion,
|
|
69
|
+
canonicalization: raw.verifiedUnder.canonicalization,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (isObject(raw.producerIdentity)) {
|
|
73
|
+
safe.producerIdentity = { status: raw.producerIdentity.status };
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(raw.steps)) {
|
|
76
|
+
safe.steps = raw.steps.map((step, index) => {
|
|
77
|
+
const s = isObject(step) ? step : {};
|
|
78
|
+
return { index, ok: s.ok, code: s.code, errors: diagnostics(s.errors) };
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return safe;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=results.js.map
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { RecordingConfig } from './record-tools.js';
|
|
3
|
+
import type { WriteConfig } from './write/config.js';
|
|
4
|
+
import type { NodeNetwork } from './network/client.js';
|
|
5
|
+
/** Trusted host inputs, never MCP arguments. HTTP callers must supply explicit
|
|
6
|
+
* request-scoped configuration rather than inheriting a stdio owner's environment. */
|
|
7
|
+
export interface ServerRuntime {
|
|
8
|
+
network?: NodeNetwork;
|
|
9
|
+
write?: WriteConfig;
|
|
10
|
+
recording?: RecordingConfig;
|
|
11
|
+
}
|
|
12
|
+
export declare function createServer(runtime?: ServerRuntime): McpServer;
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import { inputSchema, outputSchema, TOOL_NAMES } from './contracts.js';
|
|
3
|
+
import { verify } from './verify.js';
|
|
4
|
+
import { registerNetworkTools } from './network-tools.js';
|
|
5
|
+
import { registerWriteTools } from './write-tools.js';
|
|
6
|
+
import { registerRecordingTool } from './record-tools.js';
|
|
7
|
+
const DESCRIPTIONS = [
|
|
8
|
+
'Verify inline AI CER V1/V2 integrity using the NexArt SDK. No signature, signer-trust or completeness claim.',
|
|
9
|
+
'Verify inline consequential CER integrity. Producer identity and reported actions are not authenticated.',
|
|
10
|
+
'Verify inline governed execution 0.1/0.2 with explicit version dispatch. No state-hash or producer authentication.',
|
|
11
|
+
'Verify an inline Project Bundle and embedded AI CERs using the SDK; require project hash integrity.',
|
|
12
|
+
];
|
|
13
|
+
export function createServer(runtime = {}) {
|
|
14
|
+
const server = new McpServer({ name: 'nexart-mcp-server', version: '0.2.0' });
|
|
15
|
+
TOOL_NAMES.forEach((name, index) => {
|
|
16
|
+
server.registerTool(name, {
|
|
17
|
+
description: DESCRIPTIONS[index],
|
|
18
|
+
inputSchema,
|
|
19
|
+
outputSchema,
|
|
20
|
+
annotations: {
|
|
21
|
+
readOnlyHint: true, destructiveHint: false,
|
|
22
|
+
idempotentHint: true, openWorldHint: false,
|
|
23
|
+
},
|
|
24
|
+
}, (args, context) => {
|
|
25
|
+
const result = verify(name, args, context.mcpReq.signal);
|
|
26
|
+
return {
|
|
27
|
+
content: [{ type: 'text', text: JSON.stringify(result) }],
|
|
28
|
+
structuredContent: result,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
registerNetworkTools(server, runtime.network);
|
|
33
|
+
registerWriteTools(server, runtime.write);
|
|
34
|
+
registerRecordingTool(server, runtime.recording);
|
|
35
|
+
// The SDK may report parsing/validation exceptions containing input fragments.
|
|
36
|
+
server.server.onerror = () => { process.stderr.write('NEXART_MCP_PROTOCOL_ERROR\n'); };
|
|
37
|
+
return server;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=server.js.map
|
package/dist/stdio.d.ts
ADDED
package/dist/stdio.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Transform } from 'node:stream';
|
|
3
|
+
import { serveStdio, StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
4
|
+
import { createServer } from './server.js';
|
|
5
|
+
import { LIMITS } from './limits.js';
|
|
6
|
+
import { redactProtocolMessage } from './protocol-safety.js';
|
|
7
|
+
/**
|
|
8
|
+
* Pre-parse byte/depth guard. MCP framing/parsing stays in the official SDK.
|
|
9
|
+
* No evidence is stored or logged. A hard framing limit closes the connection.
|
|
10
|
+
*/
|
|
11
|
+
class InputGuard extends Transform {
|
|
12
|
+
bytes = 0;
|
|
13
|
+
depth = 0;
|
|
14
|
+
quoted = false;
|
|
15
|
+
escaped = false;
|
|
16
|
+
_transform(chunk, _encoding, done) {
|
|
17
|
+
for (const byte of chunk) {
|
|
18
|
+
if (byte === 10) {
|
|
19
|
+
this.bytes = 0;
|
|
20
|
+
this.depth = 0;
|
|
21
|
+
this.quoted = false;
|
|
22
|
+
this.escaped = false;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (++this.bytes > LIMITS.frameBytes)
|
|
26
|
+
return done(new Error('FRAME_LIMIT'));
|
|
27
|
+
if (this.quoted) {
|
|
28
|
+
if (this.escaped)
|
|
29
|
+
this.escaped = false;
|
|
30
|
+
else if (byte === 92)
|
|
31
|
+
this.escaped = true;
|
|
32
|
+
else if (byte === 34)
|
|
33
|
+
this.quoted = false;
|
|
34
|
+
}
|
|
35
|
+
else if (byte === 34)
|
|
36
|
+
this.quoted = true;
|
|
37
|
+
else if (byte === 123 || byte === 91) {
|
|
38
|
+
// JSON-RPC envelope adds depth outside the tool arguments.
|
|
39
|
+
if (++this.depth > LIMITS.depth + 8)
|
|
40
|
+
return done(new Error('DEPTH_LIMIT'));
|
|
41
|
+
}
|
|
42
|
+
else if (byte === 125 || byte === 93)
|
|
43
|
+
this.depth--;
|
|
44
|
+
}
|
|
45
|
+
done(null, chunk);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Prevent SDK-generated validation errors from echoing attacker-controlled
|
|
50
|
+
* argument names or malformed JSON. SDK result wire encodings remain intact.
|
|
51
|
+
*/
|
|
52
|
+
class SafeStdioTransport extends StdioServerTransport {
|
|
53
|
+
async close() {
|
|
54
|
+
await super.close();
|
|
55
|
+
// The SDK owns `guard`, not the original stdin: release that source too.
|
|
56
|
+
process.stdin.unpipe(guard);
|
|
57
|
+
process.stdin.destroy();
|
|
58
|
+
guard.destroy();
|
|
59
|
+
}
|
|
60
|
+
send(message) {
|
|
61
|
+
return super.send(redactProtocolMessage(message));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const guard = new InputGuard();
|
|
65
|
+
const transport = new SafeStdioTransport(guard, process.stdout, { maxBufferSize: LIMITS.frameBytes });
|
|
66
|
+
const handle = serveStdio(() => createServer(), {
|
|
67
|
+
transport,
|
|
68
|
+
onerror: () => {
|
|
69
|
+
process.stderr.write('NEXART_MCP_PROTOCOL_ERROR\n');
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
guard.on('error', () => {
|
|
73
|
+
process.stderr.write('NEXART_MCP_INPUT_LIMIT\n');
|
|
74
|
+
process.stdin.unpipe(guard);
|
|
75
|
+
process.stdin.pause();
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
void handle.close();
|
|
78
|
+
});
|
|
79
|
+
process.stdin.pipe(guard);
|
|
80
|
+
process.stdin.on('error', () => {
|
|
81
|
+
process.stderr.write('NEXART_MCP_INPUT_ERROR\n');
|
|
82
|
+
void handle.close();
|
|
83
|
+
});
|
|
84
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
85
|
+
process.once(signal, () => { void handle.close(); });
|
|
86
|
+
}
|
|
87
|
+
process.stderr.write('NEXART_MCP_READY\n');
|
|
88
|
+
//# sourceMappingURL=stdio.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ManifestKey } from '../network/contracts.js';
|
|
2
|
+
import type { ApprovedKeyPin } from './policy.js';
|
|
3
|
+
export declare const isoTime: (value: unknown) => value is string;
|
|
4
|
+
export declare function lifecycle(key: ManifestKey, attestedAt: string | undefined, pin?: ApprovedKeyPin): {
|
|
5
|
+
state: "invalid";
|
|
6
|
+
code: string;
|
|
7
|
+
} | {
|
|
8
|
+
state: "unknown";
|
|
9
|
+
code: string;
|
|
10
|
+
} | {
|
|
11
|
+
state: "valid";
|
|
12
|
+
code: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { validateKeyLifecycle } from '@nexart/ai-execution';
|
|
2
|
+
import * as z from 'zod/v4';
|
|
3
|
+
export const isoTime = (value) => typeof value === 'string' && z.iso.datetime({ offset: true }).safeParse(value).success &&
|
|
4
|
+
Number.isFinite(Date.parse(value));
|
|
5
|
+
export function lifecycle(key, attestedAt, pin) {
|
|
6
|
+
if (key.revoked === true || key.status === 'revoked') {
|
|
7
|
+
return { state: 'invalid', code: 'KEY_REVOKED' };
|
|
8
|
+
}
|
|
9
|
+
if (!isoTime(attestedAt))
|
|
10
|
+
return { state: 'unknown', code: 'ATTESTATION_TIME_UNKNOWN' };
|
|
11
|
+
for (const date of [key.notBefore, key.notAfter, key.validFrom, key.validTo]) {
|
|
12
|
+
if (date != null && !isoTime(date))
|
|
13
|
+
return { state: 'unknown', code: 'KEY_LIFECYCLE_UNKNOWN' };
|
|
14
|
+
}
|
|
15
|
+
if ((key.notAfter && key.validTo && key.notAfter !== key.validTo) ||
|
|
16
|
+
(key.notBefore && key.validFrom && key.notBefore !== key.validFrom)) {
|
|
17
|
+
return { state: 'unknown', code: 'KEY_LIFECYCLE_CONFLICT' };
|
|
18
|
+
}
|
|
19
|
+
const exception = pin?.historicalValidity;
|
|
20
|
+
if (exception && (!isoTime(exception.notBefore) || !exception.provenance.trim())) {
|
|
21
|
+
return { state: 'unknown', code: 'HISTORICAL_PROVENANCE_MISSING' };
|
|
22
|
+
}
|
|
23
|
+
// No global exception: only a matched independently approved pin may supply provenance.
|
|
24
|
+
const notBefore = exception?.notBefore ?? key.notBefore ?? key.validFrom ?? undefined;
|
|
25
|
+
const notAfter = key.notAfter ?? key.validTo ?? undefined;
|
|
26
|
+
const result = validateKeyLifecycle({
|
|
27
|
+
kid: key.kid, revoked: false,
|
|
28
|
+
...(notBefore ? { notBefore } : {}), ...(notAfter ? { notAfter } : {}),
|
|
29
|
+
}, attestedAt);
|
|
30
|
+
if (notAfter && Date.parse(attestedAt) > Date.parse(notAfter)) {
|
|
31
|
+
return { state: 'invalid', code: 'KEY_EXPIRED' };
|
|
32
|
+
}
|
|
33
|
+
if (!result.ok) {
|
|
34
|
+
// Earlier than discovery's notBefore is not proof of invalid historical signing.
|
|
35
|
+
return { state: 'unknown', code: 'HISTORICAL_LIFECYCLE_UNKNOWN' };
|
|
36
|
+
}
|
|
37
|
+
if (!key.status || key.revoked === undefined || (key.status === 'deprecated' && !notAfter)) {
|
|
38
|
+
return { state: 'unknown', code: 'KEY_LIFECYCLE_UNKNOWN' };
|
|
39
|
+
}
|
|
40
|
+
return { state: 'valid', code: 'OK' };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ApprovedKeyPin {
|
|
2
|
+
readonly kid: string;
|
|
3
|
+
/** Independently approved raw Ed25519 public key, not learned from discovery. */
|
|
4
|
+
readonly publicKeyB64Url: string;
|
|
5
|
+
readonly historicalValidity?: {
|
|
6
|
+
readonly notBefore: string;
|
|
7
|
+
readonly provenance: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface TrustPolicy {
|
|
11
|
+
readonly expectedNodeId: string;
|
|
12
|
+
readonly pins: readonly ApprovedKeyPin[];
|
|
13
|
+
}
|
|
14
|
+
export declare const TRUST_POLICY: TrustPolicy;
|
package/dist/verify.d.ts
ADDED
package/dist/verify.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
import { inputSchema } from './contracts.js';
|
|
3
|
+
import { dispatch } from './adapters.js';
|
|
4
|
+
import { checkInput, isObject, LIMITS } from './limits.js';
|
|
5
|
+
import { baseOutput, projectSdkResult } from './results.js';
|
|
6
|
+
/** Exported for tests/library callers; the MCP transport invokes this same path. */
|
|
7
|
+
export function verify(tool, args, signal) {
|
|
8
|
+
const output = baseOutput(tool, null);
|
|
9
|
+
const reject = (code, invalid = false) => ({
|
|
10
|
+
...output, reasonCode: code, artifactIntegrity: invalid ? 'invalid' : 'not_performed',
|
|
11
|
+
});
|
|
12
|
+
try {
|
|
13
|
+
const limit = checkInput(args);
|
|
14
|
+
if (limit)
|
|
15
|
+
return reject(limit);
|
|
16
|
+
const parsed = inputSchema.safeParse(args);
|
|
17
|
+
if (!parsed.success || !Object.hasOwn(parsed.data, 'bundle')) {
|
|
18
|
+
return reject('INVALID_ARGUMENTS');
|
|
19
|
+
}
|
|
20
|
+
Object.assign(output, baseOutput(tool, parsed.data.bundle));
|
|
21
|
+
if (signal?.aborted)
|
|
22
|
+
return reject('CANCELLED');
|
|
23
|
+
const bundle = parsed.data.bundle;
|
|
24
|
+
if (tool === 'nexart_verify_project_bundle' && isObject(bundle) &&
|
|
25
|
+
Array.isArray(bundle.stepRegistry) && bundle.stepRegistry.length > LIMITS.projectSteps) {
|
|
26
|
+
return reject('PROJECT_STEP_LIMIT');
|
|
27
|
+
}
|
|
28
|
+
const started = performance.now();
|
|
29
|
+
const outcome = dispatch(tool, bundle);
|
|
30
|
+
// Synchronous SDK work cannot be interrupted by a notification mid-call.
|
|
31
|
+
// This check only observes cancellation already delivered by the transport.
|
|
32
|
+
if (signal?.aborted)
|
|
33
|
+
return reject('CANCELLED');
|
|
34
|
+
if ('rejection' in outcome)
|
|
35
|
+
return reject(outcome.rejection, true);
|
|
36
|
+
const raw = outcome.result;
|
|
37
|
+
output.sdk = projectSdkResult(raw);
|
|
38
|
+
const projectHashRequired = tool !== 'nexart_verify_project_bundle' ||
|
|
39
|
+
raw.projectHashValid === true;
|
|
40
|
+
output.artifactIntegrity = raw.ok && projectHashRequired ? 'valid' : 'invalid';
|
|
41
|
+
output.reasonCode = raw.ok && !projectHashRequired ? 'PROJECT_HASH_NOT_VERIFIED' : raw.code;
|
|
42
|
+
// No falsely advertised hard deadline: benchmark findings are documented.
|
|
43
|
+
if (performance.now() - started > 1_000) {
|
|
44
|
+
output.limitations.push('Synchronous verification exceeded one second and could not be preempted.');
|
|
45
|
+
}
|
|
46
|
+
if (Buffer.byteLength(JSON.stringify(output)) > LIMITS.outputBytes) {
|
|
47
|
+
return { ...reject('OUTPUT_LIMIT_EXCEEDED'), sdk: null };
|
|
48
|
+
}
|
|
49
|
+
return output;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Never include a thrown SDK message, stack, key, field value or path.
|
|
53
|
+
return reject('SDK_EXCEPTION');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { WriteConfig } from './config.js';
|
|
2
|
+
/** Only the separate owner-operated TTY command calls this. Not exposed over MCP. */
|
|
3
|
+
export declare function issueApproval(config: WriteConfig, body: string, key: string, now?: number): void;
|
|
4
|
+
/** Atomically claim once across processes. No grant identifiers enter tool arguments. */
|
|
5
|
+
export declare function consumeApproval(config: WriteConfig, body: string, key: string, now?: number): boolean;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createHmac, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { constants, lstatSync, openSync, fstatSync, readFileSync, closeSync, realpathSync, writeFileSync, renameSync, unlinkSync, } from 'node:fs';
|
|
3
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { NODE_ORIGIN } from '../network/client.js';
|
|
5
|
+
import { PUBLIC_PROFILE } from './profile.js';
|
|
6
|
+
const MAX_AGE_MS = 300_000;
|
|
7
|
+
const GRANT_VERSION = 1;
|
|
8
|
+
/** Local approval authentication only; never used for NexArt CER/commitment crypto. */
|
|
9
|
+
function binding(body, key, account) {
|
|
10
|
+
return createHmac('sha256', key).update(JSON.stringify({
|
|
11
|
+
profile: PUBLIC_PROFILE, destination: `${NODE_ORIGIN}/api/attest`,
|
|
12
|
+
visibility: 'public', account, body,
|
|
13
|
+
})).digest('hex');
|
|
14
|
+
}
|
|
15
|
+
/** Domain-separated authentication of every persisted grant field. The digest
|
|
16
|
+
* binds the unchanged CER body, account, destination, profile and visibility. */
|
|
17
|
+
function grantMac(digest, issuedAt, expiresAt, key) {
|
|
18
|
+
return createHmac('sha256', key).update(JSON.stringify({
|
|
19
|
+
purpose: 'nexart.mcp.public-approval-grant', version: GRANT_VERSION,
|
|
20
|
+
profile: PUBLIC_PROFILE, digest, issuedAt, expiresAt,
|
|
21
|
+
})).digest('hex');
|
|
22
|
+
}
|
|
23
|
+
function directory(config) {
|
|
24
|
+
const path = config.approvalDirectory;
|
|
25
|
+
if (!path || !isAbsolute(path) || realpathSync(path) !== resolve(path))
|
|
26
|
+
throw Error('UNSAFE_DIRECTORY');
|
|
27
|
+
const stat = lstatSync(path);
|
|
28
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || (stat.mode & 0o777) !== 0o700 ||
|
|
29
|
+
stat.uid !== process.getuid?.())
|
|
30
|
+
throw Error('UNSAFE_DIRECTORY');
|
|
31
|
+
return path;
|
|
32
|
+
}
|
|
33
|
+
function context(config, body, key) {
|
|
34
|
+
if (!config.publicEnabled || !config.attestEnabled || !config.accountContext?.trim() || !key)
|
|
35
|
+
throw Error('DISABLED');
|
|
36
|
+
return { dir: directory(config), digest: binding(body, key, config.accountContext) };
|
|
37
|
+
}
|
|
38
|
+
/** Only the separate owner-operated TTY command calls this. Not exposed over MCP. */
|
|
39
|
+
export function issueApproval(config, body, key, now = Date.now()) {
|
|
40
|
+
const { dir, digest } = context(config, body, key);
|
|
41
|
+
if (!Number.isSafeInteger(now) || !Number.isSafeInteger(now + MAX_AGE_MS))
|
|
42
|
+
throw Error('INVALID_TIME');
|
|
43
|
+
const expiresAt = now + MAX_AGE_MS;
|
|
44
|
+
const file = join(dir, `${digest}.json`);
|
|
45
|
+
const fd = openSync(file, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
|
|
46
|
+
try {
|
|
47
|
+
writeFileSync(fd, JSON.stringify({
|
|
48
|
+
version: GRANT_VERSION, profile: PUBLIC_PROFILE, digest, issuedAt: now, expiresAt,
|
|
49
|
+
mac: grantMac(digest, now, expiresAt, key),
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
closeSync(fd);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Atomically claim once across processes. No grant identifiers enter tool arguments. */
|
|
57
|
+
export function consumeApproval(config, body, key, now = Date.now()) {
|
|
58
|
+
let claimed;
|
|
59
|
+
try {
|
|
60
|
+
const { dir, digest } = context(config, body, key);
|
|
61
|
+
claimed = join(dir, `.consumed-${randomUUID()}`);
|
|
62
|
+
renameSync(join(dir, `${digest}.json`), claimed);
|
|
63
|
+
const fd = openSync(claimed, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
64
|
+
try {
|
|
65
|
+
const stat = fstatSync(fd);
|
|
66
|
+
if (!stat.isFile() || stat.nlink !== 1 || stat.uid !== process.getuid?.() ||
|
|
67
|
+
(stat.mode & 0o777) !== 0o600 || stat.size > 1_024)
|
|
68
|
+
return false;
|
|
69
|
+
const data = JSON.parse(readFileSync(fd, 'utf8'));
|
|
70
|
+
return Object.keys(data).sort().join(',') === 'digest,expiresAt,issuedAt,mac,profile,version'
|
|
71
|
+
&& data.version === GRANT_VERSION && data.profile === PUBLIC_PROFILE && data.digest === digest
|
|
72
|
+
&& typeof data.issuedAt === 'number' && typeof data.expiresAt === 'number'
|
|
73
|
+
&& Number.isSafeInteger(data.issuedAt) && Number.isSafeInteger(data.expiresAt) && Number.isSafeInteger(now)
|
|
74
|
+
&& typeof data.mac === 'string' && /^[0-9a-f]{64}$/.test(data.mac)
|
|
75
|
+
&& timingSafeEqual(Buffer.from(data.mac, 'hex'), Buffer.from(grantMac(digest, data.issuedAt, data.expiresAt, key), 'hex'))
|
|
76
|
+
&& data.issuedAt <= now && data.expiresAt > now
|
|
77
|
+
&& data.expiresAt - data.issuedAt > 0 && data.expiresAt - data.issuedAt <= MAX_AGE_MS;
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
closeSync(fd);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
if (claimed) {
|
|
88
|
+
try {
|
|
89
|
+
unlinkSync(claimed);
|
|
90
|
+
}
|
|
91
|
+
catch { /* never expose paths */ }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=approval.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NodeNetwork } from '../network/client.js';
|
|
2
|
+
import { type TrustPolicy } from '../trust/policy.js';
|
|
3
|
+
import { type AttestOutput } from './contracts.js';
|
|
4
|
+
import type { WriteConfig } from './config.js';
|
|
5
|
+
import { type DisclosureProfile } from './profile.js';
|
|
6
|
+
import { AttestPoster } from './post.js';
|
|
7
|
+
export interface AttestDependencies {
|
|
8
|
+
network?: NodeNetwork;
|
|
9
|
+
poster?: AttestPoster;
|
|
10
|
+
policy?: TrustPolicy;
|
|
11
|
+
/** Trusted embedding only; never a tool argument or environment selector. */
|
|
12
|
+
disclosureProfile?: DisclosureProfile;
|
|
13
|
+
/** Trusted application exact-body single-use grant, NOT a boolean bypass.
|
|
14
|
+
* Omitted by stdio: its existing owner-file approval remains unchanged. */
|
|
15
|
+
consumePublicApproval?: (body: string, key: string) => boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function attest(args: unknown, config: WriteConfig, dependencies?: AttestDependencies, signal?: AbortSignal): Promise<AttestOutput>;
|