955
956
export function toServer(uri: URI | string): { definitionId: string; resourceURL: URL } {
958
uri = URI.parse(uri);
959
}
961
throw new Error(`Invalid MCP resource URI: ${uri.toString()}`);
962
}
964
>
if (parts.length < 3) {
965
throw new Error(`Invalid MCP resource URI: ${uri.toString()}`);
966
}
967
>
const [, serverScheme, authority, ...path] = parts;
mcpTypes.ts
968
>
969
>
// URI cannot correctly stringify empty authorities (#250905) so we use URL instead to construct
970
>
const url = new URL(`${serverScheme}://${authority.toLowerCase() === emptyAuthorityPlaceholder ? '' : authority}`);
971
>
url.pathname = path.length ? ('/' + path.join('/')) : '';
972
>
url.search = uri.query;
973
>
url.hash = uri.fragment;
974
>
975
>
return {
976
>
definitionId: decodeHex(uri.authority).toString(),
977
>
resourceURL: url,
978
>
};
979
>
}
980
981
}