mcp-use 1.9.0 → 1.9.1-canary.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/chunk-2EYAMIT3.js +76 -0
- package/dist/chunk-33U4IA4N.js +337 -0
- package/dist/chunk-362PI25Z.js +110 -0
- package/dist/chunk-LWVK6RXA.js +30 -0
- package/dist/context-storage-NA4MHWOZ.js +13 -0
- package/dist/conversion-5MA4VY3B.js +7 -0
- package/dist/conversion-OTRZZBUU.js +7 -0
- package/dist/src/server/context-storage.d.ts +8 -1
- package/dist/src/server/context-storage.d.ts.map +1 -1
- package/dist/src/server/endpoints/index.d.ts +7 -0
- package/dist/src/server/endpoints/index.d.ts.map +1 -0
- package/dist/src/server/endpoints/mount-mcp.d.ts +21 -0
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -0
- package/dist/src/server/index.cjs +4180 -3956
- package/dist/src/server/index.d.ts +4 -3
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +3590 -3040
- package/dist/src/server/inspector/index.d.ts +5 -0
- package/dist/src/server/inspector/index.d.ts.map +1 -0
- package/dist/src/server/inspector/mount.d.ts +33 -0
- package/dist/src/server/inspector/mount.d.ts.map +1 -0
- package/dist/src/server/logging.d.ts.map +1 -1
- package/dist/src/server/mcp-server.d.ts +91 -770
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/notifications/index.d.ts +7 -0
- package/dist/src/server/notifications/index.d.ts.map +1 -0
- package/dist/src/server/notifications/notification-registration.d.ts +82 -0
- package/dist/src/server/notifications/notification-registration.d.ts.map +1 -0
- package/dist/src/server/oauth/index.d.ts +1 -0
- package/dist/src/server/oauth/index.d.ts.map +1 -1
- package/dist/src/server/oauth/setup.d.ts +28 -0
- package/dist/src/server/oauth/setup.d.ts.map +1 -0
- package/dist/src/server/prompts/conversion.d.ts +22 -0
- package/dist/src/server/prompts/conversion.d.ts.map +1 -0
- package/dist/src/server/prompts/index.d.ts +60 -0
- package/dist/src/server/prompts/index.d.ts.map +1 -0
- package/dist/src/server/resources/conversion.d.ts +20 -0
- package/dist/src/server/resources/conversion.d.ts.map +1 -0
- package/dist/src/server/resources/index.d.ts +117 -0
- package/dist/src/server/resources/index.d.ts.map +1 -0
- package/dist/src/server/resources/subscriptions.d.ts +54 -0
- package/dist/src/server/resources/subscriptions.d.ts.map +1 -0
- package/dist/src/server/roots/index.d.ts +7 -0
- package/dist/src/server/roots/index.d.ts.map +1 -0
- package/dist/src/server/roots/roots-registration.d.ts +56 -0
- package/dist/src/server/roots/roots-registration.d.ts.map +1 -0
- package/dist/src/server/sessions/index.d.ts +6 -0
- package/dist/src/server/sessions/index.d.ts.map +1 -0
- package/dist/src/server/sessions/notifications.d.ts +25 -0
- package/dist/src/server/sessions/notifications.d.ts.map +1 -0
- package/dist/src/server/sessions/session-manager.d.ts +47 -0
- package/dist/src/server/sessions/session-manager.d.ts.map +1 -0
- package/dist/src/server/tools/index.d.ts +10 -0
- package/dist/src/server/tools/index.d.ts.map +1 -0
- package/dist/src/server/tools/schema-helpers.d.ts +54 -0
- package/dist/src/server/tools/schema-helpers.d.ts.map +1 -0
- package/dist/src/server/tools/tool-execution-helpers.d.ts +110 -0
- package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -0
- package/dist/src/server/tools/tool-registration.d.ts +85 -0
- package/dist/src/server/tools/tool-registration.d.ts.map +1 -0
- package/dist/src/server/types/common.d.ts +24 -0
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/index.d.ts +5 -4
- package/dist/src/server/types/index.d.ts.map +1 -1
- package/dist/src/server/types/prompt.d.ts +61 -6
- package/dist/src/server/types/prompt.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +83 -8
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/tool-context.d.ts +252 -0
- package/dist/src/server/types/tool-context.d.ts.map +1 -0
- package/dist/src/server/types/tool.d.ts +62 -5
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/src/server/utils/hono-proxy.d.ts +21 -0
- package/dist/src/server/utils/hono-proxy.d.ts.map +1 -0
- package/dist/src/server/utils/index.d.ts +3 -0
- package/dist/src/server/utils/index.d.ts.map +1 -1
- package/dist/src/server/utils/jsonrpc-helpers.d.ts +94 -0
- package/dist/src/server/utils/jsonrpc-helpers.d.ts.map +1 -0
- package/dist/src/server/utils/response-helpers.d.ts +163 -7
- package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
- package/dist/src/server/utils/server-helpers.d.ts +78 -0
- package/dist/src/server/utils/server-helpers.d.ts.map +1 -0
- package/dist/src/server/utils/server-lifecycle.d.ts +52 -0
- package/dist/src/server/utils/server-lifecycle.d.ts.map +1 -0
- package/dist/src/server/utils/session-helpers.d.ts +55 -0
- package/dist/src/server/utils/session-helpers.d.ts.map +1 -0
- package/dist/src/server/widgets/index.d.ts +30 -0
- package/dist/src/server/widgets/index.d.ts.map +1 -0
- package/dist/src/server/widgets/mcp-ui-adapter.d.ts.map +1 -0
- package/dist/src/server/widgets/mount-widgets-dev.d.ts +28 -0
- package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -0
- package/dist/src/server/widgets/mount-widgets-production.d.ts +27 -0
- package/dist/src/server/widgets/mount-widgets-production.d.ts.map +1 -0
- package/dist/src/server/widgets/setup-widget-routes.d.ts +23 -0
- package/dist/src/server/widgets/setup-widget-routes.d.ts.map +1 -0
- package/dist/src/server/widgets/ui-resource-registration.d.ts +75 -0
- package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -0
- package/dist/src/server/widgets/widget-helpers.d.ts +277 -0
- package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -0
- package/dist/src/server/widgets/widget-types.d.ts +49 -0
- package/dist/src/server/widgets/widget-types.d.ts.map +1 -0
- package/dist/tool-execution-helpers-BQJTPWPN.js +29 -0
- package/package.json +6 -5
- package/dist/chunk-F4UHAA5L.js +0 -854
- package/dist/oauth-U4NNKN4B.js +0 -30
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +0 -1
- /package/dist/src/server/{adapters → widgets}/mcp-ui-adapter.d.ts +0 -0
|
@@ -1,198 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { McpServer as OfficialMcpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { CreateMessageRequest, CreateMessageResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { Hono as HonoType } from "hono";
|
|
4
|
+
import { toolRegistration, convertZodSchemaToParams, createParamsSchema } from "./tools/index.js";
|
|
5
|
+
import { registerResource, registerResourceTemplate } from "./resources/index.js";
|
|
6
|
+
import { registerPrompt } from "./prompts/index.js";
|
|
7
|
+
import type { ToolContext, SampleOptions, ElicitOptions, ElicitFormParams, ElicitUrlParams } from "./types/tool-context.js";
|
|
8
|
+
export type { ToolContext, SampleOptions, ElicitOptions, ElicitFormParams, ElicitUrlParams, };
|
|
9
|
+
import { onRootsChanged, listRoots } from "./roots/index.js";
|
|
10
|
+
import type { SessionData } from "./sessions/index.js";
|
|
11
|
+
import { getActiveSessions, sendNotification, sendNotificationToSession } from "./notifications/index.js";
|
|
12
|
+
import type { ServerConfig } from "./types/index.js";
|
|
13
|
+
import { parseTemplateUri as parseTemplateUriHelper } from "./utils/index.js";
|
|
14
|
+
export declare class McpServer {
|
|
15
|
+
/**
|
|
16
|
+
* Native MCP server instance from @modelcontextprotocol/sdk
|
|
17
|
+
* Exposed publicly for advanced use cases
|
|
18
|
+
*/
|
|
19
|
+
readonly nativeServer: OfficialMcpServer;
|
|
20
|
+
/** @deprecated Use nativeServer instead - kept for backward compatibility */
|
|
21
|
+
get server(): OfficialMcpServer;
|
|
22
|
+
private config;
|
|
23
|
+
app: HonoType;
|
|
24
|
+
private mcpMounted;
|
|
25
|
+
private inspectorMounted;
|
|
26
|
+
serverPort?: number;
|
|
27
|
+
serverHost: string;
|
|
28
|
+
serverBaseUrl?: string;
|
|
29
|
+
registeredTools: string[];
|
|
30
|
+
registeredPrompts: string[];
|
|
31
|
+
registeredResources: string[];
|
|
32
|
+
buildId?: string;
|
|
33
|
+
sessions: Map<string, SessionData>;
|
|
34
|
+
private idleCleanupInterval?;
|
|
35
|
+
private oauthConfig?;
|
|
36
|
+
private oauthSetupState;
|
|
37
|
+
private oauthProvider?;
|
|
38
|
+
private oauthMiddleware?;
|
|
13
39
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* Progress notifications are sent to the client to prevent timeout
|
|
17
|
-
* when the client has resetTimeoutOnProgress enabled.
|
|
40
|
+
* Storage for registration "recipes" that can be replayed on new server instances
|
|
41
|
+
* Following the official SDK pattern where each session gets its own server instance
|
|
18
42
|
*/
|
|
19
|
-
|
|
43
|
+
private registrationRecipes;
|
|
20
44
|
/**
|
|
21
|
-
*
|
|
22
|
-
* Useful for logging or custom progress handling.
|
|
45
|
+
* Resource subscription manager for tracking and notifying resource updates
|
|
23
46
|
*/
|
|
24
|
-
|
|
25
|
-
progress: number;
|
|
26
|
-
total?: number;
|
|
27
|
-
message: string;
|
|
28
|
-
}) => void;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Options for the elicit() function in tool context.
|
|
32
|
-
*/
|
|
33
|
-
export interface ElicitOptions {
|
|
47
|
+
private subscriptionManager;
|
|
34
48
|
/**
|
|
35
|
-
*
|
|
36
|
-
* Default: no timeout (Infinity) - waits indefinitely for user response.
|
|
37
|
-
* Set this if you want to limit how long to wait for user input.
|
|
49
|
+
* Clean up resource subscriptions for a closed session
|
|
38
50
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* // Wait indefinitely (default)
|
|
42
|
-
* await ctx.elicit(message, schema);
|
|
51
|
+
* This method is called automatically when a session is closed to remove
|
|
52
|
+
* all resource subscriptions associated with that session.
|
|
43
53
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* ```
|
|
54
|
+
* @param sessionId - The session ID to clean up
|
|
55
|
+
* @internal
|
|
47
56
|
*/
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Parameters for form mode elicitation.
|
|
52
|
-
* Used to request structured data from users with optional JSON schema validation.
|
|
53
|
-
*/
|
|
54
|
-
export interface ElicitFormParams {
|
|
55
|
-
/** Human-readable message explaining why the information is needed */
|
|
56
|
-
message: string;
|
|
57
|
-
/** JSON Schema defining the structure of the expected response */
|
|
58
|
-
requestedSchema: Record<string, any>;
|
|
59
|
-
/** Mode specifier (optional for backwards compatibility, defaults to "form") */
|
|
60
|
-
mode?: "form";
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Parameters for URL mode elicitation.
|
|
64
|
-
* Used to direct users to external URLs for sensitive interactions.
|
|
65
|
-
* MUST be used for interactions involving sensitive information like credentials.
|
|
66
|
-
*/
|
|
67
|
-
export interface ElicitUrlParams {
|
|
68
|
-
/** Human-readable message explaining why the interaction is needed */
|
|
69
|
-
message: string;
|
|
70
|
-
/** URL for the user to navigate to */
|
|
71
|
-
url: string;
|
|
72
|
-
/** Mode specifier (required for URL mode) */
|
|
73
|
-
mode: "url";
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Context object passed to tool callbacks.
|
|
77
|
-
* Provides access to sampling, elicitation, and progress reporting capabilities.
|
|
78
|
-
*/
|
|
79
|
-
export interface ToolContext {
|
|
80
|
-
/**
|
|
81
|
-
* Request sampling from the client's LLM with automatic progress notifications.
|
|
82
|
-
*
|
|
83
|
-
* Progress notifications are sent every 5 seconds (configurable) while waiting
|
|
84
|
-
* for the sampling response. This prevents client-side timeouts when the client
|
|
85
|
-
* has `resetTimeoutOnProgress: true` enabled.
|
|
86
|
-
*
|
|
87
|
-
* By default, there is no timeout - the function waits indefinitely for the
|
|
88
|
-
* LLM response. Set `options.timeout` to limit the wait time.
|
|
89
|
-
*
|
|
90
|
-
* @param params - Sampling parameters (messages, model preferences, etc.)
|
|
91
|
-
* @param options - Optional configuration for timeout and progress
|
|
92
|
-
* @returns The sampling result from the client's LLM
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* // Basic usage - waits indefinitely with automatic progress notifications
|
|
97
|
-
* const result = await ctx.sample({
|
|
98
|
-
* messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
|
|
99
|
-
* });
|
|
100
|
-
*
|
|
101
|
-
* // With timeout and custom progress handling
|
|
102
|
-
* const result = await ctx.sample(
|
|
103
|
-
* { messages: [...] },
|
|
104
|
-
* {
|
|
105
|
-
* timeout: 120000, // 2 minute timeout
|
|
106
|
-
* progressIntervalMs: 3000, // Report progress every 3 seconds
|
|
107
|
-
* onProgress: ({ progress, message }) => console.log(message),
|
|
108
|
-
* }
|
|
109
|
-
* );
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
sample: (params: CreateMessageRequest["params"], options?: SampleOptions) => Promise<CreateMessageResult>;
|
|
113
|
-
/**
|
|
114
|
-
* Request user input via the client through elicitation.
|
|
115
|
-
*
|
|
116
|
-
* Supports two modes with automatic mode detection:
|
|
117
|
-
* - **Form mode**: Pass a Zod schema as second parameter - collects structured data
|
|
118
|
-
* - **URL mode**: Pass a URL string as second parameter - directs to external URL
|
|
119
|
-
* - **Verbose mode**: Pass an object with explicit mode for backwards compatibility
|
|
120
|
-
*
|
|
121
|
-
* By default, there is no timeout - waits indefinitely for user response.
|
|
122
|
-
* Set `options.timeout` to limit the wait time.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```typescript
|
|
126
|
-
* // Form mode (simplified) - automatically inferred from Zod schema
|
|
127
|
-
* const result = await ctx.elicit(
|
|
128
|
-
* "Please provide your information",
|
|
129
|
-
* z.object({
|
|
130
|
-
* name: z.string().default("Anonymous"),
|
|
131
|
-
* age: z.number().default(0)
|
|
132
|
-
* })
|
|
133
|
-
* );
|
|
134
|
-
* // result.data is typed as { name: string, age: number }
|
|
135
|
-
*
|
|
136
|
-
* // With timeout
|
|
137
|
-
* const result = await ctx.elicit(
|
|
138
|
-
* "Enter info",
|
|
139
|
-
* z.object({ name: z.string() }),
|
|
140
|
-
* { timeout: 60000 } // 1 minute timeout
|
|
141
|
-
* );
|
|
142
|
-
*
|
|
143
|
-
* // URL mode (simplified) - automatically inferred from URL string
|
|
144
|
-
* const authResult = await ctx.elicit(
|
|
145
|
-
* "Please authorize access",
|
|
146
|
-
* "https://example.com/oauth/authorize"
|
|
147
|
-
* );
|
|
148
|
-
*
|
|
149
|
-
* // Verbose API (backwards compatible)
|
|
150
|
-
* const verboseResult = await ctx.elicit({
|
|
151
|
-
* message: "Please provide your information",
|
|
152
|
-
* requestedSchema: { type: "object", properties: {...} },
|
|
153
|
-
* mode: "form"
|
|
154
|
-
* });
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
elicit: {
|
|
158
|
-
<T extends z.ZodObject<any>>(message: string, schema: T, options?: ElicitOptions): Promise<ElicitResult & {
|
|
159
|
-
data: z.infer<T>;
|
|
160
|
-
}>;
|
|
161
|
-
(message: string, url: string, options?: ElicitOptions): Promise<ElicitResult>;
|
|
162
|
-
(params: ElicitFormParams | ElicitUrlParams, options?: ElicitOptions): Promise<ElicitResult>;
|
|
163
|
-
};
|
|
164
|
-
/**
|
|
165
|
-
* Send a progress notification to the client.
|
|
166
|
-
* Only available if the client requested progress updates for this tool call.
|
|
167
|
-
*
|
|
168
|
-
* @param progress - Current progress value (should increase with each call)
|
|
169
|
-
* @param total - Total progress value if known
|
|
170
|
-
* @param message - Optional message describing current progress
|
|
171
|
-
*/
|
|
172
|
-
reportProgress?: (progress: number, total?: number, message?: string) => Promise<void>;
|
|
173
|
-
}
|
|
174
|
-
import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
175
|
-
import { type Hono as HonoType } from "hono";
|
|
176
|
-
import type { PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ServerConfig, ToolDefinition, ToolCallback, UIResourceDefinition, InferToolInput, InferToolOutput } from "./types/index.js";
|
|
177
|
-
export declare class McpServer<HasOAuth extends boolean = false> {
|
|
178
|
-
private server;
|
|
179
|
-
private config;
|
|
180
|
-
private app;
|
|
181
|
-
private mcpMounted;
|
|
182
|
-
private inspectorMounted;
|
|
183
|
-
private serverPort?;
|
|
184
|
-
private serverHost;
|
|
185
|
-
private serverBaseUrl?;
|
|
186
|
-
private registeredTools;
|
|
187
|
-
private registeredPrompts;
|
|
188
|
-
private registeredResources;
|
|
189
|
-
private buildId?;
|
|
190
|
-
private sessions;
|
|
191
|
-
private idleCleanupInterval?;
|
|
192
|
-
private oauthProvider?;
|
|
193
|
-
private oauthMiddleware?;
|
|
194
|
-
private oauthConfig?;
|
|
195
|
-
private oauthSetupComplete;
|
|
57
|
+
cleanupSessionSubscriptions(sessionId: string): void;
|
|
196
58
|
/**
|
|
197
59
|
* Creates a new MCP server instance with Hono integration
|
|
198
60
|
*
|
|
@@ -205,407 +67,53 @@ export declare class McpServer<HasOAuth extends boolean = false> {
|
|
|
205
67
|
*/
|
|
206
68
|
constructor(config: ServerConfig);
|
|
207
69
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*/
|
|
211
|
-
private getServerBaseUrl;
|
|
212
|
-
/**
|
|
213
|
-
* Gets additional CSP URLs from environment variable
|
|
214
|
-
* Supports comma-separated list or single URL
|
|
215
|
-
* @returns Array of URLs to add to CSP resource_domains
|
|
216
|
-
*/
|
|
217
|
-
private getCSPUrls;
|
|
218
|
-
/**
|
|
219
|
-
* Setup OAuth authentication
|
|
220
|
-
*
|
|
221
|
-
* Initializes OAuth provider, creates bearer auth middleware,
|
|
222
|
-
* sets up OAuth routes, and applies auth to /mcp endpoints.
|
|
223
|
-
*
|
|
224
|
-
* @private
|
|
225
|
-
*/
|
|
226
|
-
private setupOAuth;
|
|
227
|
-
/**
|
|
228
|
-
* Define a static resource that can be accessed by clients
|
|
229
|
-
*
|
|
230
|
-
* Registers a resource with the MCP server that clients can access via HTTP.
|
|
231
|
-
* Resources are static content like files, data, or pre-computed results that
|
|
232
|
-
* can be retrieved by clients without requiring parameters.
|
|
233
|
-
*
|
|
234
|
-
* @param resourceDefinition - Configuration object containing resource metadata and handler function
|
|
235
|
-
* @param resourceDefinition.name - Unique identifier for the resource
|
|
236
|
-
* @param resourceDefinition.uri - URI pattern for accessing the resource
|
|
237
|
-
* @param resourceDefinition.title - Optional human-readable title for the resource
|
|
238
|
-
* @param resourceDefinition.description - Optional description of the resource
|
|
239
|
-
* @param resourceDefinition.mimeType - MIME type of the resource content
|
|
240
|
-
* @param resourceDefinition.annotations - Optional annotations (audience, priority, lastModified)
|
|
241
|
-
* @param resourceDefinition.readCallback - Async callback function that returns the resource content
|
|
242
|
-
* @returns The server instance for method chaining
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```typescript
|
|
246
|
-
* server.resource({
|
|
247
|
-
* name: 'config',
|
|
248
|
-
* uri: 'config://app-settings',
|
|
249
|
-
* title: 'Application Settings',
|
|
250
|
-
* mimeType: 'application/json',
|
|
251
|
-
* description: 'Current application configuration',
|
|
252
|
-
* annotations: {
|
|
253
|
-
* audience: ['user'],
|
|
254
|
-
* priority: 0.8
|
|
255
|
-
* },
|
|
256
|
-
* readCallback: async () => ({
|
|
257
|
-
* contents: [{
|
|
258
|
-
* uri: 'config://app-settings',
|
|
259
|
-
* mimeType: 'application/json',
|
|
260
|
-
* text: JSON.stringify({ theme: 'dark', language: 'en' })
|
|
261
|
-
* }]
|
|
262
|
-
* })
|
|
263
|
-
* })
|
|
264
|
-
* ```
|
|
70
|
+
* Wrap registration methods to capture recipes following official SDK pattern.
|
|
71
|
+
* Each session will get a fresh server instance with all registrations replayed.
|
|
265
72
|
*/
|
|
266
|
-
|
|
73
|
+
private wrapRegistrationMethods;
|
|
267
74
|
/**
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* Registers a parameterized resource template with the MCP server. Templates use URI
|
|
271
|
-
* patterns with placeholders that can be filled in at request time, allowing dynamic
|
|
272
|
-
* resource generation based on parameters.
|
|
273
|
-
*
|
|
274
|
-
* @param resourceTemplateDefinition - Configuration object for the resource template
|
|
275
|
-
* @param resourceTemplateDefinition.name - Unique identifier for the template
|
|
276
|
-
* @param resourceTemplateDefinition.resourceTemplate - ResourceTemplate object with uriTemplate and metadata
|
|
277
|
-
* @param resourceTemplateDefinition.readCallback - Async callback function that generates resource content from URI and params
|
|
278
|
-
* @returns The server instance for method chaining
|
|
279
|
-
*
|
|
280
|
-
* @example
|
|
281
|
-
* ```typescript
|
|
282
|
-
* server.resourceTemplate({
|
|
283
|
-
* name: 'user-profile',
|
|
284
|
-
* resourceTemplate: {
|
|
285
|
-
* uriTemplate: 'user://{userId}/profile',
|
|
286
|
-
* name: 'User Profile',
|
|
287
|
-
* mimeType: 'application/json'
|
|
288
|
-
* },
|
|
289
|
-
* readCallback: async (uri, params) => ({
|
|
290
|
-
* contents: [{
|
|
291
|
-
* uri: uri.toString(),
|
|
292
|
-
* mimeType: 'application/json',
|
|
293
|
-
* text: JSON.stringify({ userId: params.userId, name: 'John Doe' })
|
|
294
|
-
* }]
|
|
295
|
-
* })
|
|
296
|
-
* })
|
|
297
|
-
* ```
|
|
75
|
+
* Create a new server instance for a session following official SDK pattern.
|
|
76
|
+
* This is called for each initialize request to create an isolated server.
|
|
298
77
|
*/
|
|
299
|
-
|
|
78
|
+
getServerForSession(): OfficialMcpServer;
|
|
300
79
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* Registers a tool with the MCP server that clients can invoke with parameters.
|
|
304
|
-
* Tools are functions that perform actions, computations, or operations and
|
|
305
|
-
* return results. They accept structured input parameters and return structured output.
|
|
306
|
-
*
|
|
307
|
-
* Supports Apps SDK metadata for ChatGPT integration via the _meta field.
|
|
308
|
-
*
|
|
309
|
-
* @param toolDefinition - Configuration object containing tool metadata and handler function
|
|
310
|
-
* @param toolDefinition.name - Unique identifier for the tool
|
|
311
|
-
* @param toolDefinition.description - Optional human-readable description of what the tool does
|
|
312
|
-
* @param toolDefinition.inputs - Array of input parameter definitions (legacy, use schema instead)
|
|
313
|
-
* @param toolDefinition.schema - Zod object schema for input validation (preferred)
|
|
314
|
-
* @param toolDefinition.outputSchema - Zod object schema for structured output validation
|
|
315
|
-
* @param toolDefinition.cb - Async callback function that executes the tool logic with provided parameters
|
|
316
|
-
* @param toolDefinition._meta - Optional metadata for the tool (e.g. Apps SDK metadata)
|
|
317
|
-
* @param callback - Optional separate callback function (alternative to cb property)
|
|
318
|
-
* @returns The server instance for method chaining
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* ```typescript
|
|
322
|
-
* // Using Zod schema (preferred)
|
|
323
|
-
* server.tool({
|
|
324
|
-
* name: 'calculate',
|
|
325
|
-
* description: 'Performs mathematical calculations',
|
|
326
|
-
* schema: z.object({
|
|
327
|
-
* expression: z.string(),
|
|
328
|
-
* precision: z.number().optional()
|
|
329
|
-
* }),
|
|
330
|
-
* cb: async ({ expression, precision = 2 }) => {
|
|
331
|
-
* const result = eval(expression)
|
|
332
|
-
* return text(`Result: ${result.toFixed(precision)}`)
|
|
333
|
-
* }
|
|
334
|
-
* })
|
|
335
|
-
*
|
|
336
|
-
* // Using legacy inputs array
|
|
337
|
-
* server.tool({
|
|
338
|
-
* name: 'greet',
|
|
339
|
-
* inputs: [{ name: 'name', type: 'string', required: true }],
|
|
340
|
-
* cb: async ({ name }) => text(`Hello, ${name}!`)
|
|
341
|
-
* })
|
|
342
|
-
*
|
|
343
|
-
* // With separate callback for better typing
|
|
344
|
-
* server.tool({
|
|
345
|
-
* name: 'add',
|
|
346
|
-
* schema: z.object({ a: z.number(), b: z.number() })
|
|
347
|
-
* }, async ({ a, b }) => text(`${a + b}`))
|
|
348
|
-
* ```
|
|
349
|
-
*/
|
|
350
|
-
tool<T extends ToolDefinition<any, any, HasOAuth>>(toolDefinition: T, callback: ToolCallback<InferToolInput<T>, InferToolOutput<T>, HasOAuth>): this;
|
|
351
|
-
tool<T extends ToolDefinition<any, any, HasOAuth>>(toolDefinition: T): this;
|
|
352
|
-
/**
|
|
353
|
-
* Define a prompt template
|
|
354
|
-
*
|
|
355
|
-
* Registers a prompt template with the MCP server that clients can use to generate
|
|
356
|
-
* structured prompts for AI models. Prompt templates accept parameters and return
|
|
357
|
-
* formatted text that can be used as input to language models or other AI systems.
|
|
358
|
-
*
|
|
359
|
-
* @param promptDefinition - Configuration object containing prompt metadata and handler function
|
|
360
|
-
* @param promptDefinition.name - Unique identifier for the prompt template
|
|
361
|
-
* @param promptDefinition.description - Human-readable description of the prompt's purpose
|
|
362
|
-
* @param promptDefinition.args - Array of argument definitions with types and validation
|
|
363
|
-
* @param promptDefinition.cb - Async callback function that generates the prompt from provided arguments
|
|
364
|
-
* @returns The server instance for method chaining
|
|
365
|
-
*
|
|
366
|
-
* @example
|
|
367
|
-
* ```typescript
|
|
368
|
-
* server.prompt({
|
|
369
|
-
* name: 'code-review',
|
|
370
|
-
* description: 'Generates a code review prompt',
|
|
371
|
-
* args: [
|
|
372
|
-
* { name: 'language', type: 'string', required: true },
|
|
373
|
-
* { name: 'focus', type: 'string', required: false }
|
|
374
|
-
* ],
|
|
375
|
-
* cb: async ({ language, focus = 'general' }) => {
|
|
376
|
-
* return {
|
|
377
|
-
* messages: [{
|
|
378
|
-
* role: 'user',
|
|
379
|
-
* content: `Please review this ${language} code with focus on ${focus}...`
|
|
380
|
-
* }]
|
|
381
|
-
* }
|
|
382
|
-
* }
|
|
383
|
-
* })
|
|
384
|
-
* ```
|
|
385
|
-
*/
|
|
386
|
-
prompt(promptDefinition: PromptDefinition): this;
|
|
387
|
-
/**
|
|
388
|
-
* Request LLM sampling from connected clients.
|
|
389
|
-
*
|
|
390
|
-
* This method allows server tools to request LLM completions from clients
|
|
391
|
-
* that support the sampling capability. The client will handle model selection,
|
|
392
|
-
* user approval (human-in-the-loop), and return the generated response.
|
|
393
|
-
*
|
|
394
|
-
* @param params - Sampling request parameters including messages, model preferences, etc.
|
|
395
|
-
* @param options - Optional request options (timeouts, cancellation, etc.)
|
|
396
|
-
* @returns Promise resolving to the generated message from the client's LLM
|
|
397
|
-
*
|
|
398
|
-
* @example
|
|
399
|
-
* ```typescript
|
|
400
|
-
* // In a tool callback
|
|
401
|
-
* server.tool({
|
|
402
|
-
* name: 'analyze-sentiment',
|
|
403
|
-
* description: 'Analyze sentiment using LLM',
|
|
404
|
-
* inputs: [{ name: 'text', type: 'string', required: true }],
|
|
405
|
-
* cb: async (params, ctx) => {
|
|
406
|
-
* const result = await ctx.sample({
|
|
407
|
-
* messages: [{
|
|
408
|
-
* role: 'user',
|
|
409
|
-
* content: { type: 'text', text: `Analyze sentiment: ${params.text}` }
|
|
410
|
-
* }],
|
|
411
|
-
* modelPreferences: {
|
|
412
|
-
* intelligencePriority: 0.8,
|
|
413
|
-
* speedPriority: 0.5
|
|
414
|
-
* }
|
|
415
|
-
* });
|
|
416
|
-
* return {
|
|
417
|
-
* content: [{ type: 'text', text: result.content.text }]
|
|
418
|
-
* };
|
|
419
|
-
* }
|
|
420
|
-
* })
|
|
421
|
-
* ```
|
|
80
|
+
* Gets the server base URL with fallback to host:port if not configured
|
|
81
|
+
* @returns The complete base URL for the server
|
|
422
82
|
*/
|
|
423
|
-
|
|
83
|
+
private getServerBaseUrl;
|
|
84
|
+
tool: typeof toolRegistration;
|
|
85
|
+
convertZodSchemaToParams: typeof convertZodSchemaToParams;
|
|
86
|
+
createParamsSchema: typeof createParamsSchema;
|
|
87
|
+
parseTemplateUri: typeof parseTemplateUriHelper;
|
|
88
|
+
resource: typeof registerResource;
|
|
89
|
+
resourceTemplate: typeof registerResourceTemplate;
|
|
90
|
+
prompt: typeof registerPrompt;
|
|
91
|
+
getActiveSessions: typeof getActiveSessions;
|
|
92
|
+
sendNotification: typeof sendNotification;
|
|
93
|
+
sendNotificationToSession: typeof sendNotificationToSession;
|
|
424
94
|
/**
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
* Creates a unified interface for MCP-UI compatible widgets that can be accessed
|
|
428
|
-
* either as tools (with parameters) or as resources (static access). The tool
|
|
429
|
-
* allows dynamic parameter passing while the resource provides discoverable access.
|
|
95
|
+
* Notify subscribed clients that a resource has been updated
|
|
430
96
|
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
* - rawHtml: Legacy MCP-UI raw HTML content
|
|
434
|
-
* - remoteDom: Legacy MCP-UI Remote DOM scripting
|
|
435
|
-
* - appsSdk: OpenAI Apps SDK compatible widgets (text/html+skybridge)
|
|
97
|
+
* This method sends a `notifications/resources/updated` notification to all
|
|
98
|
+
* sessions that have subscribed to the specified resource URI.
|
|
436
99
|
*
|
|
437
|
-
* @param
|
|
438
|
-
* @
|
|
439
|
-
* @param definition.type - Type of UI resource (externalUrl, rawHtml, remoteDom, appsSdk)
|
|
440
|
-
* @param definition.title - Human-readable title for the widget
|
|
441
|
-
* @param definition.description - Description of the widget's functionality
|
|
442
|
-
* @param definition.props - Widget properties configuration with types and defaults
|
|
443
|
-
* @param definition.size - Preferred iframe size [width, height] (e.g., ['900px', '600px'])
|
|
444
|
-
* @param definition.annotations - Resource annotations for discovery
|
|
445
|
-
* @param definition.appsSdkMetadata - Apps SDK specific metadata (CSP, widget description, etc.)
|
|
446
|
-
* @returns The server instance for method chaining
|
|
100
|
+
* @param uri - The URI of the resource that changed
|
|
101
|
+
* @returns Promise that resolves when all notifications have been sent
|
|
447
102
|
*
|
|
448
103
|
* @example
|
|
449
104
|
* ```typescript
|
|
450
|
-
* //
|
|
451
|
-
* server.
|
|
452
|
-
*
|
|
453
|
-
* // Legacy MCP-UI widget
|
|
454
|
-
* server.uiResource({
|
|
455
|
-
* type: 'externalUrl',
|
|
456
|
-
* name: 'kanban-board',
|
|
457
|
-
* widget: 'kanban-board',
|
|
458
|
-
* title: 'Kanban Board',
|
|
459
|
-
* description: 'Interactive task management board',
|
|
460
|
-
* props: {
|
|
461
|
-
* initialTasks: {
|
|
462
|
-
* type: 'array',
|
|
463
|
-
* description: 'Initial tasks to display',
|
|
464
|
-
* required: false
|
|
465
|
-
* }
|
|
466
|
-
* },
|
|
467
|
-
* size: ['900px', '600px']
|
|
468
|
-
* })
|
|
469
|
-
*
|
|
470
|
-
* // Apps SDK widget
|
|
471
|
-
* server.uiResource({
|
|
472
|
-
* type: 'appsSdk',
|
|
473
|
-
* name: 'kanban-board',
|
|
474
|
-
* title: 'Kanban Board',
|
|
475
|
-
* description: 'Interactive task management board',
|
|
476
|
-
* htmlTemplate: `
|
|
477
|
-
* <div id="kanban-root"></div>
|
|
478
|
-
* <style>${kanbanCSS}</style>
|
|
479
|
-
* <script type="module">${kanbanJS}</script>
|
|
480
|
-
* `,
|
|
481
|
-
* appsSdkMetadata: {
|
|
482
|
-
* 'openai/widgetDescription': 'Displays an interactive kanban board',
|
|
483
|
-
* 'openai/widgetCSP': {
|
|
484
|
-
* connect_domains: [],
|
|
485
|
-
* resource_domains: ['https://cdn.example.com']
|
|
486
|
-
* }
|
|
487
|
-
* }
|
|
488
|
-
* })
|
|
105
|
+
* // After updating a resource, notify subscribers
|
|
106
|
+
* await server.notifyResourceUpdated("file:///path/to/resource.txt");
|
|
489
107
|
* ```
|
|
490
108
|
*/
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
* Create a UIResource object for a widget with the given parameters
|
|
494
|
-
*
|
|
495
|
-
* This method is shared between tool and resource handlers to avoid duplication.
|
|
496
|
-
* It creates a consistent UIResource structure that can be rendered by MCP-UI
|
|
497
|
-
* compatible clients.
|
|
498
|
-
*
|
|
499
|
-
* @private
|
|
500
|
-
* @param definition - UIResource definition
|
|
501
|
-
* @param params - Parameters to pass to the widget via URL
|
|
502
|
-
* @returns UIResource object compatible with MCP-UI
|
|
503
|
-
*/
|
|
504
|
-
private createWidgetUIResource;
|
|
505
|
-
/**
|
|
506
|
-
* Generate a widget URI with optional build ID for cache busting
|
|
507
|
-
*
|
|
508
|
-
* @private
|
|
509
|
-
* @param widgetName - Widget name/identifier
|
|
510
|
-
* @param extension - Optional file extension (e.g., '.html')
|
|
511
|
-
* @param suffix - Optional suffix (e.g., random ID for dynamic URIs)
|
|
512
|
-
* @returns Widget URI with build ID if available
|
|
513
|
-
*/
|
|
514
|
-
private generateWidgetUri;
|
|
515
|
-
/**
|
|
516
|
-
* Convert widget props definition to tool input schema
|
|
517
|
-
*
|
|
518
|
-
* Transforms the widget props configuration into the format expected by
|
|
519
|
-
* the tool registration system, mapping types and handling defaults.
|
|
520
|
-
*
|
|
521
|
-
* @private
|
|
522
|
-
* @param props - Widget props configuration
|
|
523
|
-
* @returns Array of InputDefinition objects for tool registration
|
|
524
|
-
*/
|
|
525
|
-
private convertPropsToInputs;
|
|
526
|
-
/**
|
|
527
|
-
* Apply default values to widget props
|
|
528
|
-
*
|
|
529
|
-
* Extracts default values from the props configuration to use when
|
|
530
|
-
* the resource is accessed without parameters.
|
|
531
|
-
*
|
|
532
|
-
* @private
|
|
533
|
-
* @param props - Widget props configuration
|
|
534
|
-
* @returns Object with default values for each prop
|
|
535
|
-
*/
|
|
536
|
-
private applyDefaultProps;
|
|
537
|
-
/**
|
|
538
|
-
* Check if server is running in production mode
|
|
539
|
-
*
|
|
540
|
-
* @private
|
|
541
|
-
* @returns true if in production mode, false otherwise
|
|
542
|
-
*/
|
|
543
|
-
private isProductionMode;
|
|
544
|
-
/**
|
|
545
|
-
* Read build manifest file
|
|
546
|
-
*
|
|
547
|
-
* @private
|
|
548
|
-
* @returns Build manifest or null if not found
|
|
549
|
-
*/
|
|
550
|
-
private readBuildManifest;
|
|
551
|
-
/**
|
|
552
|
-
* Mount widget files - automatically chooses between dev and production mode
|
|
553
|
-
*
|
|
554
|
-
* In development mode: creates Vite dev servers with HMR support
|
|
555
|
-
* In production mode: serves pre-built static widgets
|
|
556
|
-
*
|
|
557
|
-
* @param options - Configuration options
|
|
558
|
-
* @param options.baseRoute - Base route for widgets (defaults to '/mcp-use/widgets')
|
|
559
|
-
* @param options.resourcesDir - Directory containing widget files (defaults to 'resources')
|
|
560
|
-
* @returns Promise that resolves when all widgets are mounted
|
|
561
|
-
*/
|
|
562
|
-
mountWidgets(options?: {
|
|
563
|
-
baseRoute?: string;
|
|
564
|
-
resourcesDir?: string;
|
|
565
|
-
}): Promise<void>;
|
|
566
|
-
/**
|
|
567
|
-
* Mount individual widget files from resources/ directory in development mode
|
|
568
|
-
*
|
|
569
|
-
* Scans the resources/ directory for .tsx/.ts widget files and creates individual
|
|
570
|
-
* Vite dev servers for each widget with HMR support. Each widget is served at its
|
|
571
|
-
* own route: /mcp-use/widgets/{widget-name}
|
|
572
|
-
*
|
|
573
|
-
* @private
|
|
574
|
-
* @param options - Configuration options
|
|
575
|
-
* @param options.baseRoute - Base route for widgets (defaults to '/mcp-use/widgets')
|
|
576
|
-
* @param options.resourcesDir - Directory containing widget files (defaults to 'resources')
|
|
577
|
-
* @returns Promise that resolves when all widgets are mounted
|
|
578
|
-
*/
|
|
579
|
-
private mountWidgetsDev;
|
|
580
|
-
/**
|
|
581
|
-
* Mount pre-built widgets from dist/resources/widgets/ directory in production mode
|
|
582
|
-
*
|
|
583
|
-
* Serves static widget bundles that were built using the build command.
|
|
584
|
-
* Sets up Express routes to serve the HTML and asset files, then registers
|
|
585
|
-
* tools and resources for each widget.
|
|
586
|
-
*
|
|
587
|
-
* @private
|
|
588
|
-
* @param options - Configuration options
|
|
589
|
-
* @param options.baseRoute - Base route for widgets (defaults to '/mcp-use/widgets')
|
|
590
|
-
* @returns Promise that resolves when all widgets are mounted
|
|
591
|
-
*/
|
|
592
|
-
private mountWidgetsProduction;
|
|
593
|
-
/**
|
|
594
|
-
* Helper to wait for transport.handleRequest to complete and response to be written
|
|
595
|
-
*
|
|
596
|
-
* Wraps the transport.handleRequest call in a Promise that only resolves when
|
|
597
|
-
* expressRes.end() is called, ensuring all async operations complete before
|
|
598
|
-
* we attempt to read the response.
|
|
599
|
-
*
|
|
600
|
-
* @private
|
|
601
|
-
*/
|
|
602
|
-
private waitForRequestComplete;
|
|
109
|
+
notifyResourceUpdated(uri: string): Promise<void>;
|
|
110
|
+
uiResource: any;
|
|
603
111
|
/**
|
|
604
112
|
* Mount MCP server endpoints at /mcp and /sse
|
|
605
113
|
*
|
|
606
114
|
* Sets up the HTTP transport layer for the MCP server, creating endpoints for
|
|
607
115
|
* Server-Sent Events (SSE) streaming, POST message handling, and DELETE session cleanup.
|
|
608
|
-
*
|
|
116
|
+
* The transport manages multiple sessions through a single server instance.
|
|
609
117
|
*
|
|
610
118
|
* This method is called automatically when the server starts listening and ensures
|
|
611
119
|
* that MCP clients can communicate with the server over HTTP.
|
|
@@ -630,7 +138,7 @@ export declare class McpServer<HasOAuth extends boolean = false> {
|
|
|
630
138
|
* The server will be accessible at the specified port with MCP endpoints at /mcp and /sse
|
|
631
139
|
* and inspector UI at /inspector (if the inspector package is installed).
|
|
632
140
|
*
|
|
633
|
-
* @param port - Port number to listen on (defaults to
|
|
141
|
+
* @param port - Port number to listen on (defaults to 3000 if not specified)
|
|
634
142
|
* @returns Promise that resolves when the server is successfully listening
|
|
635
143
|
*
|
|
636
144
|
* @example
|
|
@@ -645,6 +153,13 @@ export declare class McpServer<HasOAuth extends boolean = false> {
|
|
|
645
153
|
* Log registered tools, prompts, and resources to console
|
|
646
154
|
*/
|
|
647
155
|
private logRegisteredItems;
|
|
156
|
+
getBuildId(): string | undefined;
|
|
157
|
+
getServerPort(): number;
|
|
158
|
+
/**
|
|
159
|
+
* Create a message for sampling (calling the LLM)
|
|
160
|
+
* Delegates to the native SDK server
|
|
161
|
+
*/
|
|
162
|
+
createMessage(params: CreateMessageRequest["params"], options?: any): Promise<CreateMessageResult>;
|
|
648
163
|
listen(port?: number): Promise<void>;
|
|
649
164
|
/**
|
|
650
165
|
* Get the fetch handler for the server after mounting all endpoints
|
|
@@ -682,132 +197,8 @@ export declare class McpServer<HasOAuth extends boolean = false> {
|
|
|
682
197
|
getHandler(options?: {
|
|
683
198
|
provider?: "supabase" | "cloudflare" | "deno-deploy";
|
|
684
199
|
}): Promise<(req: Request) => Promise<Response>>;
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
*
|
|
688
|
-
* Returns an array of all currently active session IDs. This is useful for
|
|
689
|
-
* sending targeted notifications to specific clients or iterating over
|
|
690
|
-
* connected clients.
|
|
691
|
-
*
|
|
692
|
-
* Note: This only works in stateful mode. In stateless mode (edge environments),
|
|
693
|
-
* this will return an empty array.
|
|
694
|
-
*
|
|
695
|
-
* @returns Array of active session ID strings
|
|
696
|
-
*
|
|
697
|
-
* @example
|
|
698
|
-
* ```typescript
|
|
699
|
-
* const sessions = server.getActiveSessions();
|
|
700
|
-
* console.log(`${sessions.length} clients connected`);
|
|
701
|
-
*
|
|
702
|
-
* // Send notification to first connected client
|
|
703
|
-
* if (sessions.length > 0) {
|
|
704
|
-
* server.sendNotificationToSession(sessions[0], "custom/hello", { message: "Hi!" });
|
|
705
|
-
* }
|
|
706
|
-
* ```
|
|
707
|
-
*/
|
|
708
|
-
getActiveSessions(): string[];
|
|
709
|
-
/**
|
|
710
|
-
* Send a notification to all connected clients
|
|
711
|
-
*
|
|
712
|
-
* Broadcasts a JSON-RPC notification to all active sessions. Notifications are
|
|
713
|
-
* one-way messages that do not expect a response from the client.
|
|
714
|
-
*
|
|
715
|
-
* Note: This only works in stateful mode with active sessions. If no sessions
|
|
716
|
-
* are connected, the notification is silently discarded (per MCP spec: "server MAY send").
|
|
717
|
-
*
|
|
718
|
-
* @param method - The notification method name (e.g., "custom/my-notification")
|
|
719
|
-
* @param params - Optional parameters to include in the notification
|
|
720
|
-
*
|
|
721
|
-
* @example
|
|
722
|
-
* ```typescript
|
|
723
|
-
* // Send a simple notification to all clients
|
|
724
|
-
* server.sendNotification("custom/server-status", {
|
|
725
|
-
* status: "ready",
|
|
726
|
-
* timestamp: new Date().toISOString()
|
|
727
|
-
* });
|
|
728
|
-
*
|
|
729
|
-
* // Notify all clients that resources have changed
|
|
730
|
-
* server.sendNotification("notifications/resources/list_changed");
|
|
731
|
-
* ```
|
|
732
|
-
*/
|
|
733
|
-
sendNotification(method: string, params?: Record<string, unknown>): Promise<void>;
|
|
734
|
-
/**
|
|
735
|
-
* Send a notification to a specific client session
|
|
736
|
-
*
|
|
737
|
-
* Sends a JSON-RPC notification to a single client identified by their session ID.
|
|
738
|
-
* This allows sending customized notifications to individual clients.
|
|
739
|
-
*
|
|
740
|
-
* Note: This only works in stateful mode. If the session ID doesn't exist,
|
|
741
|
-
* the notification is silently discarded.
|
|
742
|
-
*
|
|
743
|
-
* @param sessionId - The target session ID (from getActiveSessions())
|
|
744
|
-
* @param method - The notification method name (e.g., "custom/my-notification")
|
|
745
|
-
* @param params - Optional parameters to include in the notification
|
|
746
|
-
* @returns true if the notification was sent, false if session not found
|
|
747
|
-
*
|
|
748
|
-
* @example
|
|
749
|
-
* ```typescript
|
|
750
|
-
* const sessions = server.getActiveSessions();
|
|
751
|
-
*
|
|
752
|
-
* // Send different messages to different clients
|
|
753
|
-
* sessions.forEach((sessionId, index) => {
|
|
754
|
-
* server.sendNotificationToSession(sessionId, "custom/welcome", {
|
|
755
|
-
* message: `Hello client #${index + 1}!`,
|
|
756
|
-
* clientNumber: index + 1
|
|
757
|
-
* });
|
|
758
|
-
* });
|
|
759
|
-
* ```
|
|
760
|
-
*/
|
|
761
|
-
sendNotificationToSession(sessionId: string, method: string, params?: Record<string, unknown>): Promise<boolean>;
|
|
762
|
-
private onRootsChangedCallback?;
|
|
763
|
-
/**
|
|
764
|
-
* Register a callback for when a client's roots change
|
|
765
|
-
*
|
|
766
|
-
* When a client sends a `notifications/roots/list_changed` notification,
|
|
767
|
-
* the server will automatically request the updated roots list and call
|
|
768
|
-
* this callback with the new roots.
|
|
769
|
-
*
|
|
770
|
-
* @param callback - Function called with the updated roots array
|
|
771
|
-
*
|
|
772
|
-
* @example
|
|
773
|
-
* ```typescript
|
|
774
|
-
* server.onRootsChanged(async (roots) => {
|
|
775
|
-
* console.log("Client roots updated:", roots);
|
|
776
|
-
* roots.forEach(root => {
|
|
777
|
-
* console.log(` - ${root.name || "unnamed"}: ${root.uri}`);
|
|
778
|
-
* });
|
|
779
|
-
* });
|
|
780
|
-
* ```
|
|
781
|
-
*/
|
|
782
|
-
onRootsChanged(callback: (roots: Array<{
|
|
783
|
-
uri: string;
|
|
784
|
-
name?: string;
|
|
785
|
-
}>) => void | Promise<void>): this;
|
|
786
|
-
/**
|
|
787
|
-
* Request the current roots list from a specific client session
|
|
788
|
-
*
|
|
789
|
-
* This sends a `roots/list` request to the client and returns
|
|
790
|
-
* the list of roots the client has configured.
|
|
791
|
-
*
|
|
792
|
-
* @param sessionId - The session ID of the client to query
|
|
793
|
-
* @returns Array of roots, or null if the session doesn't exist or request fails
|
|
794
|
-
*
|
|
795
|
-
* @example
|
|
796
|
-
* ```typescript
|
|
797
|
-
* const sessions = server.getActiveSessions();
|
|
798
|
-
* if (sessions.length > 0) {
|
|
799
|
-
* const roots = await server.listRoots(sessions[0]);
|
|
800
|
-
* if (roots) {
|
|
801
|
-
* console.log(`Client has ${roots.length} roots:`);
|
|
802
|
-
* roots.forEach(r => console.log(` - ${r.uri}`));
|
|
803
|
-
* }
|
|
804
|
-
* }
|
|
805
|
-
* ```
|
|
806
|
-
*/
|
|
807
|
-
listRoots(sessionId: string): Promise<Array<{
|
|
808
|
-
uri: string;
|
|
809
|
-
name?: string;
|
|
810
|
-
}> | null>;
|
|
200
|
+
onRootsChanged: typeof onRootsChanged;
|
|
201
|
+
listRoots: typeof listRoots;
|
|
811
202
|
/**
|
|
812
203
|
* Mount MCP Inspector UI at /inspector
|
|
813
204
|
*
|
|
@@ -831,78 +222,8 @@ export declare class McpServer<HasOAuth extends boolean = false> {
|
|
|
831
222
|
* - No inspector UI available
|
|
832
223
|
*/
|
|
833
224
|
private mountInspector;
|
|
834
|
-
/**
|
|
835
|
-
* Setup default widget serving routes
|
|
836
|
-
*
|
|
837
|
-
* Configures Hono routes to serve MCP UI widgets and their static assets.
|
|
838
|
-
* Widgets are served from the dist/resources/widgets directory and can
|
|
839
|
-
* be accessed via HTTP endpoints for embedding in web applications.
|
|
840
|
-
*
|
|
841
|
-
* Routes created:
|
|
842
|
-
* - GET /mcp-use/widgets/:widget - Serves widget's index.html
|
|
843
|
-
* - GET /mcp-use/widgets/:widget/assets/* - Serves widget-specific assets
|
|
844
|
-
* - GET /mcp-use/widgets/assets/* - Fallback asset serving with auto-discovery
|
|
845
|
-
*
|
|
846
|
-
* @private
|
|
847
|
-
* @returns void
|
|
848
|
-
*
|
|
849
|
-
* @example
|
|
850
|
-
* Widget routes:
|
|
851
|
-
* - http://localhost:3001/mcp-use/widgets/kanban-board
|
|
852
|
-
* - http://localhost:3001/mcp-use/widgets/todo-list/assets/style.css
|
|
853
|
-
* - http://localhost:3001/mcp-use/widgets/assets/script.js (auto-discovered)
|
|
854
|
-
*/
|
|
855
|
-
private setupWidgetRoutes;
|
|
856
|
-
/**
|
|
857
|
-
* Convert a Zod object schema to the internal Record<string, z.ZodSchema> format
|
|
858
|
-
*
|
|
859
|
-
* @param zodSchema - Zod object schema to convert
|
|
860
|
-
* @returns Object mapping parameter names to Zod validation schemas
|
|
861
|
-
*/
|
|
862
|
-
private convertZodSchemaToParams;
|
|
863
|
-
/**
|
|
864
|
-
* Create input schema for tools
|
|
865
|
-
*
|
|
866
|
-
* Converts tool input definitions into Zod validation schemas for runtime validation.
|
|
867
|
-
* Supports common data types (string, number, boolean, object, array) and optional
|
|
868
|
-
* parameters. Used internally when registering tools with the MCP server.
|
|
869
|
-
*
|
|
870
|
-
* @param inputs - Array of input parameter definitions with name, type, and optional flag
|
|
871
|
-
* @returns Object mapping parameter names to Zod validation schemas
|
|
872
|
-
*
|
|
873
|
-
* @example
|
|
874
|
-
* ```typescript
|
|
875
|
-
* const schema = this.createParamsSchema([
|
|
876
|
-
* { name: 'query', type: 'string', required: true, description: 'Search query' },
|
|
877
|
-
* { name: 'limit', type: 'number', required: false }
|
|
878
|
-
* ])
|
|
879
|
-
* // Returns: { query: z.string().describe('Search query'), limit: z.number().optional() }
|
|
880
|
-
* ```
|
|
881
|
-
*/
|
|
882
|
-
private createParamsSchema;
|
|
883
|
-
/**
|
|
884
|
-
* Parse parameter values from a URI based on a template
|
|
885
|
-
*
|
|
886
|
-
* Extracts parameter values from an actual URI by matching it against a URI template.
|
|
887
|
-
* The template contains placeholders like {param} which are extracted as key-value pairs.
|
|
888
|
-
*
|
|
889
|
-
* @param template - URI template with placeholders (e.g., "user://{userId}/posts/{postId}")
|
|
890
|
-
* @param uri - Actual URI to parse (e.g., "user://123/posts/456")
|
|
891
|
-
* @returns Object mapping parameter names to their values
|
|
892
|
-
*
|
|
893
|
-
* @example
|
|
894
|
-
* ```typescript
|
|
895
|
-
* const params = this.parseTemplateUri("user://{userId}/posts/{postId}", "user://123/posts/456")
|
|
896
|
-
* // Returns: { userId: "123", postId: "456" }
|
|
897
|
-
* ```
|
|
898
|
-
*/
|
|
899
|
-
private parseTemplateUri;
|
|
900
225
|
}
|
|
901
|
-
export type McpServerInstance
|
|
902
|
-
getHandler: (options?: {
|
|
903
|
-
provider?: "supabase" | "cloudflare" | "deno-deploy";
|
|
904
|
-
}) => Promise<(req: Request) => Promise<Response>>;
|
|
905
|
-
};
|
|
226
|
+
export type McpServerInstance = McpServer & HonoType;
|
|
906
227
|
/**
|
|
907
228
|
* Create a new MCP server instance
|
|
908
229
|
*
|
|
@@ -951,6 +272,6 @@ export type McpServerInstance<HasOAuth extends boolean = false> = Omit<McpServer
|
|
|
951
272
|
*/
|
|
952
273
|
export declare function createMCPServer(name: string, config: Partial<ServerConfig> & {
|
|
953
274
|
oauth: NonNullable<ServerConfig["oauth"]>;
|
|
954
|
-
}): McpServerInstance
|
|
955
|
-
export declare function createMCPServer(name: string, config?: Partial<ServerConfig>): McpServerInstance
|
|
275
|
+
}): McpServerInstance;
|
|
276
|
+
export declare function createMCPServer(name: string, config?: Partial<ServerConfig>): McpServerInstance;
|
|
956
277
|
//# sourceMappingURL=mcp-server.d.ts.map
|