MCP Documentation Server¶
The Model Context Protocol (MCP) server bundled with flarchitect exposes the project’s documentation so tools and agents can query, search, and cite it without bespoke glue code. It indexes the Sphinx docs/source tree, converts reStructuredText into plain text, and makes the content available over the MCP standard resource and tool APIs.
Tip
The MCP server installs as an optional extra. Install it with pip install flarchitect[mcp] or uv pip install '.[mcp]' inside your virtual environment.
Quick Start¶
Install the optional dependency group (installs
fastmcp):pip install flarchitect[mcp]
Launch the server from the repository root, preferring
fastmcpbut falling back automatically when it is missing:flarchitect-mcp-docs --project-root . --backend fastmcp
Configure your MCP-aware client to connect to the new
flarchitect-docsendpoint. Resources use theflarchitect-doc://URI scheme and expose the semantic-chunked Markdown generated indocs/md(the server falls back to the packaged copy when the directory is missing).
Note
The reference backend (–backend reference) requires the upstream mcp package. Install it manually when you need the pure JSON-RPC server:
pip install 'mcp @ git+https://github.com/modelcontextprotocol/python-sdk@main'
What the Server Provides¶
- Resources
Every Markdown document under
docs/md(plusllms.txt) is exposed as an MCP resource. Resource metadata includes a human-readable title, the file’s relative path, and an appropriatemimeType(text/markdownortext/plain). Whendocs/mdis missing from the supplied--project-root, the CLI automatically falls back to the copy bundled with the installed flarchitect package so clients can still browse the canonical docs. The originaldocs/sourcetree remains the authority; a conversion script keeps the Markdown in sync.- Tools
Three MCP tools are registered:
list_docsReturns the available document identifiers and titles to help clients discover what can be searched or fetched.
search_docsPerforms a case-insensitive substring search across the indexed documentation set and returns matching snippets with line numbers and headings. Each item includes
doc_id,title,url(flarchitect-doc://),score(float),snippet, and optionalheading/linemetadata for precise citations. Responses follow the MCP tool result schema, wrapping the payload under aresultkey insidestructuredContentand duplicating the JSON block in a textapplication/jsonentry so humans and machines can consume the same data.get_doc_sectionFetches an entire document or a single heading. Markdown and reStructuredText headings are detected heuristically so callers can request focused sections such as
{"doc_id": "docs/source/getting_started.rst", "heading": "Installation"}. The returned payload appears understructuredContentwith aresultobject containingdoc_id,title,url,content(plain text), and the requestedheading(when provided). A JSON text content block mirrors the same data for easy inspection.
- Incremental indexing
The server loads content on startup using
flarchitect.mcp.index.DocumentIndex. Restart the process after documentation changes to refresh the cache.
Configuration Reference¶
The flarchitect-mcp-docs CLI accepts a handful of flags to make integration simple:
--project-rootPath to the repository root. Defaults to the current working directory. This is used to locate
docs/sourceand ancillary Markdown files.--nameOverride the server name advertised to clients. The default is
flarchitect-docs.--descriptionHuman-friendly description for clients. Defaults to
Documentation browser for the flarchitect REST API generator.--backendSelect the server runtime.
fastmcpuses the high-level library from Firecrawl,referencepins to the low-levelmodelcontextprotocolimplementation, andauto(default) triesfastmcpfirst before falling back.
Integration Tips¶
Sphinx builds are not required; the MCP server works with the source files directly so updates are instantly available to clients after restart.
The
DocumentIndexhelper normalises document identifiers (doc_id) to match theflarchitect-doc://URIs. Use thelist_resourcescapability of your MCP client to discover the available values.When writing new documentation, prefer explicit headings so
get_doc_sectioncan slice sections accurately.To test the server manually, run
flarchitect-mcp-docsin one terminal and use an MCP client or curl-style helper to issuelist_resourcesandcall_toolrequests.Validate tool responses by confirming the
structuredContentblock. For example, callingsearch_docswith"home working summary"should return{"result": [...]}insidestructuredContent(plus a text echo) includingdoc_idandsnippetfields.The server implements the 2025-06-18 MCP verbs (resources/list, resources/read, tools/list, and tools/call) and advertises capabilities during the initial handshake.
The repository ships an
llms.txtmanifest (generated alongside the Markdown) so external tooling that follows the llmstxt.org proposal can discover the curated documentation index.Regenerate the Markdown chunks and
llms.txtafter updatingdocs/sourceby runningpython tools/convert_docs.pyfrom the project root. The script is idempotent and will overwrite any manual edits to the generated files.
Testing Strategy¶
Unit tests cover the DocumentIndex search/section helpers and the backend selection logic (including a stubbed fastmcp runtime). If you extend the MCP server, add tests under tests/ to keep coverage stable (the repository enforces 90%+ coverage). Use pytest tests/test_mcp_index.py tests/test_mcp_server.py to exercise the current suite.