Skip to content

Commit f887606

Browse files
kyalabsclaude
andcommitted
feat: register new tools + deprecate legacy reporting
Register kya_web_fetch and kya_getHeaders in index.ts. Deprecate kya_reportBadgeOutcome and kya_reportBadgeNotPresented to no-ops — outcomes tracked server-side via verify endpoint, not-presented event no longer scored. Both log once-per-session stderr warning. Remove unused imports. Update kya_reportBadgePresented description to stop referencing the now-deprecated kya_reportBadgeOutcome. Part of: KYA-55 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c4d37a9 commit f887606

1 file changed

Lines changed: 74 additions & 14 deletions

File tree

src/index.ts

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import {
88
onTripStarted,
99
onIdentityPresented,
1010
onServerClose,
11-
reportOutcomeFromAgent,
1211
} from "./sampling.js";
1312
import { handleReportBadgePresented } from "./lib/report-badge-presented-handler.js";
14-
import { reportBadgeNotPresented } from "./lib/report-badge.js";
1513
import { getAuthMode } from "./lib/storage.js";
1614
import { initAgentModel } from "./lib/agent-model.js";
15+
import { getHeaders } from "./tools/getHeaders.js";
16+
import { webFetch } from "./tools/webFetch.js";
1717

1818
const server = new McpServer({
1919
name: "kyalabs-badge",
20-
version: "2.3.0",
20+
version: "2.5.0",
2121
});
2222

2323
server.tool(
@@ -65,7 +65,7 @@ server.tool(
6565
"kya_reportBadgePresented",
6666
`Report that you presented your Badge to a merchant. Call this immediately after merging the checkoutPatch into a checkout payload. Required for kyaLabs to record the trip.
6767
68-
When Extended Auth is enabled, kyaLabs checks back 7 seconds later. Otherwise, call kya_reportBadgeOutcome when you know the result.`,
68+
When Extended Auth is enabled, kyaLabs checks back 7 seconds later to record the outcome automatically.`,
6969
{
7070
verification_token: z.string().describe(
7171
"The verification_token returned by kya_getAgentIdentity"
@@ -100,11 +100,13 @@ When Extended Auth is enabled, kyaLabs checks back 7 seconds later. Otherwise, c
100100
}
101101
);
102102

103+
let _warnedOutcome = false;
104+
103105
server.tool(
104106
"kya_reportBadgeOutcome",
105-
`Report how the merchant responded when you presented your Badge.
107+
`[DEPRECATED — outcomes are now tracked automatically via the verify endpoint. This tool will be removed in a future version.]
106108
107-
Call this after kya_reportBadgePresented when you know whether the merchant accepted or denied you. Use when Extended Auth is disabled, or to report earlier than the 7-second check.`,
109+
Report how the merchant responded when you presented your Badge.`,
108110
{
109111
verification_token: z.string().describe(
110112
"The verification_token returned by kya_getAgentIdentity"
@@ -121,22 +123,27 @@ Call this after kya_reportBadgePresented when you know whether the merchant acce
121123
"Trip ID from kya_getAgentIdentity — links events in this shopping session"
122124
),
123125
},
124-
async ({ verification_token, merchant, outcome, trip_id }) => {
125-
reportOutcomeFromAgent(verification_token, merchant, outcome, trip_id);
126+
async ({ merchant, outcome }) => {
127+
if (!_warnedOutcome) {
128+
process.stderr.write("[badge] WARNING: kya_reportBadgeOutcome is deprecated. Outcomes are now tracked automatically.\n");
129+
_warnedOutcome = true;
130+
}
126131
return {
127132
content: [{
128133
type: "text",
129-
text: `Outcome recorded: ${outcome} at ${merchant}`,
134+
text: `Outcome acknowledged: ${outcome} at ${merchant} (deprecated — auto-tracking active).`,
130135
}],
131136
};
132137
}
133138
);
134139

140+
let _warnedNotPresented = false;
141+
135142
server.tool(
136143
"kya_reportBadgeNotPresented",
137-
`Report that you did NOT present your Badge at a merchant.
144+
`[DEPRECATED — this event is no longer needed. This tool will be removed in a future version.]
138145
139-
Call this when you have a badge but chose not to present it (e.g., abandoned cart, merchant didn't ask).`,
146+
Report that you did NOT present your Badge at a merchant.`,
140147
{
141148
verification_token: z.string().describe(
142149
"The verification_token from kya_getAgentIdentity"
@@ -151,17 +158,70 @@ Call this when you have a badge but chose not to present it (e.g., abandoned car
151158
"Trip ID from kya_getAgentIdentity — links events in this shopping session"
152159
),
153160
},
154-
async ({ verification_token, merchant, reason, trip_id }) => {
155-
await reportBadgeNotPresented(verification_token, merchant, reason, trip_id);
161+
async ({ merchant, reason }) => {
162+
if (!_warnedNotPresented) {
163+
process.stderr.write("[badge] WARNING: kya_reportBadgeNotPresented is deprecated.\n");
164+
_warnedNotPresented = true;
165+
}
156166
return {
157167
content: [{
158168
type: "text",
159-
text: `Not presented recorded at ${merchant} (${reason})`,
169+
text: `Not-presented acknowledged at ${merchant} (${reason}) (deprecated).`,
160170
}],
161171
};
162172
}
163173
);
164174

175+
server.tool(
176+
"kya_web_fetch",
177+
`Fetch a web page with your Badge identity attached. Your Kya-Token header is injected automatically — merchants see you as an authorized actor, not a bot. Your visit is automatically recorded in your shopping journal.
178+
179+
Call kya_getAgentIdentity first. Then use this instead of web_fetch when shopping at merchant sites. HTTPS only. Returns status, headers, and body (5MB max, 30s timeout). Redirects are not followed — check the Location header if you receive a 3xx status.`,
180+
{
181+
url: z.string().max(2000).describe(
182+
"The HTTPS URL to fetch (e.g., 'https://etsy.com/products')"
183+
),
184+
method: z.enum(["GET", "HEAD", "OPTIONS"]).optional().describe(
185+
"HTTP method (default: GET)"
186+
),
187+
headers: z.record(z.string(), z.string()).optional().describe(
188+
"Additional headers to include in the request"
189+
),
190+
},
191+
async ({ url, method, headers }) => {
192+
const result = await webFetch(url, method, headers as Record<string, string> | undefined);
193+
if ("error" in result) {
194+
return {
195+
content: [{ type: "text" as const, text: JSON.stringify(result) }],
196+
isError: true,
197+
};
198+
}
199+
return {
200+
content: [{ type: "text" as const, text: JSON.stringify(result) }],
201+
};
202+
}
203+
);
204+
205+
server.tool(
206+
"kya_getHeaders",
207+
`Get identity headers for your own HTTP requests. Returns a Kya-Token header you can attach to requests made through Playwright, browser extensions, or any HTTP client you control.
208+
209+
Call kya_getAgentIdentity first to establish your identity. Then pass these headers to page.setExtraHTTPHeaders() for browser automation, or set as a cookie via document.cookie for Chrome extensions.`,
210+
{},
211+
async () => {
212+
const result = getHeaders();
213+
if ("error" in result) {
214+
return {
215+
content: [{ type: "text" as const, text: JSON.stringify(result) }],
216+
isError: true,
217+
};
218+
}
219+
return {
220+
content: [{ type: "text" as const, text: JSON.stringify(result) }],
221+
};
222+
}
223+
);
224+
165225
async function main() {
166226
const transport = new StdioServerTransport();
167227
await server.connect(transport);

0 commit comments

Comments
 (0)