Skip to main content
Glama
onigeya
by onigeya

queryCommands

Retrieve a filtered list of available commands for managing and manipulating notes in the SiYuan Note system, based on specified namespaces or command types.

Instructions

查询可用的命令列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceNo命令命名空间过滤
typeNo命令名称过滤

Implementation Reference

  • The handler function for 'queryCommands' tool. It calls registry.listCommands to fetch filtered commands, formats them into a readable list, and returns an MCP response with text content and metadata. Handles errors gracefully.
    async ({ namespace, type }) => {
        try {
            const result = registry.listCommands(namespace, type);
            const commands = (result._meta || []).map(cmd => ({
                type: cmd.namespace ? `${cmd.namespace}.${cmd.name}` : cmd.name,
                description: cmd.description,
                params: Object.entries(cmd.params)
                    .map(([name, info]) => `${name}: ${info.type}${info.required ? ' (必填)' : ' (可选)'} - ${info.description}`)
                    .join('\n    ') || '无参数'
            }));
            
            const commandList = commands.map(cmd => 
                `${cmd.type}: ${cmd.description}\n  参数: ${cmd.params}`
            ).join('\n');
            
            return {
                content: [
                    {
                        type: 'text' as const,
                        text: `可用命令列表:\n${commandList}`
                    }
                ],
                _meta: {
                    commands: commands
                },
                isError: false
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: 'text' as const,
                        text: error instanceof Error ? error.message : '查询失败'
                    }
                ],
                isError: true
            };
        }
    }
  • Zod input schema for the tool, defining optional 'namespace' and 'type' string parameters to filter the command list.
    {
        namespace: z.string().optional().describe('命令命名空间过滤'),
        type: z.string().optional().describe('命令名称过滤')
    },
  • The registerQueryTool function registers the 'queryCommands' tool on the MCP server using server.tool(), including name, description, input schema, and handler.
    export function registerQueryTool(server: McpServer) {
        server.tool(
            'queryCommands',
            '查询可用的命令列表',
            {
                namespace: z.string().optional().describe('命令命名空间过滤'),
                type: z.string().optional().describe('命令名称过滤')
            },
            async ({ namespace, type }) => {
                try {
                    const result = registry.listCommands(namespace, type);
                    const commands = (result._meta || []).map(cmd => ({
                        type: cmd.namespace ? `${cmd.namespace}.${cmd.name}` : cmd.name,
                        description: cmd.description,
                        params: Object.entries(cmd.params)
                            .map(([name, info]) => `${name}: ${info.type}${info.required ? ' (必填)' : ' (可选)'} - ${info.description}`)
                            .join('\n    ') || '无参数'
                    }));
                    
                    const commandList = commands.map(cmd => 
                        `${cmd.type}: ${cmd.description}\n  参数: ${cmd.params}`
                    ).join('\n');
                    
                    return {
                        content: [
                            {
                                type: 'text' as const,
                                text: `可用命令列表:\n${commandList}`
                            }
                        ],
                        _meta: {
                            commands: commands
                        },
                        isError: false
                    };
                } catch (error) {
                    return {
                        content: [
                            {
                                type: 'text' as const,
                                text: error instanceof Error ? error.message : '查询失败'
                            }
                        ],
                        isError: true
                    };
                }
            }
        );
    } 
  • src/server.ts:53-53 (registration)
    Invocation of registerQueryTool on the main MCP server instance, effecting the tool registration.
    registerQueryTool(server);
  • The listCommands method of CommandRegistry, used by the tool handler to retrieve and filter registered commands, extract parameter info from Zod schemas, and format the response.
    public listCommands(namespace?: string, type?: string): McpResponse<Array<{
        namespace: string;
        name: string;
        description: string;
        params: Record<string, {
            type: string;
            description: string;
            required: boolean;
        }>;
    }>> {
        const commands = Array.from(this.commands.entries()).filter(([fullName, cmd]) => {
            const [cmdNamespace] = this.parseFullCommandName(fullName);
            if (namespace && !cmdNamespace.includes(namespace)) return false;
            if (type && !cmd.name.includes(type)) return false;
            return true;
        }).map(([fullName, cmd]) => {
            // 获取参数说明
            const params: Record<string, {
                type: string;
                description: string;
                required: boolean;
            }> = {};
    
            try {
                if (cmd.params instanceof z.ZodObject) {
                    const shape = cmd.params._def.shape();
                    Object.entries(shape).forEach(([key, value]) => {
                        if (value instanceof z.ZodType) {
                            const isOptional = value instanceof z.ZodOptional;
                            params[key] = {
                                type: value._def.typeName || 'unknown',
                                description: value.description || '无说明',
                                required: !isOptional
                            };
                        }
                    });
                }
            } catch {
                // 如果无法获取 shape,返回空对象
            }
    
            const [cmdNamespace, cmdName] = this.parseFullCommandName(fullName);
            return {
                namespace: cmdNamespace,
                name: cmdName,
                description: cmd.description,
                params
            };
        });
    
        const commandList = commands.map(cmd => {
            const fullName = cmd.namespace ? `${cmd.namespace}.${cmd.name}` : cmd.name;
            const paramsList = Object.entries(cmd.params).map(([name, info]) => 
                `    ${name}: ${info.type}${info.required ? ' (必填)' : ' (可选)'} - ${info.description}`
            ).join('\n');
            
            return `${fullName}: ${cmd.description}\n${paramsList ? `  参数:\n${paramsList}` : '  参数: 无参数'}`;
        }).join('\n\n');
    
        return {
            content: [
                {
                    type: 'text',
                    text: `可用命令列表:\n${commandList}`
                }
            ],
            _meta: commands
        };
    }
Behavior2/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 of behavioral disclosure. The description only states what the tool does ('查询可用的命令列表') without revealing any behavioral traits such as whether this is a read-only operation, what format the output returns, whether there are rate limits, authentication requirements, or error conditions. For a tool with no annotation coverage, this is a significant gap.

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 extremely concise - a single phrase '查询可用的命令列表' that directly states the tool's purpose with zero wasted words. It's appropriately sized for a simple query tool and front-loaded with the essential information.

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

Completeness2/5

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

Given that there are no annotations and no output schema, the description is incomplete. While the tool appears to be a simple read operation (querying available commands), the description doesn't explain what the return format looks like, whether results are filtered/paginated, or any other behavioral aspects. For a tool with 2 parameters and no structured output documentation, the description should provide more context about what users can expect.

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?

The input schema has 100% description coverage (both parameters 'namespace' and 'type' are documented in the schema as '命令命名空间过滤' and '命令名称过滤' respectively). The tool description adds no parameter information beyond what the schema already provides. According to the rules, when schema_description_coverage is high (>80%), the baseline is 3 even with no param info in the description.

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 '查询可用的命令列表' (Query available command list) clearly states the tool's purpose with a specific verb ('查询' - query) and resource ('可用的命令列表' - available command list). It distinguishes from the sibling 'executeCommand' (which executes commands rather than listing them) and 'help' (which likely provides documentation rather than listing). However, it doesn't explicitly differentiate from 'help' which might overlap in functionality.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to use 'queryCommands' versus 'executeCommand' or 'help', nor does it specify any prerequisites or contexts where this tool is particularly appropriate. The user must infer usage from the tool name alone.

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

Related 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/onigeya/siyuan-mcp-server'

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