mcp-use 1.9.0 → 1.9.1-canary.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 (104) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/chunk-2EYAMIT3.js +76 -0
  3. package/dist/chunk-362PI25Z.js +110 -0
  4. package/dist/chunk-5URNFWCQ.js +25 -0
  5. package/dist/chunk-KHTTBIRP.js +280 -0
  6. package/dist/context-storage-TXQ4DVSS.js +11 -0
  7. package/dist/conversion-5MA4VY3B.js +7 -0
  8. package/dist/conversion-OTRZZBUU.js +7 -0
  9. package/dist/src/server/endpoints/index.d.ts +7 -0
  10. package/dist/src/server/endpoints/index.d.ts.map +1 -0
  11. package/dist/src/server/endpoints/mount-mcp.d.ts +21 -0
  12. package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -0
  13. package/dist/src/server/index.cjs +3738 -3940
  14. package/dist/src/server/index.d.ts +4 -3
  15. package/dist/src/server/index.d.ts.map +1 -1
  16. package/dist/src/server/index.js +3223 -3039
  17. package/dist/src/server/inspector/index.d.ts +5 -0
  18. package/dist/src/server/inspector/index.d.ts.map +1 -0
  19. package/dist/src/server/inspector/mount.d.ts +33 -0
  20. package/dist/src/server/inspector/mount.d.ts.map +1 -0
  21. package/dist/src/server/logging.d.ts.map +1 -1
  22. package/dist/src/server/mcp-server.d.ts +71 -780
  23. package/dist/src/server/mcp-server.d.ts.map +1 -1
  24. package/dist/src/server/notifications/index.d.ts +7 -0
  25. package/dist/src/server/notifications/index.d.ts.map +1 -0
  26. package/dist/src/server/notifications/notification-registration.d.ts +82 -0
  27. package/dist/src/server/notifications/notification-registration.d.ts.map +1 -0
  28. package/dist/src/server/oauth/index.d.ts +1 -0
  29. package/dist/src/server/oauth/index.d.ts.map +1 -1
  30. package/dist/src/server/oauth/setup.d.ts +28 -0
  31. package/dist/src/server/oauth/setup.d.ts.map +1 -0
  32. package/dist/src/server/prompts/conversion.d.ts +22 -0
  33. package/dist/src/server/prompts/conversion.d.ts.map +1 -0
  34. package/dist/src/server/prompts/index.d.ts +60 -0
  35. package/dist/src/server/prompts/index.d.ts.map +1 -0
  36. package/dist/src/server/resources/conversion.d.ts +20 -0
  37. package/dist/src/server/resources/conversion.d.ts.map +1 -0
  38. package/dist/src/server/resources/index.d.ts +116 -0
  39. package/dist/src/server/resources/index.d.ts.map +1 -0
  40. package/dist/src/server/roots/index.d.ts +7 -0
  41. package/dist/src/server/roots/index.d.ts.map +1 -0
  42. package/dist/src/server/roots/roots-registration.d.ts +56 -0
  43. package/dist/src/server/roots/roots-registration.d.ts.map +1 -0
  44. package/dist/src/server/sessions/index.d.ts +6 -0
  45. package/dist/src/server/sessions/index.d.ts.map +1 -0
  46. package/dist/src/server/sessions/notifications.d.ts +25 -0
  47. package/dist/src/server/sessions/notifications.d.ts.map +1 -0
  48. package/dist/src/server/sessions/session-manager.d.ts +41 -0
  49. package/dist/src/server/sessions/session-manager.d.ts.map +1 -0
  50. package/dist/src/server/tools/index.d.ts +10 -0
  51. package/dist/src/server/tools/index.d.ts.map +1 -0
  52. package/dist/src/server/tools/schema-helpers.d.ts +54 -0
  53. package/dist/src/server/tools/schema-helpers.d.ts.map +1 -0
  54. package/dist/src/server/tools/tool-execution-helpers.d.ts +97 -0
  55. package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -0
  56. package/dist/src/server/tools/tool-registration.d.ts +85 -0
  57. package/dist/src/server/tools/tool-registration.d.ts.map +1 -0
  58. package/dist/src/server/types/common.d.ts +24 -0
  59. package/dist/src/server/types/common.d.ts.map +1 -1
  60. package/dist/src/server/types/index.d.ts +5 -4
  61. package/dist/src/server/types/index.d.ts.map +1 -1
  62. package/dist/src/server/types/prompt.d.ts +61 -6
  63. package/dist/src/server/types/prompt.d.ts.map +1 -1
  64. package/dist/src/server/types/resource.d.ts +83 -8
  65. package/dist/src/server/types/resource.d.ts.map +1 -1
  66. package/dist/src/server/types/tool-context.d.ts +236 -0
  67. package/dist/src/server/types/tool-context.d.ts.map +1 -0
  68. package/dist/src/server/types/tool.d.ts +62 -5
  69. package/dist/src/server/types/tool.d.ts.map +1 -1
  70. package/dist/src/server/utils/hono-proxy.d.ts +21 -0
  71. package/dist/src/server/utils/hono-proxy.d.ts.map +1 -0
  72. package/dist/src/server/utils/index.d.ts +3 -0
  73. package/dist/src/server/utils/index.d.ts.map +1 -1
  74. package/dist/src/server/utils/jsonrpc-helpers.d.ts +94 -0
  75. package/dist/src/server/utils/jsonrpc-helpers.d.ts.map +1 -0
  76. package/dist/src/server/utils/response-helpers.d.ts +115 -3
  77. package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
  78. package/dist/src/server/utils/server-helpers.d.ts +78 -0
  79. package/dist/src/server/utils/server-helpers.d.ts.map +1 -0
  80. package/dist/src/server/utils/server-lifecycle.d.ts +52 -0
  81. package/dist/src/server/utils/server-lifecycle.d.ts.map +1 -0
  82. package/dist/src/server/utils/session-helpers.d.ts +55 -0
  83. package/dist/src/server/utils/session-helpers.d.ts.map +1 -0
  84. package/dist/src/server/widgets/index.d.ts +30 -0
  85. package/dist/src/server/widgets/index.d.ts.map +1 -0
  86. package/dist/src/server/widgets/mcp-ui-adapter.d.ts.map +1 -0
  87. package/dist/src/server/widgets/mount-widgets-dev.d.ts +28 -0
  88. package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -0
  89. package/dist/src/server/widgets/mount-widgets-production.d.ts +27 -0
  90. package/dist/src/server/widgets/mount-widgets-production.d.ts.map +1 -0
  91. package/dist/src/server/widgets/setup-widget-routes.d.ts +23 -0
  92. package/dist/src/server/widgets/setup-widget-routes.d.ts.map +1 -0
  93. package/dist/src/server/widgets/ui-resource-registration.d.ts +75 -0
  94. package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -0
  95. package/dist/src/server/widgets/widget-helpers.d.ts +277 -0
  96. package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -0
  97. package/dist/src/server/widgets/widget-types.d.ts +49 -0
  98. package/dist/src/server/widgets/widget-types.d.ts.map +1 -0
  99. package/dist/tool-execution-helpers-IVUDHXMK.js +23 -0
  100. package/package.json +6 -5
  101. package/dist/chunk-F4UHAA5L.js +0 -854
  102. package/dist/oauth-U4NNKN4B.js +0 -30
  103. package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +0 -1
  104. /package/dist/src/server/{adapters → widgets}/mcp-ui-adapter.d.ts +0 -0
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Tool Context Types
3
+ *
4
+ * Defines the context object and related types passed to tool callbacks.
5
+ * Provides access to sampling, elicitation, and progress reporting capabilities.
6
+ */
7
+ import type { CreateMessageRequest, CreateMessageResult, ElicitResult } from "@modelcontextprotocol/sdk/types.js";
8
+ import type { z } from "zod";
9
+ /**
10
+ * Options for the sample() function in tool context.
11
+ */
12
+ export interface SampleOptions {
13
+ /**
14
+ * Timeout in milliseconds for the sampling request.
15
+ * Default: no timeout (Infinity) - waits indefinitely for the LLM response.
16
+ * Set this if you want to limit how long to wait for sampling.
17
+ */
18
+ timeout?: number;
19
+ /**
20
+ * Interval in milliseconds between progress notifications.
21
+ * Default: 5000 (5 seconds).
22
+ * Progress notifications are sent to the client to prevent timeout
23
+ * when the client has resetTimeoutOnProgress enabled.
24
+ */
25
+ progressIntervalMs?: number;
26
+ /**
27
+ * Optional callback called each time a progress notification is sent.
28
+ * Useful for logging or custom progress handling.
29
+ */
30
+ onProgress?: (progress: {
31
+ progress: number;
32
+ total?: number;
33
+ message: string;
34
+ }) => void;
35
+ /**
36
+ * Maximum number of tokens to generate.
37
+ * Default: 1000 (when using string prompt shorthand).
38
+ * Only used when calling sample() with a string prompt.
39
+ */
40
+ maxTokens?: number;
41
+ /**
42
+ * Model preferences for sampling.
43
+ * Allows specifying which models to use via hints.
44
+ */
45
+ modelPreferences?: {
46
+ hints?: Array<{
47
+ name?: string;
48
+ }>;
49
+ costPriority?: number;
50
+ speedPriority?: number;
51
+ intelligencePriority?: number;
52
+ };
53
+ /**
54
+ * System prompt to prepend to the conversation.
55
+ */
56
+ systemPrompt?: string;
57
+ /**
58
+ * Temperature for sampling (0.0 to 1.0).
59
+ * Controls randomness in the response.
60
+ */
61
+ temperature?: number;
62
+ /**
63
+ * Stop sequences to end generation.
64
+ */
65
+ stopSequences?: string[];
66
+ /**
67
+ * Additional metadata to pass with the request.
68
+ */
69
+ metadata?: Record<string, unknown>;
70
+ }
71
+ /**
72
+ * Options for the elicit() function in tool context.
73
+ */
74
+ export interface ElicitOptions {
75
+ /**
76
+ * Timeout in milliseconds for the elicitation request.
77
+ * Default: no timeout (Infinity) - waits indefinitely for user response.
78
+ * Set this if you want to limit how long to wait for user input.
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Wait indefinitely (default)
83
+ * await ctx.elicit(message, schema);
84
+ *
85
+ * // With 2 minute timeout
86
+ * await ctx.elicit(message, schema, { timeout: 120000 });
87
+ * ```
88
+ */
89
+ timeout?: number;
90
+ }
91
+ /**
92
+ * Parameters for form mode elicitation.
93
+ * Used to request structured data from users with optional JSON schema validation.
94
+ */
95
+ export interface ElicitFormParams {
96
+ /** Human-readable message explaining why the information is needed */
97
+ message: string;
98
+ /** JSON Schema defining the structure of the expected response */
99
+ requestedSchema: Record<string, any>;
100
+ /** Mode specifier (optional for backwards compatibility, defaults to "form") */
101
+ mode?: "form";
102
+ }
103
+ /**
104
+ * Parameters for URL mode elicitation.
105
+ * Used to direct users to external URLs for sensitive interactions.
106
+ * MUST be used for interactions involving sensitive information like credentials.
107
+ */
108
+ export interface ElicitUrlParams {
109
+ /** Human-readable message explaining why the interaction is needed */
110
+ message: string;
111
+ /** URL for the user to navigate to */
112
+ url: string;
113
+ /** Mode specifier (required for URL mode) */
114
+ mode: "url";
115
+ }
116
+ /**
117
+ * Context object passed to tool callbacks.
118
+ * Provides access to sampling, elicitation, and progress reporting capabilities.
119
+ */
120
+ export interface ToolContext {
121
+ /**
122
+ * Request sampling from the client's LLM with automatic progress notifications.
123
+ *
124
+ * Supports two calling patterns:
125
+ * 1. **Simplified string API**: Pass a prompt string with optional options
126
+ * 2. **Full control API**: Pass complete CreateMessageRequest params
127
+ *
128
+ * Progress notifications are sent every 5 seconds (configurable) while waiting
129
+ * for the sampling response. This prevents client-side timeouts when the client
130
+ * has `resetTimeoutOnProgress: true` enabled.
131
+ *
132
+ * By default, there is no timeout - the function waits indefinitely for the
133
+ * LLM response. Set `options.timeout` to limit the wait time.
134
+ *
135
+ * @param promptOrParams - Either a string prompt or complete sampling parameters
136
+ * @param options - Optional configuration for timeout, progress, maxTokens, etc.
137
+ * @returns The sampling result from the client's LLM
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * // Simplified API - just pass a string prompt
142
+ * const result = await ctx.sample("What is the capital of France?");
143
+ *
144
+ * // With options (maxTokens, temperature, etc.)
145
+ * const result = await ctx.sample(
146
+ * "Analyze this code...",
147
+ * { maxTokens: 2000, temperature: 0.7 }
148
+ * );
149
+ *
150
+ * // Full control API - complete params object
151
+ * const result = await ctx.sample({
152
+ * messages: [
153
+ * { role: 'system', content: { type: 'text', text: 'You are helpful' } },
154
+ * { role: 'user', content: { type: 'text', text: 'Hello' } }
155
+ * ],
156
+ * maxTokens: 1500,
157
+ * modelPreferences: { hints: [{ name: 'claude-3-5-sonnet' }] }
158
+ * });
159
+ *
160
+ * // With timeout and custom progress handling
161
+ * const result = await ctx.sample(
162
+ * "Complex task...",
163
+ * {
164
+ * timeout: 120000, // 2 minute timeout
165
+ * progressIntervalMs: 3000, // Report progress every 3 seconds
166
+ * onProgress: ({ progress, message }) => console.log(message),
167
+ * }
168
+ * );
169
+ * ```
170
+ */
171
+ sample: {
172
+ (prompt: string, options?: SampleOptions): Promise<CreateMessageResult>;
173
+ (params: CreateMessageRequest["params"], options?: SampleOptions): Promise<CreateMessageResult>;
174
+ };
175
+ /**
176
+ * Request user input via the client through elicitation.
177
+ *
178
+ * Supports two modes with automatic mode detection:
179
+ * - **Form mode**: Pass a Zod schema as second parameter - collects structured data
180
+ * - **URL mode**: Pass a URL string as second parameter - directs to external URL
181
+ * - **Verbose mode**: Pass an object with explicit mode for backwards compatibility
182
+ *
183
+ * By default, there is no timeout - waits indefinitely for user response.
184
+ * Set `options.timeout` to limit the wait time.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * // Form mode (simplified) - automatically inferred from Zod schema
189
+ * const result = await ctx.elicit(
190
+ * "Please provide your information",
191
+ * z.object({
192
+ * name: z.string().default("Anonymous"),
193
+ * age: z.number().default(0)
194
+ * })
195
+ * );
196
+ * // result.data is typed as { name: string, age: number }
197
+ *
198
+ * // With timeout
199
+ * const result = await ctx.elicit(
200
+ * "Enter info",
201
+ * z.object({ name: z.string() }),
202
+ * { timeout: 60000 } // 1 minute timeout
203
+ * );
204
+ *
205
+ * // URL mode (simplified) - automatically inferred from URL string
206
+ * const authResult = await ctx.elicit(
207
+ * "Please authorize access",
208
+ * "https://example.com/oauth/authorize"
209
+ * );
210
+ *
211
+ * // Verbose API (backwards compatible)
212
+ * const verboseResult = await ctx.elicit({
213
+ * message: "Please provide your information",
214
+ * requestedSchema: { type: "object", properties: {...} },
215
+ * mode: "form"
216
+ * });
217
+ * ```
218
+ */
219
+ elicit: {
220
+ <T extends z.ZodObject<any>>(message: string, schema: T, options?: ElicitOptions): Promise<ElicitResult & {
221
+ data: z.infer<T>;
222
+ }>;
223
+ (message: string, url: string, options?: ElicitOptions): Promise<ElicitResult>;
224
+ (params: ElicitFormParams | ElicitUrlParams, options?: ElicitOptions): Promise<ElicitResult>;
225
+ };
226
+ /**
227
+ * Send a progress notification to the client.
228
+ * Only available if the client requested progress updates for this tool call.
229
+ *
230
+ * @param progress - Current progress value (should increase with each call)
231
+ * @param total - Total progress value if known
232
+ * @param message - Optional message describing current progress
233
+ */
234
+ reportProgress?: (progress: number, total?: number, message?: string) => Promise<void>;
235
+ }
236
+ //# sourceMappingURL=tool-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-context.d.ts","sourceRoot":"","s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AAC;KAC1B,CAAC;IAEF;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
@@ -1,6 +1,6 @@
1
1
  import type { InputDefinition } from "./common.js";
