mcpField
M
MCP Server: Demo

MCP Server: Demo

Local
github.com/jubalmData & Analytics2Updated 78w ago

About MCP Server: Demo

MCP Server: Demo is a demonstration project for building MCP servers that query database information. It is intended for developers exploring Cloudflare MCPAgent, Durable Objects, and D1.

Key features

  1. 01D1 database queries
  2. 02SQL query tool
  3. 03Database schema introspection
  4. 04Durable Object server implementation
  5. 05SQL migrations and seed data
  6. 06Integration tests

Use cases

  1. 01Explore a database-backed MCP server
  2. 02Inspect database schema before querying
  3. 03Adapt the query tools to another database

MCP support

The MCP server exposes a SQL query tool and a schema-introspection tool to MCP clients. It uses Cloudflare MCPAgent and Durable Objects, with SSE as its transport.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

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.

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.