Skip to main content
Glama
homeserverhq

OpenNotebook MCP Proxy Server

by homeserverhq
README.md
# OpenNotebook MCP Multitenant Proxy Server

This repository contains a Model Context Protocol (MCP) server that acts
as a secure, multi-tenant proxy between an AI Assistant and the
OpenNotebook backend API. It exposes **81 MCP tools** covering 14 resource
domains with full CRUD, search, chat, podcast, and command management.

## โœจ Features

- **๐Ÿ”‘ Identity Passthrough** โ€” Extracts the `Authorization: Bearer <token>`
  header from incoming HTTP requests and forwards it to the OpenNotebook API
  without server-side authentication.
- **๐Ÿ‘ฅ Multi-Tenancy** โ€” Uses Python `contextvars` to maintain thread-safe
  user identity isolation, ensuring all AI-driven actions are scoped to
  the authenticated user's permissions.
- **๐Ÿ“Š Full OpenNotebook Coverage** โ€” 81 tools mapped to OpenNotebook API
  endpoints across 14 resource domains.
- **โšก TOON Optimization** โ€” Bulk list responses are automatically compressed
  using TOON (Token-Optimized Object Notation) to reduce token consumption
  and maximize context window efficiency.
- **๐Ÿš€ Efficient Gets** โ€” GET responses return only commonly used fields by
  default. Full objects are available via an `include_all_fields` flag.
- **๐Ÿงช Comprehensive Testing** โ€” 109 automated tests covering all tool
  domains, run via the test runner pipeline.
- **๐Ÿท๏ธ Tool Annotations** โ€” All tools expose standard MCP ToolAnnotations hints (readOnlyHint, destructiveHint, idempotentHint, openWorldHint). The tags field carries grouping metadata (basic/primary/advanced + opennotebook).

## ๐Ÿ”ง Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `OPENNOTEBOOK_BASE_URL` | Yes | Docker-internal URL of the OpenNotebook API |
| `MCP_SERVER_PORT` | Yes | Port number the MCP server listens on |
| `ALLOW_ALL_AGGREGATE` | No | When `true`, aggregate listing tools honor the `include_all_fields` parameter. When `false` (default), the parameter is silently forced to `False` for aggregate list operations. |
| `IS_STATEFUL` | No | When `true`, uses stateful Streamable HTTP with session tracking. When `false` (default), uses stateless mode. |

## ๐Ÿ“ฆ Installation & Local Development

1. Ensure you have Python 3.12+ installed.
2. Install dependencies:
    ```bash
    pip install fastmcp httpx pydantic uvicorn toon-mcp-server
    ```
3. Run the server:
    ```bash
    export OPENNOTEBOOK_BASE_URL=http://localhost:5055
    export MCP_SERVER_PORT=80
    python -m src.main
    ```

## ๐Ÿณ Docker Deployment

Build and run the server using Docker:

```bash
docker build -t opennotebook-mcp:latest .
docker run -d --name opennotebook-mcp \
    -e OPENNOTEBOOK_BASE_URL="http://opennotebook-app:5055" \
    -e MCP_SERVER_PORT=80 \
    opennotebook-mcp:latest
```

The MCP server serves at `http://opennotebook-mcp:80/mcp`
(Streamable HTTP).

## โš ๏ธ Important Notes

- **๐Ÿ“‹ `include_all_fields`** โ€” The `include_all_fields` parameter (available
  on all `get_*` and `list_*` tools) controls whether all available fields
  are included in responses. Defaults to `False` for performance; set to
  `True` only when additional fields are needed.
- **โšก TOON Compression** โ€” All bulk list responses are automatically
  compressed using TOON to reduce token consumption by 30โ€“60%.
- **๐Ÿ“ Required Fields & Defaults** โ€” Each `create_*` tool requires specific
  key fields. All other fields default to empty strings or reasonable values.
  The owner field is automatically set to the authenticated user for most
  resources.

## ๐Ÿ› ๏ธ API Tool Mapping

The server implements 81 MCP tools organized into the following categories:

### ๐Ÿ““ Notebooks (9 tools)

- `check_server_status` โ€” Check the health and status of the OpenNotebook backend API
- `list_all_notebooks` โ€” List all notebook records
- `get_notebook_by_id` โ€” Get a single notebook by ID
- `create_notebook` โ€” Create a new notebook
- `update_notebook` โ€” Update an existing notebook
- `delete_notebook_by_id` โ€” Delete a notebook by ID
- `get_notebook_delete_preview` โ€” Get a preview of what will be deleted
- `add_source_to_notebook` โ€” Add an existing source to a notebook
- `remove_source_from_notebook` โ€” Remove a source from a notebook
- `list_recently_viewed` โ€” List recently viewed items

### ๐Ÿ“ Notes (5 tools)