2
2
  import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
3
- import type { ToolContext } from "../mcp-server.js";
3
+ import type { ToolContext } from "./tool-context.js";
4
4
  import type { McpContext } from "./context.js";
5
5
  import type { z } from "zod";
6
6
  import type { TypedCallToolResult } from "../utils/response-helpers.js";
@@ -18,9 +18,12 @@ import type { TypedCallToolResult } from "../utils/response-helpers.js";
18
18
  */
19
19
  export type EnhancedToolContext<HasOAuth extends boolean = false> = ToolContext & McpContext<HasOAuth>;
20
20
  /**
21
- * Callback function for tool execution.
21
+ * Callback function interface for tool execution.
22
22
  *
23
- * Accepts input parameters and an enhanced context object that provides:
23
+ * Uses method signature syntax to enable bivariant parameter checking,
24
+ * which allows more flexible destructuring patterns for optional fields.
25
+ *
26
+ * Accepts input parameters and an optional enhanced context object that provides:
24
27
  * - LLM sampling via `ctx.sample()`
25
28
  * - Progress reporting via `ctx.reportProgress()`
26
29
  * - Authentication info via `ctx.auth` (when OAuth is configured)
@@ -52,14 +55,67 @@ export type EnhancedToolContext<HasOAuth extends boolean = false> = ToolContext
52
55
  * }
53
56
  * ```
54
57
  */
