@http-forge/core 0.4.8 → 0.5.1

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.
@@ -24,6 +24,14 @@ export declare class CollectionService implements ICollectionService {
24
24
  private loader;
25
25
  /** Debounce timer for coalescing rapid file-watcher change events */
26
26
  private debounceTimer;
27
+ /**
28
+ * Set to true before any self-initiated write so that the resulting
29
+ * file-watcher event skips the expensive full `loadAll()` reload —
30
+ * the in-memory state was already updated by the write method itself.
31
+ * The watcher callback still fires `onCollectionsChanged` so tree views
32
+ * and panels are notified of the change.
33
+ */
34
+ private selfWritePending;
27
35
  /**
28
36
  * In-memory Local Values for collection variables (not persisted)
29
37
  */
@@ -76,6 +76,29 @@ export declare class FolderCollectionStore implements ICollectionStore {
76
76
  private loadFolderFromDir;
77
77
  /**
78
78
  * Load a request from directory
79
+ *
80
+ * TODO(perf/memory): This method eagerly loads ALL heavy fields for every request at
81
+ * startup (called by loadAll()). With thousands of requests, body, scripts, schemas,
82
+ * and docs can consume hundreds of MB of heap.
83
+ *
84
+ * The fix is to load only cheap metadata here (url, method, headers, auth, settings,
85
+ * name, description, deprecated) and introduce an on-demand
86
+ * `loadRequestDetail(requestPath)` that reads the heavy fields only when a request is
87
+ * actually opened or executed.
88
+ *
89
+ * Heavy fields to defer:
90
+ * - body (readBodyFromDir) — up to 100 KB+
91
+ * - scripts (loadScriptsFromDir) — pre/post JS source, up to 20 KB
92
+ * - responseSchema (readSchemaFile) — OpenAPI JSON, up to 1 MB+
93
+ * - bodySchema (readSchemaFile) — OpenAPI JSON, up to 1 MB+
94
+ * - doc (fs.readFileSync doc.md) — markdown, up to 50 KB
95
+ *
96
+ * Callers that need the heavy fields:
97
+ * - CollectionRequestExecutor (body, scripts)
98
+ * - RequestExecutionHandler (body, scripts)
99
+ * - SchemaHandler (responseSchema, bodySchema)
100
+ * - PanelDataProvider.getInitialData() (sends full request to webview)
101
+ * - MCP direct-execution: runRequest / runCollection (body, scripts)
79
102
  */
80
103
  private loadRequestFromDir;
81
104
  /**
@@ -85,6 +85,18 @@ export interface McpCorsConfig {
85
85
  /** Origins allowed to access the MCP server (defaults to localhost variants) */
86
86
  allowedOrigins: string[];
87
87
  }
88
+ /**
89
+ * How the MCP server shapes its `tools/list` response.
90
+ *
91
+ * - `flat`: one tool per request/folder/collection/suite (most discoverable;
92
+ * best for AI agents, but the list grows with the number of requests).
93
+ * - `drilldown`: a small fixed set of generic tools (`list_collections`,
94
+ * `list_requests`, `run_request`, `run_folder`, `run_collection`, `run_suite`)
95
+ * whose arguments select the target. The list stays tiny regardless of scale.
96
+ * - `auto`: use `flat` until the number of request tools would exceed
97
+ * `drilldownThreshold`, then switch to `drilldown`.
98
+ */
99
+ export type McpToolMode = 'flat' | 'drilldown' | 'auto';
88
100
  /**
89
101
  * MCP Server project-level configuration (stored in http-forge.config.json)
90
102
  *
@@ -111,6 +123,16 @@ export interface McpConfig {
111
123
  * collection or suite call. Prevents accidental runaway executions.
112
124
  */
113
125
  maxRequestsPerCall: number;
126
+ /**
127
+ * Tool-list shape. Defaults to `flat`. Use `drilldown` or `auto` for very
128
+ * large workspaces to keep `tools/list` small and AI-friendly.
129
+ */
130
+ toolMode: McpToolMode;
131
+ /**
132
+ * When `toolMode` is `auto`, switch to drilldown once the number of request
133
+ * tools would exceed this count. Ignored for `flat` and `drilldown`.
134
+ */
135
+ drilldownThreshold: number;
114
136
  /** CORS configuration */
115
137
  cors: McpCorsConfig;
116
138
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Config Services
3
3
  */
4
- export type { EnvironmentsConfig, HttpForgeConfig, IConfigService, McpConfig, McpCorsConfig, ProxyConfig, RequestConfig, RestClientExportConfig, RunnerConfig, ScriptsConfig, StorageConfig } from './config.interface';
4
+ export type { EnvironmentsConfig, HttpForgeConfig, IConfigService, McpConfig, McpCorsConfig, McpToolMode, ProxyConfig, RequestConfig, RestClientExportConfig, RunnerConfig, ScriptsConfig, StorageConfig } from './config.interface';
5
5
  export { CONFIG_FILES, DEFAULT_CONFIG, ROOT_DIRECTORIES } from './default-config';
6
6
  export { ConfigService } from './config-service';
@@ -51,7 +51,12 @@ export interface ResponseContext {
51
51
  headers: Record<string, string>;
52
52
  /** Raw response body string (Postman-compatible). Parse on demand via response.json(). */
53
53
  body: any;
54
- cookies?: Record<string, string>;
54
+ /**
55
+ * Response cookies parsed from Set-Cookie headers, including metadata such as
56
+ * domain, path, expires, maxAge, httpOnly, secure and sameSite. Exposed to
57
+ * scripts as the Postman-compatible `pm.response.cookies` CookieList.
58
+ */
59
+ cookies?: Cookie[];
55
60
  responseTime?: number;
56
61
  responseSize?: number;
57
62
  }
@@ -4,6 +4,7 @@
4
4
  * Single Responsibility: Create objects used in script execution contexts
5
5
  * Open/Closed: New factory methods can be added without modifying existing ones
6
6
  */
7
+ import { Cookie } from '../cookie/interfaces';
7
8
  import { ResponseContext } from './interfaces';
8
9
  /**
9
10
  * Minimal, dependency-free JSON Schema validator.
@@ -18,22 +19,24 @@ export declare function validateJsonSchema(data: any, schema: any, path?: string
18
19
  * Response object interface for script context
19
20
  */
20
21
  export interface ScriptResponse {
21
- status: number;
22
+ /** Reason phrase string (Postman parity, e.g. "OK"). Use `code` for the numeric status. */
23
+ status: string;
22
24
  code: number;
23
25
  statusText: string;
24
26
  headers: Record<string, string>;
25
27
  /** Raw response body string (Postman-compatible). Use json() to parse, text() for the string. */
26
28
  body: any;
27
- cookies: Record<string, string>;
29
+ /**
30
+ * Postman-compatible CookieList. Use `cookies.get(name)` for the value string,
31
+ * `cookies.one(name)` for the full cookie object (domain, path, expires, maxAge,
32
+ * httpOnly, secure, sameSite), `cookies.has(name)`, `cookies.toObject()`, or iterate.
33
+ */
34
+ cookies: CookieList;
28
35
  responseTime?: number;
29
36
  responseSize?: number;
30
- getHeader(name: string): string | undefined;
31
- getCookie(name: string): string | undefined;
32
37
  reason(): string;
33
38
  json(): any;
34
39
  text(): string;
35
- cookie(name: string): string | undefined;
36
- hasCookie(name: string): boolean;
37
40
  to: ResponseAssertions;
38
41
  }
39
42
  /**
@@ -56,6 +59,53 @@ export interface ResponseAssertions {
56
59
  readonly serverError: any;
57
60
  };
58
61
  }
62
+ /**
63
+ * Postman-compatible Cookie object (a single entry of a CookieList).
64
+ *
65
+ * Coerces to its value string via valueOf()/toString() so `cookie == 'abc'`
66
+ * and template literals work, while still exposing the full metadata.
67
+ */
68
+ export interface PostmanCookie {
69
+ name: string;
70
+ value: string;
71
+ domain?: string;
72
+ path?: string;
73
+ expires?: string;
74
+ maxAge?: number;
75
+ httpOnly: boolean;
76
+ secure: boolean;
77
+ /** True when the cookie has neither Expires nor Max-Age (cleared at session end). */
78
+ session: boolean;
79
+ hostOnly: boolean;
80
+ sameSite?: 'Strict' | 'Lax' | 'None';
81
+ valueOf(): string;
82
+ toString(): string;
83
+ }
84
+ /**
85
+ * Postman-compatible CookieList (a PropertyList of cookies).
86
+ *
87
+ * Mirrors the Postman SDK API:
88
+ * - `cookies.get(name)` → the cookie VALUE string (or undefined)
89
+ * - `cookies.one(name)` → the full cookie OBJECT (or undefined)
90
+ * - `cookies.has(name)` → boolean
91
+ * - `cookies.toObject()` → plain `{ name: value }` map
92
+ * It is also a real array, so `forEach`, `map`, `filter`, `find`, numeric
93
+ * indexing and `for...of` iteration all work over the cookie objects.
94
+ */
95
+ export interface CookieList extends Array<PostmanCookie> {
96
+ get(name: string): string | undefined;
97
+ one(name: string): PostmanCookie | undefined;
98
+ has(name: string): boolean;
99
+ toObject(): Record<string, string>;
100
+ all(): PostmanCookie[];
101
+ each(cb: (cookie: PostmanCookie) => void): void;
102
+ count(): number;
103
+ idx(index: number): PostmanCookie | undefined;
104
+ }
105
+ /**
106
+ * Create a Postman-compatible CookieList from parsed cookies.
107
+ */
108
+ export declare function createCookieList(cookies: Cookie[]): CookieList;
59
109
  /**
60
110
  * Create response object with helper methods for script context
61
111
  * Provides Postman-compatible response API
@@ -5,6 +5,7 @@
5
5
  * These are stateless helper functions with no side effects
6
6
  */
7
7
  import { TestAssertion } from '../../types/types';
8
+ import { Cookie } from '../cookie/interfaces';
8
9
  /**
9
10
  * Console message structure for script output
10
11
  */
@@ -47,3 +48,16 @@ export declare function createTestFunction(assertions: TestAssertion[]): any;
47
48
  * Converts multi-value headers (string[]) to comma-separated strings
48
49
  */
49
50
  export declare function normalizeHeaders(headers: Record<string, string | string[]>): Record<string, string>;
51
+ /**
52
+ * Build rich response cookie metadata for the legacy Postman sandbox.
53
+ *
54
+ * Prefers parsing the raw `Set-Cookie` response headers via CookieUtils, which
55
+ * captures full metadata (domain, path, expires, maxAge, httpOnly, secure,
56
+ * sameSite). Falls back to the HTTP client's already-parsed cookie array when
57
+ * the raw headers are unavailable (e.g. some fetch-based transports).
58
+ *
59
+ * @param headers - Raw response headers (Set-Cookie may be a string[])
60
+ * @param parsedCookies - Cookie objects already parsed by the HTTP client
61
+ * @param requestUrl - URL used to derive the default cookie domain
62
+ */
63
+ export declare function parseResponseCookieDetails(headers: Record<string, string | string[]> | undefined, parsedCookies: any[] | undefined, requestUrl?: string): Cookie[];
@@ -6,19 +6,37 @@
6
6
  * tool name like `request__<collectionId>__<requestId>` can exceed 240 chars
7
7
  * and be rejected by the model provider.
8
8
  *
9
- * To stay short we put a deterministic short hash token (not the raw ID) in the
10
- * tool name, and resolve a call back to the real entity by hashing the current
11
- * collections / requests / folders / suites and matching. A raw-value fallback
12
- * keeps any previously-listed long names working after the upgrade.
9
+ * To balance discoverability and the length limit we embed the raw ID verbatim
10
+ * when it is a safe, short segment (so names stay human-readable), and otherwise
11
+ * substitute a deterministic short hash token. A whole-name length guard re-hashes
12
+ * every segment when the assembled name would still be too long. A call resolves
13
+ * back to the real entity by matching the segment against the current
14
+ * collections / requests / folders / suites (raw equality OR hash), so both raw
15
+ * and hashed names — including previously-listed long names — keep working.
13
16
  *
14
17
  * IDs are NOT changed — they remain the stable external references used by
15
18
  * suites, result filenames, and history. Only the tool *name* is shortened.
16
19
  *
17
20
  * The model selects a tool by its *description* (which still contains the
18
- * human-readable names), so an opaque short name does not affect tool choice.
21
+ * human-readable names), so the exact tool name does not affect tool choice.
19
22
  */
