You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(sse_transport): Resolve connection and routing errors in SSE transport
This commit addresses several critical errors in the SSE transport layer (`sse_transport.py`) that prevented successful client connections after recent refactoring:
- Corrected `SseServerTransport` initialization to use the `/messages/` endpoint path, ensuring clients POST back to the correct handler.
- Added the necessary Starlette route `Mount` for `/messages` to handle client POSTs.
- Fixed the `handle_sse` request handler logic:
- Ensured it correctly retrieves streams yielded by `transport.connect_sse`.
- Changed the `mcp_server._mcp_server.run()` call to correctly use the underlying `Server` instance (`_mcp_server`) to generate `initialization_options`.
- Ensured `run()` is called on the underlying `Server` instance with the required streams and options, resolving previous `TypeError` and `AttributeError` issues.
- Removed redundant application setup code within the `run_sse_server` function.
These changes ensure the SSE transport now correctly establishes connections, routes client messages, and initiates the MCP session based on the `mcp-sdk`'s intended usage pattern.
See CHANGELOG.md for the release summary.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
30
30
- Bug in `notebook_read` size estimation loop (`NameError: name 'i' is not defined`).
31
31
- Multiple test failures related to incorrect mocking, error expectations, path handling, test setup, and imports (`StringIO`, `FastMCP`).
32
32
- Invalid escape sequence in `pyproject.toml` coverage exclusion pattern.
33
+
- Several issues in SSE transport (`sse_transport.py`) related to refactoring, including incorrect `SseServerTransport` initialization, missing `/messages` route handling, and incorrect parameters passed to the underlying `mcp.server.Server.run` method, causing connection failures.
Copy file name to clipboardExpand all lines: README.md
+100-2Lines changed: 100 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -242,9 +242,66 @@ For smooth collaboration with the AI agent on Jupyter Notebooks, you might want
242
242
* Ask the user for clarification only if the necessary information cannot be determined after using the investigation tools.
243
243
244
244
3. **Available Tools:**
245
-
* Be aware of the different categories of tools: File operations (`create`, `delete`, `rename`), Notebook/Cell Reading (`read`, `read_cell`, `get_cell_count`, `get_info`), Cell Manipulation (`add_cell`, `edit_cell`, `delete_cell`, `move_cell`, `change_cell_type`, `duplicate_cell`, `split_cell`, `merge_cells`), Metadata (`read/edit_metadata`, `read/edit_cell_metadata`), Outputs (`read_cell_output`, `clear_cell_outputs`, `clear_all_outputs`), and Utility (`
245
+
* Be aware of the different categories of tools: File operations (`create`, `delete`, `rename`), Notebook/Cell Reading (`read`, `read_cell`, `get_cell_count`, `get_info`), Cell Manipulation (`add_cell`, `edit_cell`, `delete_cell`, `move_cell`, `change_cell_type`, `duplicate_cell`, `split_cell`, `merge_cells`), Metadata (`read/edit_metadata`, `read/edit_cell_metadata`), Outputs (`read_cell_output`, `clear_cell_outputs`, `clear_all_outputs`), and Utility (`validate`, `export`, `diagnose_imports`).
246
+
247
+
4. **Math Notation:** For LaTeX in Markdown cells, use `$ ... $`for inline math and `$$ ... $$`for display math. Avoid `\( ... \)` and `\[ ... \]`.
248
+
249
+
5. **Cell Magics:**
250
+
* Avoid unsupported cell magics like `%%bash`, `%%timeit`, and `%%writefile`.
251
+
* Use `!command`for shell commands instead of `%%bash`.
252
+
* Use `%timeit` (line magic) for timing single statements.
253
+
*`%%html` works for rendering HTML output.
254
+
*`%%javascript` can execute (e.g., `alert`), but avoid relying on it for manipulating cell output display.
255
+
256
+
6. **Rich Outputs:** Matplotlib, Pandas DataFrames, Plotly, ipywidgets (`tqdm.notebook`), and embedded HTML in Markdown generally render correctly.
257
+
258
+
7. **Mermaid:** Diagrams in````mermaid ```` blocks are not rendered by default.
259
+
260
+
8. **Character Escaping in`source` Parameter:**
261
+
* When providing the `source` string for`add_cell` or `edit_cell`, ensure that backslashes (`\`) are handled correctly. Newline characters **must** be represented as `\n` (not `\\n`), and LaTeX commands **must** use single backslashes (e.g., `\Sigma`, not `\\Sigma`).
262
+
* Incorrect escaping by the tool or its interpretation can break Markdown formatting (like paragraphs intended to be separated by `\n\n`) and LaTeX rendering.
263
+
* After adding or editing cells with complex strings (especially those involving newlines or LaTeX), consider using `read_cell` to verify the content was saved exactly as intended and correct if necessary.
246
264
```
247
265
266
+
## Command-Line Arguments
267
+
268
+
The server accepts the following command-line arguments:
269
+
270
+
*`--allow-root`: (Required, can use multiple times) Absolute path to directory where notebooks are allowed.
271
+
*`--log-dir`: Directory to store log files. Defaults to `~/.cursor_notebook_mcp`.
272
+
*`--log-level`: Set the logging level: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`. Defaults to `INFO`.
273
+
*`--max-cell-source-size`: Maximum allowed size in bytes for cell source content. Defaults to 10 MiB.
274
+
*`--max-cell-output-size`: Maximum allowed size in bytes for cell output content. Defaults to 10 MiB.
275
+
*`--transport`: Transport type to use: `stdio` or `sse`. Defaults to `stdio`.
276
+
*`--host`: Host to bind the SSE server to. Only used with `--transport=sse`. Defaults to `127.0.0.1`.
277
+
*`--port`: Port to bind the SSE server to. Only used with `--transport=sse`. Defaults to `8080`.
278
+
279
+
## Security
280
+
281
+
***Workspace Root Enforcement:** The server **requires** the `--allow-root` command-line argument during startup. It will refuse to operate on any notebook file located outside the directories specified by these arguments. This is a critical security boundary.
282
+
***Path Handling:** The server uses `os.path.realpath` to resolve paths and checks against the allowed roots before any read or write operation.
283
+
***Input Validation:** Basic checks for`.ipynb` extension are performed.
284
+
***Cell Source Size Limit:** The server enforces a maximum size limit (configurable via `--max-cell-source-size`, default 10 MiB) on the source content provided to `notebook_edit_cell` and `notebook_add_cell` to prevent excessive memory usage.
285
+
***Cell Output Size Limit:** The server enforces a maximum size limit (configurable via `--max-cell-output-size`, default 10 MiB) on the total serialized size of outputs returned by `notebook_read_cell_output`.
286
+
287
+
## Limitations
288
+
289
+
***No Cell Execution:** This server **cannot execute** notebook cells. It operates solely on the `.ipynb` file structure using the `nbformat` library and does not interact with Jupyter kernels. Cell execution must be performed manually by the user within the Cursor UI (selecting the desired kernel and running the cell). Implementing execution capabilities in this server would require kernel management and introduce significant complexity and security considerations.
290
+
291
+
## Known Issues
292
+
293
+
***UI Refresh Issues:** Occasionally, some notebook operations (like cell splitting or merging) may succeed at the file level, but the Cursor UI might not show the updated content correctly. In such situations, you can:
294
+
* Close and re-open the notebook file
295
+
* Save the file, which might prompt to "Revert" or "Overwrite" - select"Revert" to reload the actual file content
296
+
297
+
## Development & Testing
298
+
299
+
1. Setup virtual environment and install dev dependencies:
300
+
```bash
301
+
python -m venv .venv
302
+
source .venv/bin/activate
303
+
pip install -e ".[dev]"
304
+
```
248
305
2. Run tests:
249
306
```bash
250
307
# Use the wrapper script to ensure environment variables are set
@@ -253,4 +310,45 @@ For smooth collaboration with the AI agent on Jupyter Notebooks, you might want
253
310
# ./run_tests.sh tests/test_notebook_tools.py
254
311
```
255
312
256
-
## Issues
313
+
## Issues
314
+
315
+
If you encounter any bugs or issues, please submit them to our GitHub issue tracker:
0 commit comments