Skip to main content
Glama

db-mcp

一个只读的 MCP 服务器,它让 AI 代理可以安全访问一个小型 SQLite 商店数据库(shop.db):结构发现、自由格式的只读 SQL 以及预构建的分析报表。

安装

npm install

Related MCP server: shop-db

配置

服务器从进程环境中读取 SHOP_DB_PATH 来定位数据库文件。它是可选的——如果未设置,服务器将使用项目根目录中的 shop.db。.env 文件不会被自动读取(没有 dotenv 依赖,package.json 的 scripts 中也没有 --env-file 标志);.env.example 仅用于提醒变量名。请在服务器实际运行的环境中设置 SHOP_DB_PATH——对 stdio MCP 客户端而言,就是其配置中的 env 键(参见下面的“连接客户端”)。

构建

npm run build

运行

npm start
# or directly:
node dist/index.js

服务器通过 stdio 提供 MCP 服务——它需要由 MCP 客户端/主机作为子进程启动,而不是直接交互式运行。

连接客户端

通用 stdio MCP 客户端配置:

{
  "mcpServers": {
    "db-mcp": {
      "command": "node",
      "args": ["/absolute/path/to/db-mcp/dist/index.js"],
      "env": { "SHOP_DB_PATH": "/absolute/path/to/shop.db" }
    }
  }
}

Claude Desktop:在 claude_desktop_config.json 的 mcpServers 下添加相同的块(各操作系统下的配置文件位置请参阅 MCP.md),然后重新启动 Claude Desktop。

工具

工具

说明

list_tables

列出所有表,并附上一段简短描述和行数。请先调用此工具。

describe_table

获取某个表(customers、products、orders、order_items)的列定义、键、行数和示例行。

query

运行一条只读的 SELECT(或 WITH ... SELECT)语句,并使用 limit/offset 分页。

get_top_customers

按总消费或订单数排名的顶级客户。排除已取消的订单。

get_top_products

按销售量排列的热销产品,并提供收入。排除已取消的订单。

get_revenue_report

按类别、年份或月份分组的收入,可选用某一年份过滤。排除已取消的订单。

安全说明

  • 数据库连接以 { readonly: true, fileMustExist: true } 打开——无论发送什么 SQL,SQLite 引擎本身都会在物理层面拒绝任何写操作。

  • query 工具在语句到达数据库之前,还会验证输入是否是一条单独的 SELECT(或 WITH ... SELECT)语句;对于 INSERT/UPDATE/DELETE/DROP/ALTER/CREATE/PRAGMA/ATTACH/DETACH/REPLACE/VACUUM/REINDEX/TRIGGER 以及多语句输入,它会返回一条友好的错误信息并拒绝执行。

  • 错误会在每个工具的边界被捕获,并以 isError: true 和一条简短消息作为 MCP 工具结果返回——绝不会向客户端发送堆栈跟踪或文件系统路径。

  • 所有日志都会输出到 stderr(console.error)——stdout 专门保留给 JSON-RPC 协议流。

测试

npm test

通过 tsx 运行 node --test,覆盖每个 *.test.ts 文件:包括针对真实 shop.db 的 SQL 防护、数据库连接以及每个工具查询逻辑的单元测试;此外还有一个端到端测试,会启动编译后的服务器,并通过 stdio 使用真实的 MCP 客户端对其进行驱动。

Docker

docker build -t db-mcp .
docker run -i db-mcp

本地运行服务器并不需要 Docker(上面的客户端配置期望的是一个本地 node 进程),不过这里提供一个可选的验证/运行方式。

Available Tools

6 tools
describe_tableA

Get column definitions (name, type, nullable, primary/foreign keys), row count, and a few sample rows for one table. Use this after list_tables to learn exact column names and types before writing SQL in the query tool.

ParametersJSON Schema
NameRequiredDescriptionDefault
tableYes

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description absorization all burden for behavioral disclosure. It clearly states that the operation is a read-style introspection (get definitions, row count, sample rows) and does not suggest any modification of side effects. It leaves the exact number of sample rows unspecified, but that's minor for a describe type action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two dense sentences deliver the needed information without fluff. The first sentence says what it returns; the second positions it in the overall workflow. Every phrase earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers the tool's purpose, output content, and workflow context. It doesn't describe how many sample rows are returned or whether row count is approximate, but for a one-parameter introspection tool with an enum parameter, it's sufficiently complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There is exactly one required table parameter with an enum; the schema already enumerates valid tables, but the description's coverage is 0%. The description says 'one table' and implies the table name comes from list_tables, adding some process context, but does not itself define the parameter values or formats. The enum carries most semantic weight.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb 'Get' with a distinct resource: column definitions, row count, and sample rows for one table. It clearly distinguishes itself from list_tables and query by naming when each is used, and says exactly what information to expect from the tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides an explicit workflow: call this after list_tables and before using the query tool. This conveys the intended portion in the schema-discovery flow. It does not explicitly state when not to use it, but the context and alternat structure make the situation reasonably clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_revenue_reportA

