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
        };
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.6/5.0
Behavior3/5

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

No annotations are provided, so the description must carry the full burden of behavioral disclosure. The word '查询' implies a read-only operation, but the description does not explicitly state that it makes no changes, nor does it disclose any permissions or return format details. However, for a simple query tool, the implied safety may be sufficient.

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 a single, concise sentence that immediately states the tool's purpose. There is no redundant information or unnecessary elaboration.

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 the tool's simplicity and the schema's full parameter coverage, the description provides the essential function. However, it could be improved by explicitly mentioning that it returns a list or how filters interact, but the phrase '命令列表' implies the return type. Overall, it is adequate.

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 covers both parameters (type and namespace) with descriptions, achieving 100% coverage. The tool description adds no additional parameter semantics, so it does not enhance what the schema already provides. Thus, a baseline score of 3 is appropriate.

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 '查询' (query) and identifies the resource as the list of available commands, clearly distinguishing it from sibling tools like executeCommand and help. It does not just restate the tool name, but elaborates on what is being queried.

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 like help or executeCommand, nor does it mention any exclusions or prerequisites. It leaves the usage to be inferred from the tool name and description.

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

Deploy Server

Other Tools

Related Tools