KM

kriasoft/mcp-client-gen

Developer tools公式

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

21 stars 5 forks 品質 80 トレンド 8MIT

MCP サーバーをタイプ セーフな TypeScript SDK に秒単位で回す - OAuth 2.1 とマルチ provider サポート

概要

リモート MCP サーバー (Streamable HTTP または SSE): 型付き TypeScript クライアントを URL で生成し、ツールごとに 1 つのメソッドでモジュールを取得します。 - — 入力と出力は、サーバーの JSON スキーマから来ています。各メソッドは、公式の MCP SDK を呼び出し、結果が変更されていない - — 生成されたコードは、SDK 型のみをインポートします。このパッケージは、サーバーがブラウザに尋ね、承認し、生成が続行する場合です。 MCP SDK(およびサーバが OAuth を使用した場合の oauth-callback): OAuth なし SDKだけで接続できます。クライアントを待ちます。connect(新しい StreamableHTTPClientTransport(新しいURL(url)))。 CLI は、ファイルを記述した後、サーバーの適切なスニペットを出力します。 ツールはメソッドです。 結果は、SDK の CallToolResult です。 ツールが出力スキーマを宣言すると、 構造化されたContent は、チェックした時にタイプされます。 isError: サーバがそれらを持っているとき、プロンプトとリソース, 名前空間に住んで: テストでは、実際のクライアントの代わりにプレーンオブジェクトを渡します。工場は呼び出しるメソッドだけを必要とします.

概要(AI 翻訳)

リモート MCP サーバー (Streamable HTTP または SSE): 型付き TypeScript クライアントを URL で生成し、ツールごとに 1 つのメソッドでモジュールを取得します。

  • Typed — サーバの JSON スキーマから入力と出力が来る -Thin — 各メソッドは公式のMCP SDKを呼び出し、変更されていない結果を返します。
  • ロックインなし — 生成されたコードはSDKタイプだけをインポートし、このパッケージを決して使用しません
  • OAuth が処理 — サーバが要求する場合、ブラウザと生成の承認が継続

クイックスタート

1. Generate サーバの URL からのモジュール:

2. インストール MCP SDK (およびoauth-callback) サーバが OAuth を使用する場合:

**3. SDK[Clientを接続し、それをラップ:

OAuth なし SDK単独で接続する:[await client.connect(new StreamableHTTPClientTransport(new URL(url)))] CLI は、ファイルを記述した後、サーバーの適切なスニペットを出力します。

クライアントの使用

ツールはメソッドです。 結果は SDK の [CallToolResult です。 ツールが出力スキーマを宣言すると、[structuredContent] が入力されます。

サーバがそれらを持っているとき、プロンプトとリソース, 名前空間に住んで:

テストでは、実際の[[Clientの代わりにプレーンオブジェクトを渡します。工場は呼び出しるメソッドだけを必要とします.

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。

README

以下は原文 README の抜粋です。原文を見る。

MCP Client Generator

Generate a typed TypeScript client for a remote MCP server (Streamable HTTP or SSE): point it at a URL, get a module with one method per tool.

await notion.search({ query: "Meeting Notes" }); // instead of client.callTool({ name: "notion-search", arguments: … })
  • Typed — inputs and outputs come from the server’s JSON Schemas
  • Thin — each method calls the official MCP SDK and returns its result unchanged
  • No lock-in — generated code imports only SDK types, never this package
  • OAuth handled — if the server asks, approve in the browser and generation continues

Quick Start

1. Generate a module from the server’s URL:

npx mcp-client-gen https://mcp.notion.com/mcp -o src/notion.ts

2. Install the MCP SDK (and oauth-callback if the server uses OAuth):

npm install @modelcontextprotocol/client oauth-callback

3. Connect an SDK Client and wrap it:

import { Client } from "@modelcontextprotocol/client";
import { browserAuth } from "oauth-callback/mcp";
import { createNotionClient } from "./notion.js";

const client = new Client(
  { name: "my-app", version: "1.0.0" },
  { versionNegotiation: { mode: "auto" } }, // use the newest protocol the server speaks
);
const auth = browserAuth({
  serverUrl: "https://mcp.notion.com/mcp",
  redirectUri: "http://127.0.0.1:3000/callback",
  clientName: "my-app",
});
await auth.connect(client); // opens the browser when needed
await client.listTools(); // once: lets the SDK validate typed results

const notion = createNotionClient(client);
const result = await notion.search({ query: "Meeting Notes" });

No OAuth? Connect with the SDK alone: await client.connect(new StreamableHTTPClientTransport(new URL(url))). The CLI prints the right snippet for your server after writing the file.

Using the Client

Tools are methods. Results are the SDK’s CallToolResult; when a tool declares an output schema, structuredContent is typed once you’ve checked isError:

const result = await github.searchIssues({ query: "is:open" });
if (result.isError) throw new Error("search failed");
result.structuredContent.items; // typed

Prompts and resources, when the server has them, live in namespaces:

await github.prompts.summarizePr({ number: "42" });
await github.resources.read("repo://octo/app/README.md"); // any URI
await github.resources.issue({ owner: "octo", number: "42" }); // a URI template, filled in
GitHub で README 全文を見る

インストール

npx mcp-client-gen https://mcp.notion.com/mcp -o src/notion.ts
MCP 初心者?mcpskill.org のガイドから始めましょう →

設定

// .mcp.json { "mcpServers": { "notion": { "url": "https://mcp.notion.com/mcp" }, "github": { "url": "https://api.githubcopilot.com/mcp/", "headers": { "Authorization": "Bearer ${GITHUB_TOKEN}" }, }, }, }