docs_get_doc_detail
Retrieve detailed documentation content by document ID from McpDocServer, enabling developers to access specific technical information for frameworks and libraries.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | 文档ID | |
| source | No | 文档源名称(如不提供,将搜索所有源) |
Implementation Reference
- server.js:567-673 (handler)The handler function for 'docs_get_doc_detail' tool. It retrieves the document details by ID from the global docData, optionally from a specific source, and returns formatted JSON response.async ({ id, source }) => { log(`收到文档详情请求: ID="${id}", 源="${source || '所有'}"`); try { // 确保文档已加载 if (Object.keys(docData).length === 0) { log(`文档数据为空,尝试加载...`); const loadResult = await ensureDocsLoaded(); if (!loadResult || Object.keys(docData).length === 0) { return { content: [{ type: "text", text: JSON.stringify({ error: "文档数据不可用", message: "无法加载文档数据" }, null, 2) }] }; } } // 查找指定的文档 let docDetail = null; if (source) { // 在指定源中查找文档 const sourceLower = source.toLowerCase(); if (!docData[sourceLower] || !docData[sourceLower].pages) { return { content: [{ type: "text", text: JSON.stringify({ error: `未找到文档源 "${source}"`, availableSources: Object.keys(docData) }, null, 2) }] }; } if (docData[sourceLower].pages[id]) { const page = docData[sourceLower].pages[id]; docDetail = { id, title: page.title || id, content: page.content || "", source: { name: sourceLower, url: docData[sourceLower].source?.url || "" }, url: id // 使用ID作为URL }; } } else { // 在所有源中查找文档 for (const [sourceName, data] of Object.entries(docData)) { if (data.pages && data.pages[id]) { const page = data.pages[id]; docDetail = { id, title: page.title || id, content: page.content || "", source: { name: sourceName, url: data.source?.url || "" }, url: id // 使用ID作为URL }; break; } } } if (!docDetail) { return { content: [{ type: "text", text: JSON.stringify({ error: `未找到ID为 "${id}" 的文档`, source: source || "all" }, null, 2) }] }; } // 返回文档详情 return { content: [{ type: "text", text: JSON.stringify({ success: true, document: docDetail }, null, 2) }] }; } catch (error) { log(`获取文档详情时发生错误: ${error.message}`); return { content: [{ type: "text", text: JSON.stringify({ error: "获取文档详情时发生错误", details: error.message }, null, 2) }] }; } }
- server.js:563-566 (schema)Input schema for the 'docs_get_doc_detail' tool using Zod validation: requires 'id' string, optional 'source' string.{ id: z.string().describe("文档ID"), source: z.string().optional().describe("文档源名称(如不提供,将搜索所有源)") },
- server.js:561-674 (registration)Registration of the 'docs_get_doc_detail' tool on the MCP server using server.tool() with name, schema, and handler.server.tool( "docs_get_doc_detail", // 修改工具名称,添加命名空间前缀 { id: z.string().describe("文档ID"), source: z.string().optional().describe("文档源名称(如不提供,将搜索所有源)") }, async ({ id, source }) => { log(`收到文档详情请求: ID="${id}", 源="${source || '所有'}"`); try { // 确保文档已加载 if (Object.keys(docData).length === 0) { log(`文档数据为空,尝试加载...`); const loadResult = await ensureDocsLoaded(); if (!loadResult || Object.keys(docData).length === 0) { return { content: [{ type: "text", text: JSON.stringify({ error: "文档数据不可用", message: "无法加载文档数据" }, null, 2) }] }; } } // 查找指定的文档 let docDetail = null; if (source) { // 在指定源中查找文档 const sourceLower = source.toLowerCase(); if (!docData[sourceLower] || !docData[sourceLower].pages) { return { content: [{ type: "text", text: JSON.stringify({ error: `未找到文档源 "${source}"`, availableSources: Object.keys(docData) }, null, 2) }] }; } if (docData[sourceLower].pages[id]) { const page = docData[sourceLower].pages[id]; docDetail = { id, title: page.title || id, content: page.content || "", source: { name: sourceLower, url: docData[sourceLower].source?.url || "" }, url: id // 使用ID作为URL }; } } else { // 在所有源中查找文档 for (const [sourceName, data] of Object.entries(docData)) { if (data.pages && data.pages[id]) { const page = data.pages[id]; docDetail = { id, title: page.title || id, content: page.content || "", source: { name: sourceName, url: data.source?.url || "" }, url: id // 使用ID作为URL }; break; } } } if (!docDetail) { return { content: [{ type: "text", text: JSON.stringify({ error: `未找到ID为 "${id}" 的文档`, source: source || "all" }, null, 2) }] }; } // 返回文档详情 return { content: [{ type: "text", text: JSON.stringify({ success: true, document: docDetail }, null, 2) }] }; } catch (error) { log(`获取文档详情时发生错误: ${error.message}`); return { content: [{ type: "text", text: JSON.stringify({ error: "获取文档详情时发生错误", details: error.message }, null, 2) }] }; } } );