proteum 2.2.8 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +5 -3
- package/README.md +50 -12
- package/agents/project/AGENTS.md +47 -10
- package/agents/project/CODING_STYLE.md +5 -1
- package/agents/project/client/AGENTS.md +2 -0
- package/agents/project/diagnostics.md +8 -5
- package/agents/project/optimizations.md +1 -0
- package/agents/project/root/AGENTS.md +18 -10
- package/agents/project/tests/AGENTS.md +6 -1
- package/agents/project/tests/e2e/AGENTS.md +13 -0
- package/agents/project/tests/e2e/REAL_WORLD_JOURNEY_TESTS.md +192 -0
- package/cli/commands/check.ts +21 -3
- package/cli/commands/configure.ts +1 -0
- package/cli/commands/connect.ts +40 -4
- package/cli/commands/diagnose.ts +136 -5
- package/cli/commands/doctor.ts +24 -4
- package/cli/commands/explain.ts +105 -6
- package/cli/commands/mcp.ts +16 -0
- package/cli/commands/orient.ts +66 -3
- package/cli/commands/perf.ts +118 -13
- package/cli/commands/runtime.ts +151 -0
- package/cli/commands/trace.ts +116 -21
- package/cli/mcp/provider.ts +365 -0
- package/cli/mcp/stdio.ts +16 -0
- package/cli/presentation/commands.ts +79 -22
- package/cli/presentation/devSession.ts +2 -0
- package/cli/runtime/commands.ts +95 -12
- package/cli/utils/agentOutput.ts +46 -0
- package/cli/utils/agents.ts +225 -48
- package/common/dev/inspection.ts +30 -9
- package/common/dev/mcpPayloads.ts +736 -0
- package/common/dev/mcpServer.ts +254 -0
- package/docs/agent-routing.md +126 -0
- package/docs/dev-commands.md +2 -0
- package/docs/dev-sessions.md +2 -1
- package/docs/diagnostics.md +68 -23
- package/docs/mcp.md +149 -0
- package/docs/migrate-from-2.1.3.md +15 -5
- package/docs/request-tracing.md +12 -6
- package/eslint.js +220 -0
- package/package.json +2 -1
- package/server/app/devMcp.ts +159 -0
- package/server/services/router/http/cache.ts +116 -0
- package/server/services/router/http/index.ts +94 -35
- package/server/services/router/index.ts +8 -11
- package/tests/agents-utils.test.cjs +89 -11
- package/tests/dev-transpile-watch.test.cjs +117 -8
- package/tests/eslint-rules.test.cjs +110 -0
- package/tests/inspection.test.cjs +67 -0
- package/tests/mcp.test.cjs +127 -0
- package/tests/router-cache-config.test.cjs +74 -0
package/cli/commands/trace.ts
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import { UsageError } from 'clipanion';
|
|
5
5
|
|
|
6
6
|
import cli from '..';
|
|
7
|
+
import { compactList, printAgentResponse, printJson, quoteCommandArgument, truncateForAgent } from '../utils/agentOutput';
|
|
7
8
|
import type {
|
|
8
9
|
TRequestTrace,
|
|
9
10
|
TRequestTraceArmResponse,
|
|
@@ -164,23 +165,114 @@ const renderTrace = (request: TRequestTrace) =>
|
|
|
164
165
|
),
|
|
165
166
|
].join('\n');
|
|
166
167
|
|
|
167
|
-
const
|
|
168
|
-
|
|
168
|
+
const compactCall = (call: TRequestTrace['calls'][number]) => ({
|
|
169
|
+
id: call.id,
|
|
170
|
+
origin: call.origin,
|
|
171
|
+
label: call.label,
|
|
172
|
+
method: call.method,
|
|
173
|
+
path: call.path,
|
|
174
|
+
statusCode: call.statusCode,
|
|
175
|
+
durationMs: call.durationMs,
|
|
176
|
+
errorMessage: call.errorMessage ? truncateForAgent(call.errorMessage) : undefined,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const compactSql = (query: TRequestTrace['sqlQueries'][number]) => ({
|
|
180
|
+
id: query.id,
|
|
181
|
+
caller: query.callerLabel || `${query.callerMethod} ${query.callerPath}`,
|
|
182
|
+
kind: query.kind,
|
|
183
|
+
operation: query.operation,
|
|
184
|
+
model: query.model,
|
|
185
|
+
durationMs: query.durationMs,
|
|
186
|
+
fingerprint: query.fingerprint,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const compactEvent = (event: TRequestTrace['events'][number]) => ({
|
|
190
|
+
index: event.index,
|
|
191
|
+
elapsedMs: event.elapsedMs,
|
|
192
|
+
type: event.type,
|
|
193
|
+
detailKeys: Object.keys(event.details),
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const buildTraceFullDetailCommand = (request: TRequestTrace) =>
|
|
197
|
+
[
|
|
198
|
+
'proteum trace show',
|
|
199
|
+
quoteCommandArgument(request.id),
|
|
200
|
+
typeof cli.args.port === 'string' && cli.args.port ? `--port ${cli.args.port}` : '',
|
|
201
|
+
typeof cli.args.url === 'string' && cli.args.url ? `--url ${quoteCommandArgument(cli.args.url)}` : '',
|
|
202
|
+
'--events',
|
|
203
|
+
]
|
|
204
|
+
.filter(Boolean)
|
|
205
|
+
.join(' ');
|
|
206
|
+
|
|
207
|
+
const printCompactTrace = (request: TRequestTrace) => {
|
|
208
|
+
const failedCalls = request.calls.filter((call) => call.errorMessage || (call.statusCode !== undefined && call.statusCode >= 400));
|
|
209
|
+
const errorEvents = request.events.filter((event) => event.type === 'error');
|
|
210
|
+
const hotCalls = [...request.calls].sort((left, right) => (right.durationMs || 0) - (left.durationMs || 0));
|
|
211
|
+
const hotSql = [...request.sqlQueries].sort((left, right) => right.durationMs - left.durationMs);
|
|
212
|
+
|
|
213
|
+
printAgentResponse({
|
|
214
|
+
summary: `${request.id}: ${request.method} ${request.path} status=${request.statusCode ?? 'pending'} durationMs=${request.durationMs ?? 'pending'} events=${request.events.length} calls=${request.calls.length} sql=${request.sqlQueries.length}`,
|
|
215
|
+
data: {
|
|
216
|
+
request: {
|
|
217
|
+
id: request.id,
|
|
218
|
+
method: request.method,
|
|
219
|
+
path: request.path,
|
|
220
|
+
statusCode: request.statusCode,
|
|
221
|
+
durationMs: request.durationMs,
|
|
222
|
+
capture: request.capture,
|
|
223
|
+
user: request.user,
|
|
224
|
+
errorMessage: request.errorMessage,
|
|
225
|
+
droppedEvents: request.droppedEvents,
|
|
226
|
+
persistedFilepath: request.persistedFilepath,
|
|
227
|
+
},
|
|
228
|
+
counts: {
|
|
229
|
+
calls: request.calls.length,
|
|
230
|
+
events: request.events.length,
|
|
231
|
+
sqlQueries: request.sqlQueries.length,
|
|
232
|
+
},
|
|
233
|
+
failedCalls: compactList(failedCalls, 5).map(compactCall),
|
|
234
|
+
errorEvents: compactList(errorEvents, 5).map(compactEvent),
|
|
235
|
+
hotCalls: compactList(hotCalls, 5).map(compactCall),
|
|
236
|
+
hotSql: compactList(hotSql, 5).map(compactSql),
|
|
237
|
+
},
|
|
238
|
+
nextActions: [
|
|
239
|
+
{
|
|
240
|
+
label: 'Diagnose Request',
|
|
241
|
+
command: `proteum diagnose ${quoteCommandArgument(request.path)}`,
|
|
242
|
+
reason: 'Collapse this trace with owner lookup, diagnostics, suspects, and server logs.',
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
label: 'Perf Request',
|
|
246
|
+
command: `proteum perf request ${quoteCommandArgument(request.id)}`,
|
|
247
|
+
reason: 'Inspect request timing, SQL, render, and memory rollups without full events.',
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
fullDetailCommand: buildTraceFullDetailCommand(request),
|
|
251
|
+
omitted: [
|
|
252
|
+
{
|
|
253
|
+
reason: 'Full event details, payload summaries, raw SQL, and call bodies are omitted by default.',
|
|
254
|
+
command: buildTraceFullDetailCommand(request),
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
});
|
|
169
258
|
};
|
|
170
259
|
|
|
171
260
|
export const run = async () => {
|
|
172
261
|
const action = getAction();
|
|
173
262
|
const requestId = typeof cli.args.id === 'string' ? cli.args.id : '';
|
|
174
|
-
const
|
|
263
|
+
const shouldPrintFull = cli.args.full === true || cli.args.events === true;
|
|
264
|
+
const shouldPrintHuman = cli.args.human === true;
|
|
175
265
|
|
|
176
266
|
if (action === 'requests') {
|
|
177
267
|
const response = await requestJson<TRequestTraceListResponse>('/__proteum/trace/requests');
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
268
|
+
if (shouldPrintFull) printJson(response);
|
|
269
|
+
else if (shouldPrintHuman) console.log(['Proteum trace', ...response.requests.map(renderTraceSummary)].join('\n'));
|
|
270
|
+
else
|
|
271
|
+
printAgentResponse({
|
|
272
|
+
summary: `${response.requests.length} request traces`,
|
|
273
|
+
data: { requests: compactList(response.requests, 20), totalReturned: response.requests.length },
|
|
274
|
+
fullDetailCommand: 'proteum trace requests --full',
|
|
275
|
+
});
|
|
184
276
|
return;
|
|
185
277
|
}
|
|
186
278
|
|
|
@@ -191,23 +283,20 @@ export const run = async () => {
|
|
|
191
283
|
json: { capture },
|
|
192
284
|
});
|
|
193
285
|
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
console.log(`Armed next request trace with capture=${response.capture}.`);
|
|
286
|
+
if (shouldPrintHuman) console.log(`Armed next request trace with capture=${response.capture}.`);
|
|
287
|
+
else printAgentResponse({ summary: `Armed next request trace with capture=${response.capture}.`, data: response });
|
|
200
288
|
return;
|
|
201
289
|
}
|
|
202
290
|
|
|
203
291
|
if (action === 'latest') {
|
|
204
292
|
const response = await requestJson<TRequestTraceResponse>('/__proteum/trace/latest');
|
|
205
|
-
if (
|
|
293
|
+
if (shouldPrintFull) {
|
|
206
294
|
printJson(response);
|
|
207
295
|
return;
|
|
208
296
|
}
|
|
209
297
|
|
|
210
|
-
console.log(renderTrace(response.request));
|
|
298
|
+
if (shouldPrintHuman) console.log(renderTrace(response.request));
|
|
299
|
+
else printCompactTrace(response.request);
|
|
211
300
|
return;
|
|
212
301
|
}
|
|
213
302
|
|
|
@@ -218,12 +307,13 @@ export const run = async () => {
|
|
|
218
307
|
const response = await requestJson<TRequestTraceResponse>(`/__proteum/trace/requests/${requestId}`);
|
|
219
308
|
|
|
220
309
|
if (action === 'show') {
|
|
221
|
-
if (
|
|
310
|
+
if (shouldPrintFull) {
|
|
222
311
|
printJson(response);
|
|
223
312
|
return;
|
|
224
313
|
}
|
|
225
314
|
|
|
226
|
-
console.log(renderTrace(response.request));
|
|
315
|
+
if (shouldPrintHuman) console.log(renderTrace(response.request));
|
|
316
|
+
else printCompactTrace(response.request);
|
|
227
317
|
return;
|
|
228
318
|
}
|
|
229
319
|
|
|
@@ -235,10 +325,15 @@ export const run = async () => {
|
|
|
235
325
|
fs.ensureDirSync(path.dirname(output));
|
|
236
326
|
fs.writeJSONSync(output, response.request, { spaces: 2 });
|
|
237
327
|
|
|
238
|
-
if (
|
|
328
|
+
if (shouldPrintFull) {
|
|
239
329
|
printJson({ output, request: response.request });
|
|
240
330
|
return;
|
|
241
331
|
}
|
|
242
332
|
|
|
243
|
-
console.log(`Exported trace ${response.request.id} to ${output}`);
|
|
333
|
+
if (shouldPrintHuman) console.log(`Exported trace ${response.request.id} to ${output}`);
|
|
334
|
+
else
|
|
335
|
+
printAgentResponse({
|
|
336
|
+
summary: `Exported trace ${response.request.id}.`,
|
|
337
|
+
data: { output, requestId: response.request.id },
|
|
338
|
+
});
|
|
244
339
|
};
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import got from 'got';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
import { buildContractsDoctorResponse } from '../../common/dev/contractsDoctor';
|
|
6
|
+
import { buildDoctorResponse, type TDoctorResponse } from '../../common/dev/diagnostics';
|
|
7
|
+
import { buildOrientationResponse, explainOwner } from '../../common/dev/inspection';
|
|
8
|
+
import {
|
|
9
|
+
buildRuntimeStatusPayload,
|
|
10
|
+
compactDiagnoseResponse,
|
|
11
|
+
compactDoctorResponse,
|
|
12
|
+
compactExplainSummary,
|
|
13
|
+
compactLogsResponse,
|
|
14
|
+
compactOrientationResponse,
|
|
15
|
+
compactPerfRequestResponse,
|
|
16
|
+
compactPerfTopResponse,
|
|
17
|
+
compactTraceResponse,
|
|
18
|
+
resolveInstructionRouting,
|
|
19
|
+
} from '../../common/dev/mcpPayloads';
|
|
20
|
+
import type { TProteumMcpProvider } from '../../common/dev/mcpServer';
|
|
21
|
+
import type { TDevConsoleLogLevel, TDevConsoleLogsResponse } from '../../common/dev/console';
|
|
22
|
+
import type { TDiagnoseResponse } from '../../common/dev/inspection';
|
|
23
|
+
import type { TPerfRequestResponse, TPerfTopResponse } from '../../common/dev/performance';
|
|
24
|
+
import type { TProteumManifest } from '../../common/dev/proteumManifest';
|
|
25
|
+
import type { TRequestTraceResponse } from '../../common/dev/requestTrace';
|
|
26
|
+
import { readProteumManifest } from '../compiler/common/proteumManifest';
|
|
27
|
+
import { listDevSessionInspections, type TDevSessionInspection } from '../runtime/devSessions';
|
|
28
|
+
|
|
29
|
+
type TCliProteumMcpProviderArgs = {
|
|
30
|
+
appRoot: string;
|
|
31
|
+
sessionFilePath?: string;
|
|
32
|
+
url?: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type TRequestOptions = {
|
|
36
|
+
method?: 'GET' | 'POST';
|
|
37
|
+
searchParams?: Record<string, string>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const normalizeBaseUrl = (value: string) => value.replace(/\/+$/, '');
|
|
41
|
+
const dedupe = <TValue>(values: TValue[]) => [...new Set(values)];
|
|
42
|
+
|
|
43
|
+
const buildBaseUrlCandidates = (value: string) => {
|
|
44
|
+
const normalized = normalizeBaseUrl(value);
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const parsed = new URL(normalized);
|
|
48
|
+
const port = parsed.port;
|
|
49
|
+
const pathname = parsed.pathname === '/' ? '' : parsed.pathname;
|
|
50
|
+
const search = parsed.search;
|
|
51
|
+
const hash = parsed.hash;
|
|
52
|
+
const buildUrl = (hostname: string) => `${parsed.protocol}//${hostname}${port ? `:${port}` : ''}${pathname}${search}${hash}`;
|
|
53
|
+
|
|
54
|
+
if (parsed.hostname === '127.0.0.1') return dedupe([normalized, buildUrl('localhost'), buildUrl('[::1]')]);
|
|
55
|
+
if (parsed.hostname === 'localhost') return dedupe([normalized, buildUrl('127.0.0.1'), buildUrl('[::1]')]);
|
|
56
|
+
if (parsed.hostname === '[::1]' || parsed.hostname === '::1') return dedupe([normalized, buildUrl('localhost'), buildUrl('127.0.0.1')]);
|
|
57
|
+
} catch (_error) {}
|
|
58
|
+
|
|
59
|
+
return [normalized];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const compactSession = (inspection: TDevSessionInspection) => ({
|
|
63
|
+
sessionFilePath: inspection.sessionFilePath,
|
|
64
|
+
live: inspection.live,
|
|
65
|
+
stale: inspection.stale,
|
|
66
|
+
invalid: inspection.invalid,
|
|
67
|
+
parseError: inspection.parseError,
|
|
68
|
+
pid: inspection.record?.pid,
|
|
69
|
+
routerPort: inspection.record?.routerPort,
|
|
70
|
+
publicUrl: inspection.record?.publicUrl,
|
|
71
|
+
state: inspection.record?.state,
|
|
72
|
+
startedAt: inspection.record?.startedAt,
|
|
73
|
+
updatedAt: inspection.record?.updatedAt,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const getSessionUrl = (inspection: TDevSessionInspection) => {
|
|
77
|
+
if (!inspection.record) return '';
|
|
78
|
+
if (inspection.record.publicUrl) return inspection.record.publicUrl.replace(/\/+$/, '');
|
|
79
|
+
return `http://localhost:${inspection.record.routerPort}`;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export class CliProteumMcpProvider implements TProteumMcpProvider {
|
|
83
|
+
private sessionsPromise?: Promise<TDevSessionInspection[]>;
|
|
84
|
+
|
|
85
|
+
public constructor(private args: TCliProteumMcpProviderArgs) {}
|
|
86
|
+
|
|
87
|
+
private readManifestIfAvailable() {
|
|
88
|
+
const manifestFilepath = path.join(this.args.appRoot, '.proteum', 'manifest.json');
|
|
89
|
+
if (!fs.existsSync(manifestFilepath)) return undefined;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
return readProteumManifest(this.args.appRoot);
|
|
93
|
+
} catch (_error) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private readLocalManifest() {
|
|
99
|
+
const manifest = this.readManifestIfAvailable();
|
|
100
|
+
if (!manifest) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Proteum manifest was not found in ${this.args.appRoot}. Run \`proteum refresh\`, \`proteum dev\`, or pass --url for a running dev server.`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return manifest;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private async readSessions() {
|
|
110
|
+
this.sessionsPromise ??= listDevSessionInspections({
|
|
111
|
+
appRoot: this.args.appRoot,
|
|
112
|
+
sessionFilePath: this.args.sessionFilePath,
|
|
113
|
+
});
|
|
114
|
+
return await this.sessionsPromise;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private async selectSession() {
|
|
118
|
+
const sessions = await this.readSessions();
|
|
119
|
+
const liveSessions = sessions.filter((inspection) => inspection.live && inspection.record);
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
liveSessions.find((inspection) => inspection.record?.state === 'ready') ||
|
|
123
|
+
liveSessions[0] ||
|
|
124
|
+
sessions.find((inspection) => inspection.record)
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private async getBaseUrlCandidates() {
|
|
129
|
+
if (this.args.url?.trim()) return buildBaseUrlCandidates(this.args.url.trim());
|
|
130
|
+
|
|
131
|
+
const selectedSession = await this.selectSession();
|
|
132
|
+
const selectedBaseUrl = selectedSession ? getSessionUrl(selectedSession) : '';
|
|
133
|
+
if (selectedBaseUrl) return buildBaseUrlCandidates(selectedBaseUrl);
|
|
134
|
+
|
|
135
|
+
const manifest = this.readManifestIfAvailable();
|
|
136
|
+
const routerPort = manifest?.env.resolved.routerPort;
|
|
137
|
+
if (typeof routerPort === 'number' && routerPort > 0) {
|
|
138
|
+
return dedupe([`http://localhost:${routerPort}`, `http://127.0.0.1:${routerPort}`, `http://[::1]:${routerPort}`]);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private async requestJson<TResponse>(pathname: string, options: TRequestOptions = {}) {
|
|
145
|
+
const attempts: string[] = [];
|
|
146
|
+
const baseUrls = await this.getBaseUrlCandidates();
|
|
147
|
+
|
|
148
|
+
for (const baseUrl of baseUrls) {
|
|
149
|
+
const url = `${baseUrl}${pathname}${options.searchParams ? `?${new URLSearchParams(options.searchParams).toString()}` : ''}`;
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
const response = await got(url, {
|
|
153
|
+
method: options.method || 'GET',
|
|
154
|
+
responseType: 'json',
|
|
155
|
+
retry: { limit: 0 },
|
|
156
|
+
throwHttpErrors: false,
|
|
157
|
+
timeout: { request: 2_500 },
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
if (response.statusCode >= 400) {
|
|
161
|
+
const body = response.body as { error?: string } | undefined;
|
|
162
|
+
throw new Error(body?.error || `Proteum dev endpoint returned HTTP ${response.statusCode}.`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return { baseUrl, body: response.body as TResponse };
|
|
166
|
+
} catch (error) {
|
|
167
|
+
attempts.push(`${url}: ${error instanceof Error ? error.message : String(error)}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
throw new Error(
|
|
172
|
+
[
|
|
173
|
+
'Could not reach a Proteum dev MCP data source.',
|
|
174
|
+
...attempts.map((attempt) => `- ${attempt}`),
|
|
175
|
+
'Start `proteum dev`, pass --url, or use tools that can read the local manifest from disk.',
|
|
176
|
+
].join('\n'),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private async readManifestPreferRuntime() {
|
|
181
|
+
if (this.args.url?.trim()) {
|
|
182
|
+
return (await this.requestJson<TProteumManifest>('/__proteum/explain')).body;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const localManifest = this.readManifestIfAvailable();
|
|
186
|
+
if (localManifest) return localManifest;
|
|
187
|
+
|
|
188
|
+
return (await this.requestJson<TProteumManifest>('/__proteum/explain')).body;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private async probeRuntimeHealth() {
|
|
192
|
+
try {
|
|
193
|
+
const response = await this.requestJson<TDoctorResponse>('/__proteum/doctor');
|
|
194
|
+
return {
|
|
195
|
+
reachable: true,
|
|
196
|
+
baseUrl: response.baseUrl,
|
|
197
|
+
doctor: response.body.summary,
|
|
198
|
+
};
|
|
199
|
+
} catch (error) {
|
|
200
|
+
return {
|
|
201
|
+
reachable: false,
|
|
202
|
+
error: error instanceof Error ? error.message : String(error),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public async runtimeStatus(_input: Record<string, never> = {}) {
|
|
208
|
+
const manifest = this.readManifestIfAvailable();
|
|
209
|
+
const sessions = await this.readSessions();
|
|
210
|
+
const selectedSession = await this.selectSession();
|
|
211
|
+
const health = await this.probeRuntimeHealth();
|
|
212
|
+
const runtime =
|
|
213
|
+
health.reachable && 'baseUrl' in health
|
|
214
|
+
? {
|
|
215
|
+
publicUrl: health.baseUrl,
|
|
216
|
+
routerPort: selectedSession?.record?.routerPort || manifest?.env.resolved.routerPort,
|
|
217
|
+
source: this.args.url?.trim() ? 'explicit-url' : selectedSession?.record ? 'tracked-session' : 'manifest-port',
|
|
218
|
+
session: selectedSession ? compactSession(selectedSession) : undefined,
|
|
219
|
+
mcpUrl: `${health.baseUrl}/__proteum/mcp`,
|
|
220
|
+
}
|
|
221
|
+
: selectedSession
|
|
222
|
+
? {
|
|
223
|
+
routerPort: selectedSession.record?.routerPort,
|
|
224
|
+
publicUrl: selectedSession.record?.publicUrl,
|
|
225
|
+
source: 'tracked-session',
|
|
226
|
+
session: compactSession(selectedSession),
|
|
227
|
+
}
|
|
228
|
+
: undefined;
|
|
229
|
+
|
|
230
|
+
return buildRuntimeStatusPayload({
|
|
231
|
+
appRoot: this.args.appRoot,
|
|
232
|
+
health,
|
|
233
|
+
manifest,
|
|
234
|
+
runtime,
|
|
235
|
+
sessions: sessions.map(compactSession),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
public async orient({ query }: { query: string }) {
|
|
240
|
+
return compactOrientationResponse(buildOrientationResponse(await this.readManifestPreferRuntime(), query));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
public async instructionsResolve({ query }: { query?: string }) {
|
|
244
|
+
return resolveInstructionRouting({ appRoot: this.args.appRoot, query });
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public async explainSummary({ query }: { query?: string }) {
|
|
248
|
+
const manifest = await this.readManifestPreferRuntime();
|
|
249
|
+
const normalizedQuery = query?.trim();
|
|
250
|
+
|
|
251
|
+
return compactExplainSummary({
|
|
252
|
+
manifest,
|
|
253
|
+
owner: normalizedQuery ? explainOwner(manifest, normalizedQuery) : undefined,
|
|
254
|
+
query: normalizedQuery,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public async doctor({ contracts = true }: { contracts?: boolean }) {
|
|
259
|
+
if (this.args.url?.trim()) {
|
|
260
|
+
const doctor = (await this.requestJson<TDoctorResponse>('/__proteum/doctor')).body;
|
|
261
|
+
const contractDoctor = contracts
|
|
262
|
+
? (await this.requestJson<TDoctorResponse>('/__proteum/doctor/contracts')).body
|
|
263
|
+
: undefined;
|
|
264
|
+
return compactDoctorResponse({ contracts: contractDoctor, doctor });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const manifest = this.readManifestIfAvailable();
|
|
268
|
+
if (manifest) {
|
|
269
|
+
return compactDoctorResponse({
|
|
270
|
+
contracts: contracts ? buildContractsDoctorResponse(manifest) : undefined,
|
|
271
|
+
doctor: buildDoctorResponse(manifest),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const doctor = (await this.requestJson<TDoctorResponse>('/__proteum/doctor')).body;
|
|
276
|
+
const contractDoctor = contracts
|
|
277
|
+
? (await this.requestJson<TDoctorResponse>('/__proteum/doctor/contracts')).body
|
|
278
|
+
: undefined;
|
|
279
|
+
return compactDoctorResponse({ contracts: contractDoctor, doctor });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public async diagnose(input: {
|
|
283
|
+
logsLevel?: TDevConsoleLogLevel;
|
|
284
|
+
logsLimit?: number;
|
|
285
|
+
path?: string;
|
|
286
|
+
query?: string;
|
|
287
|
+
requestId?: string;
|
|
288
|
+
}) {
|
|
289
|
+
const searchParams: Record<string, string> = {};
|
|
290
|
+
if (input.logsLevel) searchParams.logsLevel = input.logsLevel;
|
|
291
|
+
if (typeof input.logsLimit === 'number') searchParams.logsLimit = String(input.logsLimit);
|
|
292
|
+
if (input.path) searchParams.path = input.path;
|
|
293
|
+
if (input.query) searchParams.query = input.query;
|
|
294
|
+
if (input.requestId) searchParams.requestId = input.requestId;
|
|
295
|
+
|
|
296
|
+
return compactDiagnoseResponse((await this.requestJson<TDiagnoseResponse>('/__proteum/diagnose', { searchParams })).body);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public async traceLatest(input: { detail?: 'compact' | 'full'; limit?: number; offset?: number }) {
|
|
300
|
+
const response = (await this.requestJson<TRequestTraceResponse>('/__proteum/trace/latest')).body;
|
|
301
|
+
return compactTraceResponse({
|
|
302
|
+
detail: input.detail,
|
|
303
|
+
limit: input.limit,
|
|
304
|
+
offset: input.offset,
|
|
305
|
+
request: response.request,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
public async traceShow(input: { detail?: 'compact' | 'full'; limit?: number; offset?: number; requestId: string }) {
|
|
310
|
+
const response = (await this.requestJson<TRequestTraceResponse>(`/__proteum/trace/requests/${encodeURIComponent(input.requestId)}`))
|
|
311
|
+
.body;
|
|
312
|
+
return compactTraceResponse({
|
|
313
|
+
detail: input.detail,
|
|
314
|
+
limit: input.limit,
|
|
315
|
+
offset: input.offset,
|
|
316
|
+
request: response.request,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public async perfTop(input: { groupBy?: 'path' | 'route' | 'controller'; limit?: number; since?: string }) {
|
|
321
|
+
return compactPerfTopResponse(
|
|
322
|
+
(
|
|
323
|
+
await this.requestJson<TPerfTopResponse>('/__proteum/perf/top', {
|
|
324
|
+
searchParams: {
|
|
325
|
+
groupBy: input.groupBy || 'path',
|
|
326
|
+
limit: String(input.limit || 12),
|
|
327
|
+
since: input.since || 'today',
|
|
328
|
+
},
|
|
329
|
+
})
|
|
330
|
+
).body,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
public async perfRequest({ query }: { query: string }) {
|
|
335
|
+
return compactPerfRequestResponse(
|
|
336
|
+
(
|
|
337
|
+
await this.requestJson<TPerfRequestResponse>('/__proteum/perf/request', {
|
|
338
|
+
searchParams: { query },
|
|
339
|
+
})
|
|
340
|
+
).body,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
public async logsTail({ level = 'warn', limit = 40 }: { level?: TDevConsoleLogLevel; limit?: number }) {
|
|
345
|
+
return compactLogsResponse({
|
|
346
|
+
level,
|
|
347
|
+
limit,
|
|
348
|
+
response: (
|
|
349
|
+
await this.requestJson<TDevConsoleLogsResponse>('/__proteum/logs', {
|
|
350
|
+
searchParams: { level, limit: String(limit) },
|
|
351
|
+
})
|
|
352
|
+
).body,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
public async readResource(uri: string) {
|
|
357
|
+
if (uri === 'proteum://runtime/status') return await this.runtimeStatus({});
|
|
358
|
+
if (uri === 'proteum://instructions/router') return await this.instructionsResolve({});
|
|
359
|
+
if (uri === 'proteum://manifest/summary') return await this.explainSummary({});
|
|
360
|
+
if (uri === 'proteum://trace/latest/summary') return await this.traceLatest({});
|
|
361
|
+
if (uri === 'proteum://perf/top') return await this.perfTop({});
|
|
362
|
+
|
|
363
|
+
throw new Error(`Unknown Proteum MCP resource: ${uri}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
package/cli/mcp/stdio.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
2
|
+
|
|
3
|
+
import { createProteumMcpServer, type TProteumMcpProvider } from '../../common/dev/mcpServer';
|
|
4
|
+
|
|
5
|
+
export const startProteumMcpStdioServer = async ({
|
|
6
|
+
provider,
|
|
7
|
+
version,
|
|
8
|
+
}: {
|
|
9
|
+
provider: TProteumMcpProvider;
|
|
10
|
+
version: string;
|
|
11
|
+
}) => {
|
|
12
|
+
const server = createProteumMcpServer({ provider, version });
|
|
13
|
+
const transport = new StdioServerTransport();
|
|
14
|
+
|
|
15
|
+
await server.connect(transport);
|
|
16
|
+
};
|