@mastra/mcp 1.8.0-alpha.2 → 1.8.1-alpha.0

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/dist/_types/hono/dist/types/client/client.d.ts +4 -0
  3. package/dist/_types/hono/dist/types/client/fetch-result-please.d.ts +35 -0
  4. package/dist/_types/hono/dist/types/client/index.d.ts +7 -0
  5. package/dist/_types/hono/dist/types/client/types.d.ts +229 -0
  6. package/dist/_types/hono/dist/types/client/utils.d.ts +18 -0
  7. package/dist/_types/hono/dist/types/context.d.ts +455 -0
  8. package/dist/_types/hono/dist/types/helper/streaming/index.d.ts +8 -0
  9. package/dist/_types/hono/dist/types/helper/streaming/sse.d.ts +13 -0
  10. package/dist/_types/hono/dist/types/helper/streaming/stream.d.ts +3 -0
  11. package/dist/_types/hono/dist/types/helper/streaming/text.d.ts +3 -0
  12. package/dist/_types/hono/dist/types/hono-base.d.ts +220 -0
  13. package/dist/_types/hono/dist/types/hono.d.ts +19 -0
  14. package/dist/_types/hono/dist/types/index.d.ts +36 -0
  15. package/dist/_types/hono/dist/types/request/constants.d.ts +1 -0
  16. package/dist/_types/hono/dist/types/request.d.ts +311 -0
  17. package/dist/_types/hono/dist/types/router.d.ts +97 -0
  18. package/dist/_types/hono/dist/types/types.d.ts +573 -0
  19. package/dist/_types/hono/dist/types/utils/body.d.ts +79 -0
  20. package/dist/_types/hono/dist/types/utils/headers.d.ts +8 -0
  21. package/dist/_types/hono/dist/types/utils/http-status.d.ts +32 -0
  22. package/dist/_types/hono/dist/types/utils/mime.d.ts +70 -0
  23. package/dist/_types/hono/dist/types/utils/stream.d.ts +31 -0
  24. package/dist/_types/hono/dist/types/utils/types.d.ts +74 -0
  25. package/dist/_types/hono-mcp-server-sse-transport/build/index.d.ts +1 -0
  26. package/dist/_types/hono-mcp-server-sse-transport/build/sse.d.ts +25 -0
  27. package/dist/docs/SKILL.md +1 -1
  28. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  29. package/dist/docs/references/docs-mcp-mcp-apps.md +3 -3
  30. package/dist/index.cjs +2 -2
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.js +2 -2
  33. package/dist/index.js.map +1 -1
  34. package/dist/server/server.d.ts +2 -2
  35. package/package.json +8 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 1.8.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Removed zod as a required peer dependency. Internal schemas now use plain JSON Schema objects instead of zod runtime. ([#16726](https://github.com/mastra-ai/mastra/pull/16726))
8
+
9
+ - Updated dependencies [[`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`4084113`](https://github.com/mastra-ai/mastra/commit/408411370fc48a822e8b616b3b63f9409774e0e9)]:
10
+ - @mastra/core@1.37.0-alpha.8
11
+
12
+ ## 1.8.0
13
+
14
+ ### Minor Changes
15
+
16
+ - Added MCP tool annotations to the `requireToolApproval` context and exposed them on tools returned from `listTools()` / `listToolsets()`. ([#16784](https://github.com/mastra-ai/mastra/pull/16784))
17
+
18
+ The `requireToolApproval` callback now receives the server-advertised `annotations` (`title`, `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) alongside `toolName` and `args`. This lets you write declarative approval policies instead of hardcoding tool name lists. Annotations are also propagated onto Mastra tools as `tool.mcp.annotations` so apps can render them in UI.
19
+
20
+ **Security caveat (per the MCP spec):** annotations are _hints_, not guarantees. Clients MUST treat them as untrusted unless they come from a trusted server. Do not use annotations alone as a security boundary for servers you do not control — set `requireToolApproval: true` for those. When the server omits annotations entirely, this field is `undefined`, so policies can distinguish "no annotations" from "annotated as safe".
21
+
22
+ ```ts
23
+ import { MCPClient } from '@mastra/mcp';
24
+
25
+ // Before — hardcoded tool name lists, server-specific
26
+ const mcp = new MCPClient({
27
+ servers: {
28
+ github: {
29
+ url: new URL('https://example.com/mcp'),
30
+ requireToolApproval: ({ toolName }) => toolName === 'delete_repo',
31
+ },
32
+ },
33
+ });
34
+
35
+ // After — annotation-driven, works across any trusted MCP server
36
+ const mcp = new MCPClient({
37
+ servers: {
38
+ github: {
39
+ url: new URL('https://example.com/mcp'),
40
+ requireToolApproval: ({ annotations }) => {
41
+ if (!annotations) return true;
42
+ if (annotations.readOnlyHint) return false;
43
+ if (annotations.destructiveHint) return true;
44
+ return false;
45
+ },
46
+ },
47
+ },
48
+ });
49
+
50
+ // Annotations are also visible on tools returned by listTools()
51
+ const tools = await mcp.listTools();
52
+ for (const tool of Object.values(tools)) {
53
+ console.log(tool.mcp?.annotations);
54
+ }
55
+ ```
56
+
57
+ Closes #16766.
58
+
59
+ ### Patch Changes
60
+
61
+ - Fixed an issue where OAuth token requests dropped `client_id` and `client_secret` for confidential clients. The provider previously shipped an empty `addClientAuthentication` method that satisfied the MCP SDK's existence check and short-circuited its default credential attachment, causing `invalid_request` errors on token exchange and refresh against confidential-client OAuth servers. The empty stub has been removed so the SDK's built-in client authentication runs again. See [#16854](https://github.com/mastra-ai/mastra/issues/16854). ([#16862](https://github.com/mastra-ai/mastra/pull/16862))
62
+
63
+ - Close previous SSE transport before accepting a new connection in `MCPServer.connectSSE()`. Previously, sequential SSE connections to the same server would fail with "Already connected to a transport" because the underlying protocol was never closed when the previous client disconnected. ([#16695](https://github.com/mastra-ai/mastra/pull/16695))
64
+
65
+ - Updated dependencies [[`452036a`](https://github.com/mastra-ai/mastra/commit/452036a0d965b4f4c1efd93606e4f03b50b807a5), [`c272d50`](https://github.com/mastra-ai/mastra/commit/c272d50610a54496b6b6d92ccd4d37b333a2613a), [`27fd1b7`](https://github.com/mastra-ai/mastra/commit/27fd1b79ac62eb7694f92587eb7d1be05b59be01), [`5ba7253`](https://github.com/mastra-ai/mastra/commit/5ba7253745c85e8df8012a76d954c640ffa336f7), [`5556cc1`](https://github.com/mastra-ai/mastra/commit/5556cc1befec71518d84f826b3bfe3a079a9daf7), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`5499303`](https://github.com/mastra-ai/mastra/commit/54993032c1ebc09642625b78d2014e0cf84a3cae), [`a702009`](https://github.com/mastra-ai/mastra/commit/a702009d3cfaa745120f501e21c783ed4d6a3072), [`9aee493`](https://github.com/mastra-ai/mastra/commit/9aee493ed6089b5133472623dcce49934bf2d509), [`d8692af`](https://github.com/mastra-ai/mastra/commit/d8692afa253028e39cdce2aafa0ac414071a762e), [`1a9cc60`](https://github.com/mastra-ai/mastra/commit/1a9cc6069f9910fc3d59e4953ac8cd95d89ad6f5), [`8cdb86c`](https://github.com/mastra-ai/mastra/commit/8cdb86ceed1137bc2768e147dce85a0692b9fb26), [`8534d79`](https://github.com/mastra-ai/mastra/commit/8534d791fa1cb70fe1c19e2604c4b63cc10dd051), [`eda90c5`](https://github.com/mastra-ai/mastra/commit/eda90c5bfd7de11805ecc9f4552716c895fbaf78), [`a935b0a`](https://github.com/mastra-ai/mastra/commit/a935b0a0977ae3f196b33ec7621f528069c82db0), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`c78f8cd`](https://github.com/mastra-ai/mastra/commit/c78f8cd6222a86e6c60ae5210b6929ad5221b6fb), [`e146aad`](https://github.com/mastra-ai/mastra/commit/e146aadbba66c410ba0e74bac4c50135495cb8dd), [`ac79462`](https://github.com/mastra-ai/mastra/commit/ac79462b98f1062394c45093aa515b0766f27ee2), [`1a0ec78`](https://github.com/mastra-ai/mastra/commit/1a0ec789a26cae443744e9abbd62ed6ee676af39), [`e47bca7`](https://github.com/mastra-ai/mastra/commit/e47bca7b72866d3abd173b9f530ac4318113a8ff), [`afc004f`](https://github.com/mastra-ai/mastra/commit/afc004f5cc7e30697809e7021820b9f5881e6719), [`0031d0f`](https://github.com/mastra-ai/mastra/commit/0031d0f13831d7843ac5d498734a7d92862e2ce3), [`841a222`](https://github.com/mastra-ai/mastra/commit/841a222560d8c19238f8213713f30535cdd82284), [`64c1e0b`](https://github.com/mastra-ai/mastra/commit/64c1e0b35165c96b659818bd0177aa18794ef11f), [`40d83a9`](https://github.com/mastra-ai/mastra/commit/40d83a90d9be31a1b83e04649edb703eb7753e33), [`4e88dc6`](https://github.com/mastra-ai/mastra/commit/4e88dc6b89f154c0eae37221c8126be0c23c569f), [`19018f0`](https://github.com/mastra-ai/mastra/commit/19018f05722af74a5978781a7731a654b26f7f2a), [`19281c7`](https://github.com/mastra-ai/mastra/commit/19281c70424f757219782de16c2699743c5e04d0), [`3498b49`](https://github.com/mastra-ai/mastra/commit/3498b4946be94f4313cd817733589680dcda5278), [`d52b6fe`](https://github.com/mastra-ai/mastra/commit/d52b6fe1c56853eb38864baae0bbfa75cc739ccb), [`408be73`](https://github.com/mastra-ai/mastra/commit/408be73449dfab92b51eab8c6623b6c443debc25), [`359439b`](https://github.com/mastra-ai/mastra/commit/359439bb8c635e048176306828195f8297f50021), [`71a820b`](https://github.com/mastra-ai/mastra/commit/71a820b2353fa1406772c50760a3732058a8b337), [`1698f5e`](https://github.com/mastra-ai/mastra/commit/1698f5ec141d34f22a873efdb145ce3cdf848a5e)]:
66
+ - @mastra/core@1.36.0
67
+
3
68
  ## 1.8.0-alpha.2
4
69
 
5
70
  ### Patch Changes
@@ -0,0 +1,4 @@
1
+ import type { Hono } from '../hono';
2
+ import type { UnionToIntersection } from '../utils/types';
3
+ import type { Client, ClientRequestOptions } from './types';
4
+ export declare const hc: <T extends Hono<any, any, any>, Prefix extends string = string>(baseUrl: Prefix, options?: ClientRequestOptions) => UnionToIntersection<Client<T, Prefix>>;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @description This file is a modified version of `fetch-result-please` (`ofetch`), minimalized and adapted to Hono's custom needs.
3
+ *
4
+ * @link https://www.npmjs.com/package/fetch-result-please
5
+ */
6
+ /**
7
+ * Smartly parses and return the consumable result from a fetch `Response`.
8
+ *
9
+ * Throwing a structured error if the response is not `ok`. ({@link DetailedError})
10
+ */
11
+ export declare function fetchRP(fetchRes: Response | Promise<Response>): Promise<any>;
12
+ export declare class DetailedError extends Error {
13
+ /**
14
+ * Additional `message` that will be logged AND returned to client
15
+ */
16
+ detail?: any;
17
+ /**
18
+ * Additional `code` that will be logged AND returned to client
19
+ */
20
+ code?: any;
21
+ /**
22
+ * Additional value that will be logged AND NOT returned to client
23
+ */
24
+ log?: any;
25
+ /**
26
+ * Optionally set the status code to return, in a web server context
27
+ */
28
+ statusCode?: any;
29
+ constructor(message: string, options?: {
30
+ detail?: any;
31
+ code?: any;
32
+ statusCode?: number;
33
+ log?: any;
34
+ });
35
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module
3
+ * The HTTP Client for Hono.
4
+ */
5
+ export { hc } from './client';
6
+ export { parseResponse, DetailedError } from './utils';
7
+ export type { InferResponseType, InferRequestType, Fetch, ClientRequestOptions, ClientRequest, ClientResponse, ApplyGlobalResponse, PickResponseByStatusCode, } from './types';
@@ -0,0 +1,229 @@
1
+ import type { Hono } from '../hono';
2
+ import type { HonoBase } from '../hono-base';
3
+ import type { METHODS, METHOD_NAME_ALL_LOWERCASE } from '../router';
4
+ import type { Endpoint, ExtractSchema, KnownResponseFormat, ResponseFormat, Schema } from '../types';
5
+ import type { StatusCode, SuccessStatusCode } from '../utils/http-status';
6
+ import type { HasRequiredKeys } from '../utils/types';
7
+ /**
8
+ * Type representing the '$all' method name
9
+ */
10
+ type MethodNameAll = `$${typeof METHOD_NAME_ALL_LOWERCASE}`;
11
+ /**
12
+ * Type representing all standard HTTP methods prefixed with '$'
13
+ * e.g., '$get' | '$post' | '$put' | '$delete' | '$options' | '$patch'
14
+ */
15
+ type StandardMethods = `$${(typeof METHODS)[number]}`;
16
+ /**
17
+ * Expands '$all' into all standard HTTP methods.
18
+ * If the schema contains '$all', it creates a type where all standard HTTP methods
19
+ * point to the same endpoint definition as '$all', while removing '$all' itself.
20
+ */
21
+ type ExpandAllMethod<S> = MethodNameAll extends keyof S ? {
22
+ [M in StandardMethods]: S[MethodNameAll];
23
+ } & Omit<S, MethodNameAll> : S;
24
+ type HonoRequest = (typeof Hono.prototype)['request'];
25
+ export type BuildSearchParamsFn = (query: Record<string, string | string[]>) => URLSearchParams;
26
+ export type ClientRequestOptions<T = unknown> = {
27
+ fetch?: typeof fetch | HonoRequest;
28
+ webSocket?: (...args: ConstructorParameters<typeof WebSocket>) => WebSocket;
29
+ /**
30
+ * Standard `RequestInit`, caution that this take highest priority
31
+ * and could be used to overwrite things that Hono sets for you, like `body | method | headers`.
32
+ *
33
+ * If you want to add some headers, use in `headers` instead of `init`
34
+ */
35
+ init?: RequestInit;
36
+ /**
37
+ * Custom function to serialize query parameters into URLSearchParams.
38
+ * By default, arrays are serialized as multiple parameters with the same key (e.g., `key=a&key=b`).
39
+ * You can provide a custom function to change this behavior, for example to use bracket notation (e.g., `key[]=a&key[]=b`).
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const client = hc('http://localhost', {
44
+ * buildSearchParams: (query) => {
45
+ * return new URLSearchParams(qs.stringify(query))
46
+ * }
47
+ * })
48
+ * ```
49
+ */
50
+ buildSearchParams?: BuildSearchParamsFn;
51
+ } & (keyof T extends never ? {
52
+ headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
53
+ } : {
54
+ headers: T | (() => T | Promise<T>);
55
+ });
56
+ export type ClientRequest<Prefix extends string, Path extends string, S extends Schema> = {
57
+ [M in keyof ExpandAllMethod<S>]: ExpandAllMethod<S>[M] extends Endpoint & {
58
+ input: infer R;
59
+ } ? R extends object ? HasRequiredKeys<R> extends true ? (args: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<ExpandAllMethod<S>[M]>> : (args?: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<ExpandAllMethod<S>[M]>> : never : never;
60
+ } & {
61
+ $url: <const Arg extends (S[keyof S] extends {
62
+ input: infer R;
63
+ } ? R extends {
64
+ param: infer P;
65
+ } ? R extends {
66
+ query: infer Q;
67
+ } ? {
68
+ param: P;
69
+ query: Q;
70
+ } : {
71
+ param: P;
72
+ } : R extends {
73
+ query: infer Q;
74
+ } ? {
75
+ query: Q;
76
+ } : {} : {}) | undefined = undefined>(arg?: Arg) => HonoURL<Prefix, Path, Arg>;
77
+ $path: <const Arg extends (S[keyof S] extends {
78
+ input: infer R;
79
+ } ? R extends {
80
+ param: infer P;
81
+ } ? R extends {
82
+ query: infer Q;
83
+ } ? {
84
+ param: P;
85
+ query: Q;
86
+ } : {
87
+ param: P;
88
+ } : R extends {
89
+ query: infer Q;
90
+ } ? {
91
+ query: Q;
92
+ } : {} : {}) | undefined = undefined>(arg?: Arg) => BuildPath<Path, Arg>;
93
+ } & (S['$get'] extends {
94
+ outputFormat: 'ws';
95
+ } ? S['$get'] extends {
96
+ input: infer I;
97
+ } ? {
98
+ $ws: (args?: I) => WebSocket;
99
+ } : {} : {});
100
+ type ClientResponseOfEndpoint<T extends Endpoint = Endpoint> = T extends {
101
+ output: infer O;
102
+ outputFormat: infer F;
103
+ status: infer S;
104
+ } ? ClientResponse<O, S extends number ? S : never, F extends ResponseFormat ? F : never> : never;
105
+ export interface ClientResponse<T, U extends number = StatusCode, F extends ResponseFormat = ResponseFormat> {
106
+ readonly body: ReadableStream | null;
107
+ readonly bodyUsed: boolean;
108
+ ok: U extends SuccessStatusCode ? true : U extends Exclude<StatusCode, SuccessStatusCode> ? false : boolean;
109
+ redirected: boolean;
110
+ status: U;
111
+ statusText: string;
112
+ type: 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect';
113
+ headers: Headers;
114
+ url: string;
115
+ redirect(url: string, status: number): Response;
116
+ clone(): Response;
117
+ bytes(): Promise<Uint8Array<ArrayBuffer>>;
118
+ json(): F extends 'text' ? Promise<never> : F extends 'json' ? Promise<T> : Promise<unknown>;
119
+ text(): F extends 'text' ? (T extends string ? Promise<T> : Promise<never>) : Promise<string>;
120
+ blob(): Promise<Blob>;
121
+ formData(): Promise<FormData>;
122
+ arrayBuffer(): Promise<ArrayBuffer>;
123
+ }
124
+ type BuildSearch<Arg, Key extends 'query'> = Arg extends {
125
+ [K in Key]: infer Query;
126
+ } ? IsEmptyObject<Query> extends true ? '' : `?${string}` : '';
127
+ type BuildPathname<P extends string, Arg> = Arg extends {
128
+ param: infer Param;
129
+ } ? `${ApplyParam<TrimStartSlash<P>, Param>}` : `/${TrimStartSlash<P>}`;
130
+ type BuildPath<P extends string, Arg> = `${BuildPathname<P, Arg>}${BuildSearch<Arg, 'query'>}`;
131
+ type BuildTypedURL<Protocol extends string, Host extends string, Port extends string, P extends string, Arg> = TypedURL<`${Protocol}:`, Host, Port, BuildPathname<P, Arg>, BuildSearch<Arg, 'query'>>;
132
+ type HonoURL<Prefix extends string, Path extends string, Arg> = IsLiteral<Prefix> extends true ? TrimEndSlash<Prefix> extends `${infer Protocol}://${infer Rest}` ? Rest extends `${infer Hostname}/${infer P}` ? ParseHostName<Hostname> extends [infer Host extends string, infer Port extends string] ? BuildTypedURL<Protocol, Host, Port, P, Arg> : never : ParseHostName<Rest> extends [infer Host extends string, infer Port extends string] ? BuildTypedURL<Protocol, Host, Port, Path, Arg> : never : URL : URL;
133
+ type ParseHostName<T extends string> = T extends `${infer Host}:${infer Port}` ? [Host, Port] : [T, ''];
134
+ type TrimStartSlash<T extends string> = T extends `/${infer R}` ? TrimStartSlash<R> : T;
135
+ type TrimEndSlash<T extends string> = T extends `${infer R}/` ? TrimEndSlash<R> : T;
136
+ type IsLiteral<T extends string> = [T] extends [never] ? false : string extends T ? false : true;
137
+ type ApplyParam<Path extends string, P, Result extends string = ''> = Path extends `${infer Head}/${infer Rest}` ? Head extends `:${infer Param}` ? P extends Record<Param, infer Value extends string> ? IsLiteral<Value> extends true ? ApplyParam<Rest, P, `${Result}/${Value & string}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : Path extends `:${infer Param}` ? P extends Record<Param, infer Value extends string> ? IsLiteral<Value> extends true ? `${Result}/${Value & string}` : `${Result}/${Path}` : `${Result}/${Path}` : `${Result}/${Path}`;
138
+ type IsEmptyObject<T> = keyof T extends never ? true : false;
139
+ export interface TypedURL<Protocol extends string, Hostname extends string, Port extends string, Pathname extends string, Search extends string> extends URL {
140
+ protocol: Protocol;
141
+ hostname: Hostname;
142
+ port: Port;
143
+ host: Port extends '' ? Hostname : `${Hostname}:${Port}`;
144
+ origin: `${Protocol}//${Hostname}${Port extends '' ? '' : `:${Port}`}`;
145
+ pathname: Pathname;
146
+ search: Search;
147
+ href: `${Protocol}//${Hostname}${Port extends '' ? '' : `:${Port}`}${Pathname}${Search}`;
148
+ }
149
+ export interface Response extends ClientResponse<unknown> {
150
+ }
151
+ export type Fetch<T> = (args?: InferRequestType<T>, opt?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<InferEndpointType<T>>>;
152
+ type InferEndpointType<T> = T extends (args: infer R, options: any | undefined) => Promise<infer U> ? U extends ClientResponse<infer O, infer S, infer F> ? {
153
+ input: NonNullable<R>;
154
+ output: O;
155
+ outputFormat: F;
156
+ status: S;
157
+ } extends Endpoint ? {
158
+ input: NonNullable<R>;
159
+ output: O;
160
+ outputFormat: F;
161
+ status: S;
162
+ } : never : never : never;
163
+ export type InferResponseType<T, U extends StatusCode = StatusCode> = InferResponseTypeFromEndpoint<InferEndpointType<T>, U>;
164
+ type InferResponseTypeFromEndpoint<T extends Endpoint, U extends StatusCode> = T extends {
165
+ output: infer O;
166
+ status: infer S;
167
+ } ? S extends U ? O : never : never;
168
+ export type InferRequestType<T> = T extends (args: infer R, options: any | undefined) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
169
+ export type InferRequestOptionsType<T> = T extends (args: any, options: infer R) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
170
+ /**
171
+ * Filter a ClientResponse type so it only includes responses of specific status codes.
172
+ */
173
+ export type FilterClientResponseByStatusCode<T extends ClientResponse<any, any, any>, U extends number = StatusCode> = T extends ClientResponse<infer RT, infer RC, infer RF> ? RC extends U ? ClientResponse<RT, RC, RF> : never : never;
174
+ type PathToChain<Prefix extends string, Path extends string, E extends Schema, Original extends string = Path> = Path extends `/${infer P}` ? PathToChain<Prefix, P, E, Path> : Path extends `${infer P}/${infer R}` ? {
175
+ [K in P]: PathToChain<Prefix, R, E, Original>;
176
+ } : {
177
+ [K in Path extends '' ? 'index' : Path]: ClientRequest<Prefix, Original, E extends Record<string, unknown> ? E[Original] : never>;
178
+ };
179
+ export type Client<T, Prefix extends string> = T extends HonoBase<any, infer S, any> ? S extends Record<infer K, Schema> ? K extends string ? PathToChain<Prefix, K, S> : never : never : never;
180
+ export type Callback = (opts: CallbackOptions) => unknown;
181
+ interface CallbackOptions {
182
+ path: string[];
183
+ args: any[];
184
+ }
185
+ export type ObjectType<T = unknown> = {
186
+ [key: string]: T;
187
+ };
188
+ type GlobalResponseDefinition = {
189
+ [S in StatusCode]?: {
190
+ [F in KnownResponseFormat]?: unknown;
191
+ };
192
+ };
193
+ type ToEndpoints<Def extends GlobalResponseDefinition, R> = {
194
+ [S in keyof Def & StatusCode]: {
195
+ [F in keyof Def[S] & KnownResponseFormat]: Omit<R, 'output' | 'status' | 'outputFormat'> & {
196
+ output: Def[S][F];
197
+ status: S;
198
+ outputFormat: F;
199
+ };
200
+ }[keyof Def[S] & KnownResponseFormat];
201
+ }[keyof Def & StatusCode];
202
+ type ModRoute<R, Def extends GlobalResponseDefinition> = R extends Endpoint ? R | ToEndpoints<Def, R> : R;
203
+ type ModSchema<D, Def extends GlobalResponseDefinition> = {
204
+ [K in keyof D]: {
205
+ [M in keyof D[K]]: ModRoute<D[K][M], Def>;
206
+ };
207
+ };
208
+ export type ApplyGlobalResponse<App, Def extends GlobalResponseDefinition> = App extends HonoBase<infer E, infer _ extends Schema, infer B> ? ModSchema<ExtractSchema<App>, Def> extends infer S extends Schema ? Hono<E, S, B> : never : never;
209
+ type PickRoute<R, U extends StatusCode> = R extends Endpoint ? R extends {
210
+ status: U;
211
+ } ? R : never : R;
212
+ type PickSchema<D, U extends StatusCode> = {
213
+ [K in keyof D]: {
214
+ [M in keyof D[K]]: PickRoute<D[K][M], U>;
215
+ };
216
+ };
217
+ /**
218
+ * Keep only specific status code responses from all routes of an app.
219
+ * Useful when error responses are handled centrally (e.g., via custom fetch)
220
+ * and you want the client to only expose success response types.
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * type AppSuccessOnly = PickResponseByStatusCode<typeof app, 200>
225
+ * const client = hc<AppSuccessOnly>('http://localhost')
226
+ * ```
227
+ */
228
+ export type PickResponseByStatusCode<App, U extends StatusCode> = App extends HonoBase<infer E, infer _ extends Schema, infer B> ? PickSchema<ExtractSchema<App>, U> extends infer S extends Schema ? Hono<E, S, B> : never : never;
229
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { ClientErrorStatusCode, ContentfulStatusCode, ServerErrorStatusCode } from '../utils/http-status';
2
+ import { DetailedError } from './fetch-result-please';
3
+ import type { ClientResponse, FilterClientResponseByStatusCode } from './types';
4
+ export { DetailedError };
5
+ export declare const mergePath: (base: string, path: string) => string;
6
+ export declare const replaceUrlParam: (urlString: string, params: Record<string, string | undefined>) => string;
7
+ export declare const buildSearchParams: (query: Record<string, string | string[]>) => URLSearchParams;
8
+ export declare const replaceUrlProtocol: (urlString: string, protocol: "ws" | "http") => string;
9
+ export declare const removeIndexString: (urlString: string) => string;
10
+ export declare function deepMerge<T>(target: T, source: Record<string, unknown>): T;
11
+ /**
12
+ * Shortcut to get a consumable response from `hc`'s fetch calls (Response), with types inference.
13
+ *
14
+ * Smartly parse the response data, throwing a structured error if the response is not `ok`. ({@link DetailedError})
15
+ *
16
+ * @example const result = await parseResponse(client.posts.$get())
17
+ */
18
+ export declare function parseResponse<T extends ClientResponse<any>>(fetchRes: T | Promise<T>): Promise<FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends never ? undefined : FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends ClientResponse<infer RT, infer _, infer RF> ? RF extends 'json' ? RT : RT extends string ? RT : string : undefined>;