Spaces:
Runtime error
Runtime error
File size: 1,955 Bytes
e68cdf0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | 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()
|