Build

Build

Okay, I can help you understand how to use the TypeScript SDK to create different MCP (Mesh Configuration Protocol) servers. However, I need a little more context to give you the *most* helpful answer. Specifically, tell me: 1. **Which MCP SDK are you using?** There are several possibilities, including: * **Istio's MCP SDK (likely part of the `envoyproxy/go-control-plane` project, but you'd be using the TypeScript bindings).** This is the most common use case if you're working with Istio or Envoy. * **A custom MCP implementation.** If you're building your own MCP server from scratch, you'll need to define your own data structures and server logic. * **Another MCP SDK.** There might be other, less common, MCP SDKs available. 2. **What kind of MCP server do you want to create?** What specific resources will it serve? For example: * **Route Configuration (RDS) server:** Serves route configurations to Envoy proxies. * **Cluster Configuration (CDS) server:** Serves cluster definitions to Envoy proxies. * **Listener Configuration (LDS) server:** Serves listener configurations to Envoy proxies. * **Endpoint Discovery Service (EDS) server:** Serves endpoint information to Envoy proxies. * **A custom resource server:** Serves your own custom resource types. 3. **What is your desired level of detail?** Do you want: * **A high-level overview of the process?** * **Example code snippets?** * **A complete, runnable example?** (This would be more complex and require more information from you.) **General Steps (Assuming Istio/Envoy MCP):** Here's a general outline of the steps involved in creating an MCP server using a TypeScript SDK (assuming it's based on the Envoy/Istio MCP protocol): 1. **Install the Necessary Packages:** You'll need to install the appropriate TypeScript packages. This will likely involve: * The core gRPC library for TypeScript (`@grpc/grpc-js` or similar). * The generated TypeScript code from the Protocol Buffers (`.proto`) definitions for the MCP resources you want to serve (e.g., `envoy.config.route.v3`, `envoy.config.cluster.v3`, etc.). You'll typically use `protoc` (the Protocol Buffer compiler) and a TypeScript plugin to generate these files. * Potentially, a library that provides helper functions for working with MCP. ```bash npm install @grpc/grpc-js google-protobuf # And potentially other packages depending on your setup ``` 2. **Generate TypeScript Code from Protocol Buffers:** You'll need to obtain the `.proto` files that define the MCP resources (e.g., from the `envoyproxy/go-control-plane` repository or your own custom definitions). Then, use `protoc` to generate TypeScript code from these files. This will create the TypeScript classes that represent the resource types. Example `protoc` command (you'll need to adjust this based on your `.proto` file locations and plugin configuration): ```bash protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --ts_out=. your_mcp_resource.proto ``` 3. **Implement the gRPC Service:** Create a TypeScript class that implements the gRPC service defined in the `.proto` files. This class will have methods that correspond to the MCP endpoints (e.g., `StreamRoutes`, `StreamClusters`, etc.). These methods will receive requests from Envoy proxies and return the appropriate resource configurations. 4. **Handle the MCP Stream:** The core of an MCP server is handling the bidirectional gRPC stream. Your service implementation will need to: * Receive `DiscoveryRequest` messages from the client (Envoy proxy). * Process the request, determining which resources the client is requesting. * Fetch the appropriate resource configurations from your data store (e.g., a database, a configuration file, or in-memory data). * Construct `DiscoveryResponse` messages containing the resource configurations. * Send the `DiscoveryResponse` messages back to the client. * Handle errors and stream termination gracefully. 5. **Manage Resource Versions (Important for Updates):** MCP uses versioning to ensure that clients receive consistent updates. You'll need to track the versions of your resources and include them in the `DiscoveryResponse` messages. When a client sends a `DiscoveryRequest`, it will include the version of the resources it currently has. Your server should only send updates if the client's version is out of date. 6. **Implement a Data Store (Configuration Source):** You'll need a way to store and manage the resource configurations that your MCP server serves. This could be a simple configuration file, a database, or a more complex configuration management system. 7. **Start the gRPC Server:** Use the gRPC library to start a gRPC server and register your service implementation with it. The server will listen for incoming connections from Envoy proxies. 8. **Configure Envoy to Use Your MCP Server:** Configure your Envoy proxies to connect to your MCP server. This will typically involve specifying the server's address and port in the Envoy configuration. **Example (Conceptual - Requires Adaptation):** ```typescript // Assuming you've generated TypeScript code from your .proto files // import { RouteDiscoveryServiceService, RouteDiscoveryServiceHandlers } from './route_discovery_grpc_pb'; // import { DiscoveryRequest, DiscoveryResponse } from './discovery_pb'; import * as grpc from '@grpc/grpc-js'; // Replace with your actual generated code interface DiscoveryRequest { versionInfo: string; node: any; // Replace with your Node type resourceNames: string[]; typeUrl: string; responseNonce: string; errorDetail: any; // Replace with your Status type } interface DiscoveryResponse { versionInfo: string; resources: any[]; // Replace with your Resource type typeUrl: string; nonce: string; controlPlane: any; // Replace with your ControlPlane type } interface RouteDiscoveryServiceHandlers { streamRoutes: grpc.ServerDuplexStream<DiscoveryRequest, DiscoveryResponse>; } class RouteDiscoveryServiceImpl implements RouteDiscoveryServiceHandlers { streamRoutes(stream: grpc.ServerDuplexStream<DiscoveryRequest, DiscoveryResponse>): void { stream.on('data', (request: DiscoveryRequest) => { console.log('Received request:', request); // Fetch route configurations based on the request const routes = this.fetchRoutes(request); // Construct the DiscoveryResponse const response: DiscoveryResponse = { versionInfo: 'v1', // Replace with your versioning logic resources: routes, typeUrl: 'envoy.config.route.v3.RouteConfiguration', // Replace with your resource type URL nonce: 'some-nonce', // Generate a unique nonce controlPlane: null, // Replace if you have control plane info }; stream.write(response); }); stream.on('end', () => { console.log('Stream ended'); stream.end(); }); stream.on('error', (err) => { console.error('Stream error:', err); stream.end(); }); } private fetchRoutes(request: DiscoveryRequest): any[] { // Implement your logic to fetch route configurations // based on the request parameters (e.g., resourceNames, versionInfo) // This is where you would access your data store. console.log("fetching routes"); return [ { name: 'route1', domains: ['example.com'] }, { name: 'route2', domains: ['test.com'] }, ]; // Replace with actual route configurations } } function main() { const server = new grpc.Server(); // server.addService(RouteDiscoveryServiceService, new RouteDiscoveryServiceImpl()); server.addService({streamRoutes: {path: "/envoy.service.discovery.v3.RouteDiscoveryService/StreamRoutes", requestStream: true, responseStream: true, requestSerialize: (arg: any) => Buffer.from(JSON.stringify(arg)), requestDeserialize: (arg: Buffer) => JSON.parse(arg.toString()), responseSerialize: (arg: any) => Buffer.from(JSON.stringify(arg)), responseDeserialize: (arg: Buffer) => JSON.parse(arg.toString())}}, new RouteDiscoveryServiceImpl()); server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), (err, port) => { if (err) { console.error('Failed to bind:', err); return; } console.log(`Server listening on port ${port}`); server.start(); }); } main(); ``` **Important Considerations:** * **Error Handling:** Implement robust error handling to gracefully handle unexpected situations. * **Logging:** Add logging to help you debug and monitor your MCP server. * **Security:** Secure your gRPC server using TLS/SSL. * **Scalability:** Consider the scalability of your MCP server, especially if you're serving a large number of Envoy proxies. * **Testing:** Thoroughly test your MCP server to ensure that it's working correctly. **Next Steps:** 1. **Tell me which MCP SDK you're using.** 2. **Tell me what kind of MCP server you want to create.** 3. **Tell me your desired level of detail.** Once I have this information, I can provide you with more specific and helpful guidance.

Aaryash-Shakya

开发者工具
访问服务器

README

构建

  1. 安装依赖

    yarn install
    
  2. 构建项目

    yarn build
    
  3. 你将在根目录找到对应的 .js 文件。 对于每个 filename.ts 文件,将在根目录生成一个对应的 filename.js 文件。


使用示例

  1. 对于每个 .js 文件,使用 chmod +x 使其可执行。

  2. 然后将可执行文件的路径复制到 MCP 配置文件中。

{
	"mcpServers": {
		"weather": {
			"command": "npx",
			"args": ["-y", "node", "/home/aaryash-f/Documents/mcp/weather-mcp.js"]
		},
		"store": {
			"command": "npx",
			"args": ["-y", "node", "/home/aaryash-f/Documents/mcp/store-mcp.js"]
		}
	}
}

推荐服务器

Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
MCP Package Docs Server

MCP Package Docs Server

促进大型语言模型高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化来增强软件开发。

精选
本地
TypeScript
Claude Code MCP

Claude Code MCP

一个实现了 Claude Code 作为模型上下文协议(Model Context Protocol, MCP)服务器的方案,它可以通过标准化的 MCP 接口来使用 Claude 的软件工程能力(代码生成、编辑、审查和文件操作)。

精选
本地
JavaScript
@kazuph/mcp-taskmanager

@kazuph/mcp-taskmanager

用于任务管理的模型上下文协议服务器。它允许 Claude Desktop(或任何 MCP 客户端)在基于队列的系统中管理和执行任务。

精选
本地
JavaScript
mermaid-mcp-server

mermaid-mcp-server

一个模型上下文协议 (MCP) 服务器,用于将 Mermaid 图表转换为 PNG 图像。

精选
JavaScript
Jira-Context-MCP

Jira-Context-MCP

MCP 服务器向 AI 编码助手(如 Cursor)提供 Jira 工单信息。

精选
TypeScript
Linear MCP Server

Linear MCP Server

一个模型上下文协议(Model Context Protocol)服务器,它与 Linear 的问题跟踪系统集成,允许大型语言模型(LLM)通过自然语言交互来创建、更新、搜索和评论 Linear 问题。

精选
JavaScript
Sequential Thinking MCP Server

Sequential Thinking MCP Server

这个服务器通过将复杂问题分解为顺序步骤来促进结构化的问题解决,支持修订,并通过完整的 MCP 集成来实现多条解决方案路径。

精选
Python
Curri MCP Server

Curri MCP Server

通过管理文本笔记、提供笔记创建工具以及使用结构化提示生成摘要,从而实现与 Curri API 的交互。

官方
本地
JavaScript