FrameworksBackend
Node.js
Integrate the Integrate SDK with Node.js HTTP Server
The Integrate SDK provides seamless integration with Node.js through server-side configuration and HTTP route handlers. This guide assumes you have a Node.js project already set up.
Installation
Install the Integrate SDK in your Node.js project:
bun add integrate-sdkSetup
Create a server configuration file with your OAuth credentials:
// index.ts
import { createServer } from "http";
import { createMCPServer, githubIntegration } from "integrate-sdk/server";
const { client: serverClient } = createMCPServer({
apiKey: process.env.INTEGRATE_API_KEY,
integrations: [
githubIntegration({
scopes: ["repo", "user"],
}),
],
});
createServer(async (req, res) => {
res.setHeader("Access-Control-Allow-Origin", process.env.FRONTEND_URL || "http://localhost:3000");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
res.setHeader("Access-Control-Allow-Credentials", "true");
if (req.method === "OPTIONS") {
res.statusCode = 204;
res.end();
return;
}
if (req.url?.startsWith("/api/integrate/")) {
await serverClient.handler(req);
} else {
res.statusCode = 404;
res.end("Not Found");
}
}).listen(process.env.PORT || 8080, () => {
console.log(`Server running on port ${process.env.PORT || 8080}`);
});Configuration
Add your OAuth credentials to your .env file:
INTEGRATE_API_KEY=your_integrate_api_key
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
FRONTEND_URL=http://localhost:3000
PORT=8080You can get an API key from the Integrate Dashboard.
CORS Setup
CORS is configured in the setup above. If you need to customize it, adjust the CORS headers:
res.setHeader("Access-Control-Allow-Origin", process.env.FRONTEND_URL || "http://localhost:3000");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
res.setHeader("Access-Control-Allow-Credentials", "true");Usage Examples
Client-Side Authorization
The client is automatically configured when making requests to the server.
import { client } from "integrate-sdk";
await client.authorize("github");Full Example
// index.ts
import { createServer } from "http";
import { createMCPServer, githubIntegration } from "integrate-sdk/server";
const { client: serverClient } = createMCPServer({
apiKey: process.env.INTEGRATE_API_KEY,
integrations: [
githubIntegration({
scopes: ["repo", "user"],
}),
],
});
createServer(async (req, res) => {
res.setHeader("Access-Control-Allow-Origin", process.env.FRONTEND_URL || "http://localhost:3000");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
res.setHeader("Access-Control-Allow-Credentials", "true");
if (req.method === "OPTIONS") {
res.statusCode = 204;
res.end();
return;
}
if (req.url?.startsWith("/api/integrate/")) {
await serverClient.handler(req);
} else {
res.statusCode = 404;
res.end("Not Found");
}
}).listen(process.env.PORT || 8080, () => {
console.log(`Server running on port ${process.env.PORT || 8080}`);
});