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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// The body an installation sends to a hub's /v1/feedback, shared by remoteStore and the hub.
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { submitFeedbackShapeFor } from "../tools.js";
|
|
4
|
+
export const INGEST_PATHS = {
|
|
5
|
+
enroll: "/v1/enroll",
|
|
6
|
+
feedback: "/v1/feedback",
|
|
7
|
+
renew: "/v1/renew",
|
|
8
|
+
githubStart: "/v1/signin/github/start",
|
|
9
|
+
githubPoll: "/v1/signin/github/poll",
|
|
10
|
+
wellKnown: "/.well-known/mcp-feedback",
|
|
11
|
+
};
|
|
12
|
+
/** The most a hub reads of a request body. */
|
|
13
|
+
export const MAX_INGEST_BODY_BYTES = 64 * 1024;
|
|
14
|
+
/** How long a report may wait in an installation's queue, and so how old an id a hub accepts. */
|
|
15
|
+
export const MAX_QUEUE_AGE_DAYS = 30;
|
|
16
|
+
const reported = z.string().max(200).nullable().optional();
|
|
17
|
+
/**
|
|
18
|
+
* What an installation sends: the submission, plus what the installation itself recorded. Every
|
|
19
|
+
* field is the installation's own account; the hub stamps identity, project, status and time.
|
|
20
|
+
*/
|
|
21
|
+
export const ingestSubmissionSchema = z.object({
|
|
22
|
+
...submitFeedbackShapeFor(),
|
|
23
|
+
/** The installation's id for the report, reused on every retry so the hub can tell a retry from a new report. */
|
|
24
|
+
id: z.string().max(64).optional(),
|
|
25
|
+
/** When the installation built the report. Kept for reference only; the hub records when it received it. */
|
|
26
|
+
created_at: z.string().max(64).optional(),
|
|
27
|
+
/** What the server's own attachContext hook recorded. */
|
|
28
|
+
server_context: z.record(z.string(), z.unknown()).optional(),
|
|
29
|
+
server_version: reported,
|
|
30
|
+
client_name: reported,
|
|
31
|
+
client_version: reported,
|
|
32
|
+
});
|
|
33
|
+
/** The wire form of a record built by registerFeedback in an installation. */
|
|
34
|
+
export function toIngestSubmission(record) {
|
|
35
|
+
const { server_context, ...context } = record.context;
|
|
36
|
+
return {
|
|
37
|
+
id: record.id,
|
|
38
|
+
created_at: record.created_at,
|
|
39
|
+
kind: record.kind,
|
|
40
|
+
title: record.title,
|
|
41
|
+
body: record.body,
|
|
42
|
+
severity: record.severity,
|
|
43
|
+
tags: record.tags,
|
|
44
|
+
context,
|
|
45
|
+
...(server_context ? { server_context } : {}),
|
|
46
|
+
server_version: record.server.version,
|
|
47
|
+
client_name: record.identity.client_name,
|
|
48
|
+
client_version: record.identity.client_version,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Reads a token's claims without verifying them. Only for an installation's own bookkeeping (when to renew). */
|
|
52
|
+
export function unverifiedClaimsOf(token) {
|
|
53
|
+
const payload = token.split(".")[1];
|
|
54
|
+
if (!payload)
|
|
55
|
+
return null;
|
|
56
|
+
try {
|
|
57
|
+
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
58
|
+
if (typeof claims.tier !== "string" || typeof claims.iat !== "number" || typeof claims.sub !== "string")
|
|
59
|
+
return null;
|
|
60
|
+
return { tier: claims.tier, iat: claims.iat, sub: claims.sub, ...(typeof claims.exp === "number" ? { exp: claims.exp } : {}) };
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Reads the project a token names without verifying it. Only for choosing where to keep local state. */
|
|
67
|
+
export function unverifiedProjectOf(token) {
|
|
68
|
+
const payload = token.split(".")[1];
|
|
69
|
+
if (!payload)
|
|
70
|
+
return null;
|
|
71
|
+
try {
|
|
72
|
+
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
73
|
+
return typeof claims.prj === "string" && /^[a-z0-9][a-z0-9._-]{0,63}$/.test(claims.prj) ? claims.prj : null;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type KeyObject } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* What a token was issued for.
|
|
4
|
+
* - `project`: names a project. Ships inside a distributed package, so it is public; it can only enrol.
|
|
5
|
+
* - `install`: issued by the hub to one installation when it enrols. Anonymous but stable.
|
|
6
|
+
* - `issued`: names a person: issued by a maintainer, or by the hub to someone signed in.
|
|
7
|
+
* - `user`: a person who signed in (e.g. with GitHub), for every project on the hub. It can only be
|
|
8
|
+
* exchanged for that person's `issued` token for one project, or renewed.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TOKEN_TIERS: readonly ["project", "install", "issued", "user"];
|
|
11
|
+
/** `prj` of a `user` token: it is good for every project on the hub. */
|
|
12
|
+
export declare const ANY_PROJECT = "*";
|
|
13
|
+
export type TokenTier = (typeof TOKEN_TIERS)[number];
|
|
14
|
+
export interface TokenClaims {
|
|
15
|
+
/** The hub that will accept the token. */
|
|
16
|
+
iss: string;
|
|
17
|
+
/** The project the token belongs to; `*` for a `user` token. */
|
|
18
|
+
prj: string;
|
|
19
|
+
tier: TokenTier;
|
|
20
|
+
/** Who it was issued to: `project:<name>`, `install:<random>`, `github:<login>`, or the subject a maintainer chose. */
|
|
21
|
+
sub: string;
|
|
22
|
+
/** Issued at, seconds since the epoch. */
|
|
23
|
+
iat: number;
|
|
24
|
+
/** Expires at, seconds since the epoch. Optional for project keys only. */
|
|
25
|
+
exp?: number;
|
|
26
|
+
/** Unique id, for revoking one token. */
|
|
27
|
+
jti: string;
|
|
28
|
+
}
|
|
29
|
+
export interface SigningKey {
|
|
30
|
+
kid: string;
|
|
31
|
+
/** PEM (PKCS#8) or a KeyObject. */
|
|
32
|
+
privateKey: string | KeyObject;
|
|
33
|
+
}
|
|
34
|
+
export interface VerificationKey {
|
|
35
|
+
kid: string;
|
|
36
|
+
/** PEM (SPKI) or a KeyObject. */
|
|
37
|
+
publicKey: string | KeyObject;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The keys a hub trusts, and optionally the one it signs install tokens with. Listing several
|
|
41
|
+
* `kid`s lets a key be rotated without invalidating tokens signed by the old one.
|
|
42
|
+
*/
|
|
43
|
+
export interface Keyring {
|
|
44
|
+
keys: VerificationKey[];
|
|
45
|
+
signer?: SigningKey;
|
|
46
|
+
}
|
|
47
|
+
/** A token failed verification. The message is safe to return to the caller. */
|
|
48
|
+
export declare class TokenError extends Error {
|
|
49
|
+
readonly reason: "malformed" | "signature" | "expired" | "issuer" | "tier" | "unknown_key";
|
|
50
|
+
constructor(message: string, reason: "malformed" | "signature" | "expired" | "issuer" | "tier" | "unknown_key");
|
|
51
|
+
}
|
|
52
|
+
export declare function isValidProjectName(name: string): boolean;
|
|
53
|
+
/** A new Ed25519 key pair, as PEM. Keep the private key out of anything you distribute. */
|
|
54
|
+
export declare function generateKeyPair(kid?: string): {
|
|
55
|
+
kid: string;
|
|
56
|
+
privateKey: string;
|
|
57
|
+
publicKey: string;
|
|
58
|
+
};
|
|
59
|
+
/** The public half of a private key, for a keyring entry. */
|
|
60
|
+
export declare function publicKeyOf(privateKey: string | KeyObject): string;
|
|
61
|
+
export declare function newTokenId(): string;
|
|
62
|
+
/** Signs a token. Callers decide the claims; `issueToken` is the usual way in. */
|
|
63
|
+
export declare function signToken(claims: TokenClaims, signer: SigningKey): string;
|
|
64
|
+
/** Builds and signs a token for a tier with sensible defaults for the rest. */
|
|
65
|
+
export declare function issueToken(options: {
|
|
66
|
+
issuer: string;
|
|
67
|
+
project: string;
|
|
68
|
+
tier: TokenTier;
|
|
69
|
+
subject?: string;
|
|
70
|
+
ttlSeconds?: number;
|
|
71
|
+
now?: Date;
|
|
72
|
+
}, signer: SigningKey): {
|
|
73
|
+
token: string;
|
|
74
|
+
claims: TokenClaims;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Verifies a token's signature, issuer, expiry and tier, and returns its claims. Throws a
|
|
78
|
+
* TokenError otherwise. Revocation is the caller's check, against `jti` or `sub`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function verifyToken(token: string, keyring: Pick<Keyring, "keys">, options: {
|
|
81
|
+
issuer: string;
|
|
82
|
+
tiers: readonly TokenTier[];
|
|
83
|
+
now?: Date;
|
|
84
|
+
}): TokenClaims;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Signed tokens for the ingest hub (spec/ingest.md). Compact JWTs signed with Ed25519, with the
|
|
2
|
+
// algorithm fixed: a token whose header names any other algorithm is rejected, never "verified"
|
|
3
|
+
// some other way.
|
|
4
|
+
import { createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes, sign, verify } from "node:crypto";
|
|
5
|
+
/**
|
|
6
|
+
* What a token was issued for.
|
|
7
|
+
* - `project`: names a project. Ships inside a distributed package, so it is public; it can only enrol.
|
|
8
|
+
* - `install`: issued by the hub to one installation when it enrols. Anonymous but stable.
|
|
9
|
+
* - `issued`: names a person: issued by a maintainer, or by the hub to someone signed in.
|
|
10
|
+
* - `user`: a person who signed in (e.g. with GitHub), for every project on the hub. It can only be
|
|
11
|
+
* exchanged for that person's `issued` token for one project, or renewed.
|
|
12
|
+
*/
|
|
13
|
+
export const TOKEN_TIERS = ["project", "install", "issued", "user"];
|
|
14
|
+
/** `prj` of a `user` token: it is good for every project on the hub. */
|
|
15
|
+
export const ANY_PROJECT = "*";
|
|
16
|
+
/** A token failed verification. The message is safe to return to the caller. */
|
|
17
|
+
export class TokenError extends Error {
|
|
18
|
+
reason;
|
|
19
|
+
constructor(message, reason) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.reason = reason;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const KID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
25
|
+
const PROJECT_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
26
|
+
/** Tokens are short; anything longer is not one of ours and is not worth parsing. */
|
|
27
|
+
const MAX_TOKEN_LENGTH = 4096;
|
|
28
|
+
/** Accepted clock difference between whoever signed a token and the hub. */
|
|
29
|
+
const CLOCK_SKEW_SECONDS = 300;
|
|
30
|
+
const b64 = (value) => Buffer.from(value).toString("base64url");
|
|
31
|
+
const unb64 = (value) => Buffer.from(value, "base64url");
|
|
32
|
+
export function isValidProjectName(name) {
|
|
33
|
+
return PROJECT_PATTERN.test(name);
|
|
34
|
+
}
|
|
35
|
+
/** A new Ed25519 key pair, as PEM. Keep the private key out of anything you distribute. */
|
|
36
|
+
export function generateKeyPair(kid = `k${Date.now().toString(36)}`) {
|
|
37
|
+
if (!KID_PATTERN.test(kid))
|
|
38
|
+
throw new Error("kid must be 1 to 64 letters, digits, _ or -.");
|
|
39
|
+
const { privateKey, publicKey } = generateKeyPairSync("ed25519");
|
|
40
|
+
return {
|
|
41
|
+
kid,
|
|
42
|
+
privateKey: privateKey.export({ type: "pkcs8", format: "pem" }).toString(),
|
|
43
|
+
publicKey: publicKey.export({ type: "spki", format: "pem" }).toString(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** The public half of a private key, for a keyring entry. */
|
|
47
|
+
export function publicKeyOf(privateKey) {
|
|
48
|
+
const key = typeof privateKey === "string" ? createPrivateKey(privateKey) : privateKey;
|
|
49
|
+
return createPublicKey(key).export({ type: "spki", format: "pem" }).toString();
|
|
50
|
+
}
|
|
51
|
+
function asPrivate(key) {
|
|
52
|
+
const object = typeof key === "string" ? createPrivateKey(key) : key;
|
|
53
|
+
if (object.asymmetricKeyType !== "ed25519")
|
|
54
|
+
throw new Error("Signing keys must be Ed25519.");
|
|
55
|
+
return object;
|
|
56
|
+
}
|
|
57
|
+
function asPublic(key) {
|
|
58
|
+
const object = typeof key === "string" ? createPublicKey(key) : key;
|
|
59
|
+
if (object.asymmetricKeyType !== "ed25519")
|
|
60
|
+
throw new Error("Verification keys must be Ed25519.");
|
|
61
|
+
return object;
|
|
62
|
+
}
|
|
63
|
+
export function newTokenId() {
|
|
64
|
+
return randomBytes(12).toString("base64url");
|
|
65
|
+
}
|
|
66
|
+
/** Signs a token. Callers decide the claims; `issueToken` is the usual way in. */
|
|
67
|
+
export function signToken(claims, signer) {
|
|
68
|
+
if (!KID_PATTERN.test(signer.kid))
|
|
69
|
+
throw new Error("kid must be 1 to 64 letters, digits, _ or -.");
|
|
70
|
+
if (claims.tier === "user" ? claims.prj !== ANY_PROJECT : !isValidProjectName(claims.prj)) {
|
|
71
|
+
throw new Error("Project names are lowercase letters, digits, ., _ or -, at most 64 (and * only for a user token).");
|
|
72
|
+
}
|
|
73
|
+
if (claims.tier !== "project" && claims.exp === undefined)
|
|
74
|
+
throw new Error(`An ${claims.tier} token needs an expiry.`);
|
|
75
|
+
const header = b64(JSON.stringify({ alg: "EdDSA", typ: "JWT", kid: signer.kid }));
|
|
76
|
+
const payload = b64(JSON.stringify(claims));
|
|
77
|
+
const signature = sign(null, Buffer.from(`${header}.${payload}`), asPrivate(signer.privateKey));
|
|
78
|
+
return `${header}.${payload}.${b64(signature)}`;
|
|
79
|
+
}
|
|
80
|
+
/** Builds and signs a token for a tier with sensible defaults for the rest. */
|
|
81
|
+
export function issueToken(options, signer) {
|
|
82
|
+
const iat = Math.floor((options.now ?? new Date()).getTime() / 1000);
|
|
83
|
+
const subject = options.subject ?? (options.tier === "project" ? `project:${options.project}` : options.tier === "install" ? `install:${newTokenId()}` : undefined);
|
|
84
|
+
if (!subject)
|
|
85
|
+
throw new Error(`An ${options.tier} token needs a subject: who it is for.`);
|
|
86
|
+
const claims = {
|
|
87
|
+
iss: options.issuer,
|
|
88
|
+
prj: options.project,
|
|
89
|
+
tier: options.tier,
|
|
90
|
+
sub: subject,
|
|
91
|
+
iat,
|
|
92
|
+
...(options.ttlSeconds !== undefined ? { exp: iat + options.ttlSeconds } : {}),
|
|
93
|
+
jti: newTokenId(),
|
|
94
|
+
};
|
|
95
|
+
return { token: signToken(claims, signer), claims };
|
|
96
|
+
}
|
|
97
|
+
function parseJson(part) {
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(unb64(part).toString("utf8"));
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new TokenError("The token is not well formed.", "malformed");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function isClaims(value) {
|
|
106
|
+
if (!value || typeof value !== "object")
|
|
107
|
+
return false;
|
|
108
|
+
const claims = value;
|
|
109
|
+
return (typeof claims.iss === "string" &&
|
|
110
|
+
typeof claims.prj === "string" &&
|
|
111
|
+
typeof claims.tier === "string" &&
|
|
112
|
+
TOKEN_TIERS.includes(claims.tier) &&
|
|
113
|
+
(claims.tier === "user" ? claims.prj === ANY_PROJECT : isValidProjectName(claims.prj)) &&
|
|
114
|
+
typeof claims.sub === "string" &&
|
|
115
|
+
claims.sub.length > 0 &&
|
|
116
|
+
claims.sub.length <= 200 &&
|
|
117
|
+
typeof claims.iat === "number" &&
|
|
118
|
+
(claims.exp === undefined || typeof claims.exp === "number") &&
|
|
119
|
+
typeof claims.jti === "string" &&
|
|
120
|
+
claims.jti.length > 0 &&
|
|
121
|
+
claims.jti.length <= 64);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Verifies a token's signature, issuer, expiry and tier, and returns its claims. Throws a
|
|
125
|
+
* TokenError otherwise. Revocation is the caller's check, against `jti` or `sub`.
|
|
126
|
+
*/
|
|
127
|
+
export function verifyToken(token, keyring, options) {
|
|
128
|
+
if (typeof token !== "string" || token.length === 0 || token.length > MAX_TOKEN_LENGTH) {
|
|
129
|
+
throw new TokenError("The token is not well formed.", "malformed");
|
|
130
|
+
}
|
|
131
|
+
const parts = token.split(".");
|
|
132
|
+
if (parts.length !== 3 || parts.some((part) => !/^[A-Za-z0-9_-]+$/.test(part))) {
|
|
133
|
+
throw new TokenError("The token is not well formed.", "malformed");
|
|
134
|
+
}
|
|
135
|
+
const [headerPart, payloadPart, signaturePart] = parts;
|
|
136
|
+
const header = parseJson(headerPart);
|
|
137
|
+
if (!header || header.alg !== "EdDSA" || typeof header.kid !== "string") {
|
|
138
|
+
throw new TokenError("The token is not signed the way this hub signs tokens.", "malformed");
|
|
139
|
+
}
|
|
140
|
+
const key = keyring.keys.find((candidate) => candidate.kid === header.kid);
|
|
141
|
+
if (!key)
|
|
142
|
+
throw new TokenError("The token was signed by a key this hub does not know.", "unknown_key");
|
|
143
|
+
const valid = verify(null, Buffer.from(`${headerPart}.${payloadPart}`), asPublic(key.publicKey), unb64(signaturePart));
|
|
144
|
+
if (!valid)
|
|
145
|
+
throw new TokenError("The token's signature is not valid.", "signature");
|
|
146
|
+
// Only a token with a valid signature gets its claims looked at.
|
|
147
|
+
const claims = parseJson(payloadPart);
|
|
148
|
+
if (!isClaims(claims))
|
|
149
|
+
throw new TokenError("The token's claims are not well formed.", "malformed");
|
|
150
|
+
if (claims.iss !== options.issuer)
|
|
151
|
+
throw new TokenError("The token was issued for a different hub.", "issuer");
|
|
152
|
+
const now = Math.floor((options.now ?? new Date()).getTime() / 1000);
|
|
153
|
+
if (claims.exp !== undefined && claims.exp + CLOCK_SKEW_SECONDS < now)
|
|
154
|
+
throw new TokenError("The token has expired.", "expired");
|
|
155
|
+
if (claims.iat - CLOCK_SKEW_SECONDS > now)
|
|
156
|
+
throw new TokenError("The token is not valid yet.", "expired");
|
|
157
|
+
if (claims.tier !== "project" && claims.exp === undefined)
|
|
158
|
+
throw new TokenError("The token has no expiry.", "malformed");
|
|
159
|
+
if (!options.tiers.includes(claims.tier)) {
|
|
160
|
+
throw new TokenError(`A ${claims.tier} token cannot be used here.`, "tier");
|
|
161
|
+
}
|
|
162
|
+
return claims;
|
|
163
|
+
}
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// `mcp-feedback install`, `uninstall`, `status` and `harnesses`: the agent skills that ship with the package,
|
|
2
|
+
// installed into a project's or the user's agent harnesses by agentdist, from the agentdist.json beside them.
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { realEnv, runCli } from "agentdist";
|
|
7
|
+
/** The published package's root, which holds agentdist.json and the skills, or the repository's in a checkout. */
|
|
8
|
+
function packageRoot() {
|
|
9
|
+
const candidates = ["..", "../../.."].map((path) => fileURLToPath(new URL(path, import.meta.url)));
|
|
10
|
+
const found = candidates.find((path) => existsSync(join(path, "agentdist.json")));
|
|
11
|
+
if (!found)
|
|
12
|
+
throw new Error("agentdist.json is missing from this copy of mcp-feedback.");
|
|
13
|
+
return found;
|
|
14
|
+
}
|
|
15
|
+
/** Hands the command to agentdist and resolves the process exit code. */
|
|
16
|
+
export async function installCli(argv, io) {
|
|
17
|
+
// agentdist writes whole lines, ending in a newline; io.out and io.err add their own.
|
|
18
|
+
const line = (write) => (text) => write(text.replace(/\n$/, ""));
|
|
19
|
+
return runCli({
|
|
20
|
+
packageRoot: packageRoot(),
|
|
21
|
+
argv,
|
|
22
|
+
bin: "npx mcp-feedback",
|
|
23
|
+
env: io.installDirs && realEnv({ ...io.installDirs, vars: io.env }),
|
|
24
|
+
stdout: line(io.out),
|
|
25
|
+
stderr: line(io.err),
|
|
26
|
+
});
|
|
27
|
+
}
|
package/dist/reader.js
CHANGED
|
@@ -27,6 +27,7 @@ export function normalizeFilter(args) {
|
|
|
27
27
|
status: args.status,
|
|
28
28
|
severity: args.severity,
|
|
29
29
|
subject: args.subject,
|
|
30
|
+
server: args.server,
|
|
30
31
|
tool: args.tool,
|
|
31
32
|
tag: args.tag,
|
|
32
33
|
since: normalizeTimestamp("since", args.since),
|
|
@@ -77,7 +78,11 @@ export class FeedbackReaderError extends Error {
|
|
|
77
78
|
/** Reader operations straight against a store. `defaultBy` is used when a triage gives no `by`. */
|
|
78
79
|
export function storeReader(store, defaultBy = null) {
|
|
79
80
|
return {
|
|
80
|
-
|
|
81
|
+
// A custom store written before by_server existed still answers with a complete shape.
|
|
82
|
+
stats: async (filter) => {
|
|
83
|
+
const stats = await store.stats(normalizeFilter(filter));
|
|
84
|
+
return { ...stats, by_server: stats.by_server ?? {} };
|
|
85
|
+
},
|
|
81
86
|
list: (query) => listPage(store, query),
|
|
82
87
|
get: async (id) => {
|
|
83
88
|
const record = await store.get(id);
|
package/dist/register.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { type FeedbackRequestExtra, type ResolveIdentity } from "./identity.js";
|
|
3
3
|
import { type FeedbackReaderClient } from "./reader.js";
|
|
4
|
-
import type
|
|
5
|
-
import { type FeedbackRecord, type FeedbackServerInfo } from "./types.js";
|
|
4
|
+
import { type FeedbackSink, type FeedbackStore } from "./store.js";
|
|
5
|
+
import { type FeedbackContext, type FeedbackIdentity, type FeedbackRecord, type FeedbackServerInfo } from "./types.js";
|
|
6
6
|
export interface FeedbackLimits {
|
|
7
7
|
titleChars: number;
|
|
8
8
|
bodyChars: number;
|
|
@@ -29,8 +29,16 @@ interface SharedOptions {
|
|
|
29
29
|
onError?: (error: unknown, tool: string) => void;
|
|
30
30
|
}
|
|
31
31
|
export interface FeedbackOptions extends SharedOptions {
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Created once at module level and shared across requests. Any store, or a write-only sink such
|
|
34
|
+
* as `remoteStore()` for a server that runs on its users' machines.
|
|
35
|
+
*/
|
|
36
|
+
store: FeedbackSink;
|
|
37
|
+
/**
|
|
38
|
+
* Where reports go, when that is not the server the agent is talking to, e.g. `"the Acme
|
|
39
|
+
* maintainers (feedback.acme.dev)"`. Added to the submit tool's description.
|
|
40
|
+
*/
|
|
41
|
+
destination?: string;
|
|
34
42
|
/**
|
|
35
43
|
* Tell agents to file only after the user confirms the exact feedback. Pair it with
|
|
36
44
|
* `feedbackConfirmInstructions` in the server's instructions.
|
|
@@ -71,7 +79,31 @@ export type FeedbackReaderOptions = SharedOptions & {
|
|
|
71
79
|
reader: FeedbackReaderClient;
|
|
72
80
|
store?: never;
|
|
73
81
|
});
|
|
82
|
+
/** What an agent submits: the submit tool's input, before the server stamps anything on it. */
|
|
83
|
+
export type FeedbackSubmission = {
|
|
84
|
+
kind: FeedbackRecord["kind"];
|
|
85
|
+
title: string;
|
|
86
|
+
body: string;
|
|
87
|
+
severity?: FeedbackRecord["severity"];
|
|
88
|
+
tags?: string[];
|
|
89
|
+
context?: FeedbackContext;
|
|
90
|
+
};
|
|
74
91
|
export declare function uuidv7(now?: number): string;
|
|
92
|
+
/**
|
|
93
|
+
* Applies the size and shape limits to a submission, throwing a FeedbackInputError whose message
|
|
94
|
+
* tells the agent what to fix. Shared with the ingest hub so both apply the same rules.
|
|
95
|
+
*/
|
|
96
|
+
export declare function validateSubmission(input: FeedbackSubmission, limits?: FeedbackLimits): void;
|
|
97
|
+
/**
|
|
98
|
+
* A new record from a submission and what the server knows: who sent it and which server it is.
|
|
99
|
+
* Nothing in `stamp` is ever taken from the submission itself.
|
|
100
|
+
*/
|
|
101
|
+
export declare function buildRecord(input: FeedbackSubmission, stamp: {
|
|
102
|
+
id?: string;
|
|
103
|
+
now?: Date;
|
|
104
|
+
identity: FeedbackIdentity;
|
|
105
|
+
server: FeedbackServerInfo;
|
|
106
|
+
}): FeedbackRecord;
|
|
75
107
|
/** Adds `submit_feedback` to a server. Safe to call on a server built per request. */
|
|
76
108
|
export declare function registerFeedback(server: McpServer, options: FeedbackOptions): void;
|
|
77
109
|
/**
|
package/dist/register.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { defaultResolveIdentity, } from "./identity.js";
|
|
3
3
|
import { FeedbackInputError, FeedbackReaderError, normalizeFilter, storeReader, } from "./reader.js";
|
|
4
|
+
import { FeedbackDeliveryError } from "./store.js";
|
|
4
5
|
import { READER_TOOLS, SUBMIT_TOOL, submitToolDescription, SYNTHESIZE_PROMPT, feedbackStatsShape, getFeedbackShape, listFeedbackShape, submitFeedbackShapeFor, REFERENCE_KEY_PATTERN, synthesizeFeedbackArgsShape, synthesizePromptText, updateFeedbackTriageShape, } from "./tools.js";
|
|
5
6
|
import { FEEDBACK_SCHEMA_VERSION, } from "./types.js";
|
|
6
7
|
export const DEFAULT_FEEDBACK_LIMITS = {
|
|
@@ -19,6 +20,38 @@ export function uuidv7(now = Date.now()) {
|
|
|
19
20
|
const hex = bytes.toString("hex");
|
|
20
21
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Applies the size and shape limits to a submission, throwing a FeedbackInputError whose message
|
|
25
|
+
* tells the agent what to fix. Shared with the ingest hub so both apply the same rules.
|
|
26
|
+
*/
|
|
27
|
+
export function validateSubmission(input, limits = DEFAULT_FEEDBACK_LIMITS) {
|
|
28
|
+
checkLimits(input, limits);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A new record from a submission and what the server knows: who sent it and which server it is.
|
|
32
|
+
* Nothing in `stamp` is ever taken from the submission itself.
|
|
33
|
+
*/
|
|
34
|
+
export function buildRecord(input, stamp) {
|
|
35
|
+
const now = stamp.now ?? new Date();
|
|
36
|
+
const created = now.toISOString();
|
|
37
|
+
return {
|
|
38
|
+
schema_version: FEEDBACK_SCHEMA_VERSION,
|
|
39
|
+
id: stamp.id ?? uuidv7(now.getTime()),
|
|
40
|
+
created_at: created,
|
|
41
|
+
kind: input.kind,
|
|
42
|
+
title: input.title,
|
|
43
|
+
body: input.body,
|
|
44
|
+
severity: input.severity ?? "none",
|
|
45
|
+
tags: [...new Set(input.tags ?? [])],
|
|
46
|
+
context: JSON.parse(JSON.stringify(input.context ?? {})),
|
|
47
|
+
identity: stamp.identity,
|
|
48
|
+
server: stamp.server,
|
|
49
|
+
status: "new",
|
|
50
|
+
triage_note: null,
|
|
51
|
+
triaged_by: null,
|
|
52
|
+
updated_at: created,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
22
55
|
function checkLimits(input, limits) {
|
|
23
56
|
const text = (label, value, max) => {
|
|
24
57
|
if (value !== undefined && value.length > max) {
|
|
@@ -88,7 +121,7 @@ function createRuntime(server, options) {
|
|
|
88
121
|
if (!(error instanceof FeedbackInputError))
|
|
89
122
|
options.onError?.(error, tool);
|
|
90
123
|
// A remote reader's errors carry the remote server's own, already safe, messages.
|
|
91
|
-
const shown = error instanceof FeedbackInputError || error instanceof FeedbackReaderError;
|
|
124
|
+
const shown = error instanceof FeedbackInputError || error instanceof FeedbackReaderError || error instanceof FeedbackDeliveryError;
|
|
92
125
|
const text = shown ? error.message : "The feedback store is unavailable. Try again later.";
|
|
93
126
|
return { isError: true, content: [{ type: "text", text }] };
|
|
94
127
|
}
|
|
@@ -106,7 +139,7 @@ export function registerFeedback(server, options) {
|
|
|
106
139
|
}
|
|
107
140
|
server.registerTool(name, {
|
|
108
141
|
title: SUBMIT_TOOL.title,
|
|
109
|
-
description: submitToolDescription(options.requireConfirmation),
|
|
142
|
+
description: submitToolDescription(options.requireConfirmation, options.destination),
|
|
110
143
|
inputSchema: submitFeedbackShapeFor(options.contextFields),
|
|
111
144
|
annotations: SUBMIT_TOOL.annotations,
|
|
112
145
|
}, (args, extra) => guard(name, async () => {
|
|
@@ -119,28 +152,13 @@ export function registerFeedback(server, options) {
|
|
|
119
152
|
// The SDK does not expose the server's own name and version publicly; tests cover this
|
|
120
153
|
// fallback, and hosts can avoid it by passing serverInfo.
|
|
121
154
|
const constructed = server.server._serverInfo;
|
|
122
|
-
|
|
123
|
-
const created = now.toISOString();
|
|
124
|
-
let record = {
|
|
125
|
-
schema_version: FEEDBACK_SCHEMA_VERSION,
|
|
126
|
-
id: uuidv7(now.getTime()),
|
|
127
|
-
created_at: created,
|
|
128
|
-
kind: input.kind,
|
|
129
|
-
title: input.title,
|
|
130
|
-
body: input.body,
|
|
131
|
-
severity: input.severity ?? "none",
|
|
132
|
-
tags: [...new Set(input.tags ?? [])],
|
|
133
|
-
context: JSON.parse(JSON.stringify(input.context ?? {})),
|
|
155
|
+
let record = buildRecord(input, {
|
|
134
156
|
identity,
|
|
135
157
|
server: {
|
|
136
158
|
name: options.serverInfo?.name ?? constructed?.name ?? null,
|
|
137
159
|
version: options.serverInfo?.version ?? constructed?.version ?? null,
|
|
138
160
|
},
|
|
139
|
-
|
|
140
|
-
triage_note: null,
|
|
141
|
-
triaged_by: null,
|
|
142
|
-
updated_at: created,
|
|
143
|
-
};
|
|
161
|
+
});
|
|
144
162
|
if (options.attachContext) {
|
|
145
163
|
try {
|
|
146
164
|
const attached = await options.attachContext(record, extra);
|
|
@@ -153,8 +171,14 @@ export function registerFeedback(server, options) {
|
|
|
153
171
|
}
|
|
154
172
|
if (options.redact)
|
|
155
173
|
record = await options.redact(record);
|
|
156
|
-
await options.store.insert(record);
|
|
157
|
-
return {
|
|
174
|
+
const receipt = await options.store.insert(record);
|
|
175
|
+
return {
|
|
176
|
+
id: record.id,
|
|
177
|
+
created_at: record.created_at,
|
|
178
|
+
status: record.status,
|
|
179
|
+
// Only a sink that did something other than store the record says so.
|
|
180
|
+
...(receipt && receipt.delivery !== "stored" ? { delivery: receipt.delivery, ...(receipt.note ? { note: receipt.note } : {}) } : {}),
|
|
181
|
+
};
|
|
158
182
|
}));
|
|
159
183
|
}
|
|
160
184
|
/**
|
package/dist/remote.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type FeedbackReceipt, type FeedbackSink } from "./store.js";
|
|
2
|
+
import type { FeedbackRecord } from "./types.js";
|
|
3
|
+
export interface RemoteStoreOptions {
|
|
4
|
+
/** The hub's base URL, e.g. `https://feedback.example.com`. Must be HTTPS unless it is this machine. */
|
|
5
|
+
endpoint: string;
|
|
6
|
+
/**
|
|
7
|
+
* The project key the maintainer issued for this server. It is public by design and ships in the
|
|
8
|
+
* package; the hub exchanges it for this installation's own token.
|
|
9
|
+
*/
|
|
10
|
+
projectKey?: string;
|
|
11
|
+
/** A token the maintainer issued to a known person or team, usually read from the environment. Skips enrolment. */
|
|
12
|
+
token?: string;
|
|
13
|
+
/**
|
|
14
|
+
* `"github"`: reports go out as the person who signed in with GitHub, not as an anonymous
|
|
15
|
+
* installation. The first report asks them to sign in, once per machine; the sign-in is shared by
|
|
16
|
+
* every server on the machine that reports to the same hub, and renewed as they start. The hub
|
|
17
|
+
* must offer GitHub sign-in.
|
|
18
|
+
*/
|
|
19
|
+
signIn?: "github";
|
|
20
|
+
/** Where this server's token and queued reports are kept. Defaults to the platform's per-user state directory. */
|
|
21
|
+
stateDir?: string;
|
|
22
|
+
/** Where a sign-in is kept, shared by the servers that report to this hub. Defaults to the per-user state directory. */
|
|
23
|
+
identityDir?: string;
|
|
24
|
+
/** start() renews stored tokens once they are this old. Default one day. */
|
|
25
|
+
renewAfterSeconds?: number;
|
|
26
|
+
/** Limits on reports waiting to be sent. `false` turns the queue off, so an unreachable hub is an error. */
|
|
27
|
+
queue?: {
|
|
28
|
+
maxItems?: number;
|
|
29
|
+
maxAgeDays?: number;
|
|
30
|
+
} | false;
|
|
31
|
+
/** Per request. Default 10 seconds. */
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
/** For tests. */
|
|
34
|
+
fetch?: typeof fetch;
|
|
35
|
+
/** For tests: the shortest wait between polls of a pending sign-in. */
|
|
36
|
+
signInPollMs?: number;
|
|
37
|
+
/** Called with errors that do not reach the agent, e.g. a queued report the hub refused. For the host's logger. */
|
|
38
|
+
onError?: (error: unknown) => void;
|
|
39
|
+
}
|
|
40
|
+
export interface FlushResult {
|
|
41
|
+
delivered: number;
|
|
42
|
+
/** Refused by the hub or too old, and deleted. */
|
|
43
|
+
dropped: number;
|
|
44
|
+
remaining: number;
|
|
45
|
+
}
|
|
46
|
+
export interface StartResult extends FlushResult {
|
|
47
|
+
/** Tokens renewed: `user` for the sign-in, `project` for this server's own. */
|
|
48
|
+
renewed: Array<"user" | "project">;
|
|
49
|
+
}
|
|
50
|
+
export interface RemoteStore extends FeedbackSink {
|
|
51
|
+
/** Resolves `stored` once the hub has the report, or `queued` with a note saying where it is waiting and why. */
|
|
52
|
+
insert(record: FeedbackRecord): Promise<FeedbackReceipt>;
|
|
53
|
+
/**
|
|
54
|
+
* Call once when the server starts. Renews stored tokens that are more than a day old, so a machine
|
|
55
|
+
* in use never has to enrol or sign in again, then sends queued reports. Contacts the hub only if
|
|
56
|
+
* this machine already has a token or a queued report. Never throws.
|
|
57
|
+
*/
|
|
58
|
+
start(): Promise<StartResult>;
|
|
59
|
+
/** Sends any queued reports. insert also calls it. Never throws. */
|
|
60
|
+
flush(): Promise<FlushResult>;
|
|
61
|
+
/** Where this server's token and queue are kept. */
|
|
62
|
+
readonly stateDir: string;
|
|
63
|
+
}
|
|
64
|
+
/** True when the user has turned feedback off with MCP_FEEDBACK_DISABLED. Hosts should then skip registerFeedback. */
|
|
65
|
+
export declare function feedbackDisabled(env?: Record<string, string | undefined>): boolean;
|
|
66
|
+
export declare function remoteStore(options: RemoteStoreOptions): RemoteStore;
|