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 🙏

© 2026 – Pkg Stats / Ryan Hefner

learn-mcp

v1.0.9

Published

学习 ModelContextProtocol 协议

Readme

learn-mcp

学习 ModelContextProtocol 协议的示例项目。

项目简介

这是一个基于 Model Context Protocol (MCP) 的示例项目,展示了如何创建和使用自定义工具来扩展 AI 模型的能力。该项目实现了多个实用工具,包括数学计算、天气查询和文件生成等功能。

功能特性

1. 数学计算工具

  • 加法工具 (add):计算两个数的和
  • 减法工具 (odd):计算两个数的差值

2. 天气查询工具

  • 天气查询 (getCityWeatherByLocation):根据城市名称查询近 15 日天气信息
    • 支持查询具体区域天气,如"上海浦东新区"
    • 返回详细的天气预报信息,包括日期、天气状况、最高温度和最低温度

3. 文件生成工具

  • TXT 文件生成器 (generateTxtFile):根据提供的内容和路径生成 TXT 文件
    • 可以指定文件路径和文件名
    • 自动创建不存在的文件

4. 资源和提示词

  • Greeting 资源:根据姓名生成问候语
  • 代码审查提示词:可以用于代码审查

安装与使用

环境要求

  • Node.js >= 16.x
  • pnpm >= 8.x

安装依赖

pnpm install

构建项目

pnpm run build

启动服务

pnpm start

开发模式

pnpm run dev-inspector

使用示例

天气查询

// 查询上海浦东新区的天气
getCityWeatherByLocation({ location: '上海浦东新区' })

文件生成

// 生成包含内容的TXT文件
generateTxtFile({
  content: '这是文件内容',
  filePath: '/path/to/file',
  fileName: 'example.txt',
})

数学计算

// 加法运算
add({ a: 5, b: 3 }) // 结果: 8

// 减法运算
odd({ a: 10, b: 4 }) // 结果: 6

项目结构

src/
├── main.ts              # 程序入口文件
└── utils/               # 工具函数目录
    ├── caculate.ts      # 数学计算工具
    ├── generate-txt.ts  # 文件生成工具
    ├── handle-result.ts # MCP 结果处理工具
    └── query-weather.ts # 天气查询工具

技术栈

  • TypeScript
  • Model Context Protocol SDK
  • Axios (用于 HTTP 请求)
  • Cheerio (用于网页解析)
  • Zod (用于数据验证)

配置 VS Code 调试

全局安装


npm i -g learn-mcp

配置 MCP Server

"learn-mcp": {
      "command": "node",
      "args": ["D:\\Study\\learn-mcp\\node_modules\\learn-mcp\\dist\\main.js"], // 安装路径
    }

许可证

MIT License

作者

xiaoyan