search
Search documents or knowledge bases in Yuque platform using keywords, with filters for content type, scope, and author.
Instructions
在语雀平台中搜索文档或知识库内容,支持范围和作者筛选
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 搜索关键词 | |
| type | Yes | 要搜索的内容类型:doc(文档) 或 repo(知识库) | |
| scope | No | 搜索范围,不填默认搜索当前用户/团队 | |
| page | No | 页码,默认为1 | |
| creator | No | 仅搜索指定作者的内容 | |
| accessToken | No | 用于认证 API 请求的令牌 |
Implementation Reference
- src/server.ts:508-530 (handler)The main handler function for the 'search' MCP tool. It logs the search parameters, creates a YuqueService instance, calls the search method, formats the results as JSON text content, or returns an error message.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)Zod input schema defining parameters for the 'search' tool: query (required string), type (enum doc/repo), optional scope, page, creator, accessToken.{ 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 on the MCP server using server.tool(), including name, description, input schema, and handler function.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)YuqueService helper method that performs the actual HTTP GET request to Yuque API /search endpoint with query parameters.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; }
- src/services/yuque.ts:127-135 (schema)TypeScript interface defining the structure of search results returned by Yuque API.export interface YuqueSearchResult { id: number; type: 'doc' | 'repo'; title: string; summary: string; url: string; info: string; target: YuqueDoc | YuqueRepo; }