关于 MCP Server TypeScript Starter
MCP Server TypeScript Starter 是一个 TypeScript MCP 服务,可通过坐标或 IP 地址查询位置,并提供健康检查工具。IP 查询使用 IPInfo.io。
主要功能
- 01按坐标查询位置
- 02通过 IPInfo.io 按 IP 查询
- 03服务健康检查工具
- 04TypeScript 服务配置
适用场景
- 01根据经纬度查询位置
- 02获取 IP 地址对应的位置
- 03检查服务健康状态
MCP 相关
它向 MCP 客户端提供坐标查询、IP 位置查询和健康检查工具。IP 查询使用 IPInfo.io。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
4收录的工具列表 · 更新于 3 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| latitude | string | 是 | 纬度坐标 |
| longitude | string | 是 | 经度坐标 |
详细介绍
MCP 服务 TypeScript 入门模板
这是一个提供位置服务的 Model Context Protocol(MCP)服务实现。它演示了如何使用 TypeScript 构建 MCP 服务,并通过坐标或 IP 地址查询位置,提供实际功能。
功能
- TypeScript 配置
- 完整的 MCP 服务设置
- 位置服务实现
- 基于坐标的位置查询
- 基于 IP 的位置查询(使用 IPInfo.io)
- 健康检查端点
- 类型安全的开发环境
- 与外部 API 集成
安装
npm install mylocation-mcp
用法
- 创建一个
.env文件,并填入 IPInfo.io API 令牌:
IPINFO_TOKEN=your_ipinfo_token_here
- 在代码中导入并使用:
import { McpServer } from 'mylocation-mcp';
开发
如果你想修改此软件包或为其做出贡献:
# Clone the repository
git clone https://github.com/yhwancha/mylocation-mcp.git
cd mylocation-mcp
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env and add your IPInfo.io API token
# Build the project
npm run build
项目结构
.
├── src/
│ └── index.ts # Main server implementation with location tools
├── build/ # Compiled JavaScript files
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .env.example # Environment variables template
└── README.md # Documentation
已实现的工具
1. get-location-by-coordinates
server.tool(
"get-location-by-coordinates",
"Get location information from provided coordinates",
{
latitude: z.string().describe("Latitude coordinate (-90 to 90)"),
longitude: z.string().describe("Longitude coordinate (-180 to 180)")
},
async ({ latitude, longitude }) => {
// Implementation details...
}
);
2. get-location-by-ip
server.tool(
"get-location-by-ip",
"Get location information from IP address",
{
ipAddress: z.string().describe("IP address to lookup")
},
async ({ ipAddress }) => {
// Implementation details...
}
);
3. health
server.tool(
"health",
"Check the health status of the service",
{},
async () => {
// Implementation details...
}
);
MCP 服务配置
要在项目中使用此 MCP 服务,请添加以下配置:
{
"mcpServers": {
"location-service": {
"command": "npx",
"args": [
"-y",
"mylocation-mcp-server"
],
"env": {
"IPINFO_TOKEN": <IPINFO_TOKEN>
}
}
}
}
响应格式
所有工具均按以下格式返回响应:
{
"content": [
{
"type": "text",
"text": "JSON string containing the response data"
}
]
}
响应数据遵循以下结构:
{
"status": "success|error",
"source": "user_provided|ip_based",
"data": {
// Location data when successful
},
"error": "Error message when failed"
}
依赖项
@modelcontextprotocol/sdk:MCP 服务实现zod:架构验证axios:用于 IPInfo API 的 HTTP 客户端dotenv:环境变量管理- TypeScript 开发工具
许可证
MIT
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。