Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions workers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,34 @@ import { z } from "zod";
import { handleUnifiedAction, type Env } from "./orchestrate";
import { ZipBaselineFetcher } from "./zip-baseline-fetcher";
import { RequestTracer } from "./tracing";
import { parseConsumerLabel } from "./telemetry";
import { renderNotFoundPage } from "./not-found-ui";
import pkg from "../package.json";

export type { Env };

const BUILD_VERSION = pkg.version;

// ──────────────────────────────────────────────────────────────────────────────
// Consumer identification nudge
//
// DO NOT add session caching, sticky identification, or per-session memory.
// This server is stateless by design (Vodka Architecture). Cloudflare Workers
// are globally distributed across isolates — module-level Maps don't survive
// across requests reliably. The query param (?consumer=yourname) is the
// stateless solution and works on every request, every isolate, every platform.
//
// If a consumer identifies via MCP clientInfo.name on initialize but not via
// query param, they WILL see this nudge on subsequent tools/call requests.
// That is correct behavior — the nudge tells them exactly how to stop seeing
// it. Caching would mask the problem instead of solving it.
//
// See: canon/principles/vodka-architecture, canon/constraints/telemetry-governance
// ──────────────────────────────────────────────────────────────────────────────

const CONSUMER_NUDGE =
"Tip: oddkit tracks tool usage (which tools, how often) but never your prompts, searches, or responses. Add ?consumer=yourname to your oddkit URL to appear on the public transparency leaderboard. See telemetry_policy for details.";

// ──────────────────────────────────────────────────────────────────────────────
// Types
// ──────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -111,7 +132,7 @@ async function fetchPromptContent(env: Env, path: string): Promise<string | null
* (R2-cached) with module-level caching (5-minute TTL). Prompt content
* is fetched lazily on prompts/get via the same R2 pipeline.
*/
async function createServer(env: Env, tracer?: RequestTracer): Promise<McpServer> {
async function createServer(env: Env, tracer?: RequestTracer, consumerSource?: string): Promise<McpServer> {
const server = new McpServer(
{
name: "oddkit",
Expand Down Expand Up @@ -179,6 +200,9 @@ Use when:
env,
tracer,
});
if ((consumerSource === "user-agent" || consumerSource === "unknown") && result.assistant_text) {
result.assistant_text += "\n\n" + CONSUMER_NUDGE;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nudge logic duplicated across two tool handler paths

Low Severity

The identical nudge-appending condition and mutation (consumerSource check + result.assistant_text += ...) is duplicated across the unified oddkit tool handler and the individual tools loop. If the nudge condition later changes (e.g., adding more source types or excluding error responses where result.action === "error"), one location could easily be updated while the other is missed, leading to inconsistent behavior. A small helper like maybeAppendNudge(result, consumerSource) would centralize this logic.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0f04b04. Configure here.

return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
},
);
Expand Down Expand Up @@ -332,6 +356,9 @@ Use when:
env,
tracer,
});
if ((consumerSource === "user-agent" || consumerSource === "unknown") && result.assistant_text) {
result.assistant_text += "\n\n" + CONSUMER_NUDGE;
}
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
},
);
Expand Down Expand Up @@ -800,7 +827,8 @@ export default {
? request.clone()
: null;

const server = await createServer(env, tracer);
const { source: consumerSource } = parseConsumerLabel(request, {});
const server = await createServer(env, tracer, consumerSource);
const handler = createMcpHandler(server, {
route: "/mcp",
corsOptions: {
Expand Down
Loading