MCP服务器SDK

MCP-Builder.ai官方SDK,提供Python和TypeScript支持,可快速连接AI驱动的MCP服务器,实现实时聊天、工具执行和会话管理。

  • by MCP-Builder-ai
  • Python
  • 本地部署
  • 12 星标
  • 更新于
在 GitHub 查看 MCP-Builder-ai/mcpbuilder-ai

使用说明

mcpbuilder-ai

Connect your apps to AI-powered MCP servers — in minutes, not months.

mcpbuilder-ai is the official SDK for MCP-Builder.ai, available for both Python and TypeScript.
Stream chat responses, execute tools with consent handling, and manage authentication — all through a clean, callback-driven API over WebSockets.

Build your MCP server on the MCP-Builder.ai dashboard, grab your project token, and start talking to it from any app with just a few lines of code.


运作原理

┌─────────────────────┐         ┌──────────────────────────┐
│   Your Application  │  SDK    │   MCP-Builder.ai Cloud   │
│                     │ ─────►  │                          │
│  - Web frontend     │  WS     │  - MCP Server you built  │
│  - CLI tool         │ ◄─────  │  - Tool execution        │
│  - Backend service  │         │  - LLM orchestration     │
└─────────────────────┘         └──────────────────────────┘
  1. 设计 您的MCP服务器位于 mcp-builder.ai --配置工具,连接API,设置身份验证。
  2. 安装 SDK(pip install mcpbuilder-ai / npm install mcpbuilder-ai).
  3. 连接 使用您的项目令牌和部署名称。
  4. 聊天 --实时流式传输令牌、处理工具调用、管理同意流。

特性

Python TypeScript
实时令牌流 ✅ ✅
Fluent回调API ✅ ✅
工具同意处理 ✅ ✅
通过回退自动重新连接 ✅ ✅
会话和历史管理 ✅ ✅
安全参数覆盖 ✅ ✅
全型安全 ✅ (键入提示) ✅ (TypeScript泛型)
ESM+CommonJS -- ✅

快速开始

TypeScript

npm install mcpbuilder-ai
import { MCPChatClient } from 'mcpbuilder-ai';

const client = new MCPChatClient({
  projectToken: 'your-project-token',
  deploymentName: 'my-deployment',
  cacheHistory: false,
});

client
  .onToken((token) => process.stdout.write(token))
  .onFinal((text, toolCalls) => console.log('\nDone!'))
  .onError((error) => console.error('Error:', error));

await client.connect();
await client.sendMessage('Hello, what can you do?');

python

pip install mcpbuilder-ai
import asyncio
from mcpbuilder import MCPChatClient

async def main():
    client = MCPChatClient(
        project_token="your-project-token",
        deployment_name="my-deployment",
        cache_history=False,
    )

    client \
        .on_token(lambda t: print(t, end="", flush=True)) \
        .on_final(lambda text, tc: print("\nDone!")) \
        .on_error(lambda msg: print(f"Error: {msg}"))

    await client.connect()
    await client.send_message("Hello, what can you do?")

asyncio.run(main())

SDK文档

SDK 软件包 文档
TypeScript mcpbuilder-ai 在npm上 TypeScript自述
python mcpbuilder-ai 在PyPI上 Python自述

集成示例

这 例子 目录包含可运行的项目,显示如何连接到构建在其上的MCP服务器 MCP-Builder.ai:

示例 语言 描述
React MCP聊天 TypeScript 基于React的聊天UI,支持流媒体+工具同意
简单的Python命令行界面 Python 带有实时令牌流的终端聊天客户端

新加入MCP-Builder.ai? 检查 入门指南 创建您的第一个项目并获取项目令牌。


MCP-Builder.ai入门

  1. 注册 在 mcp-builder.ai 然后打开仪表板。
  2. 创建项目 --定义您的工具,连接外部API,并配置身份验证。
  3. 部署 只需单击一下即可访问您的MCP服务器。
  4. 复制 仪表板中的项目令牌和部署名称。
  5. 安装 SDK并将凭据粘贴到您的应用程序中——您就可以使用了。

贡献

欢迎投稿!请随时打开问题或提交pull请求。

许可证

Apache-2.0--有关详细信息,请参阅[LICENSE]。