Get total revenue grouped by product category, by year, or by month. Cancelled orders are excluded. year optionally restricts results to one year (also applies to 'month' grouping). Use this instead of writing the orders→order_items→products join yourself.

ParametersJSON Schema
NameRequiredDescriptionDefault
yearNo
group_byYes

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description correctly discloses the key behavioral details: canceled orders are excluded, and the `year` parameter acts as an optional filter that also applies when grouping by month. It doesn't discuss auth or rate limits, but the main data-behavior message is transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three compact sentences deliver the essential info with meaningful detail; the first sentence is the core action, the second clarifies data inclusion/exclusions, and the third tells the expected alternative. No filler or repeated schema text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 2-parameter reporting tool with no output schema and no annotations, the description covers purpose, grouping semantics, optional filter, and usage context. Omitting the exact return format is minor because the tool is narrow and the input semantics are fully explained.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schemas has zero description coverage, so the description adequately compensates: it explains the `year` parameter in context and the three allowed grouping values in `group_by`. It doesn't need to explain the enum bodies since the schema already enumerates them, and adding meaning to parameter usage is done well.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: it gets total revenue grouped by product category, year, or month, which is distinct from sibling tools like get_top_customers and get_top_products. It clearly tells the agent what the tool does.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says to use this instead of writing an orders→order_items→products join yourself, which gives direct when-to-use guidance relative to the query-type workflow. It doesn't rule out all sibling tools, but this report is different enough that no exclusion is critical.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_top_customersA

Get the top customers ranked by total amount spent or by number of orders placed. Cancelled orders are excluded from totals. Use this instead of query for 'who spent the most' / 'who ordered the most' questions.

ParametersJSON Schema
NameRequiredDescriptionDefault
byYes
limitNo

TDQS

A4.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, so the description carries the behavioral burden. It discloses the important ordering rule that cancelled orders are excluded from the calculations, which materially affects results. It does not spell out the return shape, but 'get' strongly implies a read-only list operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three short sentences, each earning its place: the operation, the non-obvious data restriction, and the usage routing. No filler, no tautology, and intent is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given only two parameters and no output schema, the description covers the main decision points: what the ranking means, how to choose the ordering, and which sibling tool to prefer. Omitted details like pagination or exact response fields are minor for this simple, well-scoped reader.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has0% description coverage, but the description maps 'spending' to total amount spent and 'orders' to order count, giving meaning to the enum. The `limit` parameter's purpose is also inferable from its default/minimum/maximum, so the critical required parameter is fully interpreted.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description specifies both the verb+resource ('Get the top customers') and the two exact rankings that define the tool's behavior ('total amount spent' or 'number of orders placed'). This clearly separates it from generic querying and from other top_N tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly tells the agent when to use this tool instead of the generic `query` tool: for 'who spent the most' / 'who ordered the most' questions. This is direct, practical routing guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_top_productsA

Get the best-selling products ranked by units sold, with revenue per product. Cancelled orders are excluded. Use this for 'best-selling products' questions instead of writing the order_items→products join yourself.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo

TDQS

A4.1/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Since no annotations are present, the description carries the full behavioral disclosure burden. It delivers key behavioral details: the ranking basis is units sold, revenue per product is included, and cancelled orders are excluded—these are non-obvious and useful. It does not mention where the list is the entire pop-Nand any caveats, but for a simple read-list the core is covered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two short sentences: the first fixes the core behavior and the second adds the usage and the exclusion nuance. Everything present earns its place, and important info is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

After reading the description, an agent understands what the tool returns, what is excluded, and when to call it. The main missing piece—then number of results limit—is the same parameter gap. There is no output schema, but the description defines what a row contains (units sold and revenue), so an agent has enough to use it.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With schema description coverage at 0%, the description needed to compensate by explaining the single limit parameter—it doesn't mention limit at all. An agent must rely on the property name and the numeric constraints to infer that limit probably controls how many products are returned. That is a significant gap for the only parameter in the tool.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description starts with a specific verb and resource ('Get the best-selling products') and clarifies the meaning: ranked by units sold, with revenue per product. It also states a non-obvious scope detail—cancelled orders are excluded—which makes the purpose unambiguous. This clearly separates the tool from siblings such as get_top_customers or list_tables.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says to use this tool for 'best-selling products' questions, and calls out the alternative: writing the order_items→products join yourself. This gives an agent both a positive trigger and a reason not to hand-write the query. It does not name the sibling get_top_customers or list exclusion conditions, which keeps it from a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_tablesA

