Skip to main content
Glama
2234839

Martin MCP Toolbox

by 2234839

siyuan_database_query

Execute SQLite SELECT queries on SiYuan note databases to fetch blocks, attributes, and refs for custom data analysis and retrieval.

Instructions

思源数据库查询工具 - 执行 SQLite 查询语句来查询思源笔记的数据库(树形视图/属性视图)

功能说明

此工具允许您查询思源笔记中的数据库(也称为树形视图或属性视图)。您可以使用标准的 SQLite 语法来查询数据库中的数据。

支持的表

  • blocks: 内容块表

  • attributes: 属性表

  • refs: 引用表

数据库表结构

blocks 表

  • id: 内容块 ID

  • parent_id: 父块 ID

  • root_id: 文档块 ID

  • box: 笔记本 ID

  • path: 内容块路径

  • hpath: 人类可读路径

  • name: 内容块名称

  • alias: 别名

  • memo: 备注

  • tag: 标签

  • content: 内容文本

  • fcontent: 第一个子块内容

  • markdown: Markdown 格式内容

  • length: 内容长度

  • type: 块类型 (d:文档, h:标题, p:段落, l:列表, t:表格, b:引述, s:超级块, c:代码块, m:数学公式, av:数据库)

  • subtype: 子类型

  • ial: 内联属性列表

  • sort: 排序权重

  • created: 创建时间

  • updated: 更新时间

attributes 表

  • id: 属性 ID

  • name: 属性名称 (自定义属性需加 custom- 前缀)

  • value: 属性值

  • type: 类型

  • block_id: 块 ID

  • root_id: 文档 ID

  • box: 笔记本 ID

  • path: 文档路径

refs 表

  • id: 引用 ID

  • def_block_id: 被引用块 ID

  • def_block_root_id: 被引用块文档 ID

  • def_block_path: 被引用块路径

  • block_id: 引用块 ID

  • root_id: 引用块文档 ID

  • box: 笔记本 ID

  • path: 引用块路径

  • content: 引用锚文本

使用示例

  1. 查询所有数据库块: SELECT * FROM blocks WHERE type = 'av' LIMIT 10

  2. 查询特定数据库中的记录: SELECT * FROM blocks WHERE parent_id = '数据库块ID' LIMIT 20

  3. 查询具有特定属性的块: SELECT * FROM attributes WHERE name = 'custom-status' AND value = '完成'

  4. 查询数据库中的记录及其属性: SELECT b.id, b.content, a.name, a.value FROM blocks b JOIN attributes a ON b.id = a.block_id WHERE b.parent_id = '数据库块ID' LIMIT 10

安全注意事项

  • 只允许执行 SELECT 查询语句

  • 禁止执行修改数据的语句 (INSERT, UPDATE, DELETE, DROP等)

  • 查询结果会自动限制返回的行数以防止过大响应

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stmtYesSQL 查询语句,例如: SELECT * FROM blocks WHERE type = 'av' LIMIT 10
limitNo限制返回结果的数量
offsetNo偏移量,用于分页查询
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It explicitly discloses that only SELECT statements are allowed, prohibits modification statements, and mentions automatic result limiting. This is strong behavioral transparency, though it does not specify the exact result limit or error behavior on invalid queries.

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 well-structured with clear sections (功能说明, 支持的表, 表结构, 示例, 安全注意事项). It is front-loaded with a concise summary, and every section serves a purpose. Despite its length, it remains focused and informative without redundancy.

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 SQL query tool with no output schema, the description is remarkably complete: it covers the tool's purpose, supported tables, full table structures, practical examples, and security constraints. While it doesn't specify the return format, the examples and schema make the expected behavior clear enough for effective use.

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 coverage is 100%, so the baseline is 3. The description adds significant value by documenting the underlying table schemas (blocks, attributes, refs) and providing SQL examples, which helps construct valid 'stmt' values beyond the schema's brief parameter descriptions.

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

Purpose4/5

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

The description clearly states it executes SQLite queries against the SiYuan database (tree/attribute views), with a specific verb and resource. However, it does not distinguish itself from the sibling tool 'siyuan_query_sql', which likely has overlapping functionality, so it misses the sibling differentiation required for a 5.

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 provides clear functional context and multiple usage examples, indicating when to use the tool (to query databases). However, it does not mention any alternative tools or exclusions (e.g., when to use siyuan_query_sql instead), so it lacks explicit when-not guidance.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/2234839/mcpserver'

If you have feedback or need assistance with the MCP directory API, please join our Discord server