MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / constructor

Method constructor

src/server/index.ts:149–173  ·  view source on GitHub ↗

* Initializes this server with the given name and version information.

(
        private _serverInfo: Implementation,
        options?: ServerOptions
    )

Source from the content-addressed store, hash-verified

147 * Initializes this server with the given name and version information.
148 */
149 constructor(
150 private _serverInfo: Implementation,
151 options?: ServerOptions
152 ) {
153 super(options);
154 this._capabilities = options?.capabilities ?? {};
155 this._instructions = options?.instructions;
156 this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
157
158 this.setRequestHandler(InitializeRequestSchema, request => this._oninitialize(request));
159 this.setNotificationHandler(InitializedNotificationSchema, () => this.oninitialized?.());
160
161 if (this._capabilities.logging) {
162 this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
163 const transportSessionId: string | undefined =
164 extra.sessionId || (extra.requestInfo?.headers['mcp-session-id'] as string) || undefined;
165 const { level } = request.params;
166 const parseResult = LoggingLevelSchema.safeParse(level);
167 if (parseResult.success) {
168 this._loggingLevels.set(transportSessionId, parseResult.data);
169 }
170 return {};
171 });
172 }
173 }
174
175 /**
176 * Access experimental features.

Callers

nothing calls this directly

Calls 2

setRequestHandlerMethod · 0.95
_oninitializeMethod · 0.95

Tested by

no test coverage detected