@utcp/http: an OpenAPI manual with `auth` but no `auth_tools` calls every generated tool unauthenticated
Summary
An http call template pointed at an OpenAPI spec, with credentials supplied in auth and no auth_tools, registers all of its tools successfully and then every tool call is sent without any credential. The API answers 401, which reads like a revoked key rather than a config problem. Nothing in the logs mentions auth.
Observed on @utcp/http 1.1.11 and still present in 1.1.13 (dist/index.cjs: the converter receives authTools: httpCallTemplate.auth_tools and _extractAuth returns undefined when this.auth_tools === null).
Reproduction
Manual:
{
"name": "keep_rest",
"call_template_type": "http",
"http_method": "GET",
"url": "https://keep.md/openapi.json",
"content_type": "application/json",
"auth": {
"auth_type": "api_key",
"api_key": "Bearer ${KEEP_API_KEY}",
"var_name": "Authorization",
"location": "header"
}
}
Registration logs Successfully registered manual 'keep_rest' with 83 tools. Then any generated tool fails with Request failed with status code 401. The same key over curl returns 200.
Without a real credential: serve a two-line OpenAPI spec with bearerAuth from 127.0.0.1, log the Authorization header of every request, point an http manual at it with a fake key, and call a generated tool:
PATH=/openapi.json AUTH='Bearer FAKEKEY-abc123' <- the spec fetch is authenticated
PATH=/api/me AUTH=None <- the generated tool call is not
Adding "auth_tools": { ...the same block... } to the manual changes the second line to AUTH='Bearer FAKEKEY-abc123' and the call succeeds.
Root cause
auth and auth_tools feed two different paths:
authauthenticates the request that fetches the spec.auth_toolsis handed toOpenApiConverterand becomes the auth of each generated tool.authis never consulted there.
HttpCallTemplateSchema turns an omitted auth_tools into null, and _extractAuth() treats null as "tools get no auth". So omitting auth_tools is indistinguishable from explicitly disabling tool auth, and the only credential the author supplied is silently unused for calls. The manual still registers because the spec fetch, the one request auth covers, succeeds.
Suggested fix
Inherit auth when auth_tools was not specified, keeping an explicit null as the opt-out. The schema needs to stop collapsing undefined into null:
auth_tools: AuthSchema.nullable().optional().transform((val) => {
- if (val === null || val === void 0) return null;
+ if (val === void 0) return void 0; // not specified: inherit from `auth`
+ if (val === null) return null; // explicit opt-out: tools stay unauthenticated
const converter = new OpenApiConverter(responseData, {
specUrl: httpCallTemplate.url,
callTemplateName: httpCallTemplate.name,
- authTools: httpCallTemplate.auth_tools,
+ authTools: httpCallTemplate.auth_tools === undefined
+ ? httpCallTemplate.auth
+ : httpCallTemplate.auth_tools,
headers: httpCallTemplate.headers
});
_extractAuth() already does the right thing from there: _isAuthCompatible() compares the inherited block against the spec's security scheme and uses it when auth_type, var_name and location line up, falling back to the spec-derived placeholder otherwise.
If inheritance is considered a breaking change, a minimum alternative is a warning at registration when a manual has auth, no auth_tools, and a spec that declares security, since every generated tool is about to be called unauthenticated.
Happy to open a PR for either variant.