Skip to main content
Glama

搜索语雀文档

search-yuque-docs

Search for documents within Yuque knowledge bases by matching keywords in titles and descriptions to quickly find relevant documentation.

Instructions

在指定的知识库中搜索文档。

会在文档标题和描述中进行关键词匹配。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes搜索关键词
namespaceNo知识库命名空间 (例如: username/repo),如果未提供则使用默认命名空间

Implementation Reference

  • The handler function for the 'search-yuque-docs' tool. Resolves the namespace, performs the search using the browser-based helper, formats the results as Markdown list, and returns structured content.
    async ({ query, namespace }) => {
      try {
        const finalNamespace = namespace || YUQUE_CONFIG.namespace;
    
        if (!finalNamespace) {
          return {
            content: [
              {
                type: "text",
                text: `错误: 请提供知识库命名空间。\n\n示例: "username/repo"`,
              },
            ],
          };
        }
    
        if (!isValidNamespace(finalNamespace)) {
          return {
            content: [
              {
                type: "text",
                text: `错误: 命名空间格式无效。\n\n命名空间应该是 "username/repo" 的格式。`,
              },
            ],
          };
        }
    
        // 搜索文档(使用无头浏览器)
        const docs = await searchYuqueDocsByBrowser(finalNamespace, query, YUQUE_CONFIG);
    
        if (docs.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `没有找到匹配 "${query}" 的文档。\n\n知识库: ${finalNamespace}`,
              },
            ],
          };
        }
    
        // 格式化输出
        let output = `# 搜索结果\n\n`;
        output += `**关键词**: ${query}\n`;
        output += `**知识库**: ${finalNamespace}\n`;
        output += `**找到**: ${docs.length} 个文档\n\n`;
        output += `---\n\n`;
    
        docs.forEach((doc, index) => {
          output += formatDocListItem(doc, index + 1);
        });
    
        return {
          content: [
            {
              type: "text",
              text: output,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `错误: ${error instanceof Error ? error.message : "未知错误"}`,
            },
          ],
        };
      }
    }
  • Input schema definition for the tool, including title, description, and Zod validation for 'query' (required string) and 'namespace' (optional string).
      {
        title: "搜索语雀文档",
        description: `在指定的知识库中搜索文档。
    
    会在文档标题和描述中进行关键词匹配。`,
        inputSchema: {
          query: z.string().describe("搜索关键词"),
          namespace: z
            .string()
            .optional()
            .describe("知识库命名空间 (例如: username/repo),如果未提供则使用默认命名空间"),
        },
      },
  • src/index.ts:308-393 (registration)
    Registers the 'search-yuque-docs' tool with the MCP server using server.registerTool, specifying name, schema, and handler.
    server.registerTool(
      "search-yuque-docs",
      {
        title: "搜索语雀文档",
        description: `在指定的知识库中搜索文档。
    
    会在文档标题和描述中进行关键词匹配。`,
        inputSchema: {
          query: z.string().describe("搜索关键词"),
          namespace: z
            .string()
            .optional()
            .describe("知识库命名空间 (例如: username/repo),如果未提供则使用默认命名空间"),
        },
      },
      async ({ query, namespace }) => {
        try {
          const finalNamespace = namespace || YUQUE_CONFIG.namespace;
    
          if (!finalNamespace) {
            return {
              content: [
                {
                  type: "text",
                  text: `错误: 请提供知识库命名空间。\n\n示例: "username/repo"`,
                },
              ],
            };
          }
    
          if (!isValidNamespace(finalNamespace)) {
            return {
              content: [
                {
                  type: "text",
                  text: `错误: 命名空间格式无效。\n\n命名空间应该是 "username/repo" 的格式。`,
                },
              ],
            };
          }
    
          // 搜索文档(使用无头浏览器)
          const docs = await searchYuqueDocsByBrowser(finalNamespace, query, YUQUE_CONFIG);
    
          if (docs.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `没有找到匹配 "${query}" 的文档。\n\n知识库: ${finalNamespace}`,
                },
              ],
            };
          }
    
          // 格式化输出
          let output = `# 搜索结果\n\n`;
          output += `**关键词**: ${query}\n`;
          output += `**知识库**: ${finalNamespace}\n`;
          output += `**找到**: ${docs.length} 个文档\n\n`;
          output += `---\n\n`;
    
          docs.forEach((doc, index) => {
            output += formatDocListItem(doc, index + 1);
          });
    
          return {
            content: [
              {
                type: "text",
                text: output,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `错误: ${error instanceof Error ? error.message : "未知错误"}`,
              },
            ],
          };
        }
      }
    );
  • Helper function implementing the search logic: lists all documents in the namespace using browser scraping and filters those whose title contains the query keyword (case-insensitive).
    export async function searchYuqueDocsByBrowser(
      namespace: string,
      query: string,
      config: YuqueConfig
    ): Promise<YuqueDocListItem[]> {
      // 先获取所有文档,然后在客户端过滤
      const allDocs = await listYuqueDocsByBrowser(namespace, config);
      return allDocs.filter((doc) =>
        doc.title.toLowerCase().includes(query.toLowerCase())
      );
    }
  • Utility function to format each document in the search results as a Markdown list item with key metadata.
    export function formatDocListItem(doc: YuqueDocListItem, index?: number): string {
      let output = "";
      if (index !== undefined) {
        output += `## ${index}. `;
      }
      output += `${doc.title}\n\n`;
      output += `- **Slug**: ${doc.slug}\n`;
      output += `- **格式**: ${doc.format}\n`;
      output += `- **字数**: ${doc.word_count}\n`;
      output += `- **更新时间**: ${new Date(doc.updated_at).toLocaleString("zh-CN")}\n`;
      output += `- **浏览量**: ${doc.hits}\n`;
    
      if (doc.description) {
        output += `- **描述**: ${doc.description}\n`;
      }
    
      output += `\n`;
    
      return output;
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. It mentions that searching occurs in document titles and descriptions, which adds some behavioral context. However, it lacks details on permissions, rate limits, pagination, or what happens if no matches are found. For a search tool with zero annotation coverage, this is insufficient.

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

Conciseness4/5

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

The description is concise with two sentences that directly state the tool's function and scope. It's front-loaded with the main purpose, though it could be slightly more structured by explicitly mentioning parameters or usage context.

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 the complexity of a search tool with no annotations and no output schema, the description is incomplete. It doesn't explain return values, error handling, or how results are formatted. The mention of keyword matching in titles and descriptions is helpful but insufficient for full contextual understanding.

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?

Schema description coverage is 100%, so the schema already documents both parameters ('query' as search keywords and 'namespace' as knowledge base namespace). The description implies the 'namespace' parameter specifies the knowledge base but doesn't add meaning beyond what the schema provides. Baseline 3 is appropriate when schema does the heavy lifting.

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 the tool's purpose: '在指定的知识库中搜索文档' (search for documents in a specified knowledge base). It specifies the verb '搜索' (search) and resource '文档' (documents), but doesn't explicitly differentiate from sibling tools like 'list-yuque-docs' or 'get-yuque-doc' beyond mentioning keyword matching in titles and descriptions.

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 'list-yuque-docs' (which might list all documents) or 'get-yuque-doc' (which retrieves a specific document). It mentions searching within a knowledge base but doesn't specify scenarios where searching is preferable to listing or getting.

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/saoqixiaomm/yuque-mcp'

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