@dudko.dev/agent 0.0.47 → 0.0.48

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.
package/README.md CHANGED
@@ -283,7 +283,12 @@ Nothing is printed or opened on your behalf; `onAuthorizationUrl` and the loopba
283
283
  - **`iss` (RFC 9207).** `finishMcpOAuth` checks the `iss` query parameter of the redirect against the authorization server the flow was started with, after `state` and before the code is exchanged. A different issuer is refused (a mix-up attack: a code meant for one server sent to another), and so is a missing `iss` when the server's metadata says `authorization_response_iss_parameter_supported: true`. The comparison is exact, character for character. Read `iss` off the callback URL together with `code` and `state`; `checkAuthorizationResponseIssuer` is the rule on its own.
284
284
  - **`clientMetadataUrl` (CIMD).** Host a client ID metadata document and pass its URL: an authorization server that advertises `client_id_metadata_document_supported` takes the URL as the `client_id`, and no registration request is made. Other servers get dynamic registration as before, and a registration already in the store wins over both. The URL must be https with a path (anything else throws when the provider is built), and the document must list the same `redirect_uris` as `redirectUrl`.
285
285
  - **Registration** describes a public PKCE client. `application_type` follows the redirect URL: `'native'` for a loopback address (the usual CLI callback), `'web'` for an https one. Change any field through `clientMetadata`.
