mcp-feedback 0.5.0 → 0.7.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 +139 -2
- package/agentdist.json +40 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.js +26 -3
- package/dist/conformance-cases.js +15 -4
- package/dist/drizzle.js +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/ingest/cli.d.ts +8 -0
- package/dist/ingest/cli.js +270 -0
- package/dist/ingest/github.d.ts +40 -0
- package/dist/ingest/github.js +80 -0
- package/dist/ingest/handler.d.ts +84 -0
- package/dist/ingest/handler.js +447 -0
- package/dist/ingest/index.d.ts +3 -0
- package/dist/ingest/index.js +5 -0
- package/dist/ingest/protocol.d.ts +203 -0
- package/dist/ingest/protocol.js +78 -0
- package/dist/ingest/tokens.d.ts +84 -0
- package/dist/ingest/tokens.js +163 -0
- package/dist/install.d.ts +3 -0
- package/dist/install.js +27 -0
- package/dist/reader.js +6 -1
- package/dist/register.d.ts +36 -4
- package/dist/register.js +45 -21
- package/dist/remote.d.ts +66 -0
- package/dist/remote.js +399 -0
- package/dist/store.d.ts +17 -0
- package/dist/store.js +5 -0
- package/dist/stores/memory.js +3 -1
- package/dist/stores/sql.js +5 -0
- package/dist/tools.d.ts +8 -1
- package/dist/tools.js +28 -7
- package/dist/types.d.ts +4 -0
- package/package.json +15 -2
- package/skills/add-feedback-to-mcp-server/SKILL.md +179 -0
- package/skills/add-feedback-to-mcp-server/references/feedback-section.md +57 -0
- package/skills/add-feedback-to-mcp-server/references/remote-ingest.md +84 -0
- package/skills/read-feedback/SKILL.md +99 -0
- package/skills/read-feedback/references/connecting.md +84 -0
- package/skills/set-up-feedback-reading/SKILL.md +60 -0
- package/skills/set-up-feedback-reading/references/project-reference.md +48 -0
package/dist/remote.js
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
// A write-only sink for MCP servers that run on their users' machines (stdio servers, CLIs): it
|
|
2
|
+
// sends each report to the maintainer's ingest hub (spec/ingest.md), and keeps it on disk to send
|
|
3
|
+
// later when the hub cannot be reached.
|
|
4
|
+
import { mkdir, readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { homedir, platform } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { INGEST_PATHS, MAX_QUEUE_AGE_DAYS, toIngestSubmission, unverifiedClaimsOf, unverifiedProjectOf, } from "./ingest/protocol.js";
|
|
8
|
+
import { FeedbackDeliveryError } from "./store.js";
|
|
9
|
+
/** True when the user has turned feedback off with MCP_FEEDBACK_DISABLED. Hosts should then skip registerFeedback. */
|
|
10
|
+
export function feedbackDisabled(env = process.env) {
|
|
11
|
+
return /^(1|true|yes)$/i.test(env.MCP_FEEDBACK_DISABLED ?? "");
|
|
12
|
+
}
|
|
13
|
+
function stateRoot() {
|
|
14
|
+
const home = homedir();
|
|
15
|
+
if (platform() === "darwin")
|
|
16
|
+
return join(home, "Library", "Application Support", "mcp-feedback");
|
|
17
|
+
if (platform() === "win32")
|
|
18
|
+
return join(process.env.LOCALAPPDATA ?? join(home, "AppData", "Local"), "mcp-feedback");
|
|
19
|
+
return join(process.env.XDG_STATE_HOME || join(home, ".local", "state"), "mcp-feedback");
|
|
20
|
+
}
|
|
21
|
+
function checkEndpoint(endpoint) {
|
|
22
|
+
let url;
|
|
23
|
+
try {
|
|
24
|
+
url = new URL(endpoint);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw new Error(`remoteStore: endpoint is not a URL: ${endpoint}`);
|
|
28
|
+
}
|
|
29
|
+
const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
30
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && local)) {
|
|
31
|
+
throw new Error("remoteStore: the endpoint must use https (plain http is allowed only for localhost).");
|
|
32
|
+
}
|
|
33
|
+
return url;
|
|
34
|
+
}
|
|
35
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
36
|
+
/** A failure worth retrying later: the hub is down, overloaded or unreachable. */
|
|
37
|
+
class RetryableError extends Error {
|
|
38
|
+
}
|
|
39
|
+
/** No usable sign-in on this machine: the user has to sign in before reports can go. */
|
|
40
|
+
class SignInRequired extends Error {
|
|
41
|
+
}
|
|
42
|
+
async function hubMessage(response) {
|
|
43
|
+
try {
|
|
44
|
+
const body = (await response.json());
|
|
45
|
+
if (typeof body.error?.message === "string")
|
|
46
|
+
return body.error.message.slice(0, 500);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Not one of the hub's error bodies.
|
|
50
|
+
}
|
|
51
|
+
return `The feedback service answered ${response.status}.`;
|
|
52
|
+
}
|
|
53
|
+
/** Worth trying again later. 501 means the hub does not offer something at all, which waiting will not change. */
|
|
54
|
+
const retryable = (status) => status === 429 || (status >= 500 && status !== 501);
|
|
55
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
56
|
+
// A wait for a sign-in must not keep a server process alive after its client has gone.
|
|
57
|
+
setTimeout(resolve, ms).unref();
|
|
58
|
+
});
|
|
59
|
+
export function remoteStore(options) {
|
|
60
|
+
const url = checkEndpoint(options.endpoint);
|
|
61
|
+
const endpoint = url.href.replace(/\/+$/, "");
|
|
62
|
+
const credential = options.token ?? options.projectKey;
|
|
63
|
+
if (!credential)
|
|
64
|
+
throw new Error("remoteStore: pass projectKey (or an issued token).");
|
|
65
|
+
const project = unverifiedProjectOf(credential);
|
|
66
|
+
if (!project)
|
|
67
|
+
throw new Error("remoteStore: the project key is not one an mcp-feedback hub issues.");
|
|
68
|
+
if (options.signIn && !options.projectKey)
|
|
69
|
+
throw new Error("remoteStore: signIn needs the projectKey.");
|
|
70
|
+
const stateDir = options.stateDir ?? join(stateRoot(), project);
|
|
71
|
+
const identityDir = options.identityDir ?? join(stateRoot(), "_hubs", `${url.host}${url.pathname}`.replace(/[^A-Za-z0-9.-]+/g, "_"));
|
|
72
|
+
const queueDir = join(stateDir, "queue");
|
|
73
|
+
const tokenFile = join(stateDir, "token.json");
|
|
74
|
+
const userFile = join(identityDir, "user.json");
|
|
75
|
+
const queueLimits = options.queue === false ? null : { maxItems: 50, maxAgeDays: MAX_QUEUE_AGE_DAYS, ...options.queue };
|
|
76
|
+
const timeoutMs = options.timeoutMs ?? 10_000;
|
|
77
|
+
const renewAfterMs = (options.renewAfterSeconds ?? 24 * 60 * 60) * 1000;
|
|
78
|
+
const doFetch = options.fetch ?? fetch;
|
|
79
|
+
// No version: reading package.json at run time breaks when the package is bundled.
|
|
80
|
+
const userAgent = "mcp-feedback-remote";
|
|
81
|
+
const request = (path, token, body) => doFetch(endpoint + path, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: { authorization: `Bearer ${token}`, "content-type": "application/json", "user-agent": userAgent },
|
|
84
|
+
body: body === undefined ? "{}" : JSON.stringify(body),
|
|
85
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
86
|
+
});
|
|
87
|
+
/** Writes through a temporary file, so a crash never leaves half a file for the next run to choke on. */
|
|
88
|
+
const writePrivate = async (file, value) => {
|
|
89
|
+
await mkdir(join(file, ".."), { recursive: true, mode: 0o700 });
|
|
90
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
91
|
+
await writeFile(temp, JSON.stringify(value), { mode: 0o600 });
|
|
92
|
+
await rename(temp, file);
|
|
93
|
+
};
|
|
94
|
+
const readCached = async (file) => {
|
|
95
|
+
try {
|
|
96
|
+
const cached = JSON.parse(await readFile(file, "utf8"));
|
|
97
|
+
return cached.endpoint === endpoint && typeof cached.token === "string" ? cached : null;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const save = (file, body) => writePrivate(file, { endpoint, token: body.token, expires_at: body.expires_at });
|
|
104
|
+
/** A cached token with more than a day to run, or null. */
|
|
105
|
+
const usable = (cached) => cached && Date.parse(cached.expires_at) - Date.now() > DAY_MS ? cached : null;
|
|
106
|
+
const tokenBody = async (response) => {
|
|
107
|
+
const body = (await response.json());
|
|
108
|
+
if (typeof body.token !== "string" || typeof body.expires_at !== "string") {
|
|
109
|
+
throw new RetryableError("The feedback service gave an unexpected answer.");
|
|
110
|
+
}
|
|
111
|
+
return { token: body.token, expires_at: body.expires_at };
|
|
112
|
+
};
|
|
113
|
+
// ---- this server's token
|
|
114
|
+
let acquiring;
|
|
115
|
+
/** With a sign-in, the hub makes this installation that person for this project; without, it is anonymous. */
|
|
116
|
+
const enroll = async (userToken) => {
|
|
117
|
+
const response = await request(INGEST_PATHS.enroll, options.projectKey, userToken ? { user_token: userToken } : {});
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
const message = await hubMessage(response);
|
|
120
|
+
if (retryable(response.status))
|
|
121
|
+
throw new RetryableError(message);
|
|
122
|
+
if (userToken && (response.status === 401 || response.status === 403)) {
|
|
123
|
+
// The sign-in expired or was revoked: drop it and ask again.
|
|
124
|
+
await rm(userFile, { force: true });
|
|
125
|
+
throw new SignInRequired(message);
|
|
126
|
+
}
|
|
127
|
+
throw new FeedbackDeliveryError(`The feedback service did not accept this server's project key: ${message}`);
|
|
128
|
+
}
|
|
129
|
+
const body = await tokenBody(response);
|
|
130
|
+
await save(tokenFile, body);
|
|
131
|
+
return body.token;
|
|
132
|
+
};
|
|
133
|
+
const acquire = async () => {
|
|
134
|
+
if (options.signIn !== "github")
|
|
135
|
+
return enroll();
|
|
136
|
+
const user = usable(await readCached(userFile));
|
|
137
|
+
if (!user)
|
|
138
|
+
throw new SignInRequired("No sign-in on this machine.");
|
|
139
|
+
return enroll(user.token);
|
|
140
|
+
};
|
|
141
|
+
const serverToken = async (fresh = false) => {
|
|
142
|
+
if (options.token)
|
|
143
|
+
return options.token;
|
|
144
|
+
if (!fresh) {
|
|
145
|
+
const cached = usable(await readCached(tokenFile));
|
|
146
|
+
// In sign-in mode, a token from earlier anonymous use does not count.
|
|
147
|
+
if (cached && (options.signIn !== "github" || unverifiedClaimsOf(cached.token)?.tier === "issued"))
|
|
148
|
+
return cached.token;
|
|
149
|
+
}
|
|
150
|
+
acquiring ??= acquire().finally(() => {
|
|
151
|
+
acquiring = undefined;
|
|
152
|
+
});
|
|
153
|
+
return acquiring;
|
|
154
|
+
};
|
|
155
|
+
// ---- signing in with GitHub
|
|
156
|
+
let pending;
|
|
157
|
+
const pollSignIn = async (signIn) => {
|
|
158
|
+
let interval = signIn.intervalMs;
|
|
159
|
+
while (pending === signIn && Date.now() < signIn.expiresAt) {
|
|
160
|
+
await sleep(interval);
|
|
161
|
+
let response;
|
|
162
|
+
try {
|
|
163
|
+
response = await request(INGEST_PATHS.githubPoll, options.projectKey, { handle: signIn.handle });
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
continue; // Unreachable for a moment; keep trying until the code expires.
|
|
167
|
+
}
|
|
168
|
+
if (response.status === 202) {
|
|
169
|
+
const body = (await response.json().catch(() => ({})));
|
|
170
|
+
if (typeof body.interval === "number")
|
|
171
|
+
interval = Math.max(interval, body.interval * 1000);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (response.ok) {
|
|
175
|
+
try {
|
|
176
|
+
await save(userFile, await tokenBody(response));
|
|
177
|
+
pending = undefined;
|
|
178
|
+
await flushInternal(); // the reports that were waiting for it
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
options.onError?.(error);
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
pending = undefined;
|
|
186
|
+
options.onError?.(new FeedbackDeliveryError(`GitHub sign-in did not complete: ${await hubMessage(response)}`));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (pending === signIn)
|
|
190
|
+
pending = undefined;
|
|
191
|
+
};
|
|
192
|
+
/** Starts a sign-in, or returns the one already waiting for the user. */
|
|
193
|
+
const beginSignIn = async () => {
|
|
194
|
+
if (pending && pending.expiresAt - Date.now() > 60_000)
|
|
195
|
+
return pending;
|
|
196
|
+
const response = await request(INGEST_PATHS.githubStart, options.projectKey);
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
const message = await hubMessage(response);
|
|
199
|
+
if (retryable(response.status))
|
|
200
|
+
throw new RetryableError(message);
|
|
201
|
+
throw new FeedbackDeliveryError(`This server sends feedback as a GitHub user, but the feedback service could not start a sign-in: ${message}`);
|
|
202
|
+
}
|
|
203
|
+
const body = (await response.json());
|
|
204
|
+
if (typeof body.verification_uri !== "string" || typeof body.user_code !== "string" || typeof body.handle !== "string") {
|
|
205
|
+
throw new RetryableError("The feedback service gave an unexpected answer to a sign-in request.");
|
|
206
|
+
}
|
|
207
|
+
const signIn = {
|
|
208
|
+
verificationUri: body.verification_uri,
|
|
209
|
+
userCode: body.user_code,
|
|
210
|
+
handle: body.handle,
|
|
211
|
+
expiresAt: Date.now() + (Number(body.expires_in) || 900) * 1000,
|
|
212
|
+
intervalMs: options.signInPollMs ?? (Number(body.interval) || 5) * 1000,
|
|
213
|
+
};
|
|
214
|
+
pending = signIn;
|
|
215
|
+
void pollSignIn(signIn);
|
|
216
|
+
return signIn;
|
|
217
|
+
};
|
|
218
|
+
// ---- sending one report
|
|
219
|
+
const send = async (submission, fresh = false) => {
|
|
220
|
+
let response;
|
|
221
|
+
try {
|
|
222
|
+
response = await request(INGEST_PATHS.feedback, await serverToken(fresh), submission);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
if (error instanceof SignInRequired)
|
|
226
|
+
return { kind: "signin" };
|
|
227
|
+
if (error instanceof FeedbackDeliveryError)
|
|
228
|
+
return { kind: "refused", message: error.message };
|
|
229
|
+
return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
|
|
230
|
+
}
|
|
231
|
+
if (response.ok)
|
|
232
|
+
return { kind: "delivered" };
|
|
233
|
+
if (response.status === 401 && !options.token && !fresh)
|
|
234
|
+
return { kind: "reauth" };
|
|
235
|
+
const message = await hubMessage(response);
|
|
236
|
+
if (retryable(response.status))
|
|
237
|
+
return { kind: "retry", reason: message };
|
|
238
|
+
return { kind: "refused", message: `The feedback service refused the report: ${message}` };
|
|
239
|
+
};
|
|
240
|
+
const deliver = async (submission) => {
|
|
241
|
+
const outcome = await send(submission);
|
|
242
|
+
return outcome.kind === "reauth" ? send(submission, true) : outcome;
|
|
243
|
+
};
|
|
244
|
+
// ---- the queue
|
|
245
|
+
const queued = async () => {
|
|
246
|
+
try {
|
|
247
|
+
return (await readdir(queueDir)).filter((name) => name.endsWith(".json")).sort();
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
let flushing;
|
|
254
|
+
const flushOnce = async () => {
|
|
255
|
+
const result = { delivered: 0, dropped: 0, remaining: 0, blocked: null };
|
|
256
|
+
const files = await queued();
|
|
257
|
+
for (const [index, name] of files.entries()) {
|
|
258
|
+
const file = join(queueDir, name);
|
|
259
|
+
let item;
|
|
260
|
+
try {
|
|
261
|
+
item = JSON.parse(await readFile(file, "utf8"));
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// Deleted by another process sending the same queue, or corrupt.
|
|
265
|
+
await rm(file, { force: true });
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (Date.now() - Date.parse(item.queued_at) > (queueLimits?.maxAgeDays ?? MAX_QUEUE_AGE_DAYS) * DAY_MS) {
|
|
269
|
+
await rm(file, { force: true });
|
|
270
|
+
result.dropped++;
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const outcome = await deliver(item.submission);
|
|
274
|
+
if (outcome.kind === "retry" || outcome.kind === "signin") {
|
|
275
|
+
// Cannot send now; the rest stays for next time.
|
|
276
|
+
result.blocked = outcome.kind === "retry" ? "unreachable" : "signin";
|
|
277
|
+
result.remaining = files.length - index;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
await rm(file, { force: true });
|
|
281
|
+
if (outcome.kind === "delivered")
|
|
282
|
+
result.delivered++;
|
|
283
|
+
else {
|
|
284
|
+
result.dropped++;
|
|
285
|
+
options.onError?.(new FeedbackDeliveryError(`A queued report was deleted. ${outcome.kind === "refused" ? outcome.message : ""}`));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
};
|
|
290
|
+
const flushInternal = () => {
|
|
291
|
+
flushing ??= flushOnce()
|
|
292
|
+
.catch((error) => {
|
|
293
|
+
options.onError?.(error);
|
|
294
|
+
return { delivered: 0, dropped: 0, remaining: 0, blocked: "unreachable" };
|
|
295
|
+
})
|
|
296
|
+
.finally(() => {
|
|
297
|
+
flushing = undefined;
|
|
298
|
+
});
|
|
299
|
+
return flushing;
|
|
300
|
+
};
|
|
301
|
+
/** Saves a report to send later. `note` tells the user why and where; `withoutQueue` is the error when queueing is off. */
|
|
302
|
+
const enqueue = async (record, submission, note, withoutQueue) => {
|
|
303
|
+
if (!queueLimits)
|
|
304
|
+
throw new FeedbackDeliveryError(`${withoutQueue} Nothing was sent.`);
|
|
305
|
+
const waiting = await queued();
|
|
306
|
+
if (waiting.length >= queueLimits.maxItems) {
|
|
307
|
+
throw new FeedbackDeliveryError(`The report could not be sent, and ${waiting.length} earlier reports are already waiting on this machine. ` +
|
|
308
|
+
"Nothing was sent or saved; try again later.");
|
|
309
|
+
}
|
|
310
|
+
const file = join(queueDir, `${record.id}.json`);
|
|
311
|
+
await writePrivate(file, { queued_at: new Date().toISOString(), submission });
|
|
312
|
+
return { delivery: "queued", note: note(file) };
|
|
313
|
+
};
|
|
314
|
+
const unreachableNote = (file) => `The feedback service could not be reached, so the report was saved on this machine at ${file} and will be sent ` +
|
|
315
|
+
"the next time this server starts or files feedback. Deleting that file cancels it.";
|
|
316
|
+
const queueUnreachable = (record, submission) => enqueue(record, submission, unreachableNote, "The feedback service could not be reached.");
|
|
317
|
+
const queueForSignIn = async (record, submission) => {
|
|
318
|
+
let signIn;
|
|
319
|
+
try {
|
|
320
|
+
signIn = await beginSignIn();
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
if (error instanceof FeedbackDeliveryError)
|
|
324
|
+
throw error;
|
|
325
|
+
return queueUnreachable(record, submission);
|
|
326
|
+
}
|
|
327
|
+
const minutes = Math.max(1, Math.round((signIn.expiresAt - Date.now()) / 60_000));
|
|
328
|
+
const instruction = `Reports from this server are sent as your GitHub user, so sign in once on this machine: open ${signIn.verificationUri} ` +
|
|
329
|
+
`and enter the code ${signIn.userCode} within ${minutes} minutes.`;
|
|
330
|
+
return enqueue(record, submission, (file) => `${instruction} The report is saved at ${file} and is sent as soon as you approve. Deleting that file cancels it.`, `${instruction} Then file the report again.`);
|
|
331
|
+
};
|
|
332
|
+
/** Renews a stored token once it is older than renewAfterSeconds. Forgets it if the hub no longer accepts it. */
|
|
333
|
+
const renewIfOld = async (file, renew) => {
|
|
334
|
+
const cached = await readCached(file);
|
|
335
|
+
const claims = cached && unverifiedClaimsOf(cached.token);
|
|
336
|
+
if (!cached || !claims || Date.now() - claims.iat * 1000 < renewAfterMs)
|
|
337
|
+
return false;
|
|
338
|
+
const response = await renew(cached.token);
|
|
339
|
+
if (response.ok) {
|
|
340
|
+
await save(file, await tokenBody(response));
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
if ([401, 403, 404].includes(response.status))
|
|
344
|
+
await rm(file, { force: true });
|
|
345
|
+
return false;
|
|
346
|
+
};
|
|
347
|
+
return {
|
|
348
|
+
stateDir,
|
|
349
|
+
async insert(record) {
|
|
350
|
+
const submission = toIngestSubmission(record);
|
|
351
|
+
// Older reports go first, and a hub that is down is found out once, not twice.
|
|
352
|
+
const flushed = await flushInternal();
|
|
353
|
+
if (flushed.blocked === "unreachable" && flushed.remaining > 0)
|
|
354
|
+
return queueUnreachable(record, submission);
|
|
355
|
+
if (flushed.blocked === "signin" && flushed.remaining > 0)
|
|
356
|
+
return queueForSignIn(record, submission);
|
|
357
|
+
const outcome = await deliver(submission);
|
|
358
|
+
if (outcome.kind === "delivered")
|
|
359
|
+
return { delivery: "stored" };
|
|
360
|
+
if (outcome.kind === "retry")
|
|
361
|
+
return queueUnreachable(record, submission);
|
|
362
|
+
if (outcome.kind === "signin")
|
|
363
|
+
return queueForSignIn(record, submission);
|
|
364
|
+
throw new FeedbackDeliveryError(outcome.kind === "refused" ? outcome.message : "The feedback service refused the report.");
|
|
365
|
+
},
|
|
366
|
+
async start() {
|
|
367
|
+
const renewed = [];
|
|
368
|
+
if (!options.token) {
|
|
369
|
+
try {
|
|
370
|
+
if (await renewIfOld(userFile, (token) => request(INGEST_PATHS.renew, token)))
|
|
371
|
+
renewed.push("user");
|
|
372
|
+
const renewedProject = await renewIfOld(tokenFile, async (token) => {
|
|
373
|
+
if (unverifiedClaimsOf(token)?.tier === "install")
|
|
374
|
+
return request(INGEST_PATHS.renew, token);
|
|
375
|
+
// A signed-in person's token for this project is renewed from their sign-in.
|
|
376
|
+
const user = usable(await readCached(userFile));
|
|
377
|
+
return user
|
|
378
|
+
? request(INGEST_PATHS.enroll, options.projectKey, { user_token: user.token })
|
|
379
|
+
: new Response(null, { status: 401 });
|
|
380
|
+
});
|
|
381
|
+
if (renewedProject)
|
|
382
|
+
renewed.push("project");
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
// Offline, or the hub is down: the tokens still work until they expire, so this is not worth reporting.
|
|
386
|
+
const network = error instanceof RetryableError || error instanceof TypeError || error?.name === "TimeoutError";
|
|
387
|
+
if (!network)
|
|
388
|
+
options.onError?.(error);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const { blocked: _blocked, ...flushed } = await flushInternal();
|
|
392
|
+
return { ...flushed, renewed };
|
|
393
|
+
},
|
|
394
|
+
async flush() {
|
|
395
|
+
const { blocked: _blocked, ...result } = await flushInternal();
|
|
396
|
+
return result;
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
}
|
package/dist/store.d.ts
CHANGED
|
@@ -14,6 +14,23 @@ export interface FeedbackStore {
|
|
|
14
14
|
stats(filter: FeedbackFilter): Promise<FeedbackStats>;
|
|
15
15
|
close?(): Promise<void>;
|
|
16
16
|
}
|
|
17
|
+
/** What became of a submission, for a sink with more to say than "stored". */
|
|
18
|
+
export interface FeedbackReceipt {
|
|
19
|
+
/** `queued`: accepted but not yet delivered, e.g. saved locally until a remote service is reachable. */
|
|
20
|
+
delivery: "stored" | "queued";
|
|
21
|
+
/** Shown to the submitting agent, e.g. where a queued report is waiting. Must be safe to show. */
|
|
22
|
+
note?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The write half of the contract, which is all `registerFeedback` needs. Every store is a sink;
|
|
26
|
+
* a sink that cannot be read locally (remoteStore) is not a store.
|
|
27
|
+
*/
|
|
28
|
+
export interface FeedbackSink {
|
|
29
|
+
insert(record: FeedbackRecord): Promise<void | FeedbackReceipt>;
|
|
30
|
+
}
|
|
31
|
+
/** A submission could not be delivered. Its message is safe to show to the caller. */
|
|
32
|
+
export declare class FeedbackDeliveryError extends Error {
|
|
33
|
+
}
|
|
17
34
|
/** Identity helper that type-checks a custom store against the contract. */
|
|
18
35
|
export declare function defineFeedbackStore<T extends FeedbackStore>(store: T): T;
|
|
19
36
|
export declare function toolNamesOf(record: FeedbackRecord): string[];
|
package/dist/store.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/** A submission could not be delivered. Its message is safe to show to the caller. */
|
|
2
|
+
export class FeedbackDeliveryError extends Error {
|
|
3
|
+
}
|
|
1
4
|
/** Identity helper that type-checks a custom store against the contract. */
|
|
2
5
|
export function defineFeedbackStore(store) {
|
|
3
6
|
return store;
|
|
@@ -33,6 +36,8 @@ export function matchesFilter(record, filter) {
|
|
|
33
36
|
return false;
|
|
34
37
|
if (filter.subject !== undefined && record.identity.subject !== filter.subject)
|
|
35
38
|
return false;
|
|
39
|
+
if (filter.server !== undefined && record.server.name !== filter.server)
|
|
40
|
+
return false;
|
|
36
41
|
if (filter.tool !== undefined && !toolNamesOf(record).includes(filter.tool))
|
|
37
42
|
return false;
|
|
38
43
|
if (filter.tag !== undefined && !record.tags.includes(filter.tag))
|
package/dist/stores/memory.js
CHANGED
|
@@ -36,7 +36,7 @@ export function memoryStore() {
|
|
|
36
36
|
return copy(record);
|
|
37
37
|
},
|
|
38
38
|
async stats(filter) {
|
|
39
|
-
const stats = { total: 0, by_kind: {}, by_status: {}, by_severity: {}, by_tool: {} };
|
|
39
|
+
const stats = { total: 0, by_kind: {}, by_status: {}, by_severity: {}, by_tool: {}, by_server: {} };
|
|
40
40
|
const bump = (counts, key) => {
|
|
41
41
|
counts[key] = (counts[key] ?? 0) + 1;
|
|
42
42
|
};
|
|
@@ -49,6 +49,8 @@ export function memoryStore() {
|
|
|
49
49
|
bump(stats.by_severity, record.severity);
|
|
50
50
|
for (const tool of toolNamesOf(record))
|
|
51
51
|
bump(stats.by_tool, tool);
|
|
52
|
+
if (record.server.name !== null)
|
|
53
|
+
bump(stats.by_server, record.server.name);
|
|
52
54
|
}
|
|
53
55
|
return stats;
|
|
54
56
|
},
|
package/dist/stores/sql.js
CHANGED
|
@@ -69,6 +69,8 @@ export function schemaStatements(dialect, table) {
|
|
|
69
69
|
`CREATE INDEX IF NOT EXISTS ${table}_created_idx ON ${table} (created_at DESC, id DESC)`,
|
|
70
70
|
`CREATE INDEX IF NOT EXISTS ${table}_status_idx ON ${table} (status)`,
|
|
71
71
|
`CREATE INDEX IF NOT EXISTS ${table}_kind_idx ON ${table} (kind)`,
|
|
72
|
+
// An ingest hub keeps many servers' feedback in one table and reads it a server at a time.
|
|
73
|
+
`CREATE INDEX IF NOT EXISTS ${table}_server_idx ON ${table} (server_name)`,
|
|
72
74
|
];
|
|
73
75
|
}
|
|
74
76
|
function toRow(record) {
|
|
@@ -150,6 +152,8 @@ function where(dialect, filter) {
|
|
|
150
152
|
add("f.severity = ?", filter.severity);
|
|
151
153
|
if (filter.subject !== undefined)
|
|
152
154
|
add("f.subject = ?", filter.subject);
|
|
155
|
+
if (filter.server !== undefined)
|
|
156
|
+
add("f.server_name = ?", filter.server);
|
|
153
157
|
if (filter.tool !== undefined)
|
|
154
158
|
contains("tool_names", filter.tool);
|
|
155
159
|
if (filter.tag !== undefined)
|
|
@@ -221,6 +225,7 @@ export function sqlOperations(dialect, table, run) {
|
|
|
221
225
|
by_status: await grouped("status"),
|
|
222
226
|
by_severity: await grouped("severity"),
|
|
223
227
|
by_tool: await counts(`SELECT j.value AS k, COUNT(*) AS c FROM ${table} f ${each}${filterSql} GROUP BY j.value`),
|
|
228
|
+
by_server: await counts(`SELECT f.server_name AS k, COUNT(*) AS c FROM ${table} f${whereSql([...clauses, "f.server_name IS NOT NULL"])} GROUP BY f.server_name`),
|
|
224
229
|
};
|
|
225
230
|
},
|
|
226
231
|
};
|
package/dist/tools.d.ts
CHANGED
|
@@ -161,6 +161,7 @@ export declare const listFeedbackShape: {
|
|
|
161
161
|
status: z.ZodOptional<z.ZodEnum<["new", "triaged", "resolved", "dismissed"]>>;
|
|
162
162
|
severity: z.ZodOptional<z.ZodEnum<["blocker", "major", "minor", "none"]>>;
|
|
163
163
|
subject: z.ZodOptional<z.ZodString>;
|
|
164
|
+
server: z.ZodOptional<z.ZodString>;
|
|
164
165
|
tool: z.ZodOptional<z.ZodString>;
|
|
165
166
|
tag: z.ZodOptional<z.ZodString>;
|
|
166
167
|
since: z.ZodOptional<z.ZodString>;
|
|
@@ -189,6 +190,7 @@ export declare const feedbackStatsShape: {
|
|
|
189
190
|
status: z.ZodOptional<z.ZodEnum<["new", "triaged", "resolved", "dismissed"]>>;
|
|
190
191
|
severity: z.ZodOptional<z.ZodEnum<["blocker", "major", "minor", "none"]>>;
|
|
191
192
|
subject: z.ZodOptional<z.ZodString>;
|
|
193
|
+
server: z.ZodOptional<z.ZodString>;
|
|
192
194
|
tool: z.ZodOptional<z.ZodString>;
|
|
193
195
|
tag: z.ZodOptional<z.ZodString>;
|
|
194
196
|
since: z.ZodOptional<z.ZodString>;
|
|
@@ -274,7 +276,11 @@ export declare const feedbackInstructions: string;
|
|
|
274
276
|
export declare const CONFIRMATION_REQUIRED: string;
|
|
275
277
|
/** The `feedbackInstructions` counterpart for hosts that set `requireConfirmation`. */
|
|
276
278
|
export declare const feedbackConfirmInstructions: string;
|
|
277
|
-
|
|
279
|
+
/**
|
|
280
|
+
* The submit tool's description. `destination` names where reports go when that is somewhere other
|
|
281
|
+
* than the server the agent is talking to, so the user can be told before they confirm.
|
|
282
|
+
*/
|
|
283
|
+
export declare function submitToolDescription(requireConfirmation?: boolean, destination?: string): string;
|
|
278
284
|
/** `{ name, description }` entries for hosts that publish a tool catalog. */
|
|
279
285
|
export declare const feedbackToolCatalog: {
|
|
280
286
|
name: "submit_feedback";
|
|
@@ -284,6 +290,7 @@ export declare const feedbackToolCatalog: {
|
|
|
284
290
|
export declare function feedbackToolCatalogFor(options?: {
|
|
285
291
|
requireConfirmation?: boolean;
|
|
286
292
|
toolPrefix?: string;
|
|
293
|
+
destination?: string;
|
|
287
294
|
}): {
|
|
288
295
|
name: string;
|
|
289
296
|
description: string;
|
package/dist/tools.js
CHANGED
|
@@ -72,6 +72,10 @@ const filterShape = {
|
|
|
72
72
|
status: z.enum(FEEDBACK_STATUSES).optional(),
|
|
73
73
|
severity: z.enum(FEEDBACK_SEVERITIES).optional(),
|
|
74
74
|
subject: z.string().optional().describe("Only feedback from this caller subject."),
|
|
75
|
+
server: z
|
|
76
|
+
.string()
|
|
77
|
+
.optional()
|
|
78
|
+
.describe("Only feedback about this server (server.name). On an ingest hub that collects for several servers, the project name."),
|
|
75
79
|
tool: z.string().optional().describe("Only feedback that involves this tool name."),
|
|
76
80
|
tag: z.string().optional(),
|
|
77
81
|
since: z.string().optional().describe("ISO 8601 timestamp; include feedback created at or after it."),
|
|
@@ -107,8 +111,9 @@ export const SUBMIT_TOOL = {
|
|
|
107
111
|
title: "Submit feedback",
|
|
108
112
|
description: "Report a problem, friction, missing capability or success with this server's tools to its maintainers. " +
|
|
109
113
|
"Call it when a tool fails or behaves unexpectedly, when the user needed something the tools could not do, " +
|
|
110
|
-
"or when a tool was confusing to use. Include enough context for someone who was not in this session to act on it
|
|
111
|
-
"Never include secrets or personal data. The caller's identity is recorded
|
|
114
|
+
"or when a tool was confusing to use. Include enough context for someone who was not in this session to act on it, " +
|
|
115
|
+
"with only ids you were actually given. Never include secrets or personal data. The caller's identity is recorded " +
|
|
116
|
+
"by the server. Each call files a new report: if a call may have gone through, do not send it again.",
|
|
112
117
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
113
118
|
};
|
|
114
119
|
export const READER_TOOLS = {
|
|
@@ -166,25 +171,41 @@ export function synthesizePromptText(prefix, args) {
|
|
|
166
171
|
.filter((line, index, lines) => line !== "" || lines[index - 1] !== "")
|
|
167
172
|
.join("\n");
|
|
168
173
|
}
|
|
174
|
+
/** Ends both instruction texts: what agents otherwise get wrong about ids and retries. */
|
|
175
|
+
const SUBMIT_ONCE = "Put the ids of the objects involved in context.references, and only ids you were actually given, never a guess. " +
|
|
176
|
+
"Submit each report once: if the call times out or its result is unclear, tell the user instead of sending it again.";
|
|
169
177
|
/** Text a host can append to its server `instructions` so agents know when to file feedback. */
|
|
170
178
|
export const feedbackInstructions = "If one of this server's tools fails, behaves unexpectedly, is confusing, or cannot do what the user needed, " +
|
|
171
179
|
"call submit_feedback once you have handled or been blocked on the user's request. Describe the goal, what you " +
|
|
172
|
-
"expected, what happened and the tool calls involved, without secrets or personal data, and tell the user you filed it."
|
|
180
|
+
"expected, what happened and the tool calls involved, without secrets or personal data, and tell the user you filed it. " +
|
|
181
|
+
SUBMIT_ONCE;
|
|
173
182
|
/** Appended to the submit tool's description when the host sets `requireConfirmation`. */
|
|
174
183
|
export const CONFIRMATION_REQUIRED = " Only call it after showing the user the exact feedback you intend to submit and receiving their explicit " +
|
|
175
184
|
"confirmation; a complaint or request is not by itself permission.";
|
|
176
185
|
/** The `feedbackInstructions` counterpart for hosts that set `requireConfirmation`. */
|
|
177
186
|
export const feedbackConfirmInstructions = "If one of this server's tools fails, behaves unexpectedly, is confusing, or cannot do what the user needed, " +
|
|
178
187
|
"offer to file feedback: show the user the exact kind, title, body and context you would submit, and call " +
|
|
179
|
-
"submit_feedback only after they explicitly confirm. Leave out secrets and personal data."
|
|
180
|
-
|
|
181
|
-
|
|
188
|
+
"submit_feedback only after they explicitly confirm. Leave out secrets and personal data. " +
|
|
189
|
+
SUBMIT_ONCE;
|
|
190
|
+
/**
|
|
191
|
+
* The submit tool's description. `destination` names where reports go when that is somewhere other
|
|
192
|
+
* than the server the agent is talking to, so the user can be told before they confirm.
|
|
193
|
+
*/
|
|
194
|
+
export function submitToolDescription(requireConfirmation = false, destination) {
|
|
195
|
+
return (SUBMIT_TOOL.description +
|
|
196
|
+
(destination ? ` Reports leave this machine and are sent to ${destination}.` : "") +
|
|
197
|
+
(requireConfirmation ? CONFIRMATION_REQUIRED : ""));
|
|
182
198
|
}
|
|
183
199
|
/** `{ name, description }` entries for hosts that publish a tool catalog. */
|
|
184
200
|
export const feedbackToolCatalog = [{ name: SUBMIT_TOOL.name, description: SUBMIT_TOOL.description }];
|
|
185
201
|
/** The catalog entry exactly as registerFeedback advertises it with these options. */
|
|
186
202
|
export function feedbackToolCatalogFor(options = {}) {
|
|
187
|
-
return [
|
|
203
|
+
return [
|
|
204
|
+
{
|
|
205
|
+
name: (options.toolPrefix ?? "") + SUBMIT_TOOL.name,
|
|
206
|
+
description: submitToolDescription(options.requireConfirmation, options.destination),
|
|
207
|
+
},
|
|
208
|
+
];
|
|
188
209
|
}
|
|
189
210
|
export const feedbackReaderToolCatalog = Object.values(READER_TOOLS).map(({ name, description }) => ({
|
|
190
211
|
name,
|
package/dist/types.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export interface FeedbackFilter {
|
|
|
64
64
|
status?: FeedbackStatus;
|
|
65
65
|
severity?: FeedbackSeverity;
|
|
66
66
|
subject?: string;
|
|
67
|
+
/** Matches records whose server.name equals this: one server, or one project on an ingest hub. */
|
|
68
|
+
server?: string;
|
|
67
69
|
/** Matches records whose context.tool_calls names include this tool. */
|
|
68
70
|
tool?: string;
|
|
69
71
|
tag?: string;
|
|
@@ -98,4 +100,6 @@ export interface FeedbackStats {
|
|
|
98
100
|
by_status: Record<string, number>;
|
|
99
101
|
by_severity: Record<string, number>;
|
|
100
102
|
by_tool: Record<string, number>;
|
|
103
|
+
/** Counts by server.name. Records with no server name are not counted here. */
|
|
104
|
+
by_server: Record<string, number>;
|
|
101
105
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-feedback",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Drop-in feedback tools for MCP servers: agents submit structured feedback, stamped with the caller's identity, into a pluggable store.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
30
|
"dist",
|
|
31
|
+
"skills",
|
|
32
|
+
"agentdist.json",
|
|
31
33
|
"README.md",
|
|
32
34
|
"LICENSE"
|
|
33
35
|
],
|
|
@@ -55,6 +57,14 @@
|
|
|
55
57
|
"./client": {
|
|
56
58
|
"types": "./dist/client.d.ts",
|
|
57
59
|
"default": "./dist/client.js"
|
|
60
|
+
},
|
|
61
|
+
"./remote": {
|
|
62
|
+
"types": "./dist/remote.d.ts",
|
|
63
|
+
"default": "./dist/remote.js"
|
|
64
|
+
},
|
|
65
|
+
"./ingest": {
|
|
66
|
+
"types": "./dist/ingest/index.d.ts",
|
|
67
|
+
"default": "./dist/ingest/index.js"
|
|
58
68
|
}
|
|
59
69
|
},
|
|
60
70
|
"scripts": {
|
|
@@ -62,7 +72,9 @@
|
|
|
62
72
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
63
73
|
"test": "vitest run",
|
|
64
74
|
"gen:spec": "UPDATE_SPEC=1 vitest run test/spec.test.ts",
|
|
65
|
-
"prepublishOnly": "pnpm run typecheck && pnpm run test && pnpm run build"
|
|
75
|
+
"prepublishOnly": "pnpm run typecheck && pnpm run test && pnpm run build",
|
|
76
|
+
"prepack": "node -e \"const fs=require('node:fs');fs.rmSync('skills',{recursive:true,force:true});fs.cpSync('../../skills','skills',{recursive:true});fs.copyFileSync('../../agentdist.json','agentdist.json')\"",
|
|
77
|
+
"postpack": "node -e \"const fs=require('node:fs');fs.rmSync('skills',{recursive:true,force:true});fs.rmSync('agentdist.json',{force:true})\""
|
|
66
78
|
},
|
|
67
79
|
"peerDependencies": {
|
|
68
80
|
"@modelcontextprotocol/sdk": "^1.20.0",
|
|
@@ -88,6 +100,7 @@
|
|
|
88
100
|
"zod": "3.25.76"
|
|
89
101
|
},
|
|
90
102
|
"dependencies": {
|
|
103
|
+
"agentdist": "^0.1.0",
|
|
91
104
|
"pg": "^8.0.0"
|
|
92
105
|
}
|
|
93
106
|
}
|