55
- export type ToolCallback<TInput = Record<string, any>, TOutput extends Record<string, unknown> = Record<string, unknown>, HasOAuth extends boolean = false> = ((params: TInput) => Promise<TypedCallToolResult<TOutput>>) | ((params: TInput, ctx: EnhancedToolContext<HasOAuth>) => Promise<TypedCallToolResult<TOutput>>);
58
+ /**
59
+ * Helper interface that uses method signature syntax to enable bivariant parameter checking.
60
+ * This allows more flexible callback assignments where users can destructure optional fields
61
+ * without explicitly marking them as optional in their function signature.
62
+ *
63
+ * @internal
64
+ */
65
+ interface ToolCallbackBivariant<TInput, TOutput extends Record<string, unknown>, HasOAuth extends boolean> {
66
+ bivarianceHack(params: TInput, ctx: EnhancedToolContext<HasOAuth>): Promise<TypedCallToolResult<TOutput>>;
67
+ }
68
+ /**
69
+ * Callback function type for tool execution.
70
+ *
71
+ * Uses bivariant parameter checking via method signature extraction,
72
+ * which allows more flexible destructuring patterns for optional fields.
73
+ *
74
+ * Accepts input parameters and an enhanced context object that provides:
75
+ * - LLM sampling via `ctx.sample()`
76
+ * - Progress reporting via `ctx.reportProgress()`
77
+ * - Elicitation via `ctx.elicit()`
78
+ * - Authentication info via `ctx.auth` (when OAuth is configured)
79
+ * - HTTP request via `ctx.req`
80
+ * - All Hono Context properties and methods
81
+ *
82
+ * @template TInput - Input parameters type
83
+ * @template TOutput - Output type (constrains the structuredContent property when outputSchema is defined)
84
+ * @template HasOAuth - Whether OAuth is configured (affects ctx.auth availability)
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // Simple tool without context
89
+ * async ({ name }) => ({
90
+ * content: [{ type: 'text', text: `Hello, ${name}!` }]
91
+ * })
92
+ *
93
+ * // Tool with sampling and context
94
+ * async ({ text }, ctx) => {
95
+ * const result = await ctx.sample({
96
+ * messages: [{ role: 'user', content: { type: 'text', text } }]
97
+ * });
98
+ * return { content: result.content };
99
+ * }
100
+ *
101
+ * // Tool with authentication
102
+ * async ({ userId }, ctx) => {
103
+ * return { content: [{ type: 'text', text: `User: ${ctx.auth.user.email}` }] };
104
+ * }
105
+ * ```
106
+ */
107
+ export type ToolCallback<TInput = Record<string, any>, TOutput extends Record<string, unknown> = Record<string, unknown>, HasOAuth extends boolean = false> = ToolCallbackBivariant<TInput, TOutput, HasOAuth>["bivarianceHack"];
56
108
  /**
57
109
  * Generic callback with full context support for better type inference.
58
110
  * This variant always requires the context parameter.
59
111
  */
