Search Documents
search_docsEnables quick document search within AFFiNE workspaces by keyword, helping users locate relevant content efficiently. Supports filtering by workspace ID and result limits for focused queries.
Instructions
Search documents in a workspace.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | Yes | ||
| limit | No | ||
| workspaceId | No |
Implementation Reference
- src/tools/docs.ts:98-112 (handler)Handler function that executes the search_docs tool by querying the GraphQL API for documents matching the keyword in the specified workspace.
const searchDocsHandler = async (parsed: { workspaceId?: string; keyword: string; limit?: number }) => { try { const workspaceId = parsed.workspaceId || defaults.workspaceId; if (!workspaceId) { throw new Error("workspaceId is required. Provide it as a parameter or set AFFINE_WORKSPACE_ID in environment."); } const query = `query SearchDocs($workspaceId:String!, $keyword:String!, $limit:Int){ workspace(id:$workspaceId){ searchDocs(input:{ keyword:$keyword, limit:$limit }){ docId title highlight createdAt updatedAt } } }`; const data = await gql.request<{ workspace: any }>(query, { workspaceId, keyword: parsed.keyword, limit: parsed.limit }); return text(data.workspace?.searchDocs || []); } catch (error: any) { // Return empty array on error (search might not be available) console.error("Search docs error:", error.message); return text([]); } }; - src/tools/docs.ts:113-125 (registration)Registers the search_docs MCP tool with its schema and handler reference.
server.registerTool( "search_docs", { title: "Search Documents", description: "Search documents in a workspace.", inputSchema: { workspaceId: z.string().optional(), keyword: z.string().min(1), limit: z.number().optional() } }, searchDocsHandler as any ); - src/tools/docs.ts:118-122 (schema)Zod input schema defining parameters for the search_docs tool: optional workspaceId, required keyword, optional limit.
inputSchema: { workspaceId: z.string().optional(), keyword: z.string().min(1), limit: z.number().optional() }