https://github.com/kriasoft/mcp-client-gen
Turn any MCP server into a type-safe TypeScript SDK in seconds - with OAuth 2.1 and multi-provider support
https://github.com/kriasoft/mcp-client-gen
ai ai-agent anthropic bun claude code-generation cursor llm llms mcp mcp-client mcp-sdk mcp-server mcp-tools model-context-protocol oauth2 openai typescript zed
Last synced: about 1 month ago
JSON representation
Turn any MCP server into a type-safe TypeScript SDK in seconds - with OAuth 2.1 and multi-provider support
- Host: GitHub
- URL: https://github.com/kriasoft/mcp-client-gen
- Owner: kriasoft
- License: mit
- Created: 2025-08-13T14:04:21.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-08-16T23:21:56.000Z (about 2 months ago)
- Last Synced: 2025-08-16T23:27:26.108Z (about 2 months ago)
- Topics: ai, ai-agent, anthropic, bun, claude, code-generation, cursor, llm, llms, mcp, mcp-client, mcp-sdk, mcp-server, mcp-tools, model-context-protocol, oauth2, openai, typescript, zed
- Language: TypeScript
- Homepage: https://medium.com/@koistya/why-i-built-mcp-client-generator-and-why-you-should-care-c860193ca902
- Size: 42 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# MCP Client Generator
๐ Generate type-safe TypeScript clients from any MCP (Model Context Protocol) server.
```typescript
import { notion, github, slack } from "./src/mcp-client";// Type-safe client calls with full IntelliSense
const page = await notion.createPage({
title: "Meeting Notes",
content: "Discussion about Q4 roadmap...",
});const issue = await github.createIssue({
title: "Bug: Login failure",
body: "Users cannot authenticate...",
});await slack.notify({
channel: "#dev",
message: `New issue created: ${issue.url}`,
});
```## Features
โจ **Type-Safe** - Full TypeScript support with generated types
๐ **Multi-Provider** - Connect to multiple MCP servers simultaneously
๐ฏ **Tree-Shakable** - Only bundle the methods you use
โก **Fast** - Built with Bun for optimal performance
๐ ๏ธ **Interactive CLI** - Smart prompts with sensible defaults
โ๏ธ **Flexible** - Works with multiple MCP config formats## Installation
```bash
npm install -g mcp-client-gen
# or use directly
npx mcp-client-gen
```## Quick Start
### 1. Configure MCP Servers
Create a `.mcp.json` file with your MCP server endpoints:
```jsonc
{
"mcpServers": {
"notion": {
"type": "http",
"url": "https://mcp.notion.com/mcp",
},
"github": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp/",
},
},
}
```### 2. Generate Client SDK
**Interactive Mode (Recommended):**
```bash
npx mcp-client-gen # Launch interactive prompts
npx mcp-client-gen -y # Accept all defaults and proceed
```**Direct Mode:**
```bash
npx mcp-client-gen ./src/mcp-client.ts
```### 3. Use the Generated Client
```typescript
import { notion } from "./src/mcp-client";// All methods are fully typed based on the MCP server schema
const page = await notion.fetchPage("page-id");
const newPage = await notion.createPage({
title: "My Page",
content: "Page content...",
});
```## CLI Reference
### Interactive Mode
```bash
npx mcp-client-gen # Launch interactive prompts
npx mcp-client-gen -y # Accept defaults and proceed
npx mcp-client-gen --yes # Same as -y
```### Direct Mode
```bash
npx mcp-client-gen [options]Arguments:
output-file Path for the generated client fileOptions:
--config MCP configuration file (default: auto-discover)
-y, --yes Accept all defaults and skip prompts
--help Show help informationExamples:
npx mcp-client-gen # Interactive mode
npx mcp-client-gen -y # Quick generation with defaults
npx mcp-client-gen ./src/mcp-client.ts # Direct mode with output file
npx mcp-client-gen --config custom.json ./src/clients.ts
```## Use Cases
๐ **API Integration** - Connect to multiple services with one SDK
๐ค **Workflow Automation** - Build cross-platform automation scripts
๐ **Data Synchronization** - Keep data in sync across different platforms
๐งช **Rapid Prototyping** - Quickly test integrations with type safety## Development Status
> **Preview Release** - This is an early preview. The core CLI and configuration parsing works, but MCP server introspection is still in development.
**Current Status:**
- โ CLI interface and configuration parsing
- โ Interactive prompts with smart defaults
- โ Multi-server client generation structure
- โ Multiple MCP config format support (.mcp.json, .cursor/, .vscode/)
- ๐ง MCP server schema introspection (in progress)
- ๐ง Real-time type generation from server capabilities
- ๐ Plugin system for custom transformations**Coming Soon:**
- Full MCP protocol implementation
- Authentication handling
- Streaming support
- Error handling and retries## Authentication
Generated MCP clients include built-in support for OAuth 2.1 authentication using RFC 7591 Dynamic Client Registration. The authentication flow is handled automatically:
### OAuth 2.1 Support
- **Dynamic Client Registration (RFC 7591)** - Clients automatically register with OAuth providers
- **PKCE Flow (RFC 7636)** - Secure authorization code exchange with Proof Key for Code Exchange
- **Multiple Auth Methods** - Supports `client_secret_basic`, `client_secret_post`, and public clients
- **Token Management** - Automatic token refresh and credential storage
- **Resource Protection** - RFC 9728 OAuth 2.0 Protected Resource Metadata support### Authentication Flow
1. **Discovery** - Client discovers OAuth authorization server metadata
2. **Registration** - Dynamic client registration if credentials not found
3. **Authorization** - PKCE-based authorization code flow initiation
4. **Token Exchange** - Secure token exchange with automatic refresh
5. **API Calls** - Authenticated requests using Bearer tokens### Configuration
Authentication is configured per MCP server in your `.mcp.json`:
```jsonc
{
"mcpServers": {
"secured-service": {
"type": "http",
"url": "https://api.example.com/mcp",
"auth": {
"type": "oauth",
"clientId": "your-client-id", // Optional for dynamic registration
"scopes": ["read", "write"],
},
},
},
}
```## Support & License
If this tool helps you build amazing integrations, consider [sponsoring the project](https://github.com/sponsors/koistya) to support continued development. ๐
---
**MIT Licensed** โข Feel free to use this in your commercial projects, contribute back, or fork it entirely. Code should be free! ๐
Built with โค๏ธ by [Konstantin Tarkus](https://github.com/koistya) and [contributors](https://github.com/kriasoft/mcp-client-gen/graphs/contributors).