- `list_all_notes` โ€” List all note records
- `get_note_by_id` โ€” Get a single note by ID
- `create_note` โ€” Create a new note
- `update_note` โ€” Update an existing note
- `delete_note_by_id` โ€” Delete a note by ID

### ๐Ÿ”— Sources (8 tools)

- `list_all_sources` โ€” List all source records
- `get_source_by_id` โ€” Get a single source by ID
- `create_source` โ€” Create a new source (link or text type)
- `update_source` โ€” Update an existing source
- `delete_source_by_id` โ€” Delete a source by ID
- `get_source_status` โ€” Get processing status for a source
- `retry_source_processing` โ€” Retry processing for a failed source
- `list_source_insights` โ€” List all insights for a source
- `create_source_insight` โ€” Start insight generation for a source

### ๐Ÿ’ก Insights (4 tools)

- `get_insight_by_id` โ€” Get a single insight by ID
- `delete_insight_by_id` โ€” Delete an insight by ID
- `save_insight_as_note` โ€” Convert an insight to a note
- `list_source_insights` โ€” List insights for a source

### ๐Ÿ” Search & Settings (4 tools)

- `search_knowledge_base` โ€” Search the knowledge base
- `ask_knowledge_base_simple` โ€” Ask the knowledge base a question
- `get_settings` โ€” Get all application settings
- `update_settings` โ€” Update application settings

### ๐Ÿค– Models (5 tools)

- `list_all_models` โ€” List all configured models
- `create_model` โ€” Create a new model configuration
- `delete_model_by_id` โ€” Delete a model by ID
- `get_default_models` โ€” Get default model assignments
- `update_default_models` โ€” Update default model assignments

### ๐Ÿ”„ Transformations (8 tools)

- `list_all_transformations` โ€” List all transformation records
- `get_transformation_by_id` โ€” Get a single transformation by ID
- `create_transformation` โ€” Create a new transformation
- `update_transformation` โ€” Update an existing transformation
- `delete_transformation_by_id` โ€” Delete a transformation by ID
- `execute_transformation` โ€” Execute a transformation on input text
- `get_default_transformation_prompt` โ€” Get the default prompt
- `update_default_transformation_prompt` โ€” Update the default prompt

### ๐Ÿงฉ Embedding (3 tools)

- `embed_content` โ€” Embed content for vector search
- `start_embedding_rebuild` โ€” Start a background rebuild job
- `get_rebuild_status` โ€” Get rebuild operation status

### ๐Ÿ’ฌ Chat (7 tools)

- `list_chat_sessions` โ€” List chat sessions for a notebook
- `create_chat_session` โ€” Create a new chat session
- `get_chat_session` โ€” Get a chat session with messages
- `update_chat_session` โ€” Update a chat session
- `delete_chat_session` โ€” Delete a chat session
- `execute_chat` โ€” Execute a chat request
- `build_chat_context` โ€” Build notebook context

### ๐Ÿ”Œ Source Chat (5 tools)

- `create_source_chat_session` โ€” Create a source chat session
- `list_source_chat_sessions` โ€” List source chat sessions
- `get_source_chat_session` โ€” Get a source chat session
- `update_source_chat_session` โ€” Update a source chat session
- `delete_source_chat_session` โ€” Delete a source chat session

### ๐ŸŽ™๏ธ Podcasts (6 tools)

- `generate_podcast` โ€” Generate a podcast episode
- `get_podcast_job_status` โ€” Get podcast job status
- `list_podcast_episodes` โ€” List all podcast episodes
- `get_podcast_episode` โ€” Get a specific episode
- `retry_podcast_episode` โ€” Retry a failed episode
- `delete_podcast_episode` โ€” Delete a podcast episode

### ๐ŸŽฌ Episode Profiles (6 tools)

- `list_episode_profiles` โ€” List all episode profiles
- `get_episode_profile` โ€” Get a profile by name
- `create_episode_profile` โ€” Create a new episode profile
- `update_episode_profile` โ€” Update an episode profile
- `delete_episode_profile` โ€” Delete an episode profile
- `duplicate_episode_profile` โ€” Duplicate an episode profile

### ๐Ÿ—ฃ๏ธ Speaker Profiles (6 tools)

- `list_speaker_profiles` โ€” List all speaker profiles
- `get_speaker_profile` โ€” Get a profile by name
- `create_speaker_profile` โ€” Create a new speaker profile
- `update_speaker_profile` โ€” Update a speaker profile
- `delete_speaker_profile` โ€” Delete a speaker profile
- `duplicate_speaker_profile` โ€” Duplicate a speaker profile

### ๐Ÿ“‹ Commands (4 tools)

- `submit_command_job` โ€” Submit a command for background processing
- `get_command_job_status` โ€” Get command job status
- `list_command_jobs` โ€” List command jobs
- `cancel_command_job` โ€” Cancel a running command job