Connect with Your MCP Client
MCPX is essentially a MCP server, just like any other. Connecting to it using the SDK is similar to any MCP integration. Because MCPX adopts a remote-first approach - that is, it is meant to be deployed on the cloud - it accepts SSE connections and not stdio ones.
You may pass extra headers when constructing a Transport
in the client app - the one that will be used in order to connect to MCPX. See Basic API Key Auth and ACL for actual extra headers' use-cases.
const client = new Client({ name: "mcpx-client", version: "1.0.0" });
await client.connect(transport);
StreamableHttp Transport
This is the recommended way to connect the MCP servers.
const transport = new StreamableHTTPClientTransport(
new URL(`${MCPX_HOST}/mcp`),
{
requestInit: {
headers: {
"x-lunar-consumer-tag": process.env["CONSUMER_TAG"] || "anonymous",
"x-lunar-api-key": process.env["API_KEY"] || "",
},
},
}
);
SSE Transport
This transport is in deprecation, however MCPX still support it to maintain backward compatibility for the time being.
const transport = new SSEClientTransport(new URL(`${MCPX_HOST}/sse`), {
eventSourceInit: {
fetch: (url, init) => {
const headers = new Headers(init?.headers);
const consumerTag = process.env["CONSUMER_TAG"] || "anonymous";
headers.set("x-lunar-consumer-tag", consumerTag);
headers.set("x-lunar-api-key", process.env["API_KEY"] || "");
return fetch(url, { ...init, headers });
},
},
});