mcp-to-ai-sdk
CLAUDE.md122 starsChanged 15 months agoApache-2.0View on GitHub
This is mcp-to-ai-sdk, a CLI tool that generates Vercel AI SDK wrappers for Model Context Protocol (MCP) tools. It connects to MCP servers, discovers their tools, and generates type-safe TypeScript wrappers that can be used with the Vercel AI SDK. Main CLI File (mcp-tools-cli.ts) Generated Code Architecture The CLI generates a directory structure like mcps/mcp.grep.app/ with: Tool Factory Pattern: Tools are generated as factory functions that accept a client getter, enabling both default shared client usage and custom client injection.
The file
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is mcp-to-ai-sdk, a CLI tool that generates Vercel AI SDK wrappers for Model Context Protocol (MCP) tools. It connects to MCP servers, discovers their tools, and generates type-safe TypeScript wrappers that can be used with the Vercel AI SDK.
Development Commands
# Build the CLI
npm run build
# Run the CLI directly (after building)
npm run dev <MCP_URL_OR_PATH>
# Test the built CLI
node dist/mcp-tools-cli.js https://mcp.grep.appArchitecture
Core Components
Main CLI File (mcp-tools-cli.ts)
- Single-file CLI that handles all generation logic
- Contains functions for connecting to MCP servers (HTTP/SSE/Stdio transports)
- Generates three types of files for each MCP server
Generated Code Architecture
The CLI generates a directory structure like mcps/mcp.grep.app/ with:
client.ts- Shared MCP client with lazy connection- Uses singleton pattern with connection promise deduplication
- Handles all transports: StreamableHTTP (default), SSE, or Stdio
- Single persistent connection shared across all tools
{toolName}.ts- Individual tool implementations- Each exports a
{toolName}ToolWithClientfactory function - Takes a client getter function as parameter for dependency injection
- Uses
json-schema-to-zodfor automatic schema conversion
- Each exports a
index.ts- Convenience exports- Domain-based naming (e.g.,
mcpGrepToolsfor mcp.grep.app) - Two export patterns: default client and custom client injection
- Individual tool re-exports for granular imports
- Domain-based naming (e.g.,
Key Design Patterns
Tool Factory Pattern: Tools are generated as factory functions that accept a client getter, enabling both default shared client usage and custom client injection.
Domain-based Naming: Export names are generated from MCP URLs (e.g., mcp.grep.app → mcpGrep) with intelligent TLD and prefix stripping.
Transport Abstraction: The CLI auto-detects URLs vs file paths and chooses appropriate MCP transport (StreamableHTTP, SSE, or Stdio).
Schema Conversion: JSON Schema from MCP tools is automatically converted to Zod schemas using json-schema-to-zod with manual fallback.
File Generation Logic
The main generation flow in mcp-tools-cli.ts:
fetchToolDefinitions()- Connects to MCP and lists toolsgenerateClientFile()- Creates shared client with lazy connectiongenerateAISDKTool()- Creates individual tool wrappersgenerateIndexFile()- Creates convenience exports with domain-based naming
Build System
- TypeScript compilation to
dist/directory - Target: ES2022 with NodeNext modules
- Generates declarations and source maps
- Excludes
mcps/directory from compilation (contains generated output)
CLI Usage Patterns
The tool supports multiple MCP connection methods:
- HTTP URLs:
mcp-to-ai-sdk https://mcp.grep.app(uses StreamableHTTP) - SSE endpoints:
mcp-to-ai-sdk --sse https://example.com/mcp/sse - Local servers:
mcp-to-ai-sdk /path/to/server.js(uses Stdio)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

