Skip to main content
Glama

parse_paper_content

Extract structured content from arXiv papers by parsing HTML or PDF formats to retrieve text, metadata, and research information for analysis.

Instructions

解析论文内容(优先使用 HTML 版本,回退到 PDF)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesarXiv 论文URL或 arXiv ID
paperInfoNo论文信息(可选,用于添加论文元数据)

Implementation Reference

  • The core handler function that implements the parse_paper_content tool logic: extracts text content from arXiv paper preferring HTML version, falling back to PDF parsing, and formats output with optional paper metadata.
    async function parsePaperContent(input: string, paperInfo?: any): Promise<{content: string, source: 'html' | 'pdf'}> {
      let tempPdfPath: string | null = null;
      
      try {
        // 获取 arXiv ID
        let arxivId: string;
        if (input.startsWith('http://') || input.startsWith('https://')) {
          const urlParts = input.split('/');
          arxivId = urlParts[urlParts.length - 1];
        } else {
          arxivId = input;
        }
        
        // 首先尝试获取 HTML 版本
        console.log("尝试获取 HTML 版本...");
        const htmlContent = await getArxivHtmlContent(arxivId);
        
        let paperText: string;
        let source: 'html' | 'pdf';
        
        if (htmlContent) {
          // 使用 HTML 版本
          console.log("使用 HTML 版本解析内容");
          paperText = extractTextFromHtml(htmlContent);
          source = 'html';
        } else {
          // 回退到 PDF 版本
          console.log("HTML 版本不可用,回退到 PDF 版本");
          const pdfUrl = getArxivPdfUrl(input);
          tempPdfPath = await downloadTempPdf(pdfUrl);
          paperText = await extractPdfText(tempPdfPath);
          source = 'pdf';
        }
        
        // 构建输出内容
        let outputContent = '';
    
        if (paperInfo) {
          outputContent += `=== 论文信息 ===\n`;
          outputContent += `标题: ${paperInfo.title}\n`;
          outputContent += `arXiv ID: ${arxivId}\n`;
          outputContent += `发布日期: ${paperInfo.published}\n`;
          outputContent += `内容来源: ${source.toUpperCase()}\n`;
    
          if (paperInfo.authors && paperInfo.authors.length > 0) {
            outputContent += `作者: ${paperInfo.authors.map((author: any) => author.name || author).join(', ')}\n`;
          }
    
          outputContent += `摘要: ${paperInfo.summary}\n`;
          outputContent += `\n=== 论文内容 ===\n\n`;
        } else {
          outputContent += `=== 论文内容 (来源: ${source.toUpperCase()}) ===\n\n`;
        }
    
        outputContent += paperText;
    
        return { content: outputContent, source };
      } catch (error) {
        console.error("解析论文内容时出错:", error);
        throw new Error(`论文内容解析失败: ${error instanceof Error ? error.message : String(error)}`);
      } finally {
        // 清理临时 PDF 文件
        if (tempPdfPath && fs.existsSync(tempPdfPath)) {
          try {
            fs.unlinkSync(tempPdfPath);
            console.log(`临时文件已删除: ${tempPdfPath}`);
          } catch (cleanupError) {
            console.warn(`清理临时文件失败: ${cleanupError}`);
          }
        }
      }
    }
  • Input schema defining parameters for the parse_paper_content tool: required 'input' (arXiv URL or ID), optional 'paperInfo' object with title, summary, published, authors.
    inputSchema: {
      type: "object",
      properties: {
        input: {
          type: "string",
          description: "arXiv 论文URL或 arXiv ID"
        },
        paperInfo: {
          type: "object",
          description: "论文信息(可选,用于添加论文元数据)",
          properties: {
            title: { type: "string" },
            summary: { type: "string" },
            published: { type: "string" },
            authors: { type: "array" }
          }
        }
      },
      required: ["input"]
    }
  • src/index.ts:366-389 (registration)
    Registration of the parse_paper_content tool in the ListToolsRequestSchema handler, specifying name, description, and input schema.
    {
      name: "parse_paper_content",
      description: "解析论文内容(优先使用 HTML 版本,回退到 PDF)",
      inputSchema: {
        type: "object",
        properties: {
          input: {
            type: "string",
            description: "arXiv 论文URL或 arXiv ID"
          },
          paperInfo: {
            type: "object",
            description: "论文信息(可选,用于添加论文元数据)",
            properties: {
              title: { type: "string" },
              summary: { type: "string" },
              published: { type: "string" },
              authors: { type: "array" }
            }
          }
        },
        required: ["input"]
      }
    }
  • src/index.ts:437-447 (registration)
    Tool dispatch/execution in the CallToolRequestSchema handler switch statement, invoking the parsePaperContent function and returning formatted text content.
    case "parse_paper_content": {
      const { input, paperInfo } = args as { input: string; paperInfo?: any };
      const result = await parsePaperContent(input, paperInfo);
    
      return {
        content: [{
          type: "text",
          text: result.content
        }]
      };
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the HTML/PDF fallback behavior, which is useful. However, it doesn't describe critical traits like whether this is a read-only operation, potential rate limits, authentication needs, error handling, or what the parsed output looks like (since there's no output schema). For a tool that likely involves network requests and content processing, this is a significant gap.

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

Conciseness5/5

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

The description is extremely concise (one sentence) and front-loaded with the core purpose. Every word earns its place by specifying the action, resource, and a key behavioral detail (HTML/PDF preference). There's no wasted text or redundancy.

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

Completeness2/5

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

Given the complexity (parsing academic papers with fallback logic), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'parsed content' includes (e.g., full text, abstracts, sections), error conditions, or performance characteristics. For a tool with 2 parameters (one nested) and no structured output definition, more context is needed for effective use.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents both parameters ('input' as arXiv URL/ID and 'paperInfo' as optional metadata). The description adds no additional parameter semantics beyond what's in the schema. It doesn't explain format expectations (e.g., arXiv ID patterns) or how 'paperInfo' might affect parsing. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('解析论文内容' - parse paper content) and specifies the resource (papers from arXiv via URL/ID). It distinguishes from siblings like 'get_arxiv_pdf_url' (which only retrieves URLs) and 'search_arxiv' (which searches metadata) by focusing on content extraction. However, it doesn't explicitly mention what content is extracted (e.g., text, sections, references).

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

Usage Guidelines3/5

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

The description provides some usage context by stating '优先使用 HTML 版本,回退到 PDF' (prefer HTML version, fallback to PDF), which implies when to use this tool for content parsing rather than just getting PDF URLs. However, it doesn't explicitly compare with alternatives like 'get_recent_ai_papers' or 'search_arxiv', nor does it specify prerequisites or when not to use it.

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/BACH-AI-Tools/bach-Arxiv-Paper-MCP'

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