一个类型安全的TypeScript SDK,用于连接到Integrate MCP(模型上下文协议)服务器。通过简单的集成式API访问GitHub、Gmail、Notion和其他集成。
📚 完整文档 | 服务器: https://mcp.integrate.dev/api/v1/mcp
client.github.createIssue())npm install integrate-sdk
# 或
bun add integrate-sdk
⚠️ 重要:使用此重定向URI配置你的OAuth应用:
http://localhost:3000/api/integrate/oauth/callback
生产环境使用:https://yourdomain.com/api/integrate/oauth/callback
定义一次OAuth提供商。集成会自动从环境变量中读取凭证:
// lib/integrate-server.ts(仅限服务器端!)
import {
createMCPServer,
githubIntegration,
gmailIntegration,
} from "integrate-sdk/server";
// 集成会自动使用GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET,
// GMAIL_CLIENT_ID, GMAIL_CLIENT_SECRET从环境变量
export const { client: serverClient } = createMCPServer({
integrations: [
githubIntegration({
scopes: ["repo", "user"],
}),
gmailIntegration({
scopes: ["gmail.readonly"],
}),
],
});
就这样!只需导入并导出:
// app/api/integrate/[...all]/route.ts
import { serverClient } from "@/lib/integrate-server";
import { toNextJsHandler } from "integrate-sdk/server";
export const { POST, GET } = toNextJsHandler({
client: serverClient, // 传递客户端
redirectUrl: "/dashboard",
});
这会从步骤1导入你的配置,并处理所有的OAuth操作(授权、回调、状态、断开连接)在一个文件中!
在API路由或服务器组件中使用服务器客户端:
// app/api/repos/route.ts
import { serverClient } from "@/lib/integrate-server";
export async function GET() {
// 在第一次调用时自动连接 - 不需要手动设置!
const repos = await serverClient.github.listOwnRepos({ per_page: 10 });
return Response.json({ repos });
}
在你的客户端组件中使用(不需要密钥):
"use client";
import { createMCPClient, githubIntegration } from "integrate-sdk";
const client = createMCPClient({
integrations: [
githubIntegration({
scopes: ["repo", "user"],
// 不需要clientId或clientSecret!
}),
],
oauthFlow: { mode: "popup" },
});
// 授权用户(打开弹出窗口)
await client.authorize("github");
// 使用客户端 - 自动连接!
const result = await client.github.createIssue({
owner: "owner",
repo: "repo",
title: "Bug report",
body: "Description of the bug",
});
console.log("Issue created:", result);
就是这样! SDK会自动:
connect())disconnect())SDK会自动为你管理连接 - 不需要手动connect()或disconnect()调用!
特性:
// ✅ 默认行为 - 自动连接
// 集成会自动使用GITHUB_CLIENT_ID和GITHUB_CLIENT_SECRET从环境变量
const client = createMCPClient({
integrations: [
githubIntegration({
scopes: ["repo", "user"],
}),
],
});
// 立即使用 - 不需要connect()!
await client.authorize("github");
await client.github.listRepos({ username: "octocat" });
// ✅ 想要手动控制?使用手动模式
const manualClient = createMCPClient({
integrations: [githubIntegration({ scopes: ["repo"] })],
connectionMode: "manual",
singleton: false,
});
await manualClient.connect();
await manualClient.authorize("github");
await manualClient.github.listRepos({ username: "octocat" });
await manualClient.disconnect();
需要帮助? 查看完整文档获取详细的指南、示例和API参考。
SDK在两种环境中都能工作:
'integrate-sdk'使用createMCPClient() - 处理OAuth UI(弹出窗口/重定向)'integrate-sdk/server'使用createMCPServer() - 包含API路由的OAuth密钥查看上面的快速开始以获取完整示例。
使用完整的自动补全的类型化方法,而不是通用工具调用:
// ✅ 新:带有自动补全的类型化方法
await client.github.createIssue({
owner: "user",
repo: "project",
title: "Bug",
});
await client.gmail.sendEmail({ to: "user@example.com", subject: "Hello" });
// 1. 类型化集成方法(推荐用于内置集成如GitHub/Gmail)
await client.github.createIssue({
owner: "user",
repo: "project",
title: "Bug",
});
await client.gmail.sendEmail({ to: "user@example.com", subject: "Hello" });
// 2. 类型化服务器方法(用于服务器级别的工具)
await client.server.listToolsByIntegration({ integration: "github" });
// 3. 直接调用工具(用于其他服务器支持的集成)
await client._callToolByName("slack_send_message", {
channel: "#general",
text: "Hello",
});
SDK实现了OAuth 2.0授权码流与PKCE进行安全授权。
关键特性:
基本用法:
// 检查授权
if (!(await client.isAuthorized("github"))) {
await client.authorize("github"); // 打开弹出窗口或重定向
}
// 使用已授权的客户端
const repos = await client.github.listOwnRepos({});
对于完整的OAuth设置包括:
使用类型安全的方法访问GitHub仓库、问题、拉取请求等。
// 可用方法
await client.github.getRepo({ owner: "facebook", repo: "react" });
await client.github.createIssue({ owner: "user", repo: "repo", title: "Bug" });
await client.github.listPullRequests({
owner: "user",
repo: "repo",
state: "open",
});
await client.github.listOwnRepos({});
使用类型安全的方法发送邮件、管理标签和搜索消息。
// 可用方法
await client.gmail.sendEmail({
to: "user@example.com",
subject: "Hello",
body: "Hi!",
});
await client.gmail.listEmails({ maxResults: 10, q: "is:unread" });
await client.gmail.searchEmails({ query: "from:notifications@github.com" });
使用genericOAuthIntegration配置任何服务器支持的集成:
import { genericOAuthIntegration } from "integrate-sdk/server";
// 自动使用SLACK_CLIENT_ID和SLACK_CLIENT_SECRET从环境变量
const slackIntegration = genericOAuthIntegration({
id: "slack",
provider: "slack",
scopes: ["chat:write", "channels:read"],
tools: ["slack_send_message", "slack_list_channels"],
});
查看/examples以获取完整的设置模式。
通过内置的Vercel AI SDK支持,给AI模型提供对所有集成的访问。
import { getVercelAITools } from "integrate-sdk";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
// 将MCP工具转换为Vercel AI SDK格式
const tools = getVercelAITools(mcpClient);
// 与AI模型一起使用
const result = await generateText({
model: openai("gpt-5"),
prompt: "创建一个关于登录bug的GitHub问题",
tools,
maxToolRoundtrips: 5,
});
对于详细的指南、API参考和示例,请访问完整文档:
SDK是用TypeScript构建的,并提供了完整的类型安全和IntelliSense支持。
欢迎贡献!请查看问题了解如何贡献。
# 运行所有测试
bun test
# 带覆盖率运行
bun run test:coverage
查看tests/目录以获取单元和集成测试示例。
MIT © Revyo