FrameworksBackend
NestJS
Integrate the Integrate SDK with NestJS
The Integrate SDK provides seamless integration with NestJS through server-side configuration and controllers. This guide assumes you have a NestJS project already set up.
Installation
Install the Integrate SDK in your NestJS project:
bun add integrate-sdkSetup
Server Configuration
Create a server configuration file with your OAuth credentials:
// src/integrate.ts
import { createMCPServer, githubIntegration } from 'integrate-sdk/server';
export const { client: serverClient } = createMCPServer({
apiKey: process.env.INTEGRATE_API_KEY,
integrations: [
githubIntegration({
scopes: ['repo', 'user'],
}),
],
});You can get an API key from the Integrate Dashboard.
OAuth Controller
Create a controller to handle OAuth routes:
// src/oauth.controller.ts
import { Controller, All, Req, Res } from "@nestjs/common";
import type { Request, Response } from "express";
import { serverClient } from "./integrate";
@Controller("api/integrate")
export class OAuthController {
@All("*")
async handleOAuth(@Req() req: Request, @Res() res: Response) {
await serverClient.handler(req, res);
}
}Register the controller in your module:
// src/app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { OAuthController } from './oauth.controller';
@Module({
imports: [],
controllers: [AppController, OAuthController],
providers: [AppService],
})
export class AppModule { }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=8080CORS Setup
Configure CORS in your main.ts:
// src/main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
bodyParser: false,
});
app.enableCors({
origin: process.env.FRONTEND_URL || "http://localhost:3000",
credentials: true,
});
await app.listen(process.env.PORT ?? 8080);
}
bootstrap().catch(console.error);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");