Skip to content

Commit 4f1da74

Browse files
committed
Address usage of "any" types in InspectorClient (members and request params)
1 parent e04c2b5 commit 4f1da74

1 file changed

Lines changed: 55 additions & 49 deletions

File tree

core/mcp/inspectorClient.ts

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ import type {
5050
Task,
5151
Progress,
5252
ProgressToken,
53+
ListToolsRequest,
54+
ListResourcesRequest,
55+
ListResourceTemplatesRequest,
56+
ListPromptsRequest,
57+
ReadResourceRequest,
58+
GetPromptRequest,
59+
CompleteRequest,
5360
} from "@modelcontextprotocol/sdk/types.js";
61+
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
5462
import type {
5563
RequestOptions,
5664
ProgressCallback,
@@ -346,8 +354,8 @@ const MAX_PAGES = 100;
346354
export class InspectorClient extends InspectorClientEventTarget {
347355
private client: Client | null = null;
348356
private appRendererClientProxy: AppRendererClient | null = null;
349-
private transport: any = null;
350-
private baseTransport: any = null;
357+
private transport: Transport | MessageTrackingTransport | null = null;
358+
private baseTransport: Transport | null = null;
351359
private messages: MessageEntry[] = [];
352360
private stderrLogs: StderrLogEntry[] = [];
353361
private fetchRequests: FetchRequestEntry[] = [];
@@ -584,7 +592,7 @@ export class InspectorClient extends InspectorClientEventTarget {
584592
};
585593
}
586594

587-
private attachTransportListeners(baseTransport: any): void {
595+
private attachTransportListeners(baseTransport: Transport): void {
588596
baseTransport.onclose = () => {
589597
if (this.status !== "disconnected") {
590598
this.status = "disconnected";
@@ -1555,13 +1563,12 @@ export class InspectorClient extends InspectorClientEventTarget {
15551563

15561564
try {
15571565
do {
1558-
const params: any =
1559-
metadata && Object.keys(metadata).length > 0
1566+
const params: ListToolsRequest["params"] = {
1567+
...(metadata && Object.keys(metadata).length > 0
15601568
? { _meta: metadata }
1561-
: {};
1562-
if (cursor) {
1563-
params.cursor = cursor;
1564-
}
1569+
: {}),
1570+
...(cursor ? { cursor } : {}),
1571+
};
15651572
const response = await this.client.listTools(
15661573
params,
15671574
this.getRequestOptions(metadata?.progressToken),
@@ -1607,11 +1614,12 @@ export class InspectorClient extends InspectorClientEventTarget {
16071614
if (!this.client) {
16081615
throw new Error("Client is not connected");
16091616
}
1610-
const params: any =
1611-
metadata && Object.keys(metadata).length > 0 ? { _meta: metadata } : {};
1612-
if (cursor) {
1613-
params.cursor = cursor;
1614-
}
1617+
const params: ListToolsRequest["params"] = {
1618+
...(metadata && Object.keys(metadata).length > 0
1619+
? { _meta: metadata }
1620+
: {}),
1621+
...(cursor ? { cursor } : {}),
1622+
};
16151623
const response = await this.client.listTools(
16161624
params,
16171625
this.getRequestOptions(metadata?.progressToken),
@@ -2088,11 +2096,12 @@ export class InspectorClient extends InspectorClientEventTarget {
20882096
if (!this.client) {
20892097
throw new Error("Client is not connected");
20902098
}
2091-
const params: any =
2092-
metadata && Object.keys(metadata).length > 0 ? { _meta: metadata } : {};
2093-
if (cursor) {
2094-
params.cursor = cursor;
2095-
}
2099+
const params: ListResourcesRequest["params"] = {
2100+
...(metadata && Object.keys(metadata).length > 0
2101+
? { _meta: metadata }
2102+
: {}),
2103+
...(cursor ? { cursor } : {}),
2104+
};
20962105
const response = await this.client.listResources(
20972106
params,
20982107
this.getRequestOptions(metadata?.progressToken),
@@ -2185,10 +2194,12 @@ export class InspectorClient extends InspectorClientEventTarget {
21852194
if (!this.client) {
21862195
throw new Error("Client is not connected");
21872196
}
2188-
const params: any = { uri };
2189-
if (metadata && Object.keys(metadata).length > 0) {
2190-
params._meta = metadata;
2191-
}
2197+
const params: ReadResourceRequest["params"] = {
2198+
uri,
2199+
...(metadata && Object.keys(metadata).length > 0
2200+
? { _meta: metadata }
2201+
: {}),
2202+
};
21922203
const result = await this.client.readResource(
21932204
params,
21942205
this.getRequestOptions(metadata?.progressToken),
@@ -2300,11 +2311,12 @@ export class InspectorClient extends InspectorClientEventTarget {
23002311
throw new Error("Client is not connected");
23012312
}
23022313
try {
2303-
const params: any =
2304-
metadata && Object.keys(metadata).length > 0 ? { _meta: metadata } : {};
2305-
if (cursor) {
2306-
params.cursor = cursor;
2307-
}
2314+
const params: ListResourceTemplatesRequest["params"] = {
2315+
...(metadata && Object.keys(metadata).length > 0
2316+
? { _meta: metadata }
2317+
: {}),
2318+
...(cursor ? { cursor } : {}),
2319+
};
23082320
const response = await this.client.listResourceTemplates(
23092321
params,
23102322
this.getRequestOptions(metadata?.progressToken),
@@ -2411,11 +2423,12 @@ export class InspectorClient extends InspectorClientEventTarget {
24112423
if (!this.client) {
24122424
throw new Error("Client is not connected");
24132425
}
2414-
const params: any =
2415-
metadata && Object.keys(metadata).length > 0 ? { _meta: metadata } : {};
2416-
if (cursor) {
2417-
params.cursor = cursor;
2418-
}
2426+
const params: ListPromptsRequest["params"] = {
2427+
...(metadata && Object.keys(metadata).length > 0
2428+
? { _meta: metadata }
2429+
: {}),
2430+
...(cursor ? { cursor } : {}),
2431+
};
24192432
const response = await this.client.listPrompts(
24202433
params,
24212434
this.getRequestOptions(metadata?.progressToken),
@@ -2508,15 +2521,14 @@ export class InspectorClient extends InspectorClientEventTarget {
25082521
// Convert all arguments to strings for prompt arguments
25092522
const stringArgs = args ? convertPromptArguments(args) : {};
25102523

2511-
const params: any = {
2524+
const params: GetPromptRequest["params"] = {
25122525
name,
25132526
arguments: stringArgs,
2527+
...(metadata && Object.keys(metadata).length > 0
2528+
? { _meta: metadata }
2529+
: {}),
25142530
};
25152531

2516-
if (metadata && Object.keys(metadata).length > 0) {
2517-
params._meta = metadata;
2518-
}
2519-
25202532
const result = await this.client.getPrompt(
25212533
params,
25222534
this.getRequestOptions(metadata?.progressToken),
@@ -2566,24 +2578,18 @@ export class InspectorClient extends InspectorClientEventTarget {
25662578
}
25672579

25682580
try {
2569-
const params: any = {
2581+
const params: CompleteRequest["params"] = {
25702582
ref,
25712583
argument: {
25722584
name: argumentName,
25732585
value: argumentValue,
25742586
},
2587+
...(context ? { context: { arguments: context } } : {}),
2588+
...(metadata && Object.keys(metadata).length > 0
2589+
? { _meta: metadata }
2590+
: {}),
25752591
};
25762592

2577-
if (context) {
2578-
params.context = {
2579-
arguments: context,
2580-
};
2581-
}
2582-
2583-
if (metadata && Object.keys(metadata).length > 0) {
2584-
params._meta = metadata;
2585-
}
2586-
25872593
const response = await this.client.complete(
25882594
params,
25892595
this.getRequestOptions(metadata?.progressToken),

0 commit comments

Comments
 (0)