60
112
  export type ToolCallbackWithContext<TInput = Record<string, any>, TOutput extends Record<string, unknown> = Record<string, unknown>, HasOAuth extends boolean = false> = (params: TInput, ctx: EnhancedToolContext<HasOAuth>) => Promise<TypedCallToolResult<TOutput>>;
61
113
  /**
62
- * Extract input type from a tool definition's schema
114
+ * Extract input type from a tool definition's schema.
115
+ * Uses z.infer which preserves Zod's optional/default handling.
116
+ *
117
+ * For .optional() fields, the type will be T | undefined
118
+ * For .default() fields, the type will be T (since Zod guarantees a value)
63
119
  */
64
120
  export type InferToolInput<T> = T extends {
65
121
  schema: infer S;
@@ -115,4 +171,5 @@ export interface ToolDefinition<TInput = Record<string, any>, TOutput extends Re
115
171
  /** Metadata for the tool */
116
172
  _meta?: Record<string, unknown>;
117
173
  }
174
+ export {};
118
175
  //# sourceMappingURL=tool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../src/server/types/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,OAAO,GAAG,KAAK,IAC9D,WAAW,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,YAAY,CACtB,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,QA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vB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Hono Proxy Utilities
3
+ *
4
+ * Utilities for creating proxied instances that allow direct access to Hono methods
5
+ * while preserving server functionality.
6
+ */
7
+ import type { Hono as HonoType } from "hono";
8
+ /**
9
+ * Create a proxy that allows direct access to Hono methods
10
+ *
11
+ * Creates a Proxy wrapper that:
12
+ * - Auto-detects and adapts Express middleware to Hono
13
+ * - Proxies all Hono methods to the underlying app
14
+ * - Preserves the target instance's own methods and properties
15
+ *
16
+ * @param target - The target instance to proxy
17
+ * @param app - The Hono app instance
18
+ * @returns Proxied instance with both target and Hono methods
19
+ */
20
+ export declare function createHonoProxy<T extends object>(target: T, app: HonoType): T & HonoType;
21
+ //# sourceMappingURL=hono-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono-proxy.d.ts","sourceRoot":"","sources":["../../../../src/server/utils/hono-proxy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAM7C;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC9C,MAAM,EAAE,CAAC,EACT,GAAG,EAAE,QAAQ,GACZ,CAAC,GAAG,QAAQ,CAqEd"}
@@ -3,4 +3,7 @@
3
3
  */