20
- /** Deterministic short token for an ID or folder path (12 hex chars). */
21
- export declare function mcpToolToken(value: string): string;
23
+ /**
24
+ * Deterministic short token for an ID or folder path (12 hex chars).
25
+ * @param value The value to be hashed.
26
+ * @param maxLen The maximum length of the raw segment before appending the hash.
27
+ * @returns A string combining the truncated value and its hash.
28
+ */
29
+ export declare function mcpToolToken(value: string, maxLen?: number): string;
30
+ /**
31
+ * Return `value` verbatim when it is a safe, short raw segment (discoverable),
32
+ * otherwise its deterministic hash token. Either way the result never contains
33
+ * `__`, so tool-name parsing by `split('__')` stays unambiguous.
34
+ *
35
+ * @param value The value to be used as a tool segment.
36
+ * @param maxLen The maximum length of the raw segment before falling back to a hash token.
37
+ * @returns A string representing the tool segment, either raw or hashed.
38
+ */
39
+ export declare function mcpToolSegment(value: string, maxLen?: number): string;
22
40
  export type McpToolKind = 'request' | 'collection' | 'folder' | 'suite';
23
41
  export declare function buildRequestToolName(prefix: string, collectionId: string, requestId: string): string;
24
42
  export declare function buildCollectionToolName(prefix: string, collectionId: string): string;
