qyl-mcp-server 7.1.0 → 7.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/README.md +118 -15
- package/dist/auth-extensions.d.ts +20 -0
- package/dist/auth-extensions.js +81 -0
- package/dist/auth-extensions.js.map +1 -0
- package/dist/auth.d.ts +4 -0
- package/dist/auth.js +5 -0
- package/dist/auth.js.map +1 -0
- package/dist/authorization.d.ts +14 -0
- package/dist/authorization.js +82 -0
- package/dist/authorization.js.map +1 -0
- package/dist/ci.d.ts +5 -5
- package/dist/ci.js +25 -19
- package/dist/ci.js.map +1 -1
- package/dist/collector-access.d.ts +17 -0
- package/dist/collector-access.js +61 -0
- package/dist/collector-access.js.map +1 -0
- package/dist/collector.d.ts +4 -1
- package/dist/collector.js +6 -2
- package/dist/collector.js.map +1 -1
- package/dist/config.d.ts +4 -3
- package/dist/config.js +5 -5
- package/dist/config.js.map +1 -1
- package/dist/contract-operations.d.ts +1 -1
- package/dist/contract-operations.js +1 -1
- package/dist/contract-operations.js.map +1 -1
- package/dist/contract-validation.d.ts +1 -1
- package/dist/contract-validation.js +45 -1
- package/dist/contract-validation.js.map +1 -1
- package/dist/events-authorization.d.ts +9 -0
- package/dist/events-authorization.js +160 -0
- package/dist/events-authorization.js.map +1 -0
- package/dist/events.d.ts +235 -0
- package/dist/events.js +647 -0
- package/dist/events.js.map +1 -0
- package/dist/main.d.ts +14 -23
- package/dist/main.js +99 -36
- package/dist/main.js.map +1 -1
- package/dist/mcp-app.html +1 -1
- package/dist/mcp-dashboard.html +1 -1
- package/dist/mcp-home.html +6 -6
- package/dist/metrics-tools.js +16 -13
- package/dist/metrics-tools.js.map +1 -1
- package/dist/native-execution.d.ts +8 -52
- package/dist/native-execution.js +51 -222
- package/dist/native-execution.js.map +1 -1
- package/dist/oauth-metadata.d.ts +8 -0
- package/dist/oauth-metadata.js +89 -0
- package/dist/oauth-metadata.js.map +1 -0
- package/dist/oauth.d.ts +7 -17
- package/dist/oauth.js +16 -68
- package/dist/oauth.js.map +1 -1
- package/dist/request-scope.d.ts +4 -12
- package/dist/request-scope.js +9 -22
- package/dist/request-scope.js.map +1 -1
- package/dist/server.d.ts +7 -1
- package/dist/server.js +83 -33
- package/dist/server.js.map +1 -1
- package/dist/summaries.d.ts +1 -1
- package/dist/summaries.js +2 -2
- package/dist/summaries.js.map +1 -1
- package/dist/telemetry-redaction.js +13 -0
- package/dist/telemetry-redaction.js.map +1 -1
- package/dist/tools.d.ts +10 -0
- package/dist/tools.js +77 -18
- package/dist/tools.js.map +1 -1
- package/dist/trace-query.d.ts +5 -0
- package/dist/trace-query.js +8 -0
- package/dist/trace-query.js.map +1 -0
- package/dist/ui-domain.d.ts +4 -0
- package/dist/ui-domain.js +28 -0
- package/dist/ui-domain.js.map +1 -0
- package/dist/webhook.d.ts +45 -0
- package/dist/webhook.js +198 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +27 -22
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Events for ChatGPT: `events/list`, `events/subscribe` and
|
|
3
|
+
* `events/unsubscribe` on the authenticated MCP endpoint, with signed webhook
|
|
4
|
+
* delivery of one event type, `trace.error`.
|
|
5
|
+
*
|
|
6
|
+
* Contract: developers.openai.com/plugins/build/mcp-events (ChatGPT supports
|
|
7
|
+
* webhook delivery with callback verification only) and the draft MCP Events
|
|
8
|
+
* design sketch in modelcontextprotocol/experimental-ext-triggers-events.
|
|
9
|
+
* `@modelcontextprotocol/server` 2.3.1 ships no `events/*` methods, so the
|
|
10
|
+
* three are custom request handlers and the capability is added by hand.
|
|
11
|
+
*
|
|
12
|
+
* Delivery source: the collector's recent-trace list, polled only while a
|
|
13
|
+
* subscription is live. The first poll sets a baseline, so a subscription
|
|
14
|
+
* never receives a backlog. Events carry `cursor: null` — there is no replay;
|
|
15
|
+
* traces that arrive while the server is down are not delivered.
|
|
16
|
+
*
|
|
17
|
+
* Access: subscribing, refreshing and unsubscribing each pass the same OAuth
|
|
18
|
+
* gate as every tool call. The required authorization callback rechecks the
|
|
19
|
+
* owner's current access while polling and before delivery, including retries.
|
|
20
|
+
* Authorization outages suspend delivery; revoked access removes the record.
|
|
21
|
+
*/
|
|
22
|
+
import type { McpServer, ServerContext } from "@modelcontextprotocol/server";
|
|
23
|
+
import * as z from "zod/v4";
|
|
24
|
+
import { AtomicJsonStore } from "./atomic-json-store.js";
|
|
25
|
+
import type { QylTrace } from "./wire.js";
|
|
26
|
+
import { type WebhookPost } from "./webhook.js";
|
|
27
|
+
export declare const TRACE_ERROR_EVENT_NAME = "trace.error";
|
|
28
|
+
/** JSON-RPC error for a callback that failed validation or verification. */
|
|
29
|
+
export declare const CALLBACK_ENDPOINT_ERROR = -32015;
|
|
30
|
+
export declare const DEFAULT_TTL_MS: number;
|
|
31
|
+
export declare const MIN_TTL_MS: number;
|
|
32
|
+
export declare const MAX_TTL_MS: number;
|
|
33
|
+
/**
|
|
34
|
+
* Live subscriptions one caller may hold. Every subscription is a stored
|
|
35
|
+
* entry, a delivery fan-out target and, for a new callback, an outbound
|
|
36
|
+
* verification POST; without a cap one account grows all three at will.
|
|
37
|
+
*/
|
|
38
|
+
export declare const MAX_SUBSCRIPTIONS_PER_PRINCIPAL = 20;
|
|
39
|
+
/** The one event definition `events/list` returns. */
|
|
40
|
+
export declare const TRACE_ERROR_EVENT: {
|
|
41
|
+
readonly name: "trace.error";
|
|
42
|
+
readonly description: string;
|
|
43
|
+
readonly delivery: readonly ["webhook"];
|
|
44
|
+
readonly inputSchema: {
|
|
45
|
+
readonly type: "object";
|
|
46
|
+
readonly properties: {
|
|
47
|
+
readonly service_name: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
readonly minLength: 1;
|
|
50
|
+
readonly maxLength: 128;
|
|
51
|
+
readonly description: "Only traces that involve this service.";
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
readonly additionalProperties: false;
|
|
55
|
+
};
|
|
56
|
+
readonly payloadSchema: {
|
|
57
|
+
readonly type: "object";
|
|
58
|
+
readonly properties: {
|
|
59
|
+
readonly trace_id: {
|
|
60
|
+
readonly type: "string";
|
|
61
|
+
readonly description: "Trace identifier; pass it to get_trace or display_traces.";
|
|
62
|
+
};
|
|
63
|
+
readonly root_span: {
|
|
64
|
+
readonly type: "string";
|
|
65
|
+
readonly description: "Name of the trace's root span.";
|
|
66
|
+
};
|
|
67
|
+
readonly services: {
|
|
68
|
+
readonly type: "array";
|
|
69
|
+
readonly items: {
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
};
|
|
72
|
+
readonly description: "Services involved in the trace.";
|
|
73
|
+
};
|
|
74
|
+
readonly span_count: {
|
|
75
|
+
readonly type: "integer";
|
|
76
|
+
readonly description: "Total span count.";
|
|
77
|
+
};
|
|
78
|
+
readonly duration_ms: {
|
|
79
|
+
readonly type: "number";
|
|
80
|
+
readonly description: "Trace duration in milliseconds.";
|
|
81
|
+
};
|
|
82
|
+
readonly start_time: {
|
|
83
|
+
readonly type: "string";
|
|
84
|
+
readonly format: "date-time";
|
|
85
|
+
readonly description: "Trace start time.";
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
readonly required: readonly ["trace_id", "root_span", "services", "span_count", "duration_ms", "start_time"];
|
|
89
|
+
readonly additionalProperties: false;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
declare const SubscribeParamsSchema: z.ZodObject<{
|
|
93
|
+
name: z.ZodString;
|
|
94
|
+
arguments: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
95
|
+
delivery: z.ZodObject<{
|
|
96
|
+
mode: z.ZodString;
|
|
97
|
+
url: z.ZodString;
|
|
98
|
+
secret: z.ZodOptional<z.ZodString>;
|
|
99
|
+
}, z.core.$loose>;
|
|
100
|
+
cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
101
|
+
ttlMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
102
|
+
}, z.core.$loose>;
|
|
103
|
+
export type SubscribeParams = z.infer<typeof SubscribeParamsSchema>;
|
|
104
|
+
declare const UnsubscribeParamsSchema: z.ZodObject<{
|
|
105
|
+
name: z.ZodString;
|
|
106
|
+
arguments: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
107
|
+
delivery: z.ZodObject<{
|
|
108
|
+
mode: z.ZodOptional<z.ZodString>;
|
|
109
|
+
url: z.ZodString;
|
|
110
|
+
}, z.core.$loose>;
|
|
111
|
+
}, z.core.$loose>;
|
|
112
|
+
export type UnsubscribeParams = z.infer<typeof UnsubscribeParamsSchema>;
|
|
113
|
+
/** The authenticated caller a subscription belongs to. */
|
|
114
|
+
export interface Principal {
|
|
115
|
+
subject: string;
|
|
116
|
+
clientId: string;
|
|
117
|
+
}
|
|
118
|
+
declare const StoredSubscriptionSchema: z.ZodObject<{
|
|
119
|
+
id: z.ZodString;
|
|
120
|
+
subject: z.ZodString;
|
|
121
|
+
clientId: z.ZodString;
|
|
122
|
+
name: z.ZodLiteral<"trace.error">;
|
|
123
|
+
arguments: z.ZodObject<{
|
|
124
|
+
service_name: z.ZodOptional<z.ZodString>;
|
|
125
|
+
}, z.core.$strict>;
|
|
126
|
+
url: z.ZodString;
|
|
127
|
+
secret: z.ZodString;
|
|
128
|
+
previousSecret: z.ZodOptional<z.ZodString>;
|
|
129
|
+
previousSecretUntil: z.ZodOptional<z.ZodString>;
|
|
130
|
+
refreshBefore: z.ZodString;
|
|
131
|
+
updatedAt: z.ZodString;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
export type StoredSubscription = z.infer<typeof StoredSubscriptionSchema>;
|
|
134
|
+
declare const EventStoreStateSchema: z.ZodObject<{
|
|
135
|
+
version: z.ZodLiteral<1>;
|
|
136
|
+
subscriptions: z.ZodArray<z.ZodObject<{
|
|
137
|
+
id: z.ZodString;
|
|
138
|
+
subject: z.ZodString;
|
|
139
|
+
clientId: z.ZodString;
|
|
140
|
+
name: z.ZodLiteral<"trace.error">;
|
|
141
|
+
arguments: z.ZodObject<{
|
|
142
|
+
service_name: z.ZodOptional<z.ZodString>;
|
|
143
|
+
}, z.core.$strict>;
|
|
144
|
+
url: z.ZodString;
|
|
145
|
+
secret: z.ZodString;
|
|
146
|
+
previousSecret: z.ZodOptional<z.ZodString>;
|
|
147
|
+
previousSecretUntil: z.ZodOptional<z.ZodString>;
|
|
148
|
+
refreshBefore: z.ZodString;
|
|
149
|
+
updatedAt: z.ZodString;
|
|
150
|
+
}, z.core.$strip>>;
|
|
151
|
+
}, z.core.$strip>;
|
|
152
|
+
export type EventStoreState = z.infer<typeof EventStoreStateSchema>;
|
|
153
|
+
/** Subscription storage that survives restarts: an atomic JSON file (0600). */
|
|
154
|
+
export declare function createEventStore(filePath: string): AtomicJsonStore<EventStoreState>;
|
|
155
|
+
/** Key-order-independent JSON, so `{a,b}` and `{b,a}` name one subscription. */
|
|
156
|
+
export declare function canonicalJson(value: unknown): string;
|
|
157
|
+
/** Deterministic ID over principal, callback URL, event name and arguments. */
|
|
158
|
+
export declare function subscriptionId(principal: Principal, url: string, name: string, args: unknown): string;
|
|
159
|
+
/** The lifetime granted for a requested `ttlMs`: bounded, and never unbounded. */
|
|
160
|
+
export declare function grantedTtlMs(ttlMs: number | null | undefined): number;
|
|
161
|
+
/** The principal of a verified request, or a JSON-RPC error without one. */
|
|
162
|
+
export declare function principalOf(ctx: Pick<ServerContext, "http">): Principal;
|
|
163
|
+
/** The `data` of a `trace.error` delivery; matches `payloadSchema`. */
|
|
164
|
+
export declare function traceErrorPayload(trace: QylTrace): Record<string, unknown>;
|
|
165
|
+
export interface EventsRuntimeOptions {
|
|
166
|
+
store: AtomicJsonStore<EventStoreState>;
|
|
167
|
+
/** Live access check. False revokes; errors suspend delivery without deleting state. */
|
|
168
|
+
isAuthorized: (principal: Principal) => Promise<boolean>;
|
|
169
|
+
/** Network seam; defaults to the public-HTTPS-only `postWebhook`. */
|
|
170
|
+
post?: WebhookPost;
|
|
171
|
+
/** Trace source scoped to the authenticated subscriber's project. */
|
|
172
|
+
recentTraces?: (principal: Principal) => Promise<readonly QylTrace[]>;
|
|
173
|
+
pollIntervalMs?: number;
|
|
174
|
+
now?: () => number;
|
|
175
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
176
|
+
log?: (message: string) => void;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* One per process: owns the subscription store, the verification cache and the
|
|
180
|
+
* poller. `register` wires the three methods into each per-request McpServer.
|
|
181
|
+
*/
|
|
182
|
+
export declare class EventsRuntime {
|
|
183
|
+
private readonly store;
|
|
184
|
+
private readonly isAuthorized;
|
|
185
|
+
private readonly post;
|
|
186
|
+
private readonly recentTraces;
|
|
187
|
+
private readonly pollIntervalMs;
|
|
188
|
+
private readonly now;
|
|
189
|
+
private readonly sleep;
|
|
190
|
+
private readonly log;
|
|
191
|
+
private readonly verified;
|
|
192
|
+
private readonly seen;
|
|
193
|
+
private ready;
|
|
194
|
+
private timer;
|
|
195
|
+
private polling;
|
|
196
|
+
private stopped;
|
|
197
|
+
private readonly deliveries;
|
|
198
|
+
constructor(options: EventsRuntimeOptions);
|
|
199
|
+
/** Advertise `events` and answer the three methods on this server instance. */
|
|
200
|
+
register(server: McpServer): void;
|
|
201
|
+
list(): {
|
|
202
|
+
events: (typeof TRACE_ERROR_EVENT)[];
|
|
203
|
+
};
|
|
204
|
+
subscribe(params: SubscribeParams, principal: Principal): Promise<{
|
|
205
|
+
id: string;
|
|
206
|
+
refreshBefore: string;
|
|
207
|
+
cursor: null;
|
|
208
|
+
truncated: false;
|
|
209
|
+
}>;
|
|
210
|
+
unsubscribe(params: UnsubscribeParams, principal: Principal): Promise<Record<string, never>>;
|
|
211
|
+
/** A refresh always passes; a new subscription needs a free slot for its caller. */
|
|
212
|
+
private assertCapacity;
|
|
213
|
+
/**
|
|
214
|
+
* A signed, single-use challenge before any application data; a success is
|
|
215
|
+
* cached per principal and callback URL for a bounded period.
|
|
216
|
+
*/
|
|
217
|
+
private verifyCallback;
|
|
218
|
+
/** Loads the store once; every store access waits for it. */
|
|
219
|
+
private initialized;
|
|
220
|
+
/** Start the poller if a live subscription exists; `stop` ends it. */
|
|
221
|
+
start(): Promise<void>;
|
|
222
|
+
stop(): Promise<void>;
|
|
223
|
+
private ensurePolling;
|
|
224
|
+
private isLive;
|
|
225
|
+
private pruneState;
|
|
226
|
+
private authorized;
|
|
227
|
+
/** One poll: drop lapsed subscriptions, then deliver each new error trace. */
|
|
228
|
+
poll(): Promise<void>;
|
|
229
|
+
private pollOnce;
|
|
230
|
+
private sourceKey;
|
|
231
|
+
private deliver;
|
|
232
|
+
/** POST one signed event, retrying transient failures with backoff. */
|
|
233
|
+
private deliverWhileActive;
|
|
234
|
+
}
|
|
235
|
+
export {};
|