4
4
  export * from "./response-helpers.js";
5
5
  export * from "./runtime.js";
6
+ export * from "./server-helpers.js";
7
+ export * from "./server-lifecycle.js";
8
+ export * from "./hono-proxy.js";
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * JSON-RPC Helper Utilities
3
+ *
4
+ * Common utilities for creating JSON-RPC notifications, requests, and error responses.
5
+ */
6
+ /**
7
+ * JSON-RPC notification object structure
8
+ */
9
+ export interface JsonRpcNotification {
10
+ jsonrpc: "2.0";
11
+ method: string;
12
+ params?: Record<string, unknown>;
13
+ }
14
+ /**
15
+ * JSON-RPC request object structure
16
+ */
17
+ export interface JsonRpcRequest {
18
+ jsonrpc: "2.0";
19
+ id: string | number;
20
+ method: string;
21
+ params?: Record<string, unknown>;
22
+ }
23
+ /**
24
+ * JSON-RPC error response object structure
25
+ */
26
+ export interface JsonRpcError {
27
+ jsonrpc: "2.0";
28
+ error: {
29
+ code: number;
30
+ message: string;
31
+ data?: unknown;
32
+ };
33
+ id: string | number | null;
34
+ }
35
+ /**
36
+ * Create a JSON-RPC notification object
37
+ *
38
+ * Notifications are one-way messages that don't expect a response.
39
+ *
40
+ * @param method - The notification method name
41
+ * @param params - Optional parameters to include in the notification
42
+ * @returns JSON-RPC notification object
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const notification = createNotification("notifications/resources/list_changed");
47
+ * const notificationWithParams = createNotification("custom/alert", { message: "Hello" });
48
+ * ```
49
+ */
50
+ export declare function createNotification(method: string, params?: Record<string, unknown>): JsonRpcNotification;
51
+ /**
52
+ * Create a JSON-RPC request object
53
+ *
54
+ * Requests are two-way messages that expect a response.
55
+ *
56
+ * @param id - Unique request identifier
57
+ * @param method - The request method name
58
+ * @param params - Optional parameters to include in the request
59
+ * @returns JSON-RPC request object
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const request = createRequest("123", "roots/list", {});
64
+ * ```
65
+ */
66
+ export declare function createRequest(id: string | number, method: string, params?: Record<string, unknown>): JsonRpcRequest;
67
+ /**
68
+ * Create a JSON-RPC error response object
69
+ *
70
+ * @param code - Error code (e.g., -32000 for application errors)
71
+ * @param message - Human-readable error message
72
+ * @param id - Request ID (null if error occurred before ID could be determined)
73
+ * @param data - Optional additional error data
74
+ * @returns JSON-RPC error response object
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const error = createJsonRpcError(-32000, "Session not found", "123");
79
+ * const errorNoId = createJsonRpcError(-32600, "Invalid Request", null);
80
+ * ```
81
+ */
82
+ export declare function createJsonRpcError(code: number, message: string, id?: string | number | null, data?: unknown): JsonRpcError;
83
+ /**
84
+ * Common JSON-RPC error codes
85
+ */
86
+ export declare const JsonRpcErrorCode: {
87
+ readonly PARSE_ERROR: -32700;
88
+ readonly INVALID_REQUEST: -32600;
89
+ readonly METHOD_NOT_FOUND: -32601;
90
+ readonly INVALID_PARAMS: -32602;
91
+ readonly INTERNAL_ERROR: -32603;
92
+ readonly APPLICATION_ERROR: -32000;
93
+ };
94
+ //# sourceMappingURL=jsonrpc-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonrpc-helpers.d.ts","sourceRoot":"","sources":["../../../../src/server/utils/jsonrpc-helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,OAAO,CAAC;KAChB,CAAC;IACF,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,mBAAmB,CAMrB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,MAAM,GAAG,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,cAAc,CAOhB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,EAAE,GAAE,MAAM,GAAG,MAAM,GAAG,IAAW,EACjC,IAAI,CAAC,EAAE,OAAO,GACb,YAAY,CAUd;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;CAQnB,CAAC"}
@@ -8,23 +8,30 @@ export interface TypedCallToolResult<T extends Record<string, unknown> = Record<
8
8
  structuredContent?: T;
