mcp-feedback 0.4.0 → 0.5.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 +34 -3
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +44 -17
- package/dist/client.d.ts +2 -22
- package/dist/client.js +2 -8
- package/dist/conformance-cases.js +38 -9
- package/dist/reader.d.ts +31 -1
- package/dist/reader.js +33 -0
- package/dist/register.d.ts +30 -6
- package/dist/register.js +37 -14
- package/dist/store.js +3 -0
- package/dist/stores/sql.js +7 -0
- package/dist/tools.d.ts +112 -0
- package/dist/tools.js +38 -1
- package/dist/types.d.ts +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,7 +38,8 @@ npx -y mcp-feedback stats
|
|
|
38
38
|
# Or straight from the store.
|
|
39
39
|
npx -y mcp-feedback stats --db ./feedback.db # or --postgres <url>
|
|
40
40
|
|
|
41
|
-
mcp-feedback list --status new --tool
|
|
41
|
+
mcp-feedback list --status new --tool search_orders --text
|
|
42
|
+
mcp-feedback list --ref orderId=ord-123 --text # everything reported about one object
|
|
42
43
|
mcp-feedback export --since 2026-11-01 > feedback.jsonl
|
|
43
44
|
mcp-feedback get <id> --text
|
|
44
45
|
mcp-feedback close <id> <id> --note "Fixed in 1.2"
|
|
@@ -46,6 +47,14 @@ mcp-feedback close <id> --dismiss --note "Working as intended"
|
|
|
46
47
|
mcp-feedback reopen <id>
|
|
47
48
|
```
|
|
48
49
|
|
|
50
|
+
`mcp-feedback serve` runs the reader tools as a **stdio MCP server**, in front of any of those sources, so an agent session can read and triage feedback without connecting to a remote HTTP endpoint itself. Messages go to stderr; stdout carries the protocol. Add `--read-only` to leave out triage. For Claude Code:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
claude mcp add myapp-feedback --scope user --env MCP_FEEDBACK_URL=https://example.com/mcp/feedback -- npx -y mcp-feedback serve
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The server inherits the environment Claude Code starts in, so `MCP_FEEDBACK_TOKEN` exported in your shell reaches it without being written into the client's configuration. With a store (`serve --db` or `--postgres`), triage is recorded as `--by` or your username.
|
|
57
|
+
|
|
49
58
|
`MCP_FEEDBACK_DB` and `MCP_FEEDBACK_POSTGRES_URL` set the store from the environment. With a reader endpoint, pass `--prefix` if the server set a `toolPrefix`; `--by` does not apply, because the server records who triaged from the credential. The same client is available in code as `connectFeedbackReader` from `mcp-feedback/client`. Output is JSON unless you pass `--text`. Exit code 2 means bad input; 1 means a failure or an id that was not found.
|
|
50
59
|
|
|
51
60
|
Append `feedbackInstructions` to your server's `instructions` so agents know when to file. If you publish a tool catalog, merge in `feedbackToolCatalog`.
|
|
@@ -64,6 +73,26 @@ registerFeedback(server, {
|
|
|
64
73
|
});
|
|
65
74
|
```
|
|
66
75
|
|
|
76
|
+
## Context
|
|
77
|
+
|
|
78
|
+
Agents describe what happened in `context`: goal, expected and actual behaviour, the tool calls involved, repro steps, an excerpt and free-form `metadata`. Two fields let a reader rebuild the situation later, whatever your server's objects are:
|
|
79
|
+
|
|
80
|
+
- **`context.references`**: ids of the objects involved, keyed by what they are (`{ orderId: "ord-123", invoiceId: "inv-9" }`). Agents can include any; declare the ones that matter to your server with `contextFields` and they appear, with their descriptions, in the tool's input. Readers filter on them (`--ref orderId=ord-123`, or `reference` in `list_feedback` and `feedback_stats`).
|
|
81
|
+
- **`context.server_context`**: what the server knows and the agent does not, attached by `attachContext` when the feedback is submitted: versions, request ids, the state of the referenced objects at that moment. Agents cannot set it.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
registerFeedback(server, {
|
|
85
|
+
store,
|
|
86
|
+
contextFields: { orderId: "The order the problem involved", invoiceId: "The invoice, if one was produced" },
|
|
87
|
+
attachContext: async (record, extra) => ({
|
|
88
|
+
version: process.env.APP_VERSION,
|
|
89
|
+
order: record.context.references?.orderId ? await snapshotOrder(record.context.references.orderId) : undefined,
|
|
90
|
+
}),
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
If `attachContext` throws, the feedback is still stored without it and the error goes to `onError`.
|
|
95
|
+
|
|
67
96
|
## Options
|
|
68
97
|
|
|
69
98
|
| Option | Purpose |
|
|
@@ -72,6 +101,8 @@ registerFeedback(server, {
|
|
|
72
101
|
| `resolveIdentity` | Override identity fields for a request. |
|
|
73
102
|
| `requireConfirmation` | Tell agents to file only after the user confirms the exact feedback. Use `feedbackConfirmInstructions` in place of `feedbackInstructions`, and `feedbackToolCatalogFor(options)` for catalogs. |
|
|
74
103
|
| `requireIdentity` | Refuse submissions with no subject and no token fingerprint. |
|
|
104
|
+
| `contextFields` | Ids agents should include in `context.references`, as name → description. |
|
|
105
|
+
| `attachContext` | Attach what the server knows (versions, object state) as `context.server_context`. |
|
|
75
106
|
| `redact` | Scrub a record before it is stored. |
|
|
76
107
|
| `limits` | Override size limits (see the spec for defaults). |
|
|
77
108
|
| `toolPrefix` | Prefix for tool and prompt names. |
|
|
@@ -84,8 +115,8 @@ registerFeedback(server, {
|
|
|
84
115
|
| Store | Import | Notes |
|
|
85
116
|
| --- | --- | --- |
|
|
86
117
|
| SQLite | `mcp-feedback/sqlite` | Default. Uses Node's built-in `node:sqlite`, so there is no native module to install. On Node versions where that module is still experimental, Node prints a warning. |
|
|
87
|
-
| Postgres | `mcp-feedback/postgres` | `postgresStore({ client: pool })` with any client that has `query(text, params)`, such as a `pg.Pool`. Timestamps are `TIMESTAMPTZ`.
|
|
88
|
-
| Drizzle schema | `mcp-feedback/drizzle` | `mcpFeedbackTable` (or `feedbackTable(name)`) to export from your Drizzle schema, so `drizzle-kit` creates the table and never drops it.
|
|
118
|
+
| Postgres | `mcp-feedback/postgres` | `postgresStore({ client: pool })` with any client that has `query(text, params)`, such as a `pg.Pool`. Timestamps are `TIMESTAMPTZ`. Creates its table and indexes on first use if missing; pass `migrate: false` only if the database user cannot create tables and your migrations reach every environment. |
|
|
119
|
+
| Drizzle schema | `mcp-feedback/drizzle` | `mcpFeedbackTable` (or `feedbackTable(name)`) to export from your Drizzle schema, so `drizzle-kit` creates the table and never drops it. Tests keep it identical to the store's own DDL (`spec/sql/postgres.sql`), so keep the store's table creation on as well: it covers databases your schema tool does not reach. |
|
|
89
120
|
| Memory | `mcp-feedback` | `memoryStore()`, for tests. |
|
|
90
121
|
|
|
91
122
|
To write your own, implement `FeedbackStore` and check it with the conformance suite:
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
3
|
import type { FeedbackStore } from "./store.js";
|
|
3
4
|
export interface CliIo {
|
|
4
5
|
out: (line: string) => void;
|
|
5
6
|
err: (line: string) => void;
|
|
7
|
+
/** Streams for serve; default to the process's own. */
|
|
8
|
+
stdin?: Readable;
|
|
9
|
+
stdout?: Writable;
|
|
6
10
|
env: Record<string, string | undefined>;
|
|
7
11
|
/** Test seam: supply the store instead of opening one from flags. */
|
|
8
12
|
openStore?: () => Promise<FeedbackStore>;
|
package/dist/cli.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Reader CLI: the same operations as the MCP reader tools, either straight
|
|
3
3
|
// against the store or through a server's reader endpoint (--mcp).
|
|
4
4
|
import { realpathSync } from "node:fs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
5
6
|
import { userInfo } from "node:os";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
import { parseArgs } from "node:util";
|
|
8
|
-
import { FeedbackInputError,
|
|
9
|
+
import { FeedbackInputError, normalizeFilter, storeReader } from "./reader.js";
|
|
9
10
|
import { FEEDBACK_KINDS, FEEDBACK_SEVERITIES, FEEDBACK_STATUSES, } from "./types.js";
|
|
10
11
|
const USAGE = `mcp-feedback: read and close out feedback collected by an MCP server
|
|
11
12
|
|
|
@@ -19,6 +20,8 @@ Commands:
|
|
|
19
20
|
triage <id...> Set --status and/or --note
|
|
20
21
|
close <id...> Mark resolved (or --dismiss), with an optional --note
|
|
21
22
|
reopen <id...> Set status back to new
|
|
23
|
+
serve Serve the reader tools as a stdio MCP server, for agent sessions
|
|
24
|
+
(stdout carries the protocol; messages go to stderr)
|
|
22
25
|
|
|
23
26
|
Source (one is required):
|
|
24
27
|
--mcp <url> A server's reader endpoint (or MCP_FEEDBACK_URL). Sends
|
|
@@ -30,7 +33,7 @@ Source (one is required):
|
|
|
30
33
|
|
|
31
34
|
Filters (stats, list, export):
|
|
32
35
|
--kind <k> --status <s> --severity <s> --subject <s> --tool <name> --tag <t>
|
|
33
|
-
--since <iso> --until <iso>
|
|
36
|
+
--since <iso> --until <iso> --ref <key=value> (an id in context.references)
|
|
34
37
|
|
|
35
38
|
Other:
|
|
36
39
|
--limit <n> Page size for list (default 25)
|
|
@@ -39,6 +42,7 @@ Other:
|
|
|
39
42
|
--note <text> Triage note
|
|
40
43
|
--clear-note Remove the triage note
|
|
41
44
|
--dismiss With close: mark dismissed instead of resolved
|
|
45
|
+
--read-only With serve: leave out update_feedback_triage
|
|
42
46
|
--by <name> Recorded as triaged_by (default: your username; with --mcp
|
|
43
47
|
the server records the credential's identity instead)
|
|
44
48
|
--text Human-readable output instead of JSON
|
|
@@ -62,21 +66,6 @@ async function openStore(values, env) {
|
|
|
62
66
|
}
|
|
63
67
|
throw new FeedbackInputError("No source given. Pass --mcp <url>, --db <path> or --postgres <url>.");
|
|
64
68
|
}
|
|
65
|
-
/** The same reader operations over a store the CLI opened itself. */
|
|
66
|
-
function storeReader(store, by) {
|
|
67
|
-
return {
|
|
68
|
-
stats: (filter) => store.stats(filter),
|
|
69
|
-
list: (query) => listPage(store, query),
|
|
70
|
-
get: async (id) => {
|
|
71
|
-
const record = await store.get(id);
|
|
72
|
-
if (!record)
|
|
73
|
-
throw new FeedbackInputError(`No feedback with id ${id}.`);
|
|
74
|
-
return record;
|
|
75
|
-
},
|
|
76
|
-
triage: (ids, change) => triageMany(store, ids, { ...change, by }),
|
|
77
|
-
close: async () => store.close?.(),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
69
|
async function openReader(values, io) {
|
|
81
70
|
const by = values.by ?? io.env.USER ?? userInfo().username;
|
|
82
71
|
if (io.openStore)
|
|
@@ -109,6 +98,14 @@ async function openReader(values, io) {
|
|
|
109
98
|
throw error;
|
|
110
99
|
}
|
|
111
100
|
}
|
|
101
|
+
function parseReference(value) {
|
|
102
|
+
if (value === undefined)
|
|
103
|
+
return undefined;
|
|
104
|
+
const split = value.indexOf("=");
|
|
105
|
+
if (split <= 0)
|
|
106
|
+
throw new FeedbackInputError("--ref takes key=value, e.g. --ref orderId=abc.");
|
|
107
|
+
return { key: value.slice(0, split), value: value.slice(split + 1) };
|
|
108
|
+
}
|
|
112
109
|
function oneOf(label, value, allowed) {
|
|
113
110
|
if (value === undefined)
|
|
114
111
|
return undefined;
|
|
@@ -132,6 +129,29 @@ function detail(record) {
|
|
|
132
129
|
}
|
|
133
130
|
return lines.join("\n");
|
|
134
131
|
}
|
|
132
|
+
const { version } = createRequire(import.meta.url)("../package.json");
|
|
133
|
+
/** Serves the reader tools over stdio until the client closes stdin. */
|
|
134
|
+
async function serve(reader, values, io) {
|
|
135
|
+
const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js");
|
|
136
|
+
const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
|
|
137
|
+
const { registerFeedbackReader } = await import("./register.js");
|
|
138
|
+
const server = new McpServer({ name: "mcp-feedback", version });
|
|
139
|
+
registerFeedbackReader(server, {
|
|
140
|
+
reader,
|
|
141
|
+
readOnly: values["read-only"] === true,
|
|
142
|
+
onError: (error, tool) => io.err(`mcp-feedback: ${tool}: ${error instanceof Error ? error.message : String(error)}`),
|
|
143
|
+
});
|
|
144
|
+
const stdin = io.stdin ?? process.stdin;
|
|
145
|
+
const closed = new Promise((resolve) => {
|
|
146
|
+
stdin.once("end", resolve);
|
|
147
|
+
stdin.once("close", resolve);
|
|
148
|
+
});
|
|
149
|
+
await server.connect(new StdioServerTransport(stdin, io.stdout ?? process.stdout));
|
|
150
|
+
io.err("mcp-feedback: serving the feedback reader tools over stdio");
|
|
151
|
+
await closed;
|
|
152
|
+
await server.close();
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
135
155
|
/** Runs the CLI and resolves the process exit code. */
|
|
136
156
|
export async function runCli(argv, io) {
|
|
137
157
|
let reader;
|
|
@@ -155,6 +175,7 @@ export async function runCli(argv, io) {
|
|
|
155
175
|
tag: { type: "string" },
|
|
156
176
|
since: { type: "string" },
|
|
157
177
|
until: { type: "string" },
|
|
178
|
+
ref: { type: "string" },
|
|
158
179
|
limit: { type: "string" },
|
|
159
180
|
cursor: { type: "string" },
|
|
160
181
|
note: { type: "string" },
|
|
@@ -162,6 +183,7 @@ export async function runCli(argv, io) {
|
|
|
162
183
|
dismiss: { type: "boolean" },
|
|
163
184
|
by: { type: "string" },
|
|
164
185
|
text: { type: "boolean" },
|
|
186
|
+
"read-only": { type: "boolean" },
|
|
165
187
|
help: { type: "boolean", short: "h" },
|
|
166
188
|
},
|
|
167
189
|
});
|
|
@@ -175,6 +197,8 @@ export async function runCli(argv, io) {
|
|
|
175
197
|
io.out(USAGE);
|
|
176
198
|
return command || values.help ? 0 : 2;
|
|
177
199
|
}
|
|
200
|
+
if (values["read-only"] && command !== "serve")
|
|
201
|
+
throw new FeedbackInputError("--read-only only applies to serve.");
|
|
178
202
|
const status = oneOf("status", values.status, FEEDBACK_STATUSES);
|
|
179
203
|
const filter = normalizeFilter({
|
|
180
204
|
kind: oneOf("kind", values.kind, FEEDBACK_KINDS),
|
|
@@ -185,6 +209,7 @@ export async function runCli(argv, io) {
|
|
|
185
209
|
tag: values.tag,
|
|
186
210
|
since: values.since,
|
|
187
211
|
until: values.until,
|
|
212
|
+
reference: parseReference(values.ref),
|
|
188
213
|
});
|
|
189
214
|
const json = (value) => io.out(JSON.stringify(value, null, 2));
|
|
190
215
|
const needIds = () => {
|
|
@@ -267,6 +292,8 @@ export async function runCli(argv, io) {
|
|
|
267
292
|
return await triage({ status: values.dismiss ? "dismissed" : "resolved" });
|
|
268
293
|
case "reopen":
|
|
269
294
|
return await triage({ status: "new" });
|
|
295
|
+
case "serve":
|
|
296
|
+
return await serve(await open(), values, io);
|
|
270
297
|
default:
|
|
271
298
|
throw new FeedbackInputError(`Unknown command: ${command}. Run mcp-feedback --help.`);
|
|
272
299
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import { FeedbackReaderError, type FeedbackReaderClient } from "./reader.js";
|
|
2
|
+
export { FeedbackReaderError, type FeedbackReaderClient };
|
|
3
3
|
/** The reader tools cap a page at this size; larger requests are clamped and continue by cursor. */
|
|
4
4
|
export declare const READER_PAGE_LIMIT = 100;
|
|
5
|
-
/** A failure reaching the reader endpoint or reported by its tools. `status` is the HTTP status, when there was one. */
|
|
6
|
-
export declare class FeedbackReaderError extends Error {
|
|
7
|
-
readonly status?: number | undefined;
|
|
8
|
-
constructor(message: string, status?: number | undefined);
|
|
9
|
-
}
|
|
10
|
-
export interface FeedbackReaderClient {
|
|
11
|
-
stats(filter: FeedbackFilter): Promise<FeedbackStats>;
|
|
12
|
-
list(query: FeedbackFilter & {
|
|
13
|
-
limit: number;
|
|
14
|
-
cursor?: string;
|
|
15
|
-
}): Promise<FeedbackPage>;
|
|
16
|
-
/** Rejects with FeedbackReaderError when the id is unknown. */
|
|
17
|
-
get(id: string): Promise<FeedbackRecord>;
|
|
18
|
-
/** The server records who triaged from the credential, and sets updated_at. */
|
|
19
|
-
triage(ids: string[], change: {
|
|
20
|
-
status?: FeedbackStatus;
|
|
21
|
-
note?: string | null;
|
|
22
|
-
}): Promise<TriageOutcome>;
|
|
23
|
-
close(): Promise<void>;
|
|
24
|
-
}
|
|
25
5
|
export interface FeedbackReaderClientOptions {
|
|
26
6
|
/** Streamable HTTP URL of the endpoint that has the reader tools mounted. */
|
|
27
7
|
url: string | URL;
|
package/dist/client.js
CHANGED
|
@@ -3,16 +3,10 @@
|
|
|
3
3
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
4
4
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
5
5
|
import { READER_TOOLS } from "./tools.js";
|
|
6
|
+
import { FeedbackReaderError } from "./reader.js";
|
|
7
|
+
export { FeedbackReaderError };
|
|
6
8
|
/** The reader tools cap a page at this size; larger requests are clamped and continue by cursor. */
|
|
7
9
|
export const READER_PAGE_LIMIT = 100;
|
|
8
|
-
/** A failure reaching the reader endpoint or reported by its tools. `status` is the HTTP status, when there was one. */
|
|
9
|
-
export class FeedbackReaderError extends Error {
|
|
10
|
-
status;
|
|
11
|
-
constructor(message, status) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.status = status;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
10
|
const HTTP_HINTS = {
|
|
17
11
|
401: "the credential is missing or was refused",
|
|
18
12
|
403: "the credential is not allowed to use this endpoint",
|
|
@@ -34,19 +34,21 @@ function record(n, created_at, fields, context = {}) {
|
|
|
34
34
|
}
|
|
35
35
|
// Records 3 and 4 share a created_at so ordering and cursors must fall back to id.
|
|
36
36
|
export const conformanceRecords = [
|
|
37
|
-
record(1, "2026-01-01T00:00:00.000Z", { kind: "bug", severity: "major", tags: ["ui"], subject: "alice", tools: ["
|
|
38
|
-
record(2, "2026-01-02T00:00:00.000Z", { kind: "tool_failure", severity: "blocker", tags: ["timeout", "ui"], subject: "bob", tools: ["
|
|
39
|
-
goal: "
|
|
37
|
+
record(1, "2026-01-01T00:00:00.000Z", { kind: "bug", severity: "major", tags: ["ui"], subject: "alice", tools: ["create_order"] }, { references: { documentId: "doc-2" } }),
|
|
38
|
+
record(2, "2026-01-02T00:00:00.000Z", { kind: "tool_failure", severity: "blocker", tags: ["timeout", "ui"], subject: "bob", tools: ["create_order", "list_orders"] }, {
|
|
39
|
+
goal: "Place an order — with “quotes”, 'apostrophes' and emoji 🎭",
|
|
40
40
|
expected: "A job id",
|
|
41
41
|
actual: "504 after 30s",
|
|
42
|
-
repro_steps: ["call
|
|
42
|
+
repro_steps: ["call create_order", "wait"],
|
|
43
43
|
excerpt: "line one\nline two",
|
|
44
44
|
metadata: { attempt: 2, nested: { ok: false, values: [1, "two", null] } },
|
|
45
|
+
references: { documentId: "doc-1", jobId: "job-9" },
|
|
46
|
+
server_context: { version: "1.2.3", job: { id: "job-9", state: "failed", attempts: [1, 2] } },
|
|
45
47
|
}),
|
|
46
48
|
record(3, "2026-01-03T00:00:00.000Z", { kind: "feature_request", severity: "none", tags: [], subject: "alice", tools: [] }),
|
|
47
|
-
record(4, "2026-01-03T00:00:00.000Z", { kind: "friction", severity: "minor", tags: ["docs"], subject: null, tools: ["
|
|
49
|
+
record(4, "2026-01-03T00:00:00.000Z", { kind: "friction", severity: "minor", tags: ["docs"], subject: null, tools: ["list_orders"] }),
|
|
48
50
|
record(5, "2026-01-04T00:00:00.000Z", { kind: "praise", severity: "none", tags: [], subject: "bob", tools: [] }),
|
|
49
|
-
record(6, "2026-01-05T00:00:00.000Z", { kind: "bug", severity: "minor", tags: ["timeout"], subject: "alice", tools: ["
|
|
51
|
+
record(6, "2026-01-05T00:00:00.000Z", { kind: "bug", severity: "minor", tags: ["timeout"], subject: "alice", tools: ["create_order"] }, { references: { documentId: "doc-1" } }),
|
|
50
52
|
];
|
|
51
53
|
const ids = (...numbers) => numbers.map(id);
|
|
52
54
|
// Cases run in order against one store seeded with conformanceRecords.
|
|
@@ -59,11 +61,26 @@ export const conformanceCases = [
|
|
|
59
61
|
{ name: "filters by severity", op: "list", filter: { severity: "minor" }, limit: 10, expect_pages: [ids(6, 4)] },
|
|
60
62
|
{ name: "filters by status", op: "list", filter: { status: "resolved" }, limit: 10, expect_pages: [[]] },
|
|
61
63
|
{ name: "filters by subject", op: "list", filter: { subject: "alice" }, limit: 10, expect_pages: [ids(6, 3, 1)] },
|
|
62
|
-
{ name: "filters by tool", op: "list", filter: { tool: "
|
|
64
|
+
{ name: "filters by tool", op: "list", filter: { tool: "create_order" }, limit: 10, expect_pages: [ids(6, 2, 1)] },
|
|
63
65
|
{ name: "filters by tag", op: "list", filter: { tag: "timeout" }, limit: 10, expect_pages: [ids(6, 2)] },
|
|
64
66
|
{ name: "since is inclusive", op: "list", filter: { since: "2026-01-03T00:00:00.000Z" }, limit: 10, expect_pages: [ids(6, 5, 4, 3)] },
|
|
65
67
|
{ name: "until is exclusive", op: "list", filter: { until: "2026-01-03T00:00:00.000Z" }, limit: 10, expect_pages: [ids(2, 1)] },
|
|
66
68
|
{ name: "combines filters with AND", op: "list", filter: { kind: "bug", tag: "timeout" }, limit: 10, expect_pages: [ids(6)] },
|
|
69
|
+
{
|
|
70
|
+
name: "filters by a reference",
|
|
71
|
+
op: "list",
|
|
72
|
+
filter: { reference: { key: "documentId", value: "doc-1" } },
|
|
73
|
+
limit: 10,
|
|
74
|
+
expect_pages: [ids(6, 2)],
|
|
75
|
+
},
|
|
76
|
+
{ name: "a reference matches one key only", op: "list", filter: { reference: { key: "jobId", value: "doc-1" } }, limit: 10, expect_pages: [[]] },
|
|
77
|
+
{
|
|
78
|
+
name: "combines a reference with other filters",
|
|
79
|
+
op: "list",
|
|
80
|
+
filter: { kind: "bug", reference: { key: "documentId", value: "doc-1" } },
|
|
81
|
+
limit: 10,
|
|
82
|
+
expect_pages: [ids(6)],
|
|
83
|
+
},
|
|
67
84
|
{ name: "round-trips a full record", op: "get", id: id(2), expect_found: true },
|
|
68
85
|
{ name: "round-trips a record with null identity", op: "get", id: id(4), expect_found: true },
|
|
69
86
|
{ name: "get resolves null for an unknown id", op: "get", id: id(9), expect_found: false },
|
|
@@ -76,7 +93,7 @@ export const conformanceCases = [
|
|
|
76
93
|
by_kind: { bug: 2, tool_failure: 1, feature_request: 1, friction: 1, praise: 1 },
|
|
77
94
|
by_status: { new: 6 },
|
|
78
95
|
by_severity: { major: 1, blocker: 1, none: 2, minor: 2 },
|
|
79
|
-
by_tool: {
|
|
96
|
+
by_tool: { create_order: 3, list_orders: 2 },
|
|
80
97
|
},
|
|
81
98
|
},
|
|
82
99
|
{
|
|
@@ -88,7 +105,19 @@ export const conformanceCases = [
|
|
|
88
105
|
by_kind: { bug: 2, feature_request: 1 },
|
|
89
106
|
by_status: { new: 3 },
|
|
90
107
|
by_severity: { major: 1, none: 1, minor: 1 },
|
|
91
|
-
by_tool: {
|
|
108
|
+
by_tool: { create_order: 2 },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "stats honour a reference",
|
|
113
|
+
op: "stats",
|
|
114
|
+
filter: { reference: { key: "documentId", value: "doc-1" } },
|
|
115
|
+
expect: {
|
|
116
|
+
total: 2,
|
|
117
|
+
by_kind: { tool_failure: 1, bug: 1 },
|
|
118
|
+
by_status: { new: 2 },
|
|
119
|
+
by_severity: { blocker: 1, minor: 1 },
|
|
120
|
+
by_tool: { create_order: 2, list_orders: 1 },
|
|
92
121
|
},
|
|
93
122
|
},
|
|
94
123
|
{
|
package/dist/reader.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FeedbackStore } from "./store.js";
|
|
2
|
-
import type { FeedbackFilter, FeedbackPage, FeedbackRecord, FeedbackStatus } from "./types.js";
|
|
2
|
+
import type { FeedbackFilter, FeedbackPage, FeedbackRecord, FeedbackStats, FeedbackStatus } from "./types.js";
|
|
3
3
|
/** A problem with the caller's input; its message is safe to show to the caller. */
|
|
4
4
|
export declare class FeedbackInputError extends Error {
|
|
5
5
|
}
|
|
@@ -19,3 +19,33 @@ export declare function triageMany(store: FeedbackStore, ids: string[], change:
|
|
|
19
19
|
note?: string | null;
|
|
20
20
|
by: string | null;
|
|
21
21
|
}): Promise<TriageOutcome>;
|
|
22
|
+
/** A failure reaching a remote reader endpoint or reported by its tools. `status` is the HTTP status, when there was one. */
|
|
23
|
+
export declare class FeedbackReaderError extends Error {
|
|
24
|
+
readonly status?: number | undefined;
|
|
25
|
+
constructor(message: string, status?: number | undefined);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The reader operations, wherever the feedback lives: a store opened in this
|
|
29
|
+
* process (storeReader) or a server's reader endpoint (connectFeedbackReader).
|
|
30
|
+
*/
|
|
31
|
+
export interface FeedbackReaderClient {
|
|
32
|
+
stats(filter: FeedbackFilter): Promise<FeedbackStats>;
|
|
33
|
+
list(query: FeedbackFilter & {
|
|
34
|
+
limit: number;
|
|
35
|
+
cursor?: string;
|
|
36
|
+
}): Promise<FeedbackPage>;
|
|
37
|
+
/** Rejects when the id is unknown. */
|
|
38
|
+
get(id: string): Promise<FeedbackRecord>;
|
|
39
|
+
/**
|
|
40
|
+
* `by` is recorded as triaged_by where this side decides it (a store). A remote
|
|
41
|
+
* endpoint records its caller's identity instead and ignores it.
|
|
42
|
+
*/
|
|
43
|
+
triage(ids: string[], change: {
|
|
44
|
+
status?: FeedbackStatus;
|
|
45
|
+
note?: string | null;
|
|
46
|
+
by?: string | null;
|
|
47
|
+
}): Promise<TriageOutcome>;
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/** Reader operations straight against a store. `defaultBy` is used when a triage gives no `by`. */
|
|
51
|
+
export declare function storeReader(store: FeedbackStore, defaultBy?: string | null): FeedbackReaderClient;
|
package/dist/reader.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Reader operations shared by the MCP reader tools and the CLI.
|
|
2
|
+
import { REFERENCE_KEY_PATTERN } from "./tools.js";
|
|
2
3
|
/** A problem with the caller's input; its message is safe to show to the caller. */
|
|
3
4
|
export class FeedbackInputError extends Error {
|
|
4
5
|
}
|
|
@@ -10,6 +11,14 @@ function normalizeTimestamp(label, value) {
|
|
|
10
11
|
throw new FeedbackInputError(`${label} is not a valid ISO 8601 timestamp.`);
|
|
11
12
|
return new Date(time).toISOString();
|
|
12
13
|
}
|
|
14
|
+
function checkReference(reference) {
|
|
15
|
+
if (reference === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (!REFERENCE_KEY_PATTERN.test(reference.key)) {
|
|
18
|
+
throw new FeedbackInputError("reference key must start with a letter and use only letters, digits, _ or - (at most 64).");
|
|
19
|
+
}
|
|
20
|
+
return { key: reference.key, value: reference.value };
|
|
21
|
+
}
|
|
13
22
|
/** Keeps only the filter fields that are set and puts timestamps in canonical form. */
|
|
14
23
|
export function normalizeFilter(args) {
|
|
15
24
|
// JSON round trip drops keys whose value is undefined.
|
|
@@ -22,6 +31,7 @@ export function normalizeFilter(args) {
|
|
|
22
31
|
tag: args.tag,
|
|
23
32
|
since: normalizeTimestamp("since", args.since),
|
|
24
33
|
until: normalizeTimestamp("until", args.until),
|
|
34
|
+
reference: checkReference(args.reference),
|
|
25
35
|
}));
|
|
26
36
|
}
|
|
27
37
|
export async function listPage(store, args) {
|
|
@@ -56,3 +66,26 @@ export async function triageMany(store, ids, change) {
|
|
|
56
66
|
}
|
|
57
67
|
return outcome;
|
|
58
68
|
}
|
|
69
|
+
/** A failure reaching a remote reader endpoint or reported by its tools. `status` is the HTTP status, when there was one. */
|
|
70
|
+
export class FeedbackReaderError extends Error {
|
|
71
|
+
status;
|
|
72
|
+
constructor(message, status) {
|
|
73
|
+
super(message);
|
|
74
|
+
this.status = status;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Reader operations straight against a store. `defaultBy` is used when a triage gives no `by`. */
|
|
78
|
+
export function storeReader(store, defaultBy = null) {
|
|
79
|
+
return {
|
|
80
|
+
stats: (filter) => store.stats(normalizeFilter(filter)),
|
|
81
|
+
list: (query) => listPage(store, query),
|
|
82
|
+
get: async (id) => {
|
|
83
|
+
const record = await store.get(id);
|
|
84
|
+
if (!record)
|
|
85
|
+
throw new FeedbackInputError(`No feedback with id ${id}.`);
|
|
86
|
+
return record;
|
|
87
|
+
},
|
|
88
|
+
triage: (ids, change) => triageMany(store, ids, { status: change.status, note: change.note, by: change.by ?? defaultBy }),
|
|
89
|
+
close: async () => store.close?.(),
|
|
90
|
+
};
|
|
91
|
+
}
|
package/dist/register.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { type ResolveIdentity } from "./identity.js";
|
|
2
|
+
import { type FeedbackRequestExtra, type ResolveIdentity } from "./identity.js";
|
|
3
|
+
import { type FeedbackReaderClient } from "./reader.js";
|
|
3
4
|
import type { FeedbackStore } from "./store.js";
|
|
4
5
|
import { type FeedbackRecord, type FeedbackServerInfo } from "./types.js";
|
|
5
6
|
export interface FeedbackLimits {
|
|
@@ -15,11 +16,9 @@ export interface FeedbackLimits {
|
|
|
15
16
|
}
|
|
16
17
|
export declare const DEFAULT_FEEDBACK_LIMITS: FeedbackLimits;
|
|
17
18
|
interface SharedOptions {
|
|
18
|
-
/** Created once at module level and shared across requests. */
|
|
19
|
-
store: FeedbackStore;
|
|
20
19
|
/** Maps a request onto an identity; overrides what the default resolver finds. */
|
|
21
20
|
resolveIdentity?: ResolveIdentity;
|
|
22
|
-
/** Prepended to every tool and prompt name, e.g. `"
|
|
21
|
+
/** Prepended to every tool and prompt name, e.g. `"shop_"`. */
|
|
23
22
|
toolPrefix?: string;
|
|
24
23
|
/**
|
|
25
24
|
* Secret for HMAC token fingerprints. Recommended; without it fingerprints are plain SHA-256.
|
|
@@ -30,6 +29,8 @@ interface SharedOptions {
|
|
|
30
29
|
onError?: (error: unknown, tool: string) => void;
|
|
31
30
|
}
|
|
32
31
|
export interface FeedbackOptions extends SharedOptions {
|
|
32
|
+
/** Created once at module level and shared across requests. */
|
|
33
|
+
store: FeedbackStore;
|
|
33
34
|
/**
|
|
34
35
|
* Tell agents to file only after the user confirms the exact feedback. Pair it with
|
|
35
36
|
* `feedbackConfirmInstructions` in the server's instructions.
|
|
@@ -37,16 +38,39 @@ export interface FeedbackOptions extends SharedOptions {
|
|
|
37
38
|
requireConfirmation?: boolean;
|
|
38
39
|
/** Refuse submissions that carry neither a subject nor a token fingerprint. */
|
|
39
40
|
requireIdentity?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Ids the server wants agents to include in `context.references`, as name -> description, e.g.
|
|
43
|
+
* `{ orderId: "The order the problem involved" }`. They appear in the submit tool's input.
|
|
44
|
+
*/
|
|
45
|
+
contextFields?: Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Attaches what the server knows that the agent cannot: versions, request ids, the state of the
|
|
48
|
+
* referenced objects. Receives the record (with the agent's `context.references`) and the request;
|
|
49
|
+
* what it returns is stored as `context.server_context`. If it throws, the feedback is stored
|
|
50
|
+
* without it and the error goes to `onError`.
|
|
51
|
+
*/
|
|
52
|
+
attachContext?: (record: Readonly<FeedbackRecord>, extra: FeedbackRequestExtra) => Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>;
|
|
40
53
|
/** Last chance to scrub a record before it is stored. */
|
|
41
54
|
redact?: (record: FeedbackRecord) => FeedbackRecord | Promise<FeedbackRecord>;
|
|
42
55
|
limits?: Partial<FeedbackLimits>;
|
|
43
56
|
/** Recorded on each record. Defaults to the name and version the server was constructed with. */
|
|
44
57
|
serverInfo?: Partial<FeedbackServerInfo>;
|
|
45
58
|
}
|
|
46
|
-
export
|
|
59
|
+
export type FeedbackReaderOptions = SharedOptions & {
|
|
47
60
|
/** Leave out `update_feedback_triage`, so the reader can look but not change anything. */
|
|
48
61
|
readOnly?: boolean;
|
|
49
|
-
}
|
|
62
|
+
} & ({
|
|
63
|
+
/** Created once at module level and shared across requests. */
|
|
64
|
+
store: FeedbackStore;
|
|
65
|
+
reader?: never;
|
|
66
|
+
} | {
|
|
67
|
+
/**
|
|
68
|
+
* Serve another source instead of a store, e.g. connectFeedbackReader() to re-serve a
|
|
69
|
+
* remote reader endpoint. Its errors are shown to the caller as they are.
|
|
70
|
+
*/
|
|
71
|
+
reader: FeedbackReaderClient;
|
|
72
|
+
store?: never;
|
|
73
|
+
});
|
|
50
74
|
export declare function uuidv7(now?: number): string;
|
|
51
75
|
/** Adds `submit_feedback` to a server. Safe to call on a server built per request. */
|
|
52
76
|
export declare function registerFeedback(server: McpServer, options: FeedbackOptions): void;
|
package/dist/register.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { defaultResolveIdentity, } from "./identity.js";
|
|
3
|
-
import { FeedbackInputError,
|
|
4
|
-
import { READER_TOOLS, SUBMIT_TOOL, submitToolDescription, SYNTHESIZE_PROMPT, feedbackStatsShape, getFeedbackShape, listFeedbackShape,
|
|
3
|
+
import { FeedbackInputError, FeedbackReaderError, normalizeFilter, storeReader, } from "./reader.js";
|
|
4
|
+
import { READER_TOOLS, SUBMIT_TOOL, submitToolDescription, SYNTHESIZE_PROMPT, feedbackStatsShape, getFeedbackShape, listFeedbackShape, submitFeedbackShapeFor, REFERENCE_KEY_PATTERN, synthesizeFeedbackArgsShape, synthesizePromptText, updateFeedbackTriageShape, } from "./tools.js";
|
|
5
5
|
import { FEEDBACK_SCHEMA_VERSION, } from "./types.js";
|
|
6
6
|
export const DEFAULT_FEEDBACK_LIMITS = {
|
|
7
7
|
titleChars: 200,
|
|
@@ -45,6 +45,16 @@ function checkLimits(input, limits) {
|
|
|
45
45
|
}
|
|
46
46
|
items("context.repro_steps", context.repro_steps);
|
|
47
47
|
context.repro_steps?.forEach((step, index) => text(`context.repro_steps[${index}]`, step, limits.fieldChars));
|
|
48
|
+
const references = Object.entries(context.references ?? {});
|
|
49
|
+
if (references.length > limits.maxItems) {
|
|
50
|
+
throw new FeedbackInputError(`context.references has ${references.length} entries; the limit is ${limits.maxItems}.`);
|
|
51
|
+
}
|
|
52
|
+
for (const [key, value] of references) {
|
|
53
|
+
if (!REFERENCE_KEY_PATTERN.test(key)) {
|
|
54
|
+
throw new FeedbackInputError(`context.references key "${key.slice(0, 80)}" must start with a letter and use only letters, digits, _ or - (at most 64).`);
|
|
55
|
+
}
|
|
56
|
+
text(`context.references.${key}`, value, limits.fieldChars);
|
|
57
|
+
}
|
|
48
58
|
items("context.tool_calls", context.tool_calls);
|
|
49
59
|
context.tool_calls?.forEach((call, index) => {
|
|
50
60
|
text(`context.tool_calls[${index}].name`, call.name, limits.fieldChars);
|
|
@@ -77,7 +87,9 @@ function createRuntime(server, options) {
|
|
|
77
87
|
catch (error) {
|
|
78
88
|
if (!(error instanceof FeedbackInputError))
|
|
79
89
|
options.onError?.(error, tool);
|
|
80
|
-
|
|
90
|
+
// A remote reader's errors carry the remote server's own, already safe, messages.
|
|
91
|
+
const shown = error instanceof FeedbackInputError || error instanceof FeedbackReaderError;
|
|
92
|
+
const text = shown ? error.message : "The feedback store is unavailable. Try again later.";
|
|
81
93
|
return { isError: true, content: [{ type: "text", text }] };
|
|
82
94
|
}
|
|
83
95
|
};
|
|
@@ -88,10 +100,14 @@ export function registerFeedback(server, options) {
|
|
|
88
100
|
const { prefix, identify, guard } = createRuntime(server, options);
|
|
89
101
|
const limits = { ...DEFAULT_FEEDBACK_LIMITS, ...options.limits };
|
|
90
102
|
const name = prefix + SUBMIT_TOOL.name;
|
|
103
|
+
for (const key of Object.keys(options.contextFields ?? {})) {
|
|
104
|
+
if (!REFERENCE_KEY_PATTERN.test(key))
|
|
105
|
+
throw new Error(`Invalid contextFields key: ${key}`);
|
|
106
|
+
}
|
|
91
107
|
server.registerTool(name, {
|
|
92
108
|
title: SUBMIT_TOOL.title,
|
|
93
109
|
description: submitToolDescription(options.requireConfirmation),
|
|
94
|
-
inputSchema:
|
|
110
|
+
inputSchema: submitFeedbackShapeFor(options.contextFields),
|
|
95
111
|
annotations: SUBMIT_TOOL.annotations,
|
|
96
112
|
}, (args, extra) => guard(name, async () => {
|
|
97
113
|
const input = args;
|
|
@@ -125,6 +141,16 @@ export function registerFeedback(server, options) {
|
|
|
125
141
|
triaged_by: null,
|
|
126
142
|
updated_at: created,
|
|
127
143
|
};
|
|
144
|
+
if (options.attachContext) {
|
|
145
|
+
try {
|
|
146
|
+
const attached = await options.attachContext(record, extra);
|
|
147
|
+
if (attached && Object.keys(attached).length)
|
|
148
|
+
record = { ...record, context: { ...record.context, server_context: attached } };
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
options.onError?.(error, name);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
128
154
|
if (options.redact)
|
|
129
155
|
record = await options.redact(record);
|
|
130
156
|
await options.store.insert(record);
|
|
@@ -138,7 +164,7 @@ export function registerFeedback(server, options) {
|
|
|
138
164
|
*/
|
|
139
165
|
export function registerFeedbackReader(server, options) {
|
|
140
166
|
const { prefix, identify, guard } = createRuntime(server, options);
|
|
141
|
-
const
|
|
167
|
+
const reader = options.reader ?? storeReader(options.store);
|
|
142
168
|
const names = {
|
|
143
169
|
list: prefix + READER_TOOLS.list.name,
|
|
144
170
|
get: prefix + READER_TOOLS.get.name,
|
|
@@ -146,27 +172,24 @@ export function registerFeedbackReader(server, options) {
|
|
|
146
172
|
stats: prefix + READER_TOOLS.stats.name,
|
|
147
173
|
};
|
|
148
174
|
server.registerTool(names.list, config(READER_TOOLS.list, listFeedbackShape), (args) => guard(names.list, async () => {
|
|
149
|
-
const page = await
|
|
175
|
+
const page = await reader.list({ ...args, limit: args.limit ?? 25 });
|
|
150
176
|
return { ...page };
|
|
151
177
|
}));
|
|
152
178
|
server.registerTool(names.get, config(READER_TOOLS.get, getFeedbackShape), (args) => guard(names.get, async () => {
|
|
153
|
-
|
|
154
|
-
if (!record)
|
|
155
|
-
throw new FeedbackInputError(`No feedback with id ${args.id}.`);
|
|
156
|
-
return { ...record };
|
|
179
|
+
return { ...(await reader.get(args.id)) };
|
|
157
180
|
}));
|
|
158
181
|
if (!options.readOnly) {
|
|
159
182
|
server.registerTool(names.triage, config(READER_TOOLS.triage, updateFeedbackTriageShape), (args, extra) => guard(names.triage, async () => {
|
|
160
|
-
const
|
|
161
|
-
const outcome = await
|
|
183
|
+
const caller = await identify(extra);
|
|
184
|
+
const outcome = await reader.triage(args.ids, {
|
|
162
185
|
status: args.status,
|
|
163
186
|
note: args.note,
|
|
164
|
-
by:
|
|
187
|
+
by: caller.subject ?? caller.client_id ?? caller.token_fingerprint,
|
|
165
188
|
});
|
|
166
189
|
return { ...outcome };
|
|
167
190
|
}));
|
|
168
191
|
}
|
|
169
|
-
server.registerTool(names.stats, config(READER_TOOLS.stats, feedbackStatsShape), (args) => guard(names.stats, async () => ({ ...(await
|
|
192
|
+
server.registerTool(names.stats, config(READER_TOOLS.stats, feedbackStatsShape), (args) => guard(names.stats, async () => ({ ...(await reader.stats(normalizeFilter(args))) })));
|
|
170
193
|
server.registerPrompt(prefix + SYNTHESIZE_PROMPT.name, {
|
|
171
194
|
title: SYNTHESIZE_PROMPT.title,
|
|
172
195
|
description: SYNTHESIZE_PROMPT.description,
|
package/dist/store.js
CHANGED
|
@@ -41,5 +41,8 @@ export function matchesFilter(record, filter) {
|
|
|
41
41
|
return false;
|
|
42
42
|
if (filter.until !== undefined && record.created_at >= filter.until)
|
|
43
43
|
return false;
|
|
44
|
+
if (filter.reference !== undefined && record.context.references?.[filter.reference.key] !== filter.reference.value) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
44
47
|
return true;
|
|
45
48
|
}
|
package/dist/stores/sql.js
CHANGED
|
@@ -158,6 +158,13 @@ function where(dialect, filter) {
|
|
|
158
158
|
add("f.created_at >= ?", filter.since);
|
|
159
159
|
if (filter.until !== undefined)
|
|
160
160
|
add("f.created_at < ?", filter.until);
|
|
161
|
+
if (filter.reference !== undefined) {
|
|
162
|
+
// Keys are checked against REFERENCE_KEY_PATTERN before they reach a store.
|
|
163
|
+
if (dialect === "postgres")
|
|
164
|
+
add("f.context -> 'references' ->> ? = ?", filter.reference.key, filter.reference.value);
|
|
165
|
+
else
|
|
166
|
+
add("json_extract(f.context, ?) = ?", `$.references."${filter.reference.key}"`, filter.reference.value);
|
|
167
|
+
}
|
|
161
168
|
return { clauses, params };
|
|
162
169
|
}
|
|
163
170
|
const whereSql = (clauses) => (clauses.length ? ` WHERE ${clauses.join(" AND ")}` : "");
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,4 +1,83 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/** Keys of `context.references`: a letter, then letters, digits, `_` or `-` (at most 64). */
|
|
3
|
+
export declare const REFERENCE_KEY_PATTERN: RegExp;
|
|
4
|
+
/** The submit tool's input, with any host-declared `context.references` fields. */
|
|
5
|
+
export declare function submitFeedbackShapeFor(contextFields?: Record<string, string>): {
|
|
6
|
+
context: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
references: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>> | z.ZodOptional<z.ZodObject<{
|
|
8
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodString, z.objectOutputType<{
|
|
10
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.ZodString, "strip">, z.objectInputType<{
|
|
12
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.ZodString, "strip">>>;
|
|
14
|
+
goal: z.ZodOptional<z.ZodString>;
|
|
15
|
+
expected: z.ZodOptional<z.ZodString>;
|
|
16
|
+
actual: z.ZodOptional<z.ZodString>;
|
|
17
|
+
workaround: z.ZodOptional<z.ZodString>;
|
|
18
|
+
suggestion: z.ZodOptional<z.ZodString>;
|
|
19
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
arguments_summary: z.ZodOptional<z.ZodString>;
|
|
22
|
+
error: z.ZodOptional<z.ZodString>;
|
|
23
|
+
is_error: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
name: string;
|
|
26
|
+
arguments_summary?: string | undefined;
|
|
27
|
+
error?: string | undefined;
|
|
28
|
+
is_error?: boolean | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
name: string;
|
|
31
|
+
arguments_summary?: string | undefined;
|
|
32
|
+
error?: string | undefined;
|
|
33
|
+
is_error?: boolean | undefined;
|
|
34
|
+
}>, "many">>;
|
|
35
|
+
repro_steps: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
36
|
+
excerpt: z.ZodOptional<z.ZodString>;
|
|
37
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
expected?: string | undefined;
|
|
40
|
+
references?: Record<string, string> | z.objectOutputType<{
|
|
41
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, z.ZodString, "strip"> | undefined;
|
|
43
|
+
goal?: string | undefined;
|
|
44
|
+
actual?: string | undefined;
|
|
45
|
+
workaround?: string | undefined;
|
|
46
|
+
suggestion?: string | undefined;
|
|
47
|
+
tool_calls?: {
|
|
48
|
+
name: string;
|
|
49
|
+
arguments_summary?: string | undefined;
|
|
50
|
+
error?: string | undefined;
|
|
51
|
+
is_error?: boolean | undefined;
|
|
52
|
+
}[] | undefined;
|
|
53
|
+
repro_steps?: string[] | undefined;
|
|
54
|
+
excerpt?: string | undefined;
|
|
55
|
+
metadata?: Record<string, unknown> | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
expected?: string | undefined;
|
|
58
|
+
references?: Record<string, string> | z.objectInputType<{
|
|
59
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
60
|
+
}, z.ZodString, "strip"> | undefined;
|
|
61
|
+
goal?: string | undefined;
|
|
62
|
+
actual?: string | undefined;
|
|
63
|
+
workaround?: string | undefined;
|
|
64
|
+
suggestion?: string | undefined;
|
|
65
|
+
tool_calls?: {
|
|
66
|
+
name: string;
|
|
67
|
+
arguments_summary?: string | undefined;
|
|
68
|
+
error?: string | undefined;
|
|
69
|
+
is_error?: boolean | undefined;
|
|
70
|
+
}[] | undefined;
|
|
71
|
+
repro_steps?: string[] | undefined;
|
|
72
|
+
excerpt?: string | undefined;
|
|
73
|
+
metadata?: Record<string, unknown> | undefined;
|
|
74
|
+
}>>;
|
|
75
|
+
kind: z.ZodEnum<["bug", "tool_failure", "feature_request", "friction", "praise", "other"]>;
|
|
76
|
+
title: z.ZodString;
|
|
77
|
+
body: z.ZodString;
|
|
78
|
+
severity: z.ZodOptional<z.ZodEnum<["blocker", "major", "minor", "none"]>>;
|
|
79
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
80
|
+
};
|
|
2
81
|
export declare const submitFeedbackShape: {
|
|
3
82
|
kind: z.ZodEnum<["bug", "tool_failure", "feature_request", "friction", "praise", "other"]>;
|
|
4
83
|
title: z.ZodString;
|
|
@@ -6,6 +85,13 @@ export declare const submitFeedbackShape: {
|
|
|
6
85
|
severity: z.ZodOptional<z.ZodEnum<["blocker", "major", "minor", "none"]>>;
|
|
7
86
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
8
87
|
context: z.ZodOptional<z.ZodObject<{
|
|
88
|
+
references: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>> | z.ZodOptional<z.ZodObject<{
|
|
89
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, "strip", z.ZodString, z.objectOutputType<{
|
|
91
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
92
|
+
}, z.ZodString, "strip">, z.objectInputType<{
|
|
93
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
94
|
+
}, z.ZodString, "strip">>>;
|
|
9
95
|
goal: z.ZodOptional<z.ZodString>;
|
|
10
96
|
expected: z.ZodOptional<z.ZodString>;
|
|
11
97
|
actual: z.ZodOptional<z.ZodString>;
|
|
@@ -32,6 +118,9 @@ export declare const submitFeedbackShape: {
|
|
|
32
118
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
33
119
|
}, "strip", z.ZodTypeAny, {
|
|
34
120
|
expected?: string | undefined;
|
|
121
|
+
references?: Record<string, string> | z.objectOutputType<{
|
|
122
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
123
|
+
}, z.ZodString, "strip"> | undefined;
|
|
35
124
|
goal?: string | undefined;
|
|
36
125
|
actual?: string | undefined;
|
|
37
126
|
workaround?: string | undefined;
|
|
@@ -47,6 +136,9 @@ export declare const submitFeedbackShape: {
|
|
|
47
136
|
metadata?: Record<string, unknown> | undefined;
|
|
48
137
|
}, {
|
|
49
138
|
expected?: string | undefined;
|
|
139
|
+
references?: Record<string, string> | z.objectInputType<{
|
|
140
|
+
[k: string]: z.ZodOptional<z.ZodString>;
|
|
141
|
+
}, z.ZodString, "strip"> | undefined;
|
|
50
142
|
goal?: string | undefined;
|
|
51
143
|
actual?: string | undefined;
|
|
52
144
|
workaround?: string | undefined;
|
|
@@ -73,6 +165,16 @@ export declare const listFeedbackShape: {
|
|
|
73
165
|
tag: z.ZodOptional<z.ZodString>;
|
|
74
166
|
since: z.ZodOptional<z.ZodString>;
|
|
75
167
|
until: z.ZodOptional<z.ZodString>;
|
|
168
|
+
reference: z.ZodOptional<z.ZodObject<{
|
|
169
|
+
key: z.ZodString;
|
|
170
|
+
value: z.ZodString;
|
|
171
|
+
}, "strip", z.ZodTypeAny, {
|
|
172
|
+
value: string;
|
|
173
|
+
key: string;
|
|
174
|
+
}, {
|
|
175
|
+
value: string;
|
|
176
|
+
key: string;
|
|
177
|
+
}>>;
|
|
76
178
|
};
|
|
77
179
|
export declare const getFeedbackShape: {
|
|
78
180
|
id: z.ZodString;
|
|
@@ -91,6 +193,16 @@ export declare const feedbackStatsShape: {
|
|
|
91
193
|
tag: z.ZodOptional<z.ZodString>;
|
|
92
194
|
since: z.ZodOptional<z.ZodString>;
|
|
93
195
|
until: z.ZodOptional<z.ZodString>;
|
|
196
|
+
reference: z.ZodOptional<z.ZodObject<{
|
|
197
|
+
key: z.ZodString;
|
|
198
|
+
value: z.ZodString;
|
|
199
|
+
}, "strip", z.ZodTypeAny, {
|
|
200
|
+
value: string;
|
|
201
|
+
key: string;
|
|
202
|
+
}, {
|
|
203
|
+
value: string;
|
|
204
|
+
key: string;
|
|
205
|
+
}>>;
|
|
94
206
|
};
|
|
95
207
|
export declare const synthesizeFeedbackArgsShape: {
|
|
96
208
|
since: z.ZodOptional<z.ZodString>;
|
package/dist/tools.js
CHANGED
|
@@ -11,6 +11,24 @@ const toolCallShape = {
|
|
|
11
11
|
error: z.string().optional().describe("Error text or unexpected output the tool returned."),
|
|
12
12
|
is_error: z.boolean().optional().describe("Whether the call failed."),
|
|
13
13
|
};
|
|
14
|
+
/** Keys of `context.references`: a letter, then letters, digits, `_` or `-` (at most 64). */
|
|
15
|
+
export const REFERENCE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
16
|
+
const REFERENCES_DESCRIPTION = "Identifiers of the objects involved (records, documents, jobs, generated outputs), keyed by what they are, " +
|
|
17
|
+
"so a reader can look them up and see what you saw. Include every relevant id you have.";
|
|
18
|
+
/**
|
|
19
|
+
* The `context.references` input. Fields a host declares are listed with their descriptions; agents may add
|
|
20
|
+
* other string ids too.
|
|
21
|
+
*/
|
|
22
|
+
function referencesSchema(fields = {}) {
|
|
23
|
+
const declared = Object.entries(fields);
|
|
24
|
+
if (!declared.length)
|
|
25
|
+
return z.record(z.string(), z.string()).optional().describe(REFERENCES_DESCRIPTION);
|
|
26
|
+
return z
|
|
27
|
+
.object(Object.fromEntries(declared.map(([key, description]) => [key, z.string().optional().describe(description)])))
|
|
28
|
+
.catchall(z.string())
|
|
29
|
+
.optional()
|
|
30
|
+
.describe(REFERENCES_DESCRIPTION);
|
|
31
|
+
}
|
|
14
32
|
const contextShape = {
|
|
15
33
|
goal: z.string().optional().describe("What the user was trying to accomplish in this session."),
|
|
16
34
|
expected: z.string().optional().describe("What you expected to happen."),
|
|
@@ -22,6 +40,16 @@ const contextShape = {
|
|
|
22
40
|
excerpt: z.string().optional().describe("A short relevant excerpt of tool output or conversation."),
|
|
23
41
|
metadata: z.record(z.string(), z.unknown()).optional().describe("Any other structured details."),
|
|
24
42
|
};
|
|
43
|
+
/** The submit tool's input, with any host-declared `context.references` fields. */
|
|
44
|
+
export function submitFeedbackShapeFor(contextFields) {
|
|
45
|
+
return {
|
|
46
|
+
...submitFeedbackShape,
|
|
47
|
+
context: z
|
|
48
|
+
.object({ ...contextShape, references: referencesSchema(contextFields) })
|
|
49
|
+
.optional()
|
|
50
|
+
.describe("Session context that lets a reader act without asking you."),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
25
53
|
export const submitFeedbackShape = {
|
|
26
54
|
kind: z
|
|
27
55
|
.enum(FEEDBACK_KINDS)
|
|
@@ -34,7 +62,10 @@ export const submitFeedbackShape = {
|
|
|
34
62
|
.optional()
|
|
35
63
|
.describe("blocker: the task could not be completed. major: completed with significant trouble. Defaults to none."),
|
|
36
64
|
tags: z.array(z.string().min(1)).optional().describe("Short labels for grouping."),
|
|
37
|
-
context: z
|
|
65
|
+
context: z
|
|
66
|
+
.object({ ...contextShape, references: referencesSchema() })
|
|
67
|
+
.optional()
|
|
68
|
+
.describe("Session context that lets a reader act without asking you."),
|
|
38
69
|
};
|
|
39
70
|
const filterShape = {
|
|
40
71
|
kind: z.enum(FEEDBACK_KINDS).optional(),
|
|
@@ -45,6 +76,10 @@ const filterShape = {
|
|
|
45
76
|
tag: z.string().optional(),
|
|
46
77
|
since: z.string().optional().describe("ISO 8601 timestamp; include feedback created at or after it."),
|
|
47
78
|
until: z.string().optional().describe("ISO 8601 timestamp; include feedback created before it."),
|
|
79
|
+
reference: z
|
|
80
|
+
.object({ key: z.string(), value: z.string() })
|
|
81
|
+
.optional()
|
|
82
|
+
.describe("Only feedback whose context.references[key] equals value, e.g. every report about one record."),
|
|
48
83
|
};
|
|
49
84
|
export const listFeedbackShape = {
|
|
50
85
|
...filterShape,
|
|
@@ -118,6 +153,8 @@ export function synthesizePromptText(prefix, args) {
|
|
|
118
153
|
`1. Call ${tool("feedback_stats")} to see volume by kind, status, severity and tool.`,
|
|
119
154
|
`2. Page through ${tool("list_feedback")} until next_cursor is null. Read every record, not a sample.`,
|
|
120
155
|
"3. Group records that describe the same underlying problem or request, even when worded differently.",
|
|
156
|
+
" Records naming the same object in context.references often belong together; context.server_context is",
|
|
157
|
+
" what the server recorded at the time (versions, object state), and is more reliable than the agent's account.",
|
|
121
158
|
"4. For each group report: what is wrong or wanted, which tools are involved, how many records and distinct",
|
|
122
159
|
" submitters, the highest severity, one representative record id, and a concrete recommended change.",
|
|
123
160
|
"5. Order groups by impact: blockers first, then by number of distinct submitters.",
|
package/dist/types.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ export interface FeedbackContext {
|
|
|
21
21
|
repro_steps?: string[];
|
|
22
22
|
excerpt?: string;
|
|
23
23
|
metadata?: Record<string, unknown>;
|
|
24
|
+
/** Ids of the objects involved, keyed by what they are (e.g. `orderId`). Supplied by the agent. */
|
|
25
|
+
references?: Record<string, string>;
|
|
26
|
+
/** Attached by the server's `attachContext` hook; never taken from tool input. */
|
|
27
|
+
server_context?: Record<string, unknown>;
|
|
24
28
|
}
|
|
25
29
|
/** Who submitted the feedback. Always stamped by the server, never read from tool input. */
|
|
26
30
|
export interface FeedbackIdentity {
|
|
@@ -67,6 +71,11 @@ export interface FeedbackFilter {
|
|
|
67
71
|
since?: string;
|
|
68
72
|
/** Exclusive upper bound on created_at. */
|
|
69
73
|
until?: string;
|
|
74
|
+
/** Matches records whose context.references[key] equals value. */
|
|
75
|
+
reference?: {
|
|
76
|
+
key: string;
|
|
77
|
+
value: string;
|
|
78
|
+
};
|
|
70
79
|
}
|
|
71
80
|
export interface FeedbackListQuery extends FeedbackFilter {
|
|
72
81
|
limit: number;
|
package/package.json
CHANGED