Skip to main content
Glama

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
NameRequiredDescriptionDefault
idYes文档ID
sourceNo文档源名称(如不提供,将搜索所有源)

Implementation Reference

  • 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)
          }]
        };
      }
    }
  • 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)
            }]
          };
        }
      }
    );
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

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/ruan11223344/McpDocServer'

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