Command Palette

Search for a command to run...

UnylyUnyly
Весь каталог

Ai Sdk Tool To

БесплатноНе проверен

converts ai sdk tools to mcp server compatible tools. supports node fastmcp

GitHubEmbed

Описание

converts ai sdk tools to mcp server compatible tools. supports node fastmcp

README

License: MIT TypeScript

A simple wrapper function to convert AI SDK tools to FastMCP tools.

Overview

This is a tiny utility that converts AI SDK tool definitions to FastMCP tool format:

  • Simple wrapper function - just one function: toFastMCPTool()
  • 🔄 Preserve type safety with full TypeScript support
  • 🛠️ Handle errors gracefully with automatic error wrapping
  • 📦 Zero dependencies - only peer dependencies you already have

Installation

bun add @tengis617/ai-sdk-tool-to-mcp
# or
npm install @tengis617/ai-sdk-tool-to-mcp

Peer dependencies (install if you don't already have them):

bun add ai zod fastmcp

Quick Start

import { tool } from 'ai';
import { z } from 'zod';
import { FastMCP } from 'fastmcp';
import { toFastMCPTool } from '@tengis617/ai-sdk-tool-to-mcp';

// Define your AI SDK tool
const weatherTool = tool({
  description: 'Get the current weather in a given location',
  inputSchema: z.object({
    location: z.string().describe('The city and state, e.g. San Francisco, CA'),
    unit: z.enum(['celsius', 'fahrenheit']).optional().default('fahrenheit'),
  }),
  execute: async ({ location, unit }) => {
    return { location, temperature: 72, unit, conditions: 'Sunny' };
  },
});

// Convert to FastMCP tool and add to server
const server = new FastMCP({ name: 'my-server', version: '1.0.0' });
server.addTool(toFastMCPTool('weather', weatherTool));

server.start({ transportType: 'stdio' });

Usage

Basic Example

import { tool } from 'ai';
import { z } from 'zod';
import { FastMCP } from 'fastmcp';
import { toFastMCPTool } from '@tengis617/ai-sdk-tool-to-mcp';

const calculatorTool = tool({
  description: 'Perform basic arithmetic operations',
  inputSchema: z.object({
    operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
    a: z.number(),
    b: z.number(),
  }),
  execute: async ({ operation, a, b }) => {
    switch (operation) {
      case 'add': return { result: a + b };
      case 'subtract': return { result: a - b };
      case 'multiply': return { result: a * b };
      case 'divide': 
        if (b === 0) throw new Error('Division by zero');
        return { result: a / b };
    }
  },
});

const server = new FastMCP({
  name: 'calculator-server',
  version: '1.0.0',
});

// Convert and add the tool
server.addTool(toFastMCPTool('calculator', calculatorTool));

server.start({ transportType: 'stdio' });

Multiple Tools

Add multiple tools to your server:

const server = new FastMCP({
  name: 'my-tools',
  version: '1.0.0',
});

server.addTool(toFastMCPTool('weather', weatherTool));
server.addTool(toFastMCPTool('calculator', calculatorTool));
server.addTool(toFastMCPTool('search', searchTool));

server.start({ transportType: 'stdio' });

Complex Schemas

The wrapper handles complex Zod schemas automatically:

const createUserTool = tool({
  description: 'Create a new user',
  inputSchema: z.object({
    username: z.string().min(3).max(20),
    profile: z.object({
      firstName: z.string(),
      lastName: z.string(),
      email: z.string().email(),
      age: z.number().optional(),
    }),
    tags: z.array(z.string()).default([]),
  }),
  execute: async (params) => {
    return {
      id: crypto.randomUUID(),
      ...params,
      createdAt: new Date().toISOString(),
    };
  },
});

server.addTool(toFastMCPTool('createUser', createUserTool));

API Reference

toFastMCPTool(name: string, aiTool: AISDKTool): FastMCPTool

Converts an AI SDK tool to a FastMCP tool.

Parameters:

  • name (string): The name of the tool
  • aiTool (AISDKTool): An AI SDK tool object created with tool() from the ai package

Returns: A FastMCP tool object that can be passed to server.addTool()

What it does:

  • Passes through the Zod schema (both AI SDK and FastMCP use Zod natively)
  • Wraps the AI SDK execute function to work with FastMCP's calling convention
  • Handles errors and wraps them with helpful messages
  • Converts results to JSON strings as expected by FastMCP

How It Works

This is a simple wrapper that adapts AI SDK tools to FastMCP's interface:

  1. Schema: Passes the Zod schema directly (no conversion needed - both use Zod!)
  2. Execution: Wraps the AI SDK execute function to provide the context object it expects
  3. Error Handling: Catches errors and wraps them with helpful messages
  4. Result Formatting: Converts the result to a JSON string as FastMCP expects

Examples

Check out the examples directory:

Run examples with:

bun run examples/basic-stdio.ts
bun run examples/server.ts

Use Cases

  • Expose AI SDK tools to MCP clients (Claude Desktop, Cline, etc.)
  • Quick MCP servers: Turn your existing AI SDK tools into MCP servers
  • Tool sharing: Use the same tool definitions across AI SDK and FastMCP applications

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

License

MIT License - see LICENSE file for details

Related

  • AI SDK - Vercel's AI SDK for building AI-powered applications
  • FastMCP - Fast, simple MCP server framework
  • Model Context Protocol - Protocol for connecting AI models with external context

from github.com/tengis617/ai-sdk-tool-to-mcp

Установка Ai Sdk Tool To

У этого сервера нет опубликованного пакета — он собирается из исходников. Открой репозиторий и следуй инструкции в README.

▸ github.com/tengis617/ai-sdk-tool-to-mcp

FAQ

Ai Sdk Tool To MCP бесплатный?

Да, Ai Sdk Tool To MCP бесплатный — установка в пару кликов через Unyly без оплаты.

Нужен ли API-ключ для Ai Sdk Tool To?

Нет, Ai Sdk Tool To работает без API-ключей и переменных окружения.

Ai Sdk Tool To — hosted или self-hosted?

Self-hosted: сервер запускается локально на твоей машине командой из раздела установки.

Как установить Ai Sdk Tool To в Claude Desktop, Claude Code или Cursor?

Открой Ai Sdk Tool To на unyly.org, выбери вкладку своего клиента (Claude Desktop, Claude Code, Cursor) и нажми Install — конфиг сгенерируется автоматически, без правки JSON.

Похожие MCP

Compare Ai Sdk Tool To with

Не уверен что выбрать?

Найди свой стек за 60 секунд

Автор?

Embed-бейдж для README

Похожее

Все в категории ai