List all tables in the shop database with a short description of what each table contains and how many rows it has. Use this first to discover what data is available before writing queries or calling other tools.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the burden of disclosing behavior. It communicates that the tool only lists tables and descriptions, and it states the nature of the output. This is sufficiently transparent for a read-only discovery tool, though it doesn't mention potential permissions or data volume considerations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences: the first states the action and output content, and the second provides usage direction. No wasted words, and the key functionality is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter, no-output-schema tool, the description is fully sufficient. It tells the agent what it returns (table names, descriptions, row counts) and why to call it first. No critical missing information affects correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters, so parameter semantics are trivial. The description adds appropriate context about what the returned list represents, fulfilling the baseline guidance for a no-parameter tool.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'List', the resource 'tables in the shop database', and specifies the output content (short description and row count). It distinguishes itself from the sibling query/specific-report tools by serving as a discovery entry point.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly tells the agent to use this tool first before writing queries or calling other tools, giving clear when-to-use guidance. It does not name specific alternative tools or state when not to use it, but the instruction to use it before others is strong.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

queryA

Run a read-only SQL SELECT query against the shop database. Use this for any question not directly covered by the specialized analytics tools, or to explore/join data freely once you know the schema. Only a single SELECT (or WITH ... SELECT) statement is allowed — write operations and multiple statements are rejected. Results are capped at limit rows; use offset to page through more.

ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYes
limitNo
offsetNo

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure, and it does so well: it states the operation is read-only, only single SELECT or WITH...SELECT statements are accepted, write operations and multiple statements are rejected, and results are capped with pagination support. No major behavioral surprise remains.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact, front-loaded with the core purpose, and each sentence adds meaningful guidance. No fluff or repeated schema information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an open-ended SQL query tool, this is complete: it identifies what tool does, what queries are permitted, what happens on violation, and how to handle large result sets. There is no output schema to document, and the sibling tools supply the schema-discovery path.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It clarifies that sql must be a SELECT-style query, that a session limit caps returned rows, and that offset pages through additional results. It does not spell out defaults or maximums, but those constraints are already visible in the JSON schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Run a read-only SQL SELECT query against the shop database.' It also distinguishes itself from the specialized analytics tools by positioning itself as the general-purpose query tool for questions those tools do not directly cover.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives clear when-to-use guidance: use it for anything not covered by specialized analytics tools and for free exploration/joins once the schema is known. It stops short of explicitly naming siblings like list_tables or get_revenue_report, but the exclusion of 'specialized analytics tools' is sufficient guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 6 tool updatesv1.0.0
    • First observeddescribe_table
    • First observedget_revenue_report
    • First observedget_top_customers
    • First observedget_top_products
    • First observedlist_tables
    • First observedquery

TDQS

A4.5/5.0

Scored across 6 tools

Disambiguation5/5

Each tool has a clearly distinct role: schema discovery, ad-hoc querying, and specific analytical reports. The specialized analytics tools explicitly tell agents to use them instead of writing equivalent queries, and the query tool remains the catch-all for anything else.

Naming Consistency5/5

Tool names consistently follow an imperative verb first pattern: list_tables, describe_table, query, get_top_customers, etc. There is no mixing of naming conventions or vague duplicate verb prefixes, making the set predictable.

Tool Count5/5

Six tools is well-scoped for a read-only database MCP server. The set covers discovery, raw querying, and common analytics needs without unnecessary redundancy or bloat.

Completeness5/5

For a read-only shop database server, the surface is complete: discover tables, inspect schemas, run arbitrary SELECT queries, and pull common analytics reports. The raw query tool covers edge cases not handled by the specialized reports, so there are no obvious dead ends.

Maintenance

ActivitySlowing
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    A
    quality
    C
    maintenance
    Enables AI agents to answer analytical questions about an online store's SQLite database through specialized read-only tools, without any risk of modifying the underlying data.
    8
    -
  • F
    license
    A
    quality
    C
    maintenance
    Enables AI agents to read-only query an online store's SQLite database, listing tables, inspecting schemas, and running SELECT queries over customers, products, orders, and order items.
    3
    -
  • F
    license
    A
    quality
    B
    maintenance
    Gives AI agents read-only analytical access to an e-commerce SQLite database (customers, orders, order_items, products) via SQL queries, table listing, and schema inspection.
    3
    -
  • F
    license
    A
    quality
    C
    maintenance
    Enables AI agents to analyze an SQLite e-commerce database via secure read-only SQL queries, providing tools for table inspection and analytical requests.
    2
    -