VA

vrknetha/aisdk-mcp-bridge

Developer tools

Эта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал

23 stars 2 forks Качество 64 Тренд 10MIT

Bridge package enabling seamless integration between Model Context Protocol (MCP) servers and AI SDK tools. Supports multiple server types, real-time communication, and TypeScript.

Обзор

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. - 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 1. Create an mcp.config.json file in your project root: 2. Import and use the bridge in your code: The mcp.config.json file supports multiple servers and communication modes. Each server can be configured independently. The bridge supports different communication modes: - Direct communication through standard input/output - Best for simple integrations and local development - Low latency and minimal setup required 2.

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

  1. Create an mcp.config.json file 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"
      }
    }
  }
}
  1. 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

{
Открыть полный README на GitHub

Установка

npx -y @enescinar/twitter-mcp
Новичок в MCP? Начните с руководства на mcpskill.org →

Конфигурация

{ "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" } } } }