Skip to content

Instantly share code, notes, and snippets.

@sciyoshi
Created March 21, 2025 15:52
Show Gist options
  • Select an option

  • Save sciyoshi/d1ce50b49cc86ddf0b851c69a27ba5a8 to your computer and use it in GitHub Desktop.

Select an option

Save sciyoshi/d1ce50b49cc86ddf0b851c69a27ba5a8 to your computer and use it in GitHub Desktop.

Revisions

  1. sciyoshi created this gist Mar 21, 2025.
    62 changes: 62 additions & 0 deletions outline-mcp.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    # /// script
    # dependencies = [
    # "mcp",
    # "httpx",
    # "dotenv",
    # ]
    # ///

    import os
    from typing import Any

    import httpx
    from dotenv import load_dotenv
    from mcp.server.fastmcp import FastMCP

    # Load environment variables from .env file
    load_dotenv()

    OUTLINE_URL: str = os.environ["OUTLINE_URL"]
    OUTLINE_API_KEY: str = os.environ["OUTLINE_API_KEY"]

    # Initialize API client
    client = httpx.Client(base_url=str(OUTLINE_URL), headers={"Authorization": f"Bearer {OUTLINE_API_KEY}"})

    # Create FastMCP server instance
    mcp = FastMCP("outline")


    # Define tools using FastMCP decorators
    @mcp.tool()
    def list_documents() -> list[dict[str, Any]]:
    """List all documents from Outline."""
    response = client.post("/api/documents.list")
    response.raise_for_status()
    return [{"id": doc["id"], "title": doc["title"]} for doc in response.json()["data"]]


    @mcp.tool()
    def get_document(document_id: str) -> dict[str, Any]:
    """Get a document by its ID."""
    response = client.post("/api/documents.export", json={"id": document_id})
    response.raise_for_status()
    return response.json()["data"]


    @mcp.tool()
    def search_documents(query: str) -> list[dict[str, Any]]:
    """Search documents in Outline."""
    response = client.post("/api/documents.search", json={"query": query})
    response.raise_for_status()
    return [
    {
    "id": doc["document"]["id"],
    "context": doc["context"],
    "title": doc["document"]["title"],
    }
    for doc in response.json()["data"]
    ]


    if __name__ == "__main__":
    mcp.run(transport="stdio")