Skip to content

Commit c4ce952

Browse files
committed
Fixing up ESM imports
1 parent 8e957cc commit c4ce952

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/client/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
ErrorCode,
4444
McpError,
4545
} from "../types.js";
46-
import Ajv from "ajv";
46+
import { Ajv } from 'ajv';
4747
import type { ValidateFunction } from "ajv";
4848

4949
export type ClientOptions = ProtocolOptions & {
@@ -92,7 +92,7 @@ export class Client<
9292
private _capabilities: ClientCapabilities;
9393
private _instructions?: string;
9494
private _cachedToolOutputValidators: Map<string, ValidateFunction> = new Map();
95-
private _ajv: InstanceType<typeof Ajv>;
95+
private _ajv: Ajv;
9696

9797
/**
9898
* Initializes this client with the given name and version information.

src/examples/client/simpleStreamableHttp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
ReadResourceResultSchema,
2121
} from '../../types.js';
2222
import { getDisplayName } from '../../shared/metadataUtils.js';
23-
import Ajv from "ajv";
23+
import { Ajv } from 'ajv';
2424

2525
// Create readline interface for user input
2626
const readline = createInterface({
@@ -373,7 +373,7 @@ async function connect(url?: string): Promise<void> {
373373
if (!isValid) {
374374
console.log('❌ Validation errors:');
375375
validate.errors?.forEach(error => {
376-
console.log(` - ${error.dataPath || 'root'}: ${error.message}`);
376+
console.log(` - ${error.instancePath || 'root'}: ${error.message}`);
377377
});
378378

379379
if (attempts < maxAttempts) {

src/server/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
ServerResult,
3434
SUPPORTED_PROTOCOL_VERSIONS,
3535
} from "../types.js";
36-
import Ajv from "ajv";
36+
import { Ajv } from 'ajv';
3737

3838
export type ServerOptions = ProtocolOptions & {
3939
/**
@@ -85,6 +85,7 @@ export class Server<
8585
private _clientVersion?: Implementation;
8686
private _capabilities: ServerCapabilities;
8787
private _instructions?: string;
88+
private _ajv: Ajv;
8889

8990
/**
9091
* Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification).
@@ -101,6 +102,7 @@ export class Server<
101102
super(options);
102103
this._capabilities = options?.capabilities ?? {};
103104
this._instructions = options?.instructions;
105+
this._ajv = new Ajv({ code: { source: false } });
104106

105107
this.setRequestHandler(InitializeRequestSchema, (request) =>
106108
this._oninitialize(request),
@@ -323,15 +325,13 @@ export class Server<
323325
// Validate the response content against the requested schema if action is "accept"
324326
if (result.action === "accept" && result.content) {
325327
try {
326-
const ajv = new Ajv();
327-
328-
const validate = ajv.compile(params.requestedSchema);
328+
const validate = this._ajv.compile(params.requestedSchema);
329329
const isValid = validate(result.content);
330330

331331
if (!isValid) {
332332
throw new McpError(
333333
ErrorCode.InvalidParams,
334-
`Elicitation response content does not match requested schema: ${ajv.errorsText(validate.errors)}`,
334+
`Elicitation response content does not match requested schema: ${this._ajv.errorsText(validate.errors)}`,
335335
);
336336
}
337337
} catch (error) {

0 commit comments

Comments
 (0)