1158
*/
1159
private _parseIcons(icons: MCP.Icons) {
1161
>
if (!cnx) {
1162
return [];
1163
}
1165
>
return parseAndValidateMcpIcon(icons, cnx.launchDefinition, this._logger);
1166
>
}
1167
1168
private _setServerTools(nonce: string | undefined, toolsPromise: Promise<MCP.Tool[]>, tx: ITransaction | undefined) {
1169
>
const toolPromiseSafe = toolsPromise.then(async tools => {
mcpServer.ts
1170
this._logger.info(`Discovered ${tools.length} tools`);
1171
const data = await this._getValidatedTools(tools);
1172
this._primitiveCache.store(this.definition.id, { tools: data, nonce });
1173
return { data, nonce };
1175
>
this._tools.fromServerPromise.set(new ObservablePromise(toolPromiseSafe), tx);
1176
>
return toolPromiseSafe;
1177
>
}
1178
1179
private _setServerPrompts(nonce: string | undefined, promptsPromise: Promise<MCP.Prompt[]>, tx: ITransaction | undefined) {
1180
>
const promptsPromiseSafe = promptsPromise.then((result): { data: StoredMcpPrompt[]; nonce: string | undefined } => {
mcpServer.ts
1181
>
const data: StoredMcpPrompt[] = result.map(prompt => ({
1182
...prompt,
1183
_icons: this._parseIcons(prompt)
1185
>
this._primitiveCache.store(this.definition.id, { prompts: data, nonce });
1186
>
return { data, nonce };
1187
>
});
1188
>
1189
>
this._prompts.fromServerPromise.set(new ObservablePromise(promptsPromiseSafe), tx);
1190
>
return promptsPromiseSafe;
1191
>
}
1192
1193
private _toStoredMetadata(serverInfo?: MCP.Implementation, instructions?: string): StoredServerMetadata {
1195
>
serverName: serverInfo ? serverInfo.title || serverInfo.name : undefined,
1196
>
serverInstructions: instructions,
1197
>
serverIcons: serverInfo ? this._parseIcons(serverInfo) : undefined,
1198
>
};
1199
>
}
1200
1201
private _setServerMetadata(
1203
>
{ serverInfo, instructions, capabilities }: { serverInfo: MCP.Implementation; instructions: string | undefined; capabilities: MCP.ServerCapabilities },
1204
>
tx: ITransaction | undefined,
1205
>
) {
1206
>
const serverMetadata: StoredServerMetadata = this._toStoredMetadata(serverInfo, instructions);
1207
>
this._serverMetadata.fromServerPromise.set(ObservablePromise.resolved({ nonce, data: serverMetadata }), tx);
1208
>
1209
>
const capabilitiesEncoded = encodeCapabilities(capabilities);
1210
>
this._capabilities.fromServerPromise.set(ObservablePromise.resolved({ data: capabilitiesEncoded, nonce }), tx);
1211
>
this._primitiveCache.store(this.definition.id, { ...serverMetadata, nonce, capabilities: capabilitiesEncoded });
1212
>
}
1213
1214
private _populateLiveData(handler: McpServerRequestHandler, cacheNonce: string | undefined, store: DisposableStore) {
1215
>
const cts = new CancellationTokenSource();
mcpServer.ts
1216
>
store.add(toDisposable(() => cts.dispose(true)));
1217
>
1218
>
const updateTools = (tx: ITransaction | undefined) => {
1219
>
const toolPromise = handler.capabilities.tools ? handler.listTools({}, cts.token) : Promise.resolve([]);
1220
>
return this._setServerTools(cacheNonce, toolPromise, tx);
1221
>
};
1222
>
1223
>
const updatePrompts = (tx: ITransaction | undefined) => {
1224
>
const promptsPromise = handler.capabilities.prompts ? handler.listPrompts({}, cts.token) : Promise.resolve([]);
1225
>
return this._setServerPrompts(cacheNonce, promptsPromise, tx);
1226
>
};
1227
>
1228
>
store.add(handler.onDidChangeToolList(() => {
1229
this._logger.info('Tool list changed, refreshing tools...');
1230
updateTools(undefined);
1232
>
1233
>
store.add(handler.onDidChangePromptList(() => {
1234
this._logger.info('Prompts list changed, refreshing prompts...');
1235
updatePrompts(undefined);
1237
>
1238
>
transaction(tx => {
1239
>
this._setServerMetadata(cacheNonce, { serverInfo: handler.serverInfo, instructions: handler.serverInstructions, capabilities: handler.capabilities }, tx);
1240
>
updatePrompts(tx);
1241
>
const toolUpdate = updateTools(tx);
1242
>
1243
>
toolUpdate.then(tools => {
1244
this._telemetryService.publicLog2<ServerBootData, ServerBootClassification>('mcp/serverBoot', {
1245
supportsLogging: !!handler.capabilities.logging,