MCP TypeScript SDK

MCP TypeScript SDK

site icon
2025.04.11 0
JavaScript税务计算金融数据交互金融服务
stripe-tax-mcp-server 是一个基于 Model Context Protocol (MCP) 的 TypeScript SDK 实现,旨在为 LLM(大型语言模型)应用提供标准化的上下文交互协议。该服务允许开发者构建 MCP 服务器,暴露资源、工具和提示,以便 LLM 应用能够安全、高效地与之交互。
View on GitHub

Overview

基本能力

产品定位

stripe-tax-mcp-server 是一个用于金融服务领域的 MCP 服务器,专注于为 LLM 应用提供税务计算和金融数据交互的标准化接口。

核心功能

  1. 资源暴露:通过 Resources 提供数据,类似于 REST API 的 GET 端点,用于加载信息到 LLM 的上下文中。
  2. 工具提供:通过 Tools 提供功能,类似于 REST API 的 POST 端点,用于执行计算或产生副作用。
  3. 提示模板:通过 Prompts 定义交互模式,提供可重用的 LLM 交互模板。
  4. 多传输支持:支持 stdio 和 HTTP with SSE 两种传输方式。

适用场景

  1. 税务计算:为 LLM 应用提供实时的税务计算功能。
  2. 金融数据查询:允许 LLM 查询金融数据,如用户账户信息、交易记录等。
  3. 自动化金融操作:通过工具执行金融操作,如转账、支付等。

工具列表

  1. add:简单的加法工具,接收两个数字并返回它们的和。
  2. calculate-bmi:计算 BMI 的工具,接收体重和身高并返回 BMI 值。
  3. fetch-weather:异步工具,调用外部 API 获取天气数据。
  4. echo:简单的回显工具,接收消息并返回相同的消息。
  5. query:SQLite 查询工具,执行 SQL 查询并返回结果。

常见问题解答

  1. 如何测试服务器?:可以使用 MCP Inspector 进行测试。
  2. 支持哪些传输方式?:支持 stdio 和 HTTP with SSE 两种传输方式。
  3. 如何贡献代码?:可以在 GitHub 上提交 issues 或 pull requests。

使用教程

使用依赖

安装 Node.js 和 npm。

安装教程

npm install @modelcontextprotocol/sdk

调试方式

  1. 使用 stdio 传输方式运行服务器:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new McpServer({
  name: "example-server",
  version: "1.0.0"
});

const transport = new StdioServerTransport();
await server.connect(transport);
  1. 使用 HTTP with SSE 传输方式运行服务器:
import express from "express";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";

const server = new McpServer({
  name: "example-server",
  version: "1.0.0"
});

const app = express();
const transports: {[sessionId: string]: SSEServerTransport} = {};

app.get("/sse", async (_: Request, res: Response) => {
  const transport = new SSEServerTransport('/messages', res);
  transports[transport.sessionId] = transport;
  res.on("close", () => {
    delete transports[transport.sessionId];
  });
  await server.connect(transport);
});

app.post("/messages", async (req: Request, res: Response) => {
  const sessionId = req.query.sessionId as string;
  const transport = transports[sessionId];
  if (transport) {
    await transport.handlePostMessage(req, res);
  } else {
    res.status(400).send('No transport found for sessionId');
  }
});

app.listen(3001);

许可证

该项目遵循 MIT 开源许可条款。