@cairul/mcp 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/bin/cairul-mcp.mjs +3 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.js +12 -0
- package/dist/check-executions.d.ts +16 -0
- package/dist/check-executions.js +89 -0
- package/dist/check-kinds.d.ts +16 -0
- package/dist/check-kinds.js +69 -0
- package/dist/checks/github.d.ts +1 -0
- package/dist/checks/github.js +1 -0
- package/dist/checks/shell.d.ts +10 -0
- package/dist/checks/shell.js +62 -0
- package/dist/environment.d.ts +1 -0
- package/dist/environment.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +76 -0
- package/dist/journeys.d.ts +14 -0
- package/dist/journeys.js +183 -0
- package/dist/local-config.d.ts +112 -0
- package/dist/local-config.js +210 -0
- package/dist/local-journeys.d.ts +647 -0
- package/dist/local-journeys.js +332 -0
- package/dist/local-plugins.d.ts +2 -0
- package/dist/local-plugins.js +54 -0
- package/dist/logging.d.ts +4 -0
- package/dist/logging.js +19 -0
- package/dist/observations/codex-rollout.d.ts +67 -0
- package/dist/observations/codex-rollout.js +241 -0
- package/dist/observations/codex.d.ts +18 -0
- package/dist/observations/codex.js +289 -0
- package/dist/observations/execution.d.ts +27 -0
- package/dist/observations/execution.js +84 -0
- package/dist/observations/harness.d.ts +40 -0
- package/dist/observations/harness.js +17 -0
- package/dist/observations/mcp.d.ts +8 -0
- package/dist/observations/mcp.js +15 -0
- package/dist/observations/publisher.d.ts +33 -0
- package/dist/observations/publisher.js +120 -0
- package/dist/observations/settings.d.ts +1 -0
- package/dist/observations/settings.js +2 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.js +1 -0
- package/package.json +42 -3
- package/README.md +0 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const capturePolicy: z.ZodObject<{
|
|
3
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
4
|
+
none: "none";
|
|
5
|
+
all: "all";
|
|
6
|
+
failed_tools: "failed_tools";
|
|
7
|
+
}>>;
|
|
8
|
+
tool_names: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export declare const journeyState: z.ZodObject<{
|
|
11
|
+
id: z.ZodUUID;
|
|
12
|
+
status: z.ZodEnum<{
|
|
13
|
+
completed: "completed";
|
|
14
|
+
aborted: "aborted";
|
|
15
|
+
active: "active";
|
|
16
|
+
}>;
|
|
17
|
+
updated_at: z.ZodString;
|
|
18
|
+
capture_policy: z.ZodObject<{
|
|
19
|
+
tool_names: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
|
+
version: z.ZodLiteral<1>;
|
|
21
|
+
mode: z.ZodEnum<{
|
|
22
|
+
none: "none";
|
|
23
|
+
all: "all";
|
|
24
|
+
failed_tools: "failed_tools";
|
|
25
|
+
}>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type JourneyState = z.infer<typeof journeyState>;
|
|
29
|
+
export type CapturePolicy = JourneyState['capture_policy'];
|
|
30
|
+
export interface RequestOutcome {
|
|
31
|
+
failed: boolean;
|
|
32
|
+
endedAt: number;
|
|
33
|
+
httpStatus?: number;
|
|
34
|
+
journey?: JourneyState;
|
|
35
|
+
}
|
|
36
|
+
export interface HarnessTracker {
|
|
37
|
+
beginTool(metadata: unknown, tool: string, at: number): Promise<((outcome: RequestOutcome) => Promise<void>) | undefined>;
|
|
38
|
+
shutdown(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export declare const withoutHarness: HarnessTracker;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const capturePolicy = z.object({
|
|
3
|
+
mode: z.enum(['all', 'failed_tools', 'none']).optional(),
|
|
4
|
+
tool_names: z.array(z.string().min(1).max(200)).max(64).optional(),
|
|
5
|
+
});
|
|
6
|
+
export const journeyState = z.object({
|
|
7
|
+
id: z.uuid(),
|
|
8
|
+
status: z.enum(['active', 'completed', 'aborted']),
|
|
9
|
+
updated_at: z.string(),
|
|
10
|
+
capture_policy: capturePolicy.extend({ version: z.literal(1), mode: z.enum(['all', 'failed_tools', 'none']) }),
|
|
11
|
+
});
|
|
12
|
+
export const withoutHarness = {
|
|
13
|
+
async beginTool() {
|
|
14
|
+
return undefined;
|
|
15
|
+
},
|
|
16
|
+
async shutdown() { },
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CallToolResult, ServerContext } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { HarnessTracker, JourneyState } from './harness.js';
|
|
3
|
+
export interface PluginRequest {
|
|
4
|
+
signal: AbortSignal;
|
|
5
|
+
journey?: JourneyState;
|
|
6
|
+
httpStatus?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function instrumentTools(tracker: HarnessTracker): (name: string, context: ServerContext, run: (request: PluginRequest) => Promise<CallToolResult>) => Promise<CallToolResult>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function instrumentTools(tracker) {
|
|
2
|
+
return async (name, context, run) => {
|
|
3
|
+
const finish = await tracker.beginTool(context.mcpReq._meta, name, Date.now());
|
|
4
|
+
const request = { signal: context.mcpReq.signal };
|
|
5
|
+
let failed = true;
|
|
6
|
+
try {
|
|
7
|
+
const result = await run(request);
|
|
8
|
+
failed = result.isError === true;
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
finally {
|
|
12
|
+
await finish?.({ failed, endedAt: Date.now(), journey: request.journey, httpStatus: request.httpStatus });
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ExecutionObservation, HarnessIdentity, JourneysApi, MCPRequestObservation, ObservationEvent, RecordingEndObservationReasonEnum } from '@cairul/sdk';
|
|
2
|
+
import type { CapturePolicy } from './harness.js';
|
|
3
|
+
export declare class Recording {
|
|
4
|
+
readonly journeyId: string;
|
|
5
|
+
readonly harness: HarnessIdentity;
|
|
6
|
+
private readonly policy;
|
|
7
|
+
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
8
|
+
readonly pending: ObservationEvent[];
|
|
9
|
+
private sequence;
|
|
10
|
+
private observed;
|
|
11
|
+
private retained;
|
|
12
|
+
closed: boolean;
|
|
13
|
+
private discarded;
|
|
14
|
+
constructor(journeyId: string, harness: HarnessIdentity, policy: CapturePolicy, at: number, request: MCPRequestObservation);
|
|
15
|
+
collect(observation: {
|
|
16
|
+
occurredAt: string;
|
|
17
|
+
execution: ExecutionObservation;
|
|
18
|
+
}): void;
|
|
19
|
+
close(reason: RecordingEndObservationReasonEnum, at: number, sourceAvailable: boolean): void;
|
|
20
|
+
private matches;
|
|
21
|
+
discard(): void;
|
|
22
|
+
private enqueue;
|
|
23
|
+
}
|
|
24
|
+
export declare class ObservationPublisher {
|
|
25
|
+
private readonly api;
|
|
26
|
+
private readonly recordings;
|
|
27
|
+
private sending?;
|
|
28
|
+
constructor(api: JourneysApi);
|
|
29
|
+
open(journeyId: string, harness: HarnessIdentity, policy: CapturePolicy, at: number, request: MCPRequestObservation): Recording;
|
|
30
|
+
flush(): Promise<void>;
|
|
31
|
+
private send;
|
|
32
|
+
shutdown(): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { errorResponse } from '../api/index.js';
|
|
3
|
+
import { log } from '../logging.js';
|
|
4
|
+
import { timestamp } from './execution.js';
|
|
5
|
+
export class Recording {
|
|
6
|
+
journeyId;
|
|
7
|
+
harness;
|
|
8
|
+
policy;
|
|
9
|
+
id = randomUUID();
|
|
10
|
+
pending = [];
|
|
11
|
+
sequence = 0;
|
|
12
|
+
observed = 0;
|
|
13
|
+
retained = 0;
|
|
14
|
+
closed = false;
|
|
15
|
+
discarded = false;
|
|
16
|
+
constructor(journeyId, harness, policy, at, request) {
|
|
17
|
+
this.journeyId = journeyId;
|
|
18
|
+
this.harness = harness;
|
|
19
|
+
this.policy = policy;
|
|
20
|
+
this.enqueue({
|
|
21
|
+
type: 'recording.started',
|
|
22
|
+
occurredAt: timestamp(at),
|
|
23
|
+
started: { policyVersion: policy.version, request },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
collect(observation) {
|
|
27
|
+
this.observed++;
|
|
28
|
+
if (!this.matches(observation.execution.tools))
|
|
29
|
+
return;
|
|
30
|
+
this.retained++;
|
|
31
|
+
this.enqueue({ type: 'execution.observed', ...observation });
|
|
32
|
+
}
|
|
33
|
+
close(reason, at, sourceAvailable) {
|
|
34
|
+
this.closed = true;
|
|
35
|
+
this.enqueue({
|
|
36
|
+
type: 'recording.ended',
|
|
37
|
+
occurredAt: timestamp(at),
|
|
38
|
+
ended: { reason, observed: this.observed, retained: this.retained, sourceAvailable },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
matches(tools) {
|
|
42
|
+
const { mode, tool_names: names = [] } = this.policy;
|
|
43
|
+
if (mode === 'none')
|
|
44
|
+
return false;
|
|
45
|
+
if (mode === 'all' && names.length === 0)
|
|
46
|
+
return true;
|
|
47
|
+
return tools.some((tool) => (names.length === 0 || names.includes(tool.name)) && (mode !== 'failed_tools' || tool.failed));
|
|
48
|
+
}
|
|
49
|
+
discard() {
|
|
50
|
+
this.discarded = true;
|
|
51
|
+
this.pending.length = 0;
|
|
52
|
+
}
|
|
53
|
+
enqueue(event) {
|
|
54
|
+
if (this.discarded)
|
|
55
|
+
return;
|
|
56
|
+
const id = event.execution?.id ?? randomUUID();
|
|
57
|
+
this.pending.push({ ...event, id, sequence: ++this.sequence });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export class ObservationPublisher {
|
|
61
|
+
api;
|
|
62
|
+
recordings = new Set();
|
|
63
|
+
sending;
|
|
64
|
+
constructor(api) {
|
|
65
|
+
this.api = api;
|
|
66
|
+
}
|
|
67
|
+
open(journeyId, harness, policy, at, request) {
|
|
68
|
+
const recording = new Recording(journeyId, harness, policy, at, request);
|
|
69
|
+
this.recordings.add(recording);
|
|
70
|
+
return recording;
|
|
71
|
+
}
|
|
72
|
+
flush() {
|
|
73
|
+
this.sending ??= Promise.all([...this.recordings].map((recording) => this.send(recording)))
|
|
74
|
+
.then(() => undefined)
|
|
75
|
+
.finally(() => {
|
|
76
|
+
this.sending = undefined;
|
|
77
|
+
});
|
|
78
|
+
return this.sending;
|
|
79
|
+
}
|
|
80
|
+
async send(recording) {
|
|
81
|
+
let batchSize = 25;
|
|
82
|
+
while (recording.pending.length > 0) {
|
|
83
|
+
const events = recording.pending.slice(0, batchSize);
|
|
84
|
+
try {
|
|
85
|
+
await this.api.publishEvent({
|
|
86
|
+
eventPublication: {
|
|
87
|
+
version: 1,
|
|
88
|
+
type: 'journey.observations',
|
|
89
|
+
journeyId: recording.journeyId,
|
|
90
|
+
observations: { recordingId: recording.id, harness: recording.harness, events },
|
|
91
|
+
},
|
|
92
|
+
}, { signal: AbortSignal.timeout(2000) });
|
|
93
|
+
recording.pending.splice(0, events.length);
|
|
94
|
+
batchSize = 25;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const status = errorResponse(error)?.status;
|
|
98
|
+
if (status === 413 && events.length > 1) {
|
|
99
|
+
batchSize = Math.ceil(events.length / 2);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
log('warn', 'journey observations were not accepted', {
|
|
103
|
+
recording_id: recording.id,
|
|
104
|
+
...(status && { status }),
|
|
105
|
+
});
|
|
106
|
+
if (status && status >= 400 && status < 500 && status !== 429) {
|
|
107
|
+
recording.discard();
|
|
108
|
+
this.recordings.delete(recording);
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (recording.closed)
|
|
114
|
+
this.recordings.delete(recording);
|
|
115
|
+
}
|
|
116
|
+
async shutdown() {
|
|
117
|
+
await this.sending;
|
|
118
|
+
await this.flush();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const observationsEnabled: () => boolean;
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export type PluginOptions = Record<string, JsonValue>;
|
|
5
|
+
export type CheckContext = {
|
|
6
|
+
projectDir: string;
|
|
7
|
+
workItemUrl: string;
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
};
|
|
10
|
+
export type CheckResult = {
|
|
11
|
+
status: 'passed' | 'pending' | 'error';
|
|
12
|
+
detail?: string;
|
|
13
|
+
};
|
|
14
|
+
export type CheckKind = {
|
|
15
|
+
execution?: 'background';
|
|
16
|
+
validate?: (options: PluginOptions) => void | Promise<void>;
|
|
17
|
+
run: (options: PluginOptions, context: CheckContext) => CheckResult | Promise<CheckResult>;
|
|
18
|
+
};
|
|
19
|
+
export type CairulPlugin = {
|
|
20
|
+
checkKinds: Record<string, CheckKind>;
|
|
21
|
+
};
|
|
22
|
+
export type PluginFactory = (options: PluginOptions) => CairulPlugin | Promise<CairulPlugin>;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cairul/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"cairul-mcp": "./bin/cairul-mcp.mjs"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@cairul/sdk": "0.1.0",
|
|
10
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
11
|
+
"import-meta-resolve": "^4.2.0",
|
|
12
|
+
"yaml": "^2.9.1",
|
|
13
|
+
"zod": "^4.6.7"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
17
|
+
"@types/node": "^24.19.2"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/index.js",
|
|
21
|
+
"./plugin": {
|
|
22
|
+
"types": "./dist/plugin.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"files": [
|
|
27
|
+
"bin/cairul-mcp.mjs",
|
|
28
|
+
"dist/"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=24"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/cairul-hq/cairul.git",
|
|
36
|
+
"directory": "apps/mcp"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -b",
|
|
40
|
+
"start": "node dist/index.js",
|
|
41
|
+
"test": "node --test",
|
|
42
|
+
"lint": "eslint bin src test",
|
|
43
|
+
"format": "prettier --write bin src test package.json tsconfig.json"
|
|
44
|
+
}
|
|
6
45
|
}
|
package/README.md
DELETED