
이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
MCP 서버가 몇 초 동안 Type-safe TypeScript SDK로 설정 - OAuth 2.1 및 멀티 프로바이더 지원
개요
Remote MCP 서버(Streamable HTTP 또는 SSE)를 위한 TypeScript 클라이언트를 생성: URL에 가하면 도구당 하나의 메소드를 가진 모듈을 얻습니다. - - 입력 및 출력은 서버의 JSON Schemas에서 옵니다. - 각 메소드는 공식 MCP SDK를 호출하고 결과 변경을 반환합니다. - 생성 된 코드는 SDK 유형 만 가져올 수 없습니다. - 서버가 요청하는 경우 브라우저 및 생성은 계속됩니다. MCP SDK (과 oauth-callback 서버가 OAuth를 사용하는 경우) : OAuth 없음? SDK를 혼자 연결: client.connect(new StreamableHTTPClientTransport(new URL(url)))를 기다립니다. CLI는 파일을 작성한 후 서버에 적합한 스니펫을 인쇄합니다. 도구는 방법입니다. 결과는 SDK의 CallToolResult입니다. 도구가 출력 스키마를 선언할 때 StructuredContent는 check isError를 한 번 입력됩니다. Prompts 및 리소스, 서버가있을 때, namespaces에 살고: 테스트에서 실제 클라이언트 대신 일반 객체를 통과하십시오. 공장은 호출하는 방법 만 필요합니다.
개요(AI 번역)
Remote MCP 서버(Streamable HTTP 또는 SSE)를 위한 TypeScript 클라이언트를 생성: URL에 가하면 도구당 하나의 메소드를 가진 모듈을 얻습니다.
- Typed - 입력 및 출력은 서버의 JSON Schemas에서 제공됩니다. -Thin — 각 메소드는 공식 MCP SDK를 호출하고 결과가 변경되지 않습니다. -No lock-in — 생성된 코드 가져오기만 SDK 유형, 결코 이 패키지 -OAuth handled — 서버가 요청한 경우, 브라우저 및 생성에 대한 승인이 계속됩니다.
빠른 시작
**1. 생성 ** 서버의 URL에서 모듈:
**2. 설치 ** MCP SDK (및 oauth-callback] 서버가 OAuth를 사용하는 경우:
3. Connect SDK Client 및 래핑:
OAuth 없음? 혼자 SDK와 연결: await client.connect(new StreamableHTTPClientTransport(new URL(url))). CLI는 파일을 작성한 후 서버에 적합한 스니펫을 인쇄합니다.
클라이언트 사용
도구는 방법입니다. 결과는 SDK의 CallToolResult입니다. 도구가 출력 스키마를 선언할 때, structuredContent]를 한 번 입력하면 isError]를 확인할 수 있습니다.
Prompts 및 리소스, 서버가있을 때, namespaces에 살고:
테스트에서, 실제 대신 일반 객체를 통과 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
설치
npx mcp-client-gen https://mcp.notion.com/mcp -o src/notion.ts설정
// .mcp.json
{
"mcpServers": {
"notion": { "url": "https://mcp.notion.com/mcp" },
"github": {
"url": "https://api.githubcopilot.com/mcp/",
"headers": { "Authorization": "Bearer ${GITHUB_TOKEN}" },
},
},
}