READMEmain
We couldn't render this README. Read it on GitHub
TypeScript SDK for Model Context Protocol (中文版)
这是一个 Model Context Protocol (MCP) 的 TypeScript SDK 的中文版本实现。它提供了一种标准化的方式来与支持 MCP 的服务进行交互。
项目来源
本项目是基于 Model Context Protocol TypeScript SDK 的中文翻译版本,包含完整的文档翻译和代码示例。
原项目采用 MIT 许可证,本翻译版本同样遵循 MIT 许可证。
安装
npm install typescript-sdk-cn
基本用法
import { Client } from 'typescript-sdk-cn';
// 创建一个客户端实例
const client = new Client({
name: "MyClient",
version: "1.0.0"
});
// 连接到服务器
await client.connect(transport);
// 调用方法
const result = await client.callTool({
name: "some_tool",
arguments: {
// 工具参数
}
});
传输层支持
SDK 提供了多种传输层实现:
WebSocket
import { WebSocketClientTransport } from 'typescript-sdk-cn';
const transport = new WebSocketClientTransport(new URL('ws://localhost:8000'));
Server-Sent Events (SSE)
import { SSEClientTransport } from 'typescript-sdk-cn';
const transport = new SSEClientTransport(new URL('http://localhost:8000'));
Standard I/O
import { StdioClientTransport } from 'typescript-sdk-cn';
const transport = new StdioClientTransport({
command: './path/to/server',
args: ['--some-arg']
});
OAuth 认证
SDK 支持 OAuth 2.0 认证流程:
import { auth } from 'typescript-sdk-cn';
const result = await auth(authProvider, {
serverUrl: 'http://localhost:8000'
});
if (result === 'REDIRECT') {
// 用户需要授权
} else {
// 授权成功
}
开发
# 安装依赖
npm install
# 构建项目
npm run build
# 运行测试
npm test
# 检查代码风格
npm run lint
许可证
MIT
贡献指南
欢迎提交 Pull Request 和 Issue。请确保:
- 遵循现有的代码风格
- 添加适当的测试
- 更新相关文档
- 所有测试都能通过
- 代码经过 lint 检查
更多细节请参考 CONTRIBUTING.md。