@smithery/sdk
Version:
SDK to develop with Smithery
31 lines (30 loc) • 1.16 kB
JavaScript
/**
* Creates a URL to connect to the Smithery MCP server.
* @param baseUrl The base URL of the Smithery server
* @param options Optional configuration object
* @returns A URL object with properly encoded parameters. Example: https://server.smithery.ai/{namespace}/mcp?config=BASE64_ENCODED_CONFIG&api_key=API_KEY
*/
export function createSmitheryUrl(baseUrl, options) {
const url = new URL(`${baseUrl}/mcp`);
if (options?.config) {
const param = typeof window !== "undefined"
? btoa(JSON.stringify(options.config))
: Buffer.from(JSON.stringify(options.config)).toString("base64");
url.searchParams.set("config", param);
}
if (options?.apiKey) {
url.searchParams.set("api_key", options.apiKey);
}
if (options?.profile) {
url.searchParams.set("profile", options.profile);
}
return url;
}
/**
* Parses the config from an express request by checking the query parameter "config".
* @param req The express request
* @returns The config
*/
export function parseExpressRequestConfig(req) {
return JSON.parse(Buffer.from(req.query.config, "base64").toString());
}