src/vs/workbench/contrib/mcp/common/mcpIcons.ts
145 LOC · 142 covered · 3 uncovered · 35 ranges · 129 concepts · 17 introducers · 81 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
mcpIcons.ts ×6
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { getMediaMime } from '../../../../base/common/mime.js';
import { URI } from '../../../../base/common/uri.js';
import { ILogger } from '../../../../platform/log/common/log.js';
import { Dto } from '../../../services/extensions/common/proxyIdentifier.js';
import { IMcpIcons, McpServerLaunch, McpServerTransportType } from './mcpTypes.js';
import { MCP } from './modelContextProtocol.js';
const mcpAllowableContentTypes: readonly string[] = [
'image/webp',
'image/png',
'image/jpeg',
'image/jpg',
'image/gif'
];
const enum IconTheme {
Light,
Dark,
Any,
}
interface IIcon {
/** URI the image can be loaded from */
src: URI;
/** Theme for this icon. */
theme: IconTheme;
/** Sizes of the icon in ascending order. */
sizes: { width: number; height: number }[];
}
export type ParsedMcpIcons = IIcon[];
export type StoredMcpIcons = Dto<IIcon>[];
function validateIcon(icon: MCP.Icon, launch: McpServerLaunch, logger: ILogger): URI | undefined {
mcpIcons.ts ×5
const mimeType = icon.mimeType?.toLowerCase() || getMediaMime(icon.src);
if (!mimeType || !mcpAllowableContentTypes.includes(mimeType)) {
logger.debug(`Ignoring icon with unsupported mime type: ${icon.src} (${mimeType}), allowed: ${mcpAllowableContentTypes.join(', ')}`);
return;
}
const uri = URI.parse(icon.src);
if (uri.scheme === 'data') {
}
if (uri.scheme === 'https' || uri.scheme === 'http') {
logger.debug(`Ignoring icon with HTTP/HTTPS URL: ${icon.src} as the MCP server is not launched with HTTP transport.`);
mcpIcons.ts ×2
return;
}
const expectedAuthority = launch.uri.authority.toLowerCase();
if (uri.authority.toLowerCase() !== expectedAuthority) {
logger.debug(`Ignoring icon with untrusted authority: ${icon.src}, expected authority: ${expectedAuthority}`);
mcpIcons.ts ×2
return;
}
return uri;
}
if (uri.scheme === 'file') {
logger.debug(`Ignoring icon with file URL: ${icon.src} as the MCP server is not launched as a local process.`);
return;
}
return uri;
}
logger.debug(`Ignoring icon with unsupported scheme: ${icon.src}. Allowed: data:, http:, https:, file:`);
return;
}
export function parseAndValidateMcpIcon(icons: MCP.Icons, launch: McpServerLaunch, logger: ILogger): ParsedMcpIcons {
for (const icon of icons.icons || []) {
if (!uri) {
}
// check for sizes as string for back-compat with early 2025-11-25 drafts
const sizesArr = typeof icon.sizes === 'string' ? (icon.sizes as string).split(' ') : Array.isArray(icon.sizes) ? icon.sizes : [];
result.push({
src: uri,
theme: icon.theme === 'light' ? IconTheme.Light : icon.theme === 'dark' ? IconTheme.Dark : IconTheme.Any,
sizes: sizesArr.map(size => {
const [widthStr, heightStr] = size.toLowerCase().split('x');
return { width: Number(widthStr) || 0, height: Number(heightStr) || 0 };
}).sort((a, b) => a.width - b.width)
});
}
result.sort((a, b) => a.sizes[0]?.width - b.sizes[0]?.width);
return result;
}
export class McpIcons implements IMcpIcons {
public static fromStored(icons: StoredMcpIcons | undefined) {
return McpIcons.fromParsed(icons?.map(i => ({ src: URI.revive(i.src), theme: i.theme, sizes: i.sizes })));
}
public static fromParsed(icons: ParsedMcpIcons | undefined) {
}
protected constructor(private readonly _icons: IIcon[]) { }
getUrl(size: number): { dark: URI; light?: URI } | undefined {
if (dark?.theme === IconTheme.Any) {
}
const light = this.getSizeWithTheme(size, IconTheme.Light);
}
}
private getSizeWithTheme(size: number, theme: IconTheme): IIcon | undefined {
for (const icon of this._icons) {
if (icon.theme === theme || icon.theme === IconTheme.Any || icon.theme === undefined) { // undefined check for back compat
mcpIcons.ts ×1
bestOfAnySize = icon;
const matchingSize = icon.sizes.find(s => s.width >= size);
if (matchingSize) {
return { ...icon, sizes: [matchingSize] };
}
}
}