npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@opentiny/next

v0.3.1

Published

OpenTiny NEXT

Readme

OpenTiny NEXT

OpenTiny NEXT 是一个基于 Model Context Protocol(MCP)的 TypeScript 库,提供了多种传输方式来支持 MCP 客户端与服务端的通信。本库支持三种主要的传输方式:

  1. MessageChannel API - 用于浏览器内部不同上下文之间的通信
  2. SSE (Server-Sent Events) Client Proxy - 基于 HTTP 长连接实现单向数据推送的 Client 连接代理
  3. Streamable HTTP Client Proxy - 通过分块传输编码实现任意数据的流式传输的 Client 连接代理

安装

npm install @opentiny/next

客户端 API

客户端 API 主要用于在浏览器环境中的 MCP 通信。

MessageChannel API

在同一浏览器窗口内互相通信的场景

使用 createTransportPair 创建一对可互通的 Transport 服务的和客户端实例来进行通信。

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { createTransportPair } from '@opentiny/next';

// 创建一对可互通的 Transport 实例
const [serverTransport, clientTransport] = createTransportPair();

// 创建 MCP 服务端和客户端实例
const capabilities = { prompts: {}, resources: {}, tools: {}, logging: {} };
const server = new McpServer({ name: 'mcp-server', version: '1.0.0' }, { capabilities });
const client = new Client({ name: 'mcp-client', version: '1.0.0' }, { capabilities });

// 建立服务端和客户端的通信连接
await server.connect(serverTransport);
await client.connect(clientTransport);

// 将客户端实例存储到状态中
state.client = client;

在浏览器主线程与 iframe、Web Worker 等互相通信的场景

使用 MessageChannelServerTransportMessageChannelClientTransport 创建用于监听的 Transport 服务端实例,以及用于连接的 Transport 客户端实例来进行通信。

以下是在浏览器主线程的代码:

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { MessageChannelServerTransport } from '@opentiny/next';

// 创建用于监听的 Transport 服务端实例
const serverTransport = new MessageChannelServerTransport('endpoint');

// 创建 MCP 服务端实例
const capabilities = { prompts: {}, resources: {}, tools: {}, logging: {} };
const server = new McpServer({ name: 'mcp-server', version: '1.0.0' }, { capabilities });

// 监听 endpoint 端点,等待客户端连接
await serverTransport.listen();

// 建立服务端和客户端的通信连接
await server.connect(serverTransport);

以下是在 iframe、Web Worker 的代码:

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { MessageChannelClientTransport } from '@opentiny/next';

// 创建用于连接的 Transport 客户端实例
const clientTransport = new MessageChannelClientTransport('endpoint');

// 创建 MCP 客户端实例
const capabilities = { prompts: {}, resources: {}, tools: {}, logging: {} };
const client = new Client({ name: 'mcp-client', version: '1.0.0' }, { capabilities });

// 建立服务端和客户端的通信连接
await client.connect(clientTransport);

// 将客户端实例存储到状态中
state.client = client;

请注意:创建 MessageChannelServerTransport 实例必须在创建 MessageChannelClientTransport 实例之前,确保客户端连接之前服务端已经开始监听。由于 iframe、Web Worker 等代码运行通常在浏览器主线程之后,所以上述示例代码执行顺序一般是先创建 MessageChannelServerTransport 实例,后创建 MessageChannelClientTransport 实例。

许可证

MIT