Skip to main content
Glama
onigeya
by onigeya

executeCommand

Execute specific commands on the SiYuan Note MCP Server to manage notebooks, manipulate documents, and control content within the note system, enabling efficient data operations.

Instructions

执行指定的命令

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNo命令参数
typeYes命令类型

Implementation Reference

  • The handler function for the 'executeCommand' MCP tool. It delegates execution to the registry's executeCommand method and formats the response as MCP format.
    async ({ type, params = {} }) => {
        try {
            const result = await registry.executeCommand(type, params);
            return {
                content: [
                    {
                        type: 'text' as const,
                        text: result.content[0].text
                    }
                ],
                _meta: {
                    result: result._meta || {}
                },
                isError: result.isError
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: 'text' as const,
                        text: error instanceof Error ? error.message : '命令执行失败'
                    }
                ],
                isError: true
            };
        }
  • Zod input schema for the executeCommand tool: 'type' (required string, command type), 'params' (optional record of any).
    {
        type: z.string().describe('命令类型'),
        params: z.record(z.any()).optional().describe('命令参数')
    },
  • Registration of the 'executeCommand' tool on the MCP server using server.tool(), including name, description, schema, and handler.
    server.tool(
        'executeCommand',
        '执行指定的命令',
        {
            type: z.string().describe('命令类型'),
            params: z.record(z.any()).optional().describe('命令参数')
        },
        async ({ type, params = {} }) => {
            try {
                const result = await registry.executeCommand(type, params);
                return {
                    content: [
                        {
                            type: 'text' as const,
                            text: result.content[0].text
                        }
                    ],
                    _meta: {
                        result: result._meta || {}
                    },
                    isError: result.isError
                };
            } catch (error) {
                return {
                    content: [
                        {
                            type: 'text' as const,
                            text: error instanceof Error ? error.message : '命令执行失败'
                        }
                    ],
                    isError: true
                };
            }
        }
    );
  • Core dispatch logic in CommandRegistry.executeCommand: resolves command name, parses/validates params, invokes handler, handles errors - called by the tool handler.
    public async executeCommand(commandName: string, params: unknown = {}): Promise<McpResponse> {
        // 尝试直接查找完整命令名
        let command = this.commands.get(commandName);
        
        if (!command) {
            // 如果找不到,尝试解析命名空间
            const [namespace, name] = this.parseFullCommandName(commandName);
            const fullName = this.getFullCommandName(namespace, name);
            command = this.commands.get(fullName);
        }
    
        if (!command) {
            return {
                content: [
                    {
                        type: 'text',
                        text: `命令 ${commandName} 不存在`
                    }
                ],
                isError: true
            };
        }
    
        try {
            const validatedParams = command.params.parse(params);
            return await command.handler(validatedParams);
        } catch (error) {
            if (error instanceof z.ZodError) {
                const issues = error.issues.map(issue => 
                    `  - ${issue.path.join('.')}: ${issue.message}`
                ).join('\n');
                
                return {
                    content: [
                        {
                            type: 'text',
                            text: `参数验证失败:\n${issues}`
                        }
                    ],
                    isError: true
                };
            }
    
            return {
                content: [
                    {
                        type: 'text',
                        text: `命令执行失败:${error instanceof Error ? error.message : String(error)}`
                    }
                ],
                isError: true
            };
        }
    }
  • src/server.ts:52-52 (registration)
    Invocation of registerCommandTool which registers the executeCommand tool on the server instance.
    registerCommandTool(server);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

D1.8/5.0
Behavior2/5

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

With no annotations present, the description must carry the full burden of behavioral disclosure. It merely states 'execute the specified command' without mentioning whether it can cause side effects, require permissions, return output, or fail. For a command execution tool, this is a significant transparency gap.

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

Conciseness2/5

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

The description is a single short sentence, but it is under-specified rather than concise. It lacks essential information and reads like a placeholder, similar to the low-quality 'process' example.

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

Completeness1/5

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

This tool has two parameters including a nested object, no output schema, and no annotations. The description provides no details on supported command types, parameter structure, return values, or safety implications. It is critically incomplete for an operational tool.

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 provides descriptions for both parameters (100% coverage), so the baseline is 3. The tool description adds no extra meaning beyond the schema's minimal 'command type' and 'command parameters' labels, but the schema at least names the parameters.

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

Purpose1/5

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

The description '执行指定的命令' (Execute the specified command) is a direct tautology of the tool name 'executeCommand'. It does not specify what types of commands, which resources, or how it differs from siblings like queryCommands or help.

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?

No usage guidance is provided. The description gives no context on when to use executeCommand versus alternatives, nor any prerequisites, scenarios, or exclusions.

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