A Rust MCP server for searching books through Anna's Archive via RapidAPI and downloading selected results safely to your machine.
This section is a practical manual for getting AnnasArchiveMCP running and using it from an MCP client.
Clone the repository and compile the binary:
git clone <your-repo-url>
cd AnnasArchiveMCP
cargo build --releaseThe compiled binary will be:
target/release/annas-archive-mcpAnnasArchiveMCP needs a RapidAPI key that has access to the Anna's Archive API.
Set it in your environment before starting the server:
export RAPIDAPI_KEY=your_api_key_hereYou can also place it in a local .env file if that fits your setup better.
You can run with only RAPIDAPI_KEY, but these optional variables are useful:
RAPIDAPI_HOSTβ defaults toannas-archive-api.p.rapidapi.comANNAS_ARCHIVE_MCP_DOWNLOAD_DIRβ default folder for downloaded filesANNAS_ARCHIVE_MCP_OPEN_AFTER_DOWNLOADβtrueorfalseANNAS_ARCHIVE_MCP_CREATE_SUBDIRSβtrueorfalseANNAS_ARCHIVE_MCP_OVERWRITE_DEFAULTβtrueorfalseANNAS_ARCHIVE_MCP_DEFAULT_LIMITβ default number of search resultsANNAS_ARCHIVE_MCP_MAX_LIMITβ maximum allowed search resultsRUST_LOGβ log level such asinfoordebug
Example:
RAPIDAPI_KEY=your_api_key_here
ANNAS_ARCHIVE_MCP_DOWNLOAD_DIR=~/Downloads
ANNAS_ARCHIVE_MCP_OPEN_AFTER_DOWNLOAD=false
ANNAS_ARCHIVE_MCP_CREATE_SUBDIRS=true
ANNAS_ARCHIVE_MCP_OVERWRITE_DEFAULT=false
RUST_LOG=infoRun it with Cargo during development:
cargo runOr run the compiled binary directly:
./target/release/annas-archive-mcpThe server uses stdio, so it is normally started by your MCP client instead of being used as a standalone interactive CLI.
Point your MCP client at the built binary and provide the required environment variables.
Example MCP client configuration:
{
"mcpServers": {
"annas-archive": {
"command": "/absolute/path/to/AnnasArchiveMCP/target/release/annas-archive-mcp",
"env": {
"RAPIDAPI_KEY": "your_api_key_here",
"RUST_LOG": "info"
}
}
}
}Replace the path with the actual absolute path on your machine.
Use the search_books tool first. This is the recommended workflow.
Typical search arguments:
queryβ the search text, for example a title, author, or bothformatsβ optional preferred formats such aspdforepublanguagesβ optional language filtersyearFrom/yearToβ optional year rangelimitβ maximum number of results to returnsortβrelevance,year, orsize
A typical search request would be conceptually like:
- query:
clean code - formats:
["pdf", "epub"] - limit:
5
The response includes ranked results with stable result_id values. Save the result_id for the result you want to download.
After searching, use download_book with either:
resultIdβ recommended, because it comes directly fromsearch_booksproviderItemIdβ provider-native identifier
Optional download arguments include:
downloadDirfilenameTemplateoverwriteopenAfterDownloadcreateSubdirs
Typical workflow:
- Search with
search_books - Review the returned results
- Copy the desired
result_id - Call
download_bookwith thatresultId
The response includes the final saved path, filename, bytes written, and whether the file was opened automatically.
AnnasArchiveMCP also provides search_and_download_book.
This workflow:
- searches first
- returns results when manual selection is needed
- or automatically downloads the top match when selection settings allow it
Useful selectionMode values:
manualβ always return choices for you to inspectauto_if_confidentβ auto-download only when the top match is strong enoughforce_topβ always pick the top-ranked result
This mode is convenient, but the separate search_books β download_book flow is usually easier to control.
For the safest and most predictable experience, use this routine:
- Start the MCP server through your MCP client
- Call
search_bookswith a clear query - Inspect title, author, year, language, format, and relevance
- Choose the best
result_id - Call
download_book - Confirm the returned
destination_path
If you want an EPUB copy of a book:
- Search for the title and author together
- Pass
formats: ["epub"] - Limit results to a small number such as
5 - Inspect the best matches
- Download the result with the most accurate metadata
If you get too few results, remove format or language filters and try again.
search_books returns structured information such as:
- a summary
- the normalized query
- a result count
- ranked results
- warnings when relevant
download_book returns structured information such as:
- selected result identifiers
- title and authors
- file format and MIME type
- destination path
- final filename
- bytes written
- warnings
If the server does not start:
- confirm
RAPIDAPI_KEYis set - confirm your key has Anna's Archive API access
- confirm your MCP client points to the correct binary path
If searching returns nothing useful:
- broaden the query
- remove some filters
- verify the upstream API is available
If downloading fails:
- check destination directory permissions
- check available disk space
- verify the selected result is downloadable
- retry later if the upstream service is unavailable or rate-limited
- Do not hardcode API keys in source code
- Prefer environment variables or MCP client secret storage
- Do not commit
.envfiles containing real secrets
- MCP stdio server implemented in Rust
- Normalized search results with stable
result_idvalues - Separate tools for search and download
- Compatibility
search_and_download_bookworkflow - Safer path handling and filename generation
- Ranked result selection with manual and auto-selection modes
- Optional open-after-download behavior
- Structured JSON responses for MCP clients
- Rust 1.78+ recommended
- Cargo
- A RapidAPI key with access to the Anna's Archive API
Clone the repository and build it:
git clone <your-repo-url>
cd AnnasArchiveMCP
cargo build --releaseThe server binary will be available at:
target/release/annas-archive-mcpAnnasArchiveMCP reads configuration from environment variables and optionally from a local .env file.
RAPIDAPI_KEYβ your RapidAPI API key
RAPIDAPI_HOSTβ defaults toannas-archive-api.p.rapidapi.comANNAS_ARCHIVE_MCP_DEFAULT_PROVIDERβ defaults toannas_archiveANNAS_ARCHIVE_MCP_DOWNLOAD_DIRβ default download directoryANNAS_ARCHIVE_MCP_OPEN_AFTER_DOWNLOADβtrueorfalseANNAS_ARCHIVE_MCP_CREATE_SUBDIRSβtrueorfalseANNAS_ARCHIVE_MCP_OVERWRITE_DEFAULTβtrueorfalseANNAS_ARCHIVE_MCP_FILENAME_TEMPLATEβ filename template stringANNAS_ARCHIVE_MCP_MAX_FILENAME_LENGTHβ max generated filename lengthANNAS_ARCHIVE_MCP_DEFAULT_LIMITβ default search result limitANNAS_ARCHIVE_MCP_MAX_LIMITβ max allowed search result limitANNAS_ARCHIVE_MCP_ENABLE_DEBUG_FIELDSβ include provider debug fields by defaultANNAS_ARCHIVE_MCP_TIMEOUT_SECSβ HTTP timeoutANNAS_ARCHIVE_MCP_MAX_RETRIESβ provider retry countANNAS_ARCHIVE_MCP_USER_AGENTβ custom HTTP user agentRUST_LOGβ log level, for exampleinfoordebug
RAPIDAPI_KEY=your_api_key_here
RAPIDAPI_HOST=annas-archive-api.p.rapidapi.com
ANNAS_ARCHIVE_MCP_DOWNLOAD_DIR=~/Downloads
ANNAS_ARCHIVE_MCP_OPEN_AFTER_DOWNLOAD=false
ANNAS_ARCHIVE_MCP_CREATE_SUBDIRS=true
ANNAS_ARCHIVE_MCP_OVERWRITE_DEFAULT=false
ANNAS_ARCHIVE_MCP_DEFAULT_LIMIT=10
ANNAS_ARCHIVE_MCP_MAX_LIMIT=50
RUST_LOG=infoRun directly with Cargo:
cargo runOr run the release binary:
./target/release/annas-archive-mcpThe server communicates over stdio and is intended to be launched by an MCP client.
Example command-based MCP configuration:
{
"mcpServers": {
"annas-archive": {
"command": "/absolute/path/to/AnnasArchiveMCP/target/release/annas-archive-mcp",
"env": {
"RAPIDAPI_KEY": "your_api_key_here",
"RUST_LOG": "info"
}
}
}
}Adjust the path for your machine and MCP client.
Searches for books and returns ranked normalized results.
query(required): free-text search queryformats: array of preferred formats likepdf,epub,mobicategories: array likefiction,nonfictionlanguages: array of language codes or labelsyearFrom: lower year boundyearTo: upper year boundlimit: maximum results to returnprovider: provider hint, currentlyannas_archivesort:relevance,year, orsizedebug: include ranking/debug metadata
Structured content including:
summaryquerycountresultswarnings
Each result includes fields such as:
result_idproviderprovider_item_idtitlesubtitleauthorspublisheryearlanguageformatfile_size_bytescover_urlchecksum_md5checksum_sha1downloadablerelevance_score
Downloads a specific result using either resultId or providerItemId.
resultId: stable result id returned fromsearch_booksproviderItemId: provider-native identifierdownloadDir: override destination directoryfilenameTemplate: override filename templateoverwrite: overwrite existing filesopenAfterDownload: open the file after downloadcreateSubdirs: create destination directory if needed
You must provide either resultId or providerItemId.
Structured content including:
summaryresult_idproviderprovider_item_idtitleauthorsformatmime_typedestination_pathfinal_file_namebytes_writtenopenedwarnings
Compatibility workflow that searches first, then either:
- returns matching results if manual selection is required, or
- auto-selects a result and downloads it
Includes all major search and download fields plus:
selectionMode: one ofmanualauto_if_confidentforce_top
- Call
search_books - Inspect results
- Choose a
result_id - Call
download_book
- Call
search_and_download_book - If
selection_requiredistrue, calldownload_bookwith a chosenresultId - Otherwise use the returned download result
- Automatic file opening is opt-in
- Downloads are written using safer filename/path handling
- Result ranking attempts to prefer better title/author/format matches
- The provider currently supported is Anna's Archive through RapidAPI
- If your API key is missing, startup will fail with a configuration error
Build:
cargo buildRun tests:
cargo testRun with debug logging:
RUST_LOG=debug cargo runFormat and lint:
cargo fmt
cargo clippy --all-targets --all-featuresCheck that:
RAPIDAPI_KEYis set- your key has access to the Anna's Archive API
- the binary path in your MCP client config is correct
Try:
- a broader query
- removing restrictive filters
- verifying the upstream API is reachable
Check:
- destination directory permissions
- available disk space
- whether the provider result is actually downloadable
- whether the upstream API is rate-limiting or unavailable
- Do not hardcode API keys in source files
- Prefer environment variables or MCP client-managed secrets
- Review your MCP client config so secrets are not committed to version control
This project is a Rust rewrite focused on a cleaner MCP architecture, safer downloads, and better maintainability than the legacy implementation.