9
9
  }
10
10
  /**
11
- * Create a text content response for MCP tools
11
+ * Create a text content response for MCP tools and resources
12
12
  *
13
13
  * @param content - The text content to return
14
14
  * @returns CallToolResult with text content
15
15
  *
16
16
  * @example
17
17
  * ```typescript
18
+ * // For tools
18
19
  * server.tool({
19
20
  * name: 'greet',
20
21
  * schema: z.object({ name: z.string() }),
21
22
  * cb: async ({ name }) => text(`Hello, ${name}!`)
22
23
  * })
24
+ *
25
+ * // For resources
26
+ * server.resource(
27
+ * { name: 'greeting', uri: 'app://greeting' },
28
+ * async () => text('Hello World!')
29
+ * )
23
30
  * ```
24
31
  */
25
32
  export declare function text(content: string): CallToolResult;
26
33
  /**
27
- * Create an image content response for MCP tools
34
+ * Create an image content response for MCP tools and resources
28
35
  *
29
36
  * @param data - The image data (data URL or base64)
30
37
  * @param mimeType - MIME type (e.g., 'image/png', defaults to 'image/png')
@@ -32,10 +39,17 @@ export declare function text(content: string): CallToolResult;
32
39
  *
33
40
  * @example
34
41
  * ```typescript
42
+ * // For tools
35
43
  * server.tool({
36
44
  * name: 'generate-image',
37
45
  * cb: async () => image('data:image/png;base64,...', 'image/png')
38
46
  * })
47
+ *
48
+ * // For resources
49
+ * server.resource(
50
+ * { name: 'logo', uri: 'asset://logo' },
51
+ * async () => image(base64Data, 'image/png')
52
+ * )
39
53
  * ```
40
54
  */
