search
Search documents or knowledge bases on Yuque platform with filters for scope and author, enabling precise content discovery based on type and criteria.
Instructions
在语雀平台中搜索文档或知识库内容,支持范围和作者筛选
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accessToken | No | 用于认证 API 请求的令牌 | |
| creator | No | 仅搜索指定作者的内容 | |
| page | No | 页码,默认为1 | |
| query | Yes | 搜索关键词 | |
| scope | No | 搜索范围,不填默认搜索当前用户/团队 | |
| type | Yes | 要搜索的内容类型:doc(文档) 或 repo(知识库) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"accessToken": {
"description": "用于认证 API 请求的令牌",
"type": "string"
},
"creator": {
"description": "仅搜索指定作者的内容",
"type": "string"
},
"page": {
"description": "页码,默认为1",
"type": "number"
},
"query": {
"description": "搜索关键词",
"type": "string"
},
"scope": {
"description": "搜索范围,不填默认搜索当前用户/团队",
"type": "string"
},
"type": {
"description": "要搜索的内容类型:doc(文档) 或 repo(知识库)",
"enum": [
"doc",
"repo"
],
"type": "string"
}
},
"required": [
"query",
"type"
],
"type": "object"
}
Implementation Reference
- src/server.ts:508-530 (handler)Handler function that executes the 'search' tool logic by calling the Yuque service search method and formatting the response.async ({ query, type, scope, page, creator, accessToken }) => { try { Logger.log(`Searching for: ${query} with type: ${type}`); const yuqueService = this.createYuqueService(accessToken); const results = await yuqueService.search( query, type, scope, page, creator ); Logger.log(`Successfully found ${results.length} results`); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }], }; } catch (error) { Logger.error(`Error searching for ${query}:`, error); return { content: [{ type: "text", text: `Error searching: ${error}` }], }; } }
- src/server.ts:495-507 (schema)Input schema using Zod for validating parameters of the 'search' tool.{ query: z.string().describe("搜索关键词"), type: z .enum(["doc", "repo"]) .describe("要搜索的内容类型:doc(文档) 或 repo(知识库)"), scope: z .string() .optional() .describe("搜索范围,不填默认搜索当前用户/团队"), page: z.number().optional().describe("页码,默认为1"), creator: z.string().optional().describe("仅搜索指定作者的内容"), accessToken: z.string().optional().describe("用于认证 API 请求的令牌"), },
- src/server.ts:492-531 (registration)Registration of the 'search' tool with McpServer using this.server.tool, including name, description, schema, and handler.this.server.tool( "search", "在语雀平台中搜索文档或知识库内容,支持范围和作者筛选", { query: z.string().describe("搜索关键词"), type: z .enum(["doc", "repo"]) .describe("要搜索的内容类型:doc(文档) 或 repo(知识库)"), scope: z .string() .optional() .describe("搜索范围,不填默认搜索当前用户/团队"), page: z.number().optional().describe("页码,默认为1"), creator: z.string().optional().describe("仅搜索指定作者的内容"), accessToken: z.string().optional().describe("用于认证 API 请求的令牌"), }, async ({ query, type, scope, page, creator, accessToken }) => { try { Logger.log(`Searching for: ${query} with type: ${type}`); const yuqueService = this.createYuqueService(accessToken); const results = await yuqueService.search( query, type, scope, page, creator ); Logger.log(`Successfully found ${results.length} results`); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }], }; } catch (error) { Logger.error(`Error searching for ${query}:`, error); return { content: [{ type: "text", text: `Error searching: ${error}` }], }; } } );
- src/services/yuque.ts:421-429 (helper)Supporting method in YuqueService that makes the actual HTTP request to Yuque's search API.async search(q: string, type: 'doc' | 'repo', scope?: string, page?: number, creator?: string): Promise<YuqueSearchResult[]> { const params: any = { q, type }; if (scope) params.scope = scope; if (page) params.page = page; if (creator) params.creator = creator; const response = await this.client.get('/search', { params }); return response.data.data; }