Skip to content

Commit b0bb04c

Browse files
committed
Trim processed spec and lower default response token limit
- Drop components, info, and operationId from processSpec output (all $refs are resolved inline, so these are redundant context) - Remove components/info from SPEC_TYPES tool description - Lower default maxResponseTokens from 25K to 6K (matches CF) - Bump version to 0.1.2
1 parent 130632e commit b0bb04c

8 files changed

Lines changed: 19 additions & 33 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.1",
3+
"version": "0.1.2",
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/codemode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class CodeMode {
9292
this.executor = options.executor ?? null;
9393
this.searchToolName = "search";
9494
this.executeToolName = "execute";
95-
this.maxResponseTokens = options.maxResponseTokens ?? 25_000;
95+
this.maxResponseTokens = options.maxResponseTokens ?? 6_000;
9696

9797
validateNamespace(this.namespace);
9898

src/spec.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ interface OperationObject {
7373
summary?: string;
7474
description?: string;
7575
tags?: string[];
76-
operationId?: string;
7776
parameters?: unknown;
7877
requestBody?: unknown;
7978
responses?: unknown;
@@ -106,7 +105,7 @@ export function extractServerBasePath(spec: OpenAPISpec): string {
106105
* Process an OpenAPI spec into a simplified format for the search tool.
107106
* Resolves all $refs inline and extracts only the fields needed for search.
108107
* Prepends the server base path to all path keys so they're directly usable.
109-
* Preserves info and components.schemas alongside processed paths.
108+
* Only paths are returned — info and components are omitted since refs are resolved inline.
110109
*
111110
* @param maxRefDepth - Maximum $ref resolution depth (default: 50)
112111
*/
@@ -133,7 +132,6 @@ export function processSpec(
133132
summary: op.summary,
134133
description: op.description,
135134
tags: op.tags,
136-
operationId: op.operationId,
137135
parameters: resolveRefs(
138136
op.parameters,
139137
spec as Record<string, unknown>,
@@ -157,20 +155,8 @@ export function processSpec(
157155
}
158156
}
159157

160-
const result: Record<string, unknown> = { paths };
161-
162-
if (spec.info) result.info = spec.info;
163-
// servers is omitted — the base path is already prepended to all path keys
164-
if ((spec as Record<string, unknown>).components) {
165-
result.components = resolveRefs(
166-
(spec as Record<string, unknown>).components,
167-
spec as Record<string, unknown>,
168-
undefined,
169-
maxRefDepth,
170-
);
171-
}
172-
173-
return result;
158+
// Only paths — info and components are omitted since all $refs are resolved inline.
159+
return { paths };
174160
}
175161

176162
/**

src/tools.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ interface OperationInfo {
55
summary?: string;
66
description?: string;
77
tags?: string[];
8-
operationId?: string;
98
parameters?: Array<{ name: string; in: string; required?: boolean; schema?: unknown; description?: string }>;
109
requestBody?: { required?: boolean; content?: Record<string, { schema?: unknown }> };
1110
responses?: Record<string, { description?: string; content?: Record<string, { schema?: unknown }> }>;
@@ -21,8 +20,6 @@ interface PathItem {
2120
2221
declare const spec: {
2322
paths: Record<string, PathItem>;
24-
components?: { schemas?: Record<string, unknown> };
25-
info?: { title?: string; version?: string; description?: string };
2623
};
2724
`;
2825

src/truncate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const CHARS_PER_TOKEN = 4;
2-
const DEFAULT_MAX_TOKENS = 25_000;
2+
const DEFAULT_MAX_TOKENS = 6_000;
33

44
/**
55
* Truncate a response to fit within a token budget.

test/codemode.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ describe("CodeMode", () => {
179179
});
180180
});
181181

182-
it("can access spec metadata", async () => {
182+
it("can access spec paths", async () => {
183183
const result = await codemode.search(`
184-
async () => ({ title: spec.info.title, version: spec.info.version })
184+
async () => Object.keys(spec.paths)
185185
`);
186186
const data = JSON.parse(result.content[0]!.text);
187-
expect(data).toEqual({ title: "Test API", version: "1.0.0" });
187+
expect(data).toContain("/v1/clusters");
188188
});
189189

190190
it("returns error for invalid code", async () => {

test/isolated-vm-executor.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,27 @@ describe("CodeMode with IsolatedVMExecutor", () => {
327327
codemode.dispose();
328328
});
329329

330-
it("search returns spec metadata", async () => {
330+
it("search returns spec paths", async () => {
331331
const codemode = new CodeMode({
332332
spec: {
333333
openapi: "3.0.0",
334334
info: { title: "Test API", version: "2.0.0", description: "My test API" },
335-
paths: {},
335+
paths: {
336+
"/test": { get: { summary: "Test endpoint" } },
337+
},
336338
},
337339
request: () => new Response("not used"),
338340
executor: new IsolatedVMExecutor(),
339341
});
340342

341343
const result = await codemode.search(`
342344
async () => ({
343-
title: spec.info.title,
344-
version: spec.info.version,
345345
pathCount: Object.keys(spec.paths).length,
346+
paths: Object.keys(spec.paths),
346347
})
347348
`);
348349

349350
const data = JSON.parse(result.content[0]!.text);
350-
expect(data).toEqual({ title: "Test API", version: "2.0.0", pathCount: 0 });
351+
expect(data).toEqual({ pathCount: 1, paths: ["/test"] });
351352
});
352353
});

test/spec.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,19 @@ describe("processSpec", () => {
211211
expect(paths["/pet"]).toBeUndefined();
212212
});
213213

214-
it("preserves info, omits servers", () => {
214+
it("omits info, servers, and components", () => {
215215
const spec = {
216216
openapi: "3.0.0",
217217
info: { title: "My API", version: "2.0.0" },
218218
servers: [{ url: "/api/v3" }],
219219
paths: {},
220+
components: { schemas: { Foo: { type: "object" } } },
220221
};
221222

222223
const result = processSpec(spec);
223-
expect((result as any).info.title).toBe("My API");
224+
expect((result as any).info).toBeUndefined();
224225
expect((result as any).servers).toBeUndefined();
226+
expect((result as any).components).toBeUndefined();
225227
});
226228

227229
it("skips non-HTTP method keys", () => {

0 commit comments

Comments
 (0)