@vitemcp/server 1.0.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.
@@ -0,0 +1,400 @@
1
+ import { CacheScope, InputRequest, InputRequiredResult, ToolAnnotations, McpServer } from '@modelcontextprotocol/server';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ import { Hono } from 'hono';
4
+ import { cors } from 'hono/cors';
5
+ export { setTimeout as delay } from 'timers/promises';
6
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-Cg7nUJJT.js';
7
+ export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-Cg7nUJJT.js';
8
+
9
+ declare class DiscoveryDocumentCache {
10
+ #private;
11
+ get size(): number;
12
+ /**
13
+ * @param options - configuration options
14
+ * @param options.timeoutMs - timeout in miliseconds for the upstream fetch
15
+ * @param options.ttl - time-to-live in miliseconds
16
+ */
17
+ constructor(options?: {
18
+ timeoutMs?: number;
19
+ ttl?: number;
20
+ });
21
+ /**
22
+ * @param url - optional URL to clear. if omitted, clears all cached documents.
23
+ */
24
+ clear(url?: string): void;
25
+ /**
26
+ * fetches a discovery document from the given URL.
27
+ * uses cached value if available and not expired.
28
+ * coalesces concurrent requests for the same URL to prevent duplicate fetches.
29
+ *
30
+ * @param url - the discovery document URL (e.g., /.well-known/openid-configuration)
31
+ * @returns the discovery document as a JSON object
32
+ * @throws Error if the fetch fails or returns non-OK status
33
+ */
34
+ get(url: string): Promise<unknown>;
35
+ /**
36
+ * @param url - the URL to check
37
+ * @returns true if the URL is cached and nott expired
38
+ */
39
+ has(url: string): boolean;
40
+ }
41
+
42
+ /**
43
+ * A plain JSON Schema object descriptor.
44
+ */
45
+ type JsonSchemaObject = {
46
+ [key: string]: unknown;
47
+ $schema?: string;
48
+ additionalProperties?: boolean;
49
+ properties?: Record<string, unknown>;
50
+ required?: string[];
51
+ type: string;
52
+ };
53
+ /**
54
+ * A Standard Schema that also carries the JSON Schema it was built from.
55
+ *
56
+ * `~standard.jsonSchema` is the Standard JSON Schema extension. Anything that
57
+ * knows about it — including the `xsschema` conversion ViteMCP uses to build
58
+ * `tools/list` — reads the schema straight off the object instead of trying to
59
+ * derive one from a validation library it does not recognise.
60
+ */
61
+ interface JsonSchemaStandardSchema extends StandardSchemaV1 {
62
+ readonly "~standard": {
63
+ readonly jsonSchema: {
64
+ readonly input: () => JsonSchemaObject;
65
+ readonly output: () => JsonSchemaObject;
66
+ };
67
+ } & StandardSchemaV1.Props;
68
+ }
69
+ /**
70
+ * Wraps a plain JSON Schema object for use as a tool's `parameters` or
71
+ * `outputSchema`, without pulling in Zod or Valibot.
72
+ *
73
+ * Validation uses AJV, an optional peer dependency — install `ajv` (plus
74
+ * `ajv-formats` for `format` keywords). It is imported on first validation, so
75
+ * servers that never call it pay nothing.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * server.addTool({
80
+ * name: "greet",
81
+ * parameters: jsonSchemaAdapter({
82
+ * type: "object",
83
+ * properties: { name: { type: "string" } },
84
+ * required: ["name"],
85
+ * }),
86
+ * execute: async ({ name }) => `Hello, ${name}!`,
87
+ * });
88
+ * ```
89
+ */
90
+ declare function jsonSchemaAdapter(schema: JsonSchemaObject): JsonSchemaStandardSchema;
91
+
92
+ interface Logger {
93
+ debug: (...args: unknown[]) => void;
94
+ error: (...args: unknown[]) => void;
95
+ info: (...args: unknown[]) => void;
96
+ log: (...args: unknown[]) => void;
97
+ warn: (...args: unknown[]) => void;
98
+ }
99
+ declare const MEDIA_FETCH_TIMEOUT_MS = 30000;
100
+ type MediaSource = {
101
+ timeoutMs?: number;
102
+ } & ({
103
+ buffer: Buffer;
104
+ } | {
105
+ path: string;
106
+ } | {
107
+ url: string;
108
+ });
109
+ declare abstract class ViteMCPError extends Error {
110
+ constructor(message?: string);
111
+ }
112
+ declare class UnexpectedStateError extends ViteMCPError {
113
+ extras?: Record<string, unknown>;
114
+ constructor(message: string, extras?: Record<string, unknown>);
115
+ }
116
+ /**
117
+ * An error that is meant to be surfaced to the user, rather than logged as an
118
+ * internal failure. Thrown from a tool handler, it becomes the tool's error
119
+ * result rather than a protocol-level error.
120
+ */
121
+ declare class UserError extends UnexpectedStateError {
122
+ }
123
+ declare const imageContent: (source: MediaSource) => Promise<ImageContent>;
124
+ declare const audioContent: (source: MediaSource) => Promise<AudioContent>;
125
+ declare enum ServerState {
126
+ Error = "error",
127
+ Running = "running",
128
+ Starting = "starting",
129
+ Stopped = "stopped"
130
+ }
131
+ type AudioContent = {
132
+ data: string;
133
+ mimeType: string;
134
+ type: "audio";
135
+ };
136
+ /**
137
+ * Freshness hint attached to cacheable results (`tools/list`, `prompts/list`,
138
+ * `resources/list`, `resources/templates/list`, `resources/read`). Required by
139
+ * the 2026-07-28 revision's `CacheableResult`.
140
+ */
141
+ type CacheHint = {
142
+ cacheScope?: CacheScope;
143
+ ttlMs?: number;
144
+ };
145
+ /** The spec's completion payload. */
146
+ type Completion = {
147
+ hasMore?: boolean;
148
+ total?: number;
149
+ values: string[];
150
+ };
151
+ type Content = AudioContent | ImageContent | ResourceContent | ResourceLink | TextContent;
152
+ type ContentResult = {
153
+ content: Content[];
154
+ isError?: boolean;
155
+ structuredContent?: unknown;
156
+ };
157
+ /**
158
+ * Context handed to `execute` / `load`. Everything here is per-request: the
159
+ * 2026-07-28 revision has no protocol session.
160
+ */
161
+ type Context<T extends ViteMCPAuth> = {
162
+ /** Authentication result for this request, if an `authenticate` hook ran. */
163
+ auth: T | undefined;
164
+ /**
165
+ * Builds an elicitation request for {@link Context.inputRequired}.
166
+ *
167
+ * A builder, not a promise — the server cannot block waiting for a reply.
168
+ * The client re-issues the whole request with `inputResponses` populated.
169
+ */
170
+ elicit: (params: {
171
+ message: string;
172
+ requestedSchema: StandardSchemaV1;
173
+ }) => InputRequest;
174
+ /**
175
+ * Reads one entry of `inputResponses` and validates it against the schema
176
+ * used to request it. Returns `undefined` when the client declined or the
177
+ * content does not match.
178
+ */
179
+ input: <S extends StandardSchemaV1>(key: string, schema: S) => StandardSchemaV1.InferOutput<S> | undefined;
180
+ /**
181
+ * Ask the client for more input and end this round.
182
+ *
183
+ * `requestState` round-trips through the client, so it is
184
+ * attacker-controlled on return: sign it if it affects authorization.
185
+ */
186
+ inputRequired: (inputRequests: Record<string, InputRequest>, requestState?: string) => InputRequiredResult;
187
+ /**
188
+ * Present when the client is retrying a request that previously returned
189
+ * `input_required`. Absent on the first call.
190
+ */
191
+ inputResponses?: Record<string, unknown>;
192
+ /**
193
+ * Emits `notifications/message`. The spec forbids emitting these unless the
194
+ * request opted in via `_meta` log level, so these are dropped when the
195
+ * client did not ask for logs.
196
+ */
197
+ log: {
198
+ debug: (message: string, data?: SerializableValue) => void;
199
+ error: (message: string, data?: SerializableValue) => void;
200
+ info: (message: string, data?: SerializableValue) => void;
201
+ warn: (message: string, data?: SerializableValue) => void;
202
+ };
203
+ reportProgress: (progress: Progress) => Promise<void>;
204
+ /** Request ID of the current MCP request. */
205
+ requestId?: string;
206
+ /** The `requestState` echoed back by the client on an MRTR retry. */
207
+ requestState?: string;
208
+ };
209
+ type ImageContent = {
210
+ data: string;
211
+ mimeType: string;
212
+ type: "image";
213
+ };
214
+ /**
215
+ * A single loaded resource body. `uri` is optional: when omitted the server
216
+ * fills it in from the resource (or the expanded template) that produced it.
217
+ */
218
+ type LoadedResource = {
219
+ blob?: string;
220
+ mimeType?: string;
221
+ text?: string;
222
+ uri?: string;
223
+ };
224
+ type Prompt<T extends ViteMCPAuth> = {
225
+ arguments?: PromptArgument[];
226
+ canAccess?: (auth: T) => boolean;
227
+ /** Completes any argument. Per-argument `complete` wins over this. */
228
+ complete?: (name: string, value: string) => Promise<Completion>;
229
+ description?: string;
230
+ load: (args: Record<string, string>, context: LoadContext<T>) => Promise<{
231
+ messages: unknown[];
232
+ } | string>;
233
+ name: string;
234
+ };
235
+ type PromptArgument = {
236
+ complete?: (value: string) => Promise<Completion>;
237
+ description?: string;
238
+ /** Constrains the argument to a fixed set of values. */
239
+ enum?: string[];
240
+ name: string;
241
+ required?: boolean;
242
+ };
243
+ type Resource<T extends ViteMCPAuth> = {
244
+ cache?: CacheHint;
245
+ canAccess?: (auth: T) => boolean;
246
+ description?: string;
247
+ load: (context: LoadContext<T>) => Promise<LoadedResource | LoadedResource[]>;
248
+ mimeType?: string;
249
+ name: string;
250
+ uri: string;
251
+ };
252
+ type ResourceTemplate<T extends ViteMCPAuth> = {
253
+ arguments?: ResourceTemplateArgument[];
254
+ cache?: CacheHint;
255
+ canAccess?: (auth: T) => boolean;
256
+ /** Completes any template variable. Per-argument `complete` wins over this. */
257
+ complete?: (name: string, value: string) => Promise<Completion>;
258
+ description?: string;
259
+ load: (args: Record<string, string>, context: LoadContext<T>) => Promise<LoadedResource | LoadedResource[]>;
260
+ mimeType?: string;
261
+ name: string;
262
+ uriTemplate: string;
263
+ };
264
+ type ResourceTemplateArgument = {
265
+ complete?: (value: string) => Promise<Completion>;
266
+ description?: string;
267
+ name: string;
268
+ required?: boolean;
269
+ };
270
+ type ServerOptions<T extends ViteMCPAuth> = {
271
+ auth?: AuthProvider<T extends OAuthSession ? T : OAuthSession>;
272
+ authenticate?: Authenticate<T>;
273
+ health?: {
274
+ enabled?: boolean;
275
+ message?: string;
276
+ path?: string;
277
+ status?: number;
278
+ };
279
+ instructions?: string;
280
+ logger?: Logger;
281
+ name: string;
282
+ oauth?: {
283
+ authorizationServer?: Record<string, unknown>;
284
+ enabled?: boolean;
285
+ protectedResource?: Record<string, unknown>;
286
+ proxy?: OAuthProxy;
287
+ };
288
+ version: `${number}.${number}.${number}`;
289
+ };
290
+ type TextContent = {
291
+ text: string;
292
+ type: "text";
293
+ };
294
+ type Tool<T extends ViteMCPAuth, Params extends ToolParameters = ToolParameters, OutputParams extends ToolParameters = ToolParameters> = {
295
+ _meta?: Record<string, unknown>;
296
+ annotations?: ToolAnnotations;
297
+ canAccess?: (auth: T) => boolean;
298
+ description?: string;
299
+ execute: (args: StandardSchemaV1.InferOutput<Params>, context: Context<T>) => Promise<AudioContent | ContentResult | ImageContent | InputRequiredResult | ResourceContent | ResourceLink | StandardSchemaV1.InferOutput<OutputParams> | string | TextContent | void>;
300
+ name: string;
301
+ outputSchema?: OutputParams;
302
+ parameters?: Params;
303
+ timeoutMs?: number;
304
+ };
305
+ type ViteMCPAuth = Record<string, unknown> | undefined;
306
+ type Authenticate<T> = (request: Request) => Promise<T>;
307
+ type Literal = boolean | null | number | string | undefined;
308
+ type LoadContext<T extends ViteMCPAuth> = Omit<Context<T>, "reportProgress">;
309
+ type Progress = {
310
+ message?: string;
311
+ progress: number;
312
+ total?: number;
313
+ };
314
+ type ResourceContent = {
315
+ resource: {
316
+ blob?: string;
317
+ mimeType?: string;
318
+ text?: string;
319
+ uri: string;
320
+ };
321
+ type: "resource";
322
+ };
323
+ type ResourceLink = {
324
+ description?: string;
325
+ mimeType?: string;
326
+ name: string;
327
+ type: "resource_link";
328
+ uri: string;
329
+ };
330
+ type SerializableValue = {
331
+ [key: string]: SerializableValue;
332
+ } | Literal | SerializableValue[];
333
+ type ToolParameters = StandardSchemaV1;
334
+ declare class ViteMCP<T extends ViteMCPAuth = ViteMCPAuth> {
335
+ #private;
336
+ get serverState(): ServerState;
337
+ constructor(options: ServerOptions<T>);
338
+ addPrompt(prompt: Prompt<T>): void;
339
+ addPrompts(prompts: Prompt<T>[]): void;
340
+ addResource(resource: Resource<T>): void;
341
+ addResources(resources: Resource<T>[]): void;
342
+ addResourceTemplate(template: ResourceTemplate<T>): void;
343
+ addResourceTemplates(templates: ResourceTemplate<T>[]): void;
344
+ addTool<Params extends ToolParameters>(tool: Tool<T, Params>): void;
345
+ addTools<Params extends ToolParameters>(tools: Tool<T, Params>[]): void;
346
+ /**
347
+ * Connects the server to an arbitrary transport — used for in-memory unit
348
+ * testing, where a linked transport pair replaces a real socket.
349
+ */
350
+ connect(transport: Parameters<McpServer["connect"]>[0]): Promise<McpServer>;
351
+ /**
352
+ * Resolves a resource (or resource template) URI to an embeddable resource
353
+ * body, for returning inline from a tool.
354
+ */
355
+ embedded(uri: string): Promise<LoadedResource>;
356
+ /** The Hono app serving the HTTP transport, for mounting custom routes. */
357
+ getApp(): Hono;
358
+ /**
359
+ * Publishes `notifications/resources/updated` for a URI to any subscription
360
+ * that opted in to it.
361
+ */
362
+ notifyResourceUpdated(uri: string): void;
363
+ removePrompt(name: string): void;
364
+ removePrompts(names: string[]): void;
365
+ removeResource(name: string): void;
366
+ removeResources(names: string[]): void;
367
+ removeResourceTemplate(name: string): void;
368
+ removeResourceTemplates(names: string[]): void;
369
+ removeTool(name: string): void;
370
+ removeTools(names: string[]): void;
371
+ start(options: {
372
+ httpStream: {
373
+ /** Origins permitted to reach the MCP endpoint (DNS-rebinding guard). */
374
+ allowedOrigins?: string[];
375
+ basePath?: string;
376
+ cors?: false | Parameters<typeof cors>[0];
377
+ enableJsonResponse?: boolean;
378
+ endpoint?: string;
379
+ host?: string;
380
+ /**
381
+ * Whether to also serve 2025-era clients. Defaults to
382
+ * `"stateless"`: the SDK client negotiates 2025 unless given
383
+ * `versionNegotiation: { mode: "auto" }`. `"reject"` serves only
384
+ * 2026-07-28 and enforces `Mcp-Method`/`Mcp-Name`.
385
+ */
386
+ legacy?: "reject" | "stateless";
387
+ maxBodySize?: number;
388
+ port: number;
389
+ sslCa?: string;
390
+ sslCert?: string;
391
+ sslKey?: string;
392
+ };
393
+ transportType: "httpStream";
394
+ } | {
395
+ transportType: "stdio";
396
+ }): Promise<void>;
397
+ stop(): Promise<void>;
398
+ }
399
+
400
+ export { type AudioContent, AuthProvider, type CacheHint, type Completion, type Content, type ContentResult, type Context, DiscoveryDocumentCache, type ImageContent, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadedResource, type Logger, MEDIA_FETCH_TIMEOUT_MS, OAuthSession, type Prompt, type PromptArgument, type Resource, type ResourceTemplate, type ResourceTemplateArgument, type ServerOptions, ServerState, type TextContent, type Tool, UnexpectedStateError, UserError, ViteMCP, type ViteMCPAuth, ViteMCPError, audioContent, imageContent, jsonSchemaAdapter };