Command Palette

Search for a command to run...

UnylyUnyly
Browse all

Ai Sdk Tool To

FreeNot checked

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

GitHubEmbed

About

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

Installing Ai Sdk Tool To

This server has no published package — it is built from source. Open the repository and follow its README.

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

FAQ

Is Ai Sdk Tool To MCP free?

Yes, Ai Sdk Tool To MCP is free — one-click install via Unyly at no cost.

Does Ai Sdk Tool To need an API key?

No, Ai Sdk Tool To runs without API keys or environment variables.

Is Ai Sdk Tool To hosted or self-hosted?

Self-hosted: the server runs locally on your machine via the install command above.

How do I install Ai Sdk Tool To in Claude Desktop, Claude Code or Cursor?

Open Ai Sdk Tool To on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.

Related MCPs

Compare Ai Sdk Tool To with

Not sure what to pick?

Find your stack in 60 seconds

Author?

Embed badge for your README

Browse similar

All ai MCPs