index.d.ts•8.86 kB
import { Protocol, type ProtocolOptions, type RequestOptions } from '../shared/protocol.js';
import { type ClientCapabilities, type CreateMessageRequest, type ElicitRequest, type ElicitResult, type Implementation, type ListRootsRequest, type LoggingMessageNotification, type Notification, type Request, type ResourceUpdatedNotification, type Result, type ServerCapabilities, type ServerNotification, type ServerRequest, type ServerResult } from '../types.js';
import type { jsonSchemaValidator } from '../validation/types.js';
export type ServerOptions = ProtocolOptions & {
/**
* Capabilities to advertise as being supported by this server.
*/
capabilities?: ServerCapabilities;
/**
* Optional instructions describing how to use the server and its features.
*/
instructions?: string;
/**
* JSON Schema validator for elicitation response validation.
*
* The validator is used to validate user input returned from elicitation
* requests against the requested schema.
*
* @default AjvJsonSchemaValidator
*
* @example
* ```typescript
* // ajv (default)
* const server = new Server(
* { name: 'my-server', version: '1.0.0' },
* {
* capabilities: {}
* jsonSchemaValidator: new AjvJsonSchemaValidator()
* }
* );
*
* // @cfworker/json-schema
* const server = new Server(
* { name: 'my-server', version: '1.0.0' },
* {
* capabilities: {},
* jsonSchemaValidator: new CfWorkerJsonSchemaValidator()
* }
* );
* ```
*/
jsonSchemaValidator?: jsonSchemaValidator;
};
/**
* An MCP server on top of a pluggable transport.
*
* This server will automatically respond to the initialization flow as initiated from the client.
*
* To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:
*
* ```typescript
* // Custom schemas
* const CustomRequestSchema = RequestSchema.extend({...})
* const CustomNotificationSchema = NotificationSchema.extend({...})
* const CustomResultSchema = ResultSchema.extend({...})
*
* // Type aliases
* type CustomRequest = z.infer<typeof CustomRequestSchema>
* type CustomNotification = z.infer<typeof CustomNotificationSchema>
* type CustomResult = z.infer<typeof CustomResultSchema>
*
* // Create typed server
* const server = new Server<CustomRequest, CustomNotification, CustomResult>({
* name: "CustomServer",
* version: "1.0.0"
* })
* ```
* @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases.
*/
export declare class Server<RequestT extends Request = Request, NotificationT extends Notification = Notification, ResultT extends Result = Result> extends Protocol<ServerRequest | RequestT, ServerNotification | NotificationT, ServerResult | ResultT> {
private _serverInfo;
private _clientCapabilities?;
private _clientVersion?;
private _capabilities;
private _instructions?;
private _jsonSchemaValidator;
/**
* Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification).
*/
oninitialized?: () => void;
/**
* Initializes this server with the given name and version information.
*/
constructor(_serverInfo: Implementation, options?: ServerOptions);
private _loggingLevels;
private readonly LOG_LEVEL_SEVERITY;
private isMessageIgnored;
/**
* Registers new capabilities. This can only be called before connecting to a transport.
*
* The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
*/
registerCapabilities(capabilities: ServerCapabilities): void;
protected assertCapabilityForMethod(method: RequestT['method']): void;
protected assertNotificationCapability(method: (ServerNotification | NotificationT)['method']): void;
protected assertRequestHandlerCapability(method: string): void;
private _oninitialize;
/**
* After initialization has completed, this will be populated with the client's reported capabilities.
*/
getClientCapabilities(): ClientCapabilities | undefined;
/**
* After initialization has completed, this will be populated with information about the client's name and version.
*/
getClientVersion(): Implementation | undefined;
private getCapabilities;
ping(): Promise<{
_meta?: Record<string, unknown> | undefined;
}>;
createMessage(params: CreateMessageRequest['params'], options?: RequestOptions): Promise<import("zod").objectOutputType<import("zod").objectUtil.extendShape<{
_meta: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
}, {
model: import("zod").ZodString;
stopReason: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEnum<["endTurn", "stopSequence", "maxTokens"]>, import("zod").ZodString]>>;
role: import("zod").ZodEnum<["user", "assistant"]>;
content: import("zod").ZodDiscriminatedUnion<"type", [import("zod").ZodObject<{
type: import("zod").ZodLiteral<"text">;
text: import("zod").ZodString;
_meta: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
}, "strip", import("zod").ZodTypeAny, {
type: "text";
text: string;
_meta?: Record<string, unknown> | undefined;
}, {
type: "text";
text: string;
_meta?: Record<string, unknown> | undefined;
}>, import("zod").ZodObject<{
type: import("zod").ZodLiteral<"image">;
data: import("zod").ZodEffects<import("zod").ZodString, string, string>;
mimeType: import("zod").ZodString;
_meta: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
}, "strip", import("zod").ZodTypeAny, {
type: "image";
data: string;
mimeType: string;
_meta?: Record<string, unknown> | undefined;
}, {
type: "image";
data: string;
mimeType: string;
_meta?: Record<string, unknown> | undefined;
}>, import("zod").ZodObject<{
type: import("zod").ZodLiteral<"audio">;
data: import("zod").ZodEffects<import("zod").ZodString, string, string>;
mimeType: import("zod").ZodString;
_meta: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
}, "strip", import("zod").ZodTypeAny, {
type: "audio";
data: string;
mimeType: string;
_meta?: Record<string, unknown> | undefined;
}, {
type: "audio";
data: string;
mimeType: string;
_meta?: Record<string, unknown> | undefined;
}>]>;
}>, import("zod").ZodTypeAny, "passthrough">>;
elicitInput(params: ElicitRequest['params'], options?: RequestOptions): Promise<ElicitResult>;
listRoots(params?: ListRootsRequest['params'], options?: RequestOptions): Promise<import("zod").objectOutputType<import("zod").objectUtil.extendShape<{
_meta: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
}, {
roots: import("zod").ZodArray<import("zod").ZodObject<{
uri: import("zod").ZodString;
name: import("zod").ZodOptional<import("zod").ZodString>;
_meta: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
}, "strip", import("zod").ZodTypeAny, {
uri: string;
_meta?: Record<string, unknown> | undefined;
name?: string | undefined;
}, {
uri: string;
_meta?: Record<string, unknown> | undefined;
name?: string | undefined;
}>, "many">;
}>, import("zod").ZodTypeAny, "passthrough">>;
/**
* Sends a logging message to the client, if connected.
* Note: You only need to send the parameters object, not the entire JSON RPC message
* @see LoggingMessageNotification
* @param params
* @param sessionId optional for stateless and backward compatibility
*/
sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string): Promise<void>;
sendResourceUpdated(params: ResourceUpdatedNotification['params']): Promise<void>;
sendResourceListChanged(): Promise<void>;
sendToolListChanged(): Promise<void>;
sendPromptListChanged(): Promise<void>;
}
//# sourceMappingURL=index.d.ts.map