doc-analysis-mcp
# doc-analysis-mcp
`doc-analysis-mcp` packages the [doc-analysis](https://github.com/xhlyy/doc-analysis) workflow as a standard MCP server. Any MCP-capable agent can use it; compatible Skill loaders can also read the bundled `SKILL.md`.
The plugin makes an agent:
1. Build a map of the document before reading it.
2. Extract exact source text instead of relying on memory.
3. Attach evidence and locations to claims.
4. Separate author claims, source facts, and agent inference.
5. Grade uncertainty and avoid analysis of unread sections.
## Why MCP
MCP is the portable integration layer. The server uses only Python's standard library and JSON-RPC over stdio, so it does not require an MCP SDK or a framework-specific plugin runtime.
## Install
Python 3.9 or newer is required.
```bash
python -m pip install -e ".[documents]"
```
The prebuilt v0.1.0 wheel is available at
[artifacts/doc_analysis_mcp-0.1.0-py3-none-any.whl](https://github.com/xhlyy/doc-analysis-mcp/raw/main/artifacts/doc_analysis_mcp-0.1.0-py3-none-any.whl).
For plain Markdown/text-only use, the three document parser dependencies are optional:
```bash
python -m pip install -e .
```
Check the runtime:
```bash
doc-analysis-mcp --check
```
Start the server:
```bash
doc-analysis-mcp
```
The server communicates only over stdin/stdout. Diagnostics must not be printed to stdout.
## MCP tools
| Tool | Purpose |
|---|---|
| `doc_prepare` | Build a structure map and return the required evidence-first workflow. Start here. |
| `doc_map` | Map headings, paragraph/page ranges, tables, images, and structural warnings. |
| `doc_extract` | Extract text by range or keyword, search paragraph numbers, or dump tables. |
| `doc_guide` | Read the complete Skill guide or a specific analysis reference. |
| `doc_health` | Check Python, parser packages, scripts, and supported formats. |
Supported by `doc_map`: `.docx`, `.pptx`, `.xlsx`, `.md`, `.markdown`, `.txt`.
Supported by `doc_extract`: `.docx`, `.pptx`, `.md`, `.markdown`, `.txt`.
PDF input is intentionally not parsed directly. Render the relevant pages to images with an Office/PDF tool, cite page numbers, and disclose that reading was image-based.
## Generic MCP configuration
After installation:
```json
{
"mcpServers": {
"doc-analysis": {
"command": "doc-analysis-mcp",
"args": []
}
}
}
```
Without installing the console script:
```json
{
"mcpServers": {
"doc-analysis": {
"command": "python",
"args": ["-m", "doc_analysis_mcp"],
"env": {
"PYTHONPATH": "/absolute/path/to/doc-analysis-mcp/src"
}
}
}
}
```
See [examples/mcp.json](examples/mcp.json) and [examples/codex-config.toml](examples/codex-config.toml).
## Suggested agent workflow
```text
doc_prepare(path)
doc_guide(section="lenses")
doc_extract(path, start=12, end=24)
doc_extract(path, find="关键词", context=2)
```
For L2/L3 analysis, the agent should maintain an internal evidence table:
```text
claim | quoted source (<=30 chars) | paragraph/page | empirical / argument / assertion
```
Every conclusion must point to at least one evidence row. If the source does not support a conclusion, label it as inference or remove it.
## Resources and prompts
The server exposes:
- Resource `doc-analysis://skill`
- Resources for analysis lenses, evidence extraction, and output templates
- Prompt `doc_analysis` with `path`, `mode`, and optional `focus`
Agents that do not expose resources or prompts can call `doc_guide` instead.
## Native Skill use
The bundled [SKILL.md](src/doc_analysis_mcp/assets/SKILL.md) remains directly usable by Skill-compatible agents. The MCP server is additive: it makes the same workflow callable through tools.
## Development
```bash
python -m unittest discover -s tests -v
```
The test suite starts the server as a real subprocess and exercises initialization, tool discovery, resources, prompts, health checks, and Markdown document mapping.
The GitHub Actions template is stored as `.github/ci.yml.example`. Move it to
`.github/workflows/ci.yml` from a token/account that has permission to manage
workflow files to enable automatic CI.
## Security and privacy
- Files are read locally by the MCP server.
- The server does not upload documents or call a network service.
- Document contents are returned to the calling agent and are subject to that agent's privacy policy.
- Path arguments are passed as separate subprocess arguments; shell command construction is not used.
## License
MIT. The bundled analysis workflow originates from `xhlyy/doc-analysis`.
TDQS
Scored across 5 tools
Most tools have distinct roles, but doc_prepare and doc_map overlap because both appear to build structural maps, and doc_guide and doc_prepare both provide workflow guidance. The descriptions clarify intended order and usage, but an agent could still hesitate between prepare and map for initial structural discovery.
All names use the same doc_ prefix and snake_case convention, with concise action-oriented suffixes. doc_health is slightly less verb-like than the others, but the pattern remains predictable overall.
Five tools is well-scoped for a document-analysis server, with each covering a clear phase: preparation, guidance, mapping, extraction, and diagnostics. There is no obvious bloat or missing role.
The surface covers the core analysis workflow from preparation through structural mapping and exact extraction, plus diagnostics. However, doc_map claims xlsx support while doc_extract does not, leaving a possible extraction gap for spreadsheet content.