286
- - **Discovery is stored** next to the tokens (the authorization server and its metadata), so later calls skip it and the issuer check has something to compare with. `auth.reset()` forgets it with everything else - use it when a server moved to another authorization server.
286
+ - **Discovery is stored** next to the tokens (the authorization server and its metadata), so later calls skip it and the issuer check has something to compare with. `auth.reset()` forgets it with everything else - use it when a server moved to another authorization server. A code is exchanged only when that record is still there: a flow whose discovery state is gone (started by a version that did not keep it, or the store was cleared in between) is refused by `finishMcpOAuth` with `Authorization cannot be completed: ... start the authorization again`. Tokens already in the store are not touched; begin again and the new redirect completes.
287
+ - **Credentials belong to the authorization server that issued them.** The registration and the tokens are stored with an `issuer` stamp and are never presented to another authorization server: stamped for a different one, they are read as absent and a new authorization is asked for. A store written before the stamp existed keeps working - its values are used as they are and stamped on first use (the SDK says so once on stderr). A custom `IOAuthStore` only has to return what it was given.
288
+ - **A token endpoint must be https** (or loopback). The SDK refuses to send a code, a refresh token or a grant to a plain-http token endpoint; the error names it, and no new authorization is started in its place.
289
+ - **The metadata must be the server's own.** Authorization server metadata whose `issuer` is not the URL it was fetched for is refused by the SDK (RFC 8414 section 3.3): the connect fails with the two issuers named, and nothing is registered. The 1.x SDK accepted such a document.
290
+ - **`403 insufficient_scope`.** When the server answers a request with `403` and `WWW-Authenticate: Bearer error="insufficient_scope"`, the tool call fails with `Insufficient scope: required "<scope>"` (the SDK's `InsufficientScopeError`, with `requiredScope`). No authorization is started from inside a run: a new authorization URL in the middle of a tool call would replace the state and PKCE verifier of the one you may have open. Provide the scope up front (`scope`), or authorize again with it. A provider **without** a human step (no `redirectUrl`: the enterprise one below) asks once for the wider scope and retries the request once.
291
+ - **A refresh whose result cannot be saved is an error**, not a new authorization: when the store throws while saving refreshed tokens, the connect (or the tool call) fails with the store's error.
287
292
 
288
293
  ### MCP with enterprise-managed authorization (ID-JAG)
289
294
 
@@ -570,7 +575,7 @@ Server "docs":
570
575
 
571
576
  Images, audio and resources are handled as before (spilled to the run's sandbox directory), and `compaction.maxToolOutputChars` caps the result whatever its shape. With an `outputSanitizer`, the structured value goes through it in a call of its own (it receives the object; the duplicate text part is dropped first).
572
577
 
573
- **A result that breaks its `outputSchema`.** The MCP SDK's client validates `structuredContent` against the schema from `tools/list` and throws when it does not match, or when a tool that declares a schema returns none. The agent does **not** turn that into a failed call: the call ran on the server, and a tool the model is told failed is a tool it calls again — a second write. The result is passed on with a note instead (`{ note, structuredContent?, content? }`: *"The tool "x" ran, but its result does not follow the output schema the server declared… do not call the tool again only because of this note"*), and a `warn` line is logged. A request that really failed (transport, protocol, abort) is a failed tool call as before — never a crashed run.
578
+ **A result that breaks its `outputSchema`.** `structuredContent` is validated against the schema from `tools/list` (with the MCP SDK's own validator: JSON Schema 2020-12 unless the schema declares another `$schema`); it may not match, and a tool that declares a schema may return none. The agent does **not** turn that into a failed call: the call ran on the server, and a tool the model is told failed is a tool it calls again — a second write. The result is passed on with a note instead (`{ note, structuredContent?, content? }`: *"The tool "x" ran, but its result does not follow the output schema the server declared… do not call the tool again only because of this note"*), and a `warn` line is logged. A request that really failed (transport, protocol, abort) is a failed tool call as before — never a crashed run. A tool whose `outputSchema` cannot be compiled at all (an unsupported dialect, an unresolvable `$ref`) is refused before anything is sent: `Tool 'x' has an invalid outputSchema: …`; the server's other tools are unaffected.
574
579
 
575
580
  ## Prompt caching
576
581
 
@@ -1445,11 +1450,21 @@ CI runs this as a **gate on publishing** (`live-model.yml`, wired into
1445
1450
  mechanics only — the loop finished, the model drove the MCP tool, the arguments
1446
1451
  parsed — never the wording, which would make it a coin flip.
1447
1452
 
1453
+ ## Upgrading to the 2.x MCP SDK
1454
+
1455
+ This package moved from `@modelcontextprotocol/sdk` 1.x to `@modelcontextprotocol/client` 2.x in one step. Nothing changes on the wire, and nothing changes for you if you use `createNodeOAuthProvider` / `createEnterpriseOAuthProvider` and no SDK types of your own. If you do:
1456
+
1457
+ - **Types come from the new package.** `mcpServers[name].authProvider` is the `OAuthClientProvider` of `@modelcontextprotocol/client`, and `fetch` its `FetchLike`. Change the import (`@modelcontextprotocol/sdk/client/auth.js`, `.../shared/transport.js` → `@modelcontextprotocol/client`) and install that package instead of the old one; the member names are the same. A provider that is only structurally an `OAuthClientProvider` (no import) keeps compiling. A plain `fetch`-shaped function is still a `FetchLike`.
1458
+ - **Your own `OAuthClientProvider`.** `tokens`, `saveTokens`, `clientInformation` and `saveClientInformation` get an optional last argument `ctx: { issuer }`; ignore it if you keep one credential set. The objects handed to the two `save*` methods carry an `issuer` field: store and return them **verbatim**, or the per-server binding is off and the SDK warns on every read. `invalidateCredentials` is called with `'client'` and then `'tokens'` on an `invalid_client` (it was `'all'`). When your provider implements `saveDiscoveryState`, `discoveryState()` must still return it when the code comes back, or the exchange is refused. A `saveTokens` that throws after a refresh now fails the request instead of starting a new authorization.
1459
+ - **Errors.** Classes are the new package's: `UnauthorizedError`, `ProtocolError` (was `McpError`), `SdkError` / `SdkHttpError` (was `StreamableHTTPError`; the HTTP status is `.status`). An `instanceof` against a class imported from the 1.x package no longer matches. Messages lost the `MCP error <code>: ` prefix.
1460
+ - **Zod.** The 2.x SDK needs `zod ^4.2`; this package already depends on zod 4.
1461
+
1448
1462
  ## Behavior notes & limitations
1449
1463
 
1450
- - **Module formats.** ESM is the primary target; the CJS build (`dist/index.cjs`) is best-effort and depends on upstream deps (`ai`, `@ai-sdk/*`, `@modelcontextprotocol/sdk`) keeping their CJS fallbacks. If they go pure-ESM, CJS will break — the dual-format guard in [`tests/dist-loadable.test.ts`](./tests/dist-loadable.test.ts) catches the regression on the next build.
1464
+ - **Module formats.** ESM is the primary target; the CJS build (`dist/index.cjs`) is best-effort and depends on upstream deps (`ai`, `@ai-sdk/*`, `@modelcontextprotocol/client`) keeping their CJS fallbacks. If they go pure-ESM, CJS will break — the dual-format guard in [`tests/dist-loadable.test.ts`](./tests/dist-loadable.test.ts) catches the regression on the next build.
1451
1465
  - **MCP connect failures.** By default `createAgent` is fail-tolerant: a server that can't connect is logged at `error` level and skipped. The agent still starts with whatever tools did mount. Set `failOnNoTools: true` to throw when **every** configured server failed. Servers connect concurrently, so one slow server no longer delays the ones declared after it; tools still mount in declaration order.
1452
- - **MCP tool errors.** A tool result carrying `isError: true` is surfaced as a **thrown** tool error, so the step records `ok: false` and `replanAfter: 'failure'` sees it. The error text the server returned becomes the error message (after `outputSanitizer`, if you set one). A result that only breaks the tool's declared `outputSchema` is **not** an error: it is passed on with a note (see [structured results](#mcp-server-instructions-and-structured-results)).
1466
+ - **MCP SDK.** The MCP client is the official 2.x SDK, `@modelcontextprotocol/client` (a dependency; `@modelcontextprotocol/sdk` 1.x is no longer used). It negotiates the 2025 protocol revisions with the unchanged `initialize` handshake, so servers see the same requests as before; a server that speaks **only** the 2026-07-28 revision fails to connect with `Unsupported protocol version: 2025-11-25` in `results[].error`. See [upgrading](#upgrading-to-the-2x-mcp-sdk) if you pass your own `authProvider` or `fetch`.
1467
+ - **MCP tool errors.** A tool result carrying `isError: true` is surfaced as a **thrown** tool error, so the step records `ok: false` and `replanAfter: 'failure'` sees it. The error text the server returned becomes the error message (after `outputSanitizer`, if you set one). A JSON-RPC error answered to `tools/call` (what a 2.x server sends for an unknown tool, `-32602`) is a failed call too; its message is the server's, without the `MCP error <code>: ` prefix the 1.x SDK added - read `error.code` for the number. A result that only breaks the tool's declared `outputSchema` is **not** an error: it is passed on with a note (see [structured results](#mcp-server-instructions-and-structured-results)).
1453
1468
  - **MCP tool names.** Server and tool names are sanitized into `[a-zA-Z0-9_-]` (what OpenAI, Anthropic and Gemini accept) before being joined as `server__tool`, and a collision produced by that mapping gets a `_2` suffix rather than being dropped. `callTool` always uses the server's original name. If you pin `availableTools` / `excludedTools`, use the sanitized names.
1454
1469
  - **Tool-output cap.** Since compaction landed, the model sees at most `compaction.maxToolOutputChars` (default 20 000) of each tool result; set it to `0` for the old unlimited behaviour. The trace and events keep the full output.
1455
1470
  - **Default tool strategy.** `toolSelectionStrategy` defaults to `'auto'`, which is `'all'` (the previous default) up to 40 tools; set `'all'` explicitly to keep every tool in every step regardless of catalogue size.