41
55
  export declare function image(data: string, mimeType?: string): CallToolResult;
@@ -77,13 +91,14 @@ export declare function resource(uri: string, mimeType?: string, text?: string):
77
91
  */
78
92
  export declare function error(message: string): CallToolResult;
79
93
  /**
80
- * Create a JSON object response for MCP tools
94
+ * Create a JSON object response for MCP tools and resources
81
95
  *
82
96
  * @param data - The object to return as JSON
83
97
  * @returns TypedCallToolResult with JSON text content and typed structuredContent
84
98
  *
85
99
  * @example
86
100
  * ```typescript
101
+ * // For tools
87
102
  * server.tool({
88
103
  * name: 'get-user-info',
89
104
  * cb: async (_args, _ctx, { auth }) => object({
@@ -91,12 +106,109 @@ export declare function error(message: string): CallToolResult;
91
106
  * email: auth.user.email
92
107
  * })
93
108
  * })
109
+ *
110
+ * // For resources
111
+ * server.resource(
112
+ * { name: 'config', uri: 'config://settings' },
113
+ * async () => object({ theme: 'dark', version: '1.0' })
114
+ * )
94
115
  * ```
95
116
  */
96
117
  export declare function object<T extends Record<string, any>>(data: T): TypedCallToolResult<T>;
