
桥接包支持模型上下文协议(MCP)服务器与 AI SDK 工具之间的无缝集成。支持多种服务器类型、实时通信和 TypeScript。
概览
一个桥接包,实现模型上下文协议(MCP)与 AI SDK 之间的无缝集成,实现 MCP 服务器与 AI 模型之间的高效通信和工具执行。 - MCP服务器与AI SDK之间的无缝集成 - 支持多种MCP服务器类型(Node.js、Python、UVX) - 多服务器支持且独立配置 - 通过mcp.config.json灵活配置 - 支持TypeScript及完整类型定义 - 强大的错误处理和日志记录 - 易用的工具执行API 1. 在你的项目根创建一个mcp.config.json文件: 2. 导入并在代码中使用桥接: mcp.config.json文件支持多台服务器和通信模式。每个服务器都可以独立配置。 桥接器支持不同的通信模式: - 通过标准输入/输出实现直接通信 - 最适合简单集成和本地开发 - 低延迟且设置需求最小 2.
概述(AI 翻译)
一个桥接包,实现模型上下文协议(MCP)与 AI SDK 之间的无缝集成,实现 MCP 服务器与 AI 模型之间的高效通信和工具执行。
特色
- MCP服务器与AI SDK之间的无缝集成
- 支持多种MCP服务器类型(Node.js、Python、UVX)
- 多服务器支持,配置独立
- 通过[[T0]实现灵活配置]
- 支持TypeScript,支持完整的类型定义
- 稳健的错误处理和日志记录
- 易用的工具执行API
安装
快速启动
-
在你的项目根创建一个
mcp.config.json文件: -
导入并在代码中使用桥接:
配置
mcp.config.json 文件支持多个服务器和通信模式。每个服务器都可以独立配置。
服务器配置示例:
推特MCP服务器
火爬服务器
SSE 服务器
服务器模式
桥接器支持不同的通信模式:
- stdio 模式(默认)
- 通过标准输入/输出实现直接通信
- 最适合简单集成和本地开发
- 低延迟和最小的设置需求
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
AISDK MCP Bridge
A bridge package that enables seamless integration between the Model Context Protocol (MCP) and AI SDK, allowing for efficient communication and tool execution between MCP servers and AI models.
Features
- Seamless integration between MCP servers and AI SDK
- Support for various MCP server types (Node.js, Python, UVX)
- Multi-server support with independent configuration
- Flexible configuration through
mcp.config.json - TypeScript support with full type definitions
- Robust error handling and logging
- Easy-to-use API for tool execution
Installation
npm install aisdk-mcp-bridge
Quick Start
- Create an
mcp.config.jsonfile in your project root:
{
"mcpServers": {
"twitter-mcp": {
"command": "npx",
"args": ["-y", "@enescinar/twitter-mcp"],
"env": {
"API_KEY": "your-twitter-api-key",
"API_SECRET_KEY": "your-twitter-api-secret",
"ACCESS_TOKEN": "your-twitter-access-token",
"ACCESS_TOKEN_SECRET": "your-twitter-access-token-secret"
}
},
"firecrawl": {
"command": "npx",
"args": ["-y", "mcp-server-firecrawl"],
"env": {
"FIRE_CRAWL_API_KEY": "your-firecrawl-api-key",
"FIRE_CRAWL_API_URL": "https://api.firecrawl.com"
}
}
}
}
- Import and use the bridge in your code:
import { generateText } from 'ai';
import { google } from '@ai-sdk/google';
import { getMcpTools, cleanupMcp, initializeMcp } from 'aisdk-mcp-bridge';
import dotenv from 'dotenv';
dotenv.config();
async function main() {
try {
// Initialize MCP
await initializeMcp({ debug: true });
// Get tools from all servers
const allTools = await getMcpTools({ debug: true });
// Or get tools from a specific server
const twitterTools = await getMcpTools({
debug: true,
serverName: 'twitter-mcp',
});
// Use tools with AI SDK
const result = await generateText({
model: google('gemini-1.5-pro'),
messages: [
{
role: 'system',
content:
'You are an AI assistant that uses various tools to help users.',
},
{
role: 'user',
content: 'Your task description here',
},
],
tools: twitterTools, // or allTools for all available tools
});
console.log('Result:', result.text);
} finally {
// Clean up resources
await cleanupMcp();
}
}
main().catch(error => {
console.error('Error:', error);
process.exit(1);
});
Configuration
The mcp.config.json file supports multiple servers and communication modes. Each server can be configured independently.
Server Configuration Examples:
Twitter MCP Server
{
安装
npx -y @enescinar/twitter-mcp配置
{
"mcpServers": {
"twitter-mcp": {
"command": "npx",
"args": ["-y", "@enescinar/twitter-mcp"],
"env": {
"API_KEY": "your-twitter-api-key",
"API_SECRET_KEY": "your-twitter-api-secret",
"ACCESS_TOKEN": "your-twitter-access-token",
"ACCESS_TOKEN_SECRET": "your-twitter-access-token-secret"
}
},
"firecrawl": {
"command": "npx",
"args": ["-y", "mcp-server-firecrawl"],
"env": {
"FIRE_CRAWL_API_KEY": "your-firecrawl-api-key",
"FIRE_CRAWL_API_URL": "https://api.firecrawl.com"
}
}
}
}