Sponsored by Deepsite.site

MCP Server: Demo

Created By
jubalm8 months ago
Demo MCP Server build using Cloudflare MCPAgent Durable Objects and D1 database
Content

MCP Server: Demo

Overview

This repository serves as a demonstration of building an MCP (Model Context Protocol) server that can access and query actual database information. Uses the @modelcontextprotocol/sdk library leveraging Cloudflare's MCPAgent to implement tools, manage resources, and a D1 database.

Features

Database

The project integrates with a D1 database (mcp-agent-d1-data) to retrieve data but you should be able to work with any database with some minor adjustments on the tools. Also included some niceties:

  • Schema Management: SQL migration files (up.sql, down.sql, seed.sql) in the db/ directory manage the database schema and seed data.

MCP Server (MyMCP)

The MyMCP class extends the McpAgent class from the @modelcontextprotocol/sdk library. It acts as the core server implementation, providing server sent events (SSE) as a foundational transport.

  • Durable Object: The server is implemented as a Durable Object, which allows stateful interactions and long process operations. It also comes with hibernation built-in when idle.

Query Tool

The query tool is designed to interact with the database by providing an interface where the LLM can send SQL queries onto the database. Use with care in production environments and practice proper authorization safeguards.

Introspection Tool

The schema-introspection tool is particularly useful to help the LLM understand the structure of the database to produce a more accurate query design.

Integration Tests

Included integration tests in the tests/ directory to get started. Validate the functionality of the MCP server and its tools, or use the tests for TDD.

npm run test

Project Structure

📦 d1-mcp
├── package.json
├── README.md
├── tsconfig.json
├── vitest.config.js
├── worker-configuration.d.ts
├── wrangler.jsonc
├── db
│   ├── down.sql
│   ├── seed.sql
│   └── up.sql
├── public
│   └── index.html
├── src
│   ├── index.ts
│   ├── metadata.ts
│   ├── tools.ts
│   └── utils.ts
└── tests
    ├── index.test.ts
    └── tsconfig.json

Getting Started

Prerequisites

  • Node.js
  • Cloudflare Workers CLI (wrangler)

Installation

  1. Clone the repository.
  2. Install dependencies:
    npm install
    

Development

  • Start the development server:
    npm run dev
    

Deployment

  • Deploy to Cloudflare Workers:
    npm run deploy
    

License

This project is licensed under the MIT License.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
ChatWiseThe second fastest AI chatbot™
WindsurfThe new purpose-built IDE to harness magic
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Tavily Mcp
Playwright McpPlaywright MCP server
Serper MCP ServerA Serper MCP Server
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.
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"
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.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Amap Maps高德地图官方 MCP Server
CursorThe AI Code Editor
DeepChatYour AI Partner on Desktop
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.
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.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.