Created
March 21, 2025 15:52
-
-
Save sciyoshi/d1ce50b49cc86ddf0b851c69a27ba5a8 to your computer and use it in GitHub Desktop.
Outline MCP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /// 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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment