Ai Sdk Tool To
БесплатноНе проверенconverts ai sdk tools to mcp server compatible tools. supports node fastmcp
Описание
converts ai sdk tools to mcp server compatible tools. supports node fastmcp
README
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 toolaiTool(AISDKTool): An AI SDK tool object created withtool()from theaipackage
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
executefunction 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:
- Schema: Passes the Zod schema directly (no conversion needed - both use Zod!)
- Execution: Wraps the AI SDK
executefunction to provide the context object it expects - Error Handling: Catches errors and wraps them with helpful messages
- Result Formatting: Converts the result to a JSON string as FastMCP expects
Examples
Check out the examples directory:
- basic-stdio.ts - Basic stdio server example
- server.ts - Full server with multiple tools
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
Установка Ai Sdk Tool To
У этого сервера нет опубликованного пакета — он собирается из исходников. Открой репозиторий и следуй инструкции в README.
▸ github.com/tengis617/ai-sdk-tool-to-mcpFAQ
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
Fetch
Web content fetching and conversion for efficient LLM usage.
AWS KB Retrieval
Retrieval from AWS Knowledge Base using Bedrock Agent Runtime.
автор: modelcontextprotocolSpring AI MCP Server
Provides auto-configuration for setting up an MCP server in Spring Boot applications.
llm-analysis-assistant
A very streamlined mcp client that supports calling and monitoring stdio/sse/streamableHttp, and can also view request responses through the /logs page. It also
автор: xuzexin-hzMCP-Agent
A simple, composable framework to build agents using Model Context Protocol by [LastMile AI](https://www.lastmileai.dev)
автор: lastmile-aiSpring AI MCP Client
Provides auto-configuration for MCP client functionality in Spring Boot applications.
mcp.natoma.ai
A Hosted MCP Platform to discover, install, manage and deploy MCP servers by [Natoma Labs](https://www.natoma.ai)
MCPHub
Website to list high quality MCP servers and reviews by real users. Also provide online chatbot for popular LLM models with MCP server support.
MCP Servers Rating and User Reviews
Website to rate MCP servers, write authentic user reviews, and [search engine for agent & mcp](http://www.deepnlp.org/search/agent)
mkinf
An Open Source registry of hosted MCP Servers to accelerate AI agent workflows.
Compare Ai Sdk Tool To with
Не уверен что выбрать?
Найди свой стек за 60 секунд
Автор?
Embed-бейдж для README
Похожее
Все в категории ai
