ebook-builder-mcp / server.py
Brettapps's picture
Upload folder using huggingface_hub
e68cdf0 verified
from mcp.server.fastmcp import FastMCP
from ebook_agent.tools import EbookAgentTools
import os
from dotenv import load_dotenv
from typing import Optional
# Load environment variables
load_dotenv()
# Initialize FastMCP
mcp = FastMCP("Ebook-Builder")
# Initialize Tools
agent_tools = EbookAgentTools()
@mcp.tool()
def outline_ebook(topic: str, genre: str) -> str:
"""
Generate a table of contents and outline for an ebook.
Args:
topic: The main theme or subject of the book.
genre: The literary genre (e.g., Sci-Fi, Mystery, Non-fiction).
"""
return agent_tools.create_book_outline(topic, genre)
@mcp.tool()
def write_chapter(title: str, context: str) -> str:
"""
Draft a complete chapter for the ebook.
Args:
title: The title of the chapter.
context: Background information or a summary of what happens in the chapter.
"""
return agent_tools.write_book_chapter(title, context)
@mcp.tool()
def generate_cover(title: str, genre: str, description: str) -> str:
"""
Generate a professional cover image for the ebook.
Args:
title: The title of the book.
genre: The genre of the book.
description: A visual description for the cover art.
"""
return agent_tools.create_book_cover(title, genre, description)
@mcp.tool()
def compile_ebook(title: str, author: str, chapters_json: str, cover_path: Optional[str] = None) -> str:
"""
Assembles the generated chapters and cover into a final EPUB file.
Args:
title: The title of the book.
author: The author's name.
chapters_json: A JSON string containing a list of chapters (e.g., '[{"title": "Chap 1", "content": "..."}]').
cover_path: Optional path to the cover image file.
"""
return agent_tools.build_final_ebook(title, author, chapters_json, cover_path)
def main():
mcp.run()
if __name__ == "__main__":
main()