Skip to content

Commit 7300451

Browse files
committed
Strip error responses from processed spec
Only keep 2xx/default responses — error schemas (401, 404, etc.) are identical boilerplate on every endpoint and waste context. Full CNAP spec: ~58K → ~26K tokens (56% reduction) Single endpoint: ~990 → ~358 tokens (64% reduction) Bump version to 0.1.3.
1 parent b0bb04c commit 7300451

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@robinbraemer/codemode",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Code Mode MCP tools from OpenAPI specs. Two tools (search + execute) replace hundreds of individual MCP tools.",
55
"type": "module",
66
"main": "./dist/index.js",

src/spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ interface OperationObject {
7575
tags?: string[];
7676
parameters?: unknown;
7777
requestBody?: unknown;
78-
responses?: unknown;
78+
responses?: Record<string, unknown>;
7979
}
8080

8181
/**
@@ -128,6 +128,16 @@ export function processSpec(
128128
for (const method of HTTP_METHODS) {
129129
const op = pathItem[method];
130130
if (op) {
131+
// Only keep success responses (2xx) — error schemas are redundant noise
132+
const successResponses: Record<string, unknown> = {};
133+
if (op.responses) {
134+
for (const [status, resp] of Object.entries(op.responses)) {
135+
if (status.startsWith("2") || status === "default") {
136+
successResponses[status] = resp;
137+
}
138+
}
139+
}
140+
131141
paths[fullPath][method] = {
132142
summary: op.summary,
133143
description: op.description,
@@ -145,7 +155,7 @@ export function processSpec(
145155
maxRefDepth,
146156
),
147157
responses: resolveRefs(
148-
op.responses,
158+
Object.keys(successResponses).length > 0 ? successResponses : op.responses,
149159
spec as Record<string, unknown>,
150160
undefined,
151161
maxRefDepth,

0 commit comments

Comments
 (0)