97
118
  export declare function array<T extends any[]>(data: T): TypedCallToolResult<{
98
119
  data: T;
99
120
  }>;
121
+ /**
122
+ * Create an HTML content response for MCP tools and resources
123
+ *
124
+ * @param content - The HTML content to return
125
+ * @returns CallToolResult with HTML text content and MIME type metadata
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * server.resource(
130
+ * { name: 'page', uri: 'ui://dashboard' },
131
+ * async () => html('<h1>Dashboard</h1><p>Welcome</p>')
132
+ * )
133
+ * ```
134
+ */
135
+ export declare function html(content: string): CallToolResult;
136
+ /**
137
+ * Create a Markdown content response for MCP tools and resources
138
+ *
139
+ * @param content - The Markdown content to return
140
+ * @returns CallToolResult with Markdown text content and MIME type metadata
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * server.resource(
145
+ * { name: 'readme', uri: 'doc://readme' },
146
+ * async () => markdown('# Welcome\n\nGetting started...')
147
+ * )
148
+ * ```
149
+ */
150
+ export declare function markdown(content: string): CallToolResult;
151
+ /**
152
+ * Create an XML content response for MCP tools and resources
153
+ *
154
+ * @param content - The XML content to return
155
+ * @returns CallToolResult with XML text content and MIME type metadata
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * server.resource(
160
+ * { name: 'sitemap', uri: 'data://sitemap' },
161
+ * async () => xml('<?xml version="1.0"?><root>...</root>')
162
+ * )
163
+ * ```
164
+ */
165
+ export declare function xml(content: string): CallToolResult;
166
+ /**
167
+ * Create a CSS content response for MCP tools and resources
168
+ *
169
+ * @param content - The CSS content to return
170
+ * @returns CallToolResult with CSS text content and MIME type metadata
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * server.resource(
175
+ * { name: 'styles', uri: 'asset://theme.css' },
176
+ * async () => css('body { margin: 0; }')
177
+ * )
178
+ * ```
179
+ */
180
+ export declare function css(content: string): CallToolResult;
181
+ /**
182
+ * Create a JavaScript content response for MCP tools and resources
183
+ *
184
+ * @param content - The JavaScript content to return
185
+ * @returns CallToolResult with JavaScript text content and MIME type metadata
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * server.resource(
190
+ * { name: 'script', uri: 'asset://main.js' },
191
+ * async () => javascript('console.log("Hello");')
192
+ * )
193
+ * ```
194
+ */
195
+ export declare function javascript(content: string): CallToolResult;
196
+ /**
197
+ * Create a binary content response for MCP tools and resources
198
+ *
199
+ * @param base64Data - The base64-encoded binary data
200
+ * @param mimeType - The MIME type of the binary content
201
+ * @returns CallToolResult with binary content and MIME type metadata
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * server.resource(
206
+ * { name: 'document', uri: 'file://document.pdf' },
207
+ * async () => binary(base64PdfData, 'application/pdf')
208
+ * )
209
+ * ```
210
+ */
211
+ export declare function binary(base64Data: string, mimeType: string): CallToolResult;
100
212
  /**
101
213
  * Configuration for widget response utility
102
214
  */