Sponsored by Deepsite.site

MCP 数据库服务器 (TypeScript)

Created By
cherla year ago
Content

MCP 数据库服务器 (TypeScript)

这是一个基于 Model Context Protocol (MCP) 的数据库查询服务器,用 TypeScript 实现。它允许 AI 模型安全地查询关系型数据库,如 MySQL 和 PostgreSQL。

功能特性

  • 支持 MySQL 和 PostgreSQL 数据库
  • 提供表结构信息作为资源
  • 支持只读 SQL 查询执行
  • 使用事务确保查询安全性

安装

使用 cnpm 进行安装:

git clone <repository-url>
cd mcp-server-db-ts
cnpm install

配置

  1. 复制 .env.example 文件为 .env:
cp .env.example .env
  1. 编辑 .env 文件,设置您的数据库连接信息:
# 数据库连接配置
# 数据库类型: mysql 或 postgres
DB_TYPE=mysql

# MySQL 配置
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASS=your_password
MYSQL_DB=your_database

# PostgreSQL 配置
PG_HOST=127.0.0.1
PG_PORT=5432
PG_USER=postgres
PG_PASS=your_password
PG_DB=your_database

# 服务器配置
SERVER_NAME=mcp-server-db-ts
SERVER_VERSION=1.0.0

构建

cnpm run build

运行

cnpm start

开发模式

cnpm run dev

支持的 MCP 功能

资源

  • list_resources: 列出数据库中的所有表
  • read_resource: 获取指定表的结构信息

工具

  • db_query: 执行只读 SQL 查询

使用示例

  1. 列出所有表:

    • MCP 请求: list_resources
    • 响应: 以 URI 形式返回所有表的列表
  2. 获取表结构:

    • MCP 请求: read_resource 使用特定表的 URI
    • 响应: 返回表的列信息
  3. 执行查询:

    • MCP 请求: call_tool 使用 db_query 工具和 SQL 查询
    • 响应: 返回查询结果

许可证

MIT

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
ChatWiseThe second fastest AI chatbot™
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Playwright McpPlaywright MCP server
Tavily Mcp
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
DeepChatYour AI Partner on Desktop
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Serper MCP ServerA Serper MCP Server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
CursorThe AI Code Editor
WindsurfThe new purpose-built IDE to harness magic
Amap Maps高德地图官方 MCP Server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.