使用说明
Hono MCP样本服务器
Hono框架和hono/mcp使用Model Context Protocol (MCP)
服务器的示例实现。
机能
此示例服务器包括:MCP提供功能:
资源
- weather://tokyo:获取东京的天气信息
- news://latest:获取最新新闻标题
工具
- 计算器:将两个数字相加
- 参数:
a(数字),b(编号)
- 参数:
- 反向字符串:反转字符串
- 参数:
text(字符串)
- 参数:
提示
- 代码审查:请求代码审核的提示模板
- 引数:
code(字符串)
- 引数:
安装,安装
安装相关性
npm install
使用方法
开发模式
npm run dev
构建
npm run build
在生产环境中运行
npm start
端点
服务器启动后,以下端点可用:
http://localhost:3000/-服务器信息http://localhost:3000/mcp- MCP端点
技术栈
- 荣誉:快速轻巧Web框架结构
- hono/mcp: Hono的,之MCP支持包
- @模型上下文协议/sdk: MCP公式SDK
- 动物圈:架构定义(使用v3系统)
- TypeScript:型安全开发
- TSX: TypeScript运行环境
构成
mcp-sample/
├── src/
│ └── index.ts # メインサーバーファイル
├── package.json # プロジェクト設定
├── tsconfig.json # TypeScript設定
└── README.md # このファイル
自定义
添加新资源
mcpServer.registerResource(
"custom resource",
new ResourceTemplate("custom://resource", { list: undefined }),
{
description: "リソースの説明",
mimeType: "text/plain",
},
async (uri) => ({
contents: [
{
url: uri.href,
mimeType: "text/plain",
text: "リソースの内容",
},
],
}),
);
添加新工具
mcpServer.registerTool(
"custom-tool",
{
description: "ツールの説明",
inputSchema: {
param1: z.string().describe("パラメータの説明"),
},
},
async ({ param1 }) => {
const result = a + b;
return {
content: [
{
type: "text",
text: `処理結果: ${param1}`,
},
],
};
},
);
许可证
麻省理工学院