@@ -168,3 +168,25 @@ export declare const SUITE_INPUT_SCHEMA: {
168
168
  };
169
169
  };
170
170
  };
171
+ /** Stable names of the generic drill-down tools (prefix is added separately). */
172
+ export declare const GENERIC_TOOL_NAMES: {
173
+ readonly listCollections: "list_collections";
174
+ readonly listRequests: "list_requests";
175
+ readonly runRequest: "run_request";
176
+ readonly runFolder: "run_folder";
177
+ readonly runCollection: "run_collection";
178
+ readonly runSuite: "run_suite";
179
+ };
180
+ export type GenericToolName = (typeof GENERIC_TOOL_NAMES)[keyof typeof GENERIC_TOOL_NAMES];
181
+ interface GenericToolDef {
182
+ name: string;
183
+ description: string;
184
+ inputSchema: Record<string, unknown>;
185
+ }
186
+ /**
187
+ * Build the generic drill-down tool definitions. `collectionLabels` and
188
+ * `suiteLabels` are the human-readable names injected as enums so the model can
189
+ * only choose targets that exist.
190
+ */
191
+ export declare function buildGenericTools(prefix: string, collectionLabels: readonly string[], suiteLabels: readonly string[]): GenericToolDef[];
192
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@http-forge/core",
3
- "version": "0.4.8",
3
+ "version": "0.5.1",
4
4
  "description": "Headless HTTP testing engine with Postman collection support, dynamic variables, and script-based automation.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",