notebook-intelligence 2.4.2__tar.gz → 2.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/.gitignore +8 -0
  2. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/PKG-INFO +115 -96
  3. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/README.md +114 -95
  4. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/__init__.py +5 -1
  5. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/_version.py +1 -1
  6. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/ai_service_manager.py +118 -23
  7. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/api.py +85 -5
  8. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/base_chat_participant.py +21 -2
  9. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/config.py +25 -0
  10. notebook_intelligence-2.6.0/notebook_intelligence/context_factory.py +18 -0
  11. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/extension.py +144 -26
  12. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/package.json +2 -2
  13. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/schemas/@notebook-intelligence/notebook-intelligence/package.json.orig +1 -1
  14. notebook_intelligence-2.6.0/notebook_intelligence/labextension/static/30.24ece679f97c20752fb9.js +1 -0
  15. notebook_intelligence-2.4.2/notebook_intelligence/labextension/static/728.e21c211a709fe0ab1e1f.js → notebook_intelligence-2.6.0/notebook_intelligence/labextension/static/728.24e04da1a60d59d4a565.js +1 -1
  16. notebook_intelligence-2.6.0/notebook_intelligence/labextension/static/editor.worker.js +1407 -0
  17. notebook_intelligence-2.6.0/notebook_intelligence/labextension/static/remoteEntry.68563306a9ea67f847ba.js +1 -0
  18. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/mcp_manager.py +344 -32
  19. notebook_intelligence-2.6.0/notebook_intelligence/rule_injector.py +24 -0
  20. notebook_intelligence-2.6.0/notebook_intelligence/rule_manager.py +272 -0
  21. notebook_intelligence-2.6.0/notebook_intelligence/ruleset.py +282 -0
  22. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/package.json +1 -1
  23. notebook_intelligence-2.6.0/tests/conftest.py +168 -0
  24. notebook_intelligence-2.6.0/tests/fixtures/rules/01-test-global.md +17 -0
  25. notebook_intelligence-2.6.0/tests/fixtures/rules/02-test-security.md +15 -0
  26. notebook_intelligence-2.6.0/tests/fixtures/rules/03-invalid-rule.md +11 -0
  27. notebook_intelligence-2.6.0/tests/fixtures/rules/modes/agent/01-test-production.md +15 -0
  28. notebook_intelligence-2.6.0/tests/fixtures/rules/modes/ask/01-test-exploration.md +13 -0
  29. notebook_intelligence-2.6.0/tests/fixtures/rules/modes/inline-chat/01-test-quick.md +14 -0
  30. notebook_intelligence-2.6.0/tests/test_ai_service_manager_integration.py +99 -0
  31. notebook_intelligence-2.6.0/tests/test_base_chat_participant_integration.py +153 -0
  32. notebook_intelligence-2.6.0/tests/test_config_integration.py +116 -0
  33. notebook_intelligence-2.6.0/tests/test_context_factory.py +43 -0
  34. notebook_intelligence-2.6.0/tests/test_end_to_end_rule_integration.py +303 -0
  35. notebook_intelligence-2.6.0/tests/test_models.py +403 -0
  36. notebook_intelligence-2.6.0/tests/test_rule_auto_reload.py +246 -0
  37. notebook_intelligence-2.6.0/tests/test_rule_injector.py +106 -0
  38. notebook_intelligence-2.6.0/tests/test_rule_manager.py +312 -0
  39. notebook_intelligence-2.6.0/tests/test_websocket_handler_integration.py +211 -0
  40. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/tsconfig.json +1 -1
  41. notebook_intelligence-2.4.2/notebook_intelligence/labextension/static/144.3ed487e60baf9785fae1.js +0 -1
  42. notebook_intelligence-2.4.2/notebook_intelligence/labextension/static/editor.worker.js +0 -1407
  43. notebook_intelligence-2.4.2/notebook_intelligence/labextension/static/remoteEntry.d9d709f6862dfa2e5a69.js +0 -1
  44. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/.copier-answers.yml +0 -0
  45. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/.prettierignore +0 -0
  46. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/.yarnrc.yml +0 -0
  47. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/CHANGELOG.md +0 -0
  48. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/CONTRIBUTING.md +0 -0
  49. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/LICENSE +0 -0
  50. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/RELEASE.md +0 -0
  51. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/install.json +0 -0
  52. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/jupyter-config/server-config/notebook_intelligence.json +0 -0
  53. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/built_in_toolsets.py +0 -0
  54. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/github_copilot.py +0 -0
  55. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/github_copilot_chat_participant.py +0 -0
  56. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/schemas/@notebook-intelligence/notebook-intelligence/plugin.json +0 -0
  57. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/196.db3f5562c0372c6e07f6.js +0 -0
  58. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/1b55f12eca93ba6743e7.ttf +0 -0
  59. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/326.4de77f44c9c6c2bbad47.js +0 -0
  60. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/326.4de77f44c9c6c2bbad47.js.LICENSE.txt +0 -0
  61. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/327.fe6b84491254fcaf64bf.js +0 -0
  62. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/327.fe6b84491254fcaf64bf.js.LICENSE.txt +0 -0
  63. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/671.1797d409270b24758991.js +0 -0
  64. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/694.d0b052d80c0397c7f1ea.js +0 -0
  65. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/830.46ab52f7b558fb3c1a20.js +0 -0
  66. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/977.7e3d66ffc344a0af7a4e.js +0 -0
  67. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/be02dcbf2787b0b29ec8.module.wasm +0 -0
  68. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/e589c9ba04e3e5a90081.module.wasm +0 -0
  69. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/editor.worker.js.LICENSE.txt +0 -0
  70. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/style.js +0 -0
  71. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/labextension/static/third-party-licenses.json +0 -0
  72. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/llm_providers/github_copilot_llm_provider.py +0 -0
  73. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/llm_providers/litellm_compatible_llm_provider.py +0 -0
  74. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/llm_providers/ollama_llm_provider.py +0 -0
  75. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/llm_providers/openai_compatible_llm_provider.py +0 -0
  76. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/prompts.py +0 -0
  77. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/notebook_intelligence/util.py +0 -0
  78. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/pyproject.toml +0 -0
  79. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/schema/plugin.json +0 -0
  80. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/setup.py +0 -0
  81. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/webpack.config.js +0 -0
  82. {notebook_intelligence-2.4.2 → notebook_intelligence-2.6.0}/yarn.lock +0 -0
@@ -83,6 +83,14 @@ target/
83
83
  # pyenv
84
84
  .python-version
85
85
 
86
+ # Virtual environments
87
+ venv/
88
+ env/
89
+ ENV/
90
+ .venv/
91
+ .env/
92
+ venv*/
93
+ .vscode/
86
94
  # celery beat schedule file
87
95
  celerybeat-schedule
88
96
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notebook_intelligence
3
- Version: 2.4.2
3
+ Version: 2.6.0
4
4
  Summary: AI coding assistant for JupyterLab
5
5
  Project-URL: Homepage, https://github.com/notebook-intelligence/notebook-intelligence
6
6
  Project-URL: Bug Tracker, https://github.com/notebook-intelligence/notebook-intelligence/issues
@@ -801,18 +801,18 @@ jupyter lab --NotebookIntelligence.notebook_execute_tool=env_enabled
801
801
 
802
802
  ### Configuration files
803
803
 
804
- NBI saves configuration at `~/.jupyter/nbi-config.json`. It also supports environment wide base configuration at `<env-prefix>/share/jupyter/nbi-config.json`. Organizations can ship default configuration at this environment wide config path. User's changes will be stored as overrides at `~/.jupyter/nbi-config.json`.
804
+ NBI saves configuration at `~/.jupyter/nbi/config.json`. It also supports environment wide base configuration at `<env-prefix>/share/jupyter/nbi/config.json`. Organizations can ship default configuration at this environment wide config path. User's changes will be stored as overrides at `~/.jupyter/nbi/config.json`.
805
805
 
806
806
  These config files are used for saving LLM provider, model and MCP configuration. Note that API keys you enter for your custom LLM providers will also be stored in these config files.
807
807
 
808
808
  > [!IMPORTANT]
809
- > Note that updating nbi-config.json manually requires restarting JupyterLab to take effect.
809
+ > Note that updating config.json manually requires restarting JupyterLab to take effect.
810
810
 
811
811
  ### Model Context Protocol ([MCP](https://modelcontextprotocol.io)) Support
812
812
 
813
813
  NBI seamlessly integrates with MCP servers. It supports servers with both Standard Input/Output (stdio) and Server-Sent Events (SSE) transports. The MCP support is limited to server tools at the moment.
814
814
 
815
- You can easily add MCP servers to NBI by editing the configuration file [nbi-config.json](#configuration-files). Simply add a key "mcp" and "mcpServers" under it as shown below.
815
+ You can easily add MCP servers to NBI by editing the configuration file [~/.jupyter/nbi/mcp.json](#configuration-files). Environment wide base configuration is also support using the file at `<env-prefix>/share/jupyter/nbi/mcp.json`.
816
816
 
817
817
  > [!NOTE]
818
818
  > Using MCP servers requires an LLM model with tool calling capabilities. All of the GitHub Copilot models provided in NBI support this feature. If you are using other providers make sure you choose a tool calling capable model.
@@ -820,47 +820,24 @@ You can easily add MCP servers to NBI by editing the configuration file [nbi-con
820
820
  > [!CAUTION]
821
821
  > Note that most MCP servers are run on the same computer as your JupyterLab installation and they can make irreversible changes to your computer and/or access private data. Make sure that you only install MCP servers from trusted sources.
822
822
 
823
+ ### MCP Config file example
824
+
823
825
  ```json
824
826
  {
825
- "chat_model": {
826
- ...
827
- },
828
- ...<other configuration>,
829
-
830
- "mcp": {
831
- "mcpServers": {
832
- "filesystem": {
833
- "command": "npx",
834
- "args": [
835
- "-y",
836
- "@modelcontextprotocol/server-filesystem",
837
- "/Users/mbektas/mcp-test"
838
- ]
839
- },
840
- }
827
+ "mcpServers": {
828
+ "filesystem": {
829
+ "command": "npx",
830
+ "args": [
831
+ "-y",
832
+ "@modelcontextprotocol/server-filesystem",
833
+ "/Users/mbektas/mcp-test"
834
+ ]
841
835
  }
836
+ }
842
837
  }
843
838
  ```
844
839
 
845
- This will automatically create a new chat participant in NBI and you can access it by starting your prompts with `@mcp`. Use `@mcp /info` prompt to get information on the tools provided by the MCP servers you configured. This chat participant will have access all the tools provided by the servers you configure.
846
-
847
- <img src="media/mcp-prompt.png" alt="Settings dialog" width=600 />
848
-
849
- By default, each tool call to MCP servers will require approval. If you would like to auto approve tools, you can do so by using the `"alwaysAllow": []` configuration key in the nbi-config.json. Simply list the names of tools.
850
-
851
- ```json
852
- "mcpServers": {
853
- "filesystem": {
854
- "command": "npx",
855
- "args": [
856
- "-y",
857
- "@modelcontextprotocol/server-filesystem",
858
- "/Users/mbektas/mcp-test"
859
- ],
860
- "alwaysAllow": ["list_allowed_directories", "list_directory"]
861
- },
862
- }
863
- ```
840
+ You can use Agent mode to access tools provided by MCP servers you configured.
864
841
 
865
842
  For servers with stdio transport, you can also set additional environment variables by using the `env` key. Environment variables are specified as key value pairs.
866
843
 
@@ -876,12 +853,12 @@ For servers with stdio transport, you can also set additional environment variab
876
853
  }
877
854
  ```
878
855
 
879
- Below is an example of a server configuration with SSE transport. For SSE transport servers, you can also specify headers to be sent as part of the requests.
856
+ Below is an example of a server configuration with Streamable HTTP transport. For Streamable HTTP transport servers, you can also specify headers to be sent as part of the requests.
880
857
 
881
858
  ```json
882
859
  "mcpServers": {
883
860
  "remoterservername": {
884
- "url": "http://127.0.0.1:8080/sse",
861
+ "url": "http://127.0.0.1:8080/mcp",
885
862
  "headers": {
886
863
  "Authorization": "Bearer mysecrettoken"
887
864
  }
@@ -905,77 +882,119 @@ If you have multiple servers configured but you would like to disable some for a
905
882
  }
906
883
  ```
907
884
 
908
- #### Grouping MCP servers
885
+ ### Ruleset System
909
886
 
910
- When you integrate multiple MCP servers to NBI, all of their tools will be available under the same chat participant `@mcp`. However, this may not be ideal in many situations. You may want to group certain servers and their tools based on their functionality. NBI lets you do that easily by configuring MCP chat participants. You can list the servers for each custom participant. If there are any unassigned MCP servers, then they will be used the default `@mcp` chat participant.
887
+ NBI includes a powerful ruleset system that allows you to define custom guidelines and best practices that are automatically injected into AI prompts. This helps ensure consistent coding standards, project-specific conventions, and domain knowledge across all AI interactions.
911
888
 
912
- Below is an example of creating a custom MCP participant. This configuration results in two chat participants `@mcp-fs` with `filesytem` MC server tools and `@mcp` with `servername1` and `servername1` MCP server tools.
889
+ #### How It Works
913
890
 
914
- ```json
915
- {
916
- "chat_model": {
917
- ...
918
- },
919
- ...<other configuration>,
920
-
921
- "mcp": {
922
- "mcpServers": {
923
- "filesystem": {
924
- "command": "npx",
925
- "args": [
926
- "-y",
927
- "@modelcontextprotocol/server-filesystem",
928
- "/Users/mbektas/mcp-test"
929
- ]
930
- },
931
- "servername1": {
932
- "command": "",
933
- "args": [],
934
- },
935
- "servername2": {
936
- "command": "",
937
- "args": [],
938
- "disabled": true
939
- }
940
- },
941
- "participants": {
942
- "fs": {
943
- "name": "MCP - File system",
944
- "servers": ["filesystem"]
945
- }
946
- }
947
- }
948
- }
891
+ Rules are markdown files with optional YAML frontmatter stored in `~/.jupyter/nbi/rules/`. They are automatically discovered and applied based on context (file type, notebook kernel, chat mode).
892
+
893
+ #### Creating Rules
894
+
895
+ **Global Rules** - Apply to all contexts:
896
+
897
+ Create a file like `~/.jupyter/nbi/rules/01-coding-standards.md`:
898
+
899
+ ```markdown
900
+ ---
901
+ priority: 10
902
+ ---
903
+
904
+ # Coding Standards
905
+
906
+ - Always use type hints in Python functions
907
+ - Prefer list comprehensions over loops when appropriate
908
+ - Add docstrings to all public functions
949
909
  ```
950
910
 
951
- #### Using NBI tools within MCP chat participants
911
+ **Mode-Specific Rules** - Apply only to specific chat modes:
952
912
 
953
- NBI allows you to access built-in tools from an MCP participant. You can do that by adding the list of built in NBI tools to your MCP participant configuration. The built-in tools available to MCP are `create_new_notebook`, `add_markdown_cell_to_notebook`, `add_code_cell_to_notebook`. Below is an example that integrates all these tools to MCP participant `@mcp-fs`.
913
+ NBI supports mode-specific rules for three modes:
914
+
915
+ - **ask** - Question/answer mode
916
+ - **agent** - Autonomous agent mode with tool access
917
+ - **inline-chat** - Inline code generation and editing
918
+
919
+ Create a file like `~/.jupyter/nbi/rules/modes/agent/01-testing.md`:
920
+
921
+ ```markdown
922
+ ---
923
+ priority: 20
924
+ scope:
925
+ kernels: ['python3']
926
+ ---
927
+
928
+ # Testing Guidelines
929
+
930
+ When writing code in agent mode:
931
+
932
+ - Always include error handling
933
+ - Add logging for debugging
934
+ - Test edge cases
935
+ ```
936
+
937
+ #### Rule Frontmatter Options
938
+
939
+ ```yaml
940
+ ---
941
+ apply: always # 'always', 'auto', or 'manual'
942
+ active: true # Enable/disable the rule
943
+ priority: 10 # Lower numbers = higher priority
944
+ scope:
945
+ file_patterns: # Apply to specific file patterns
946
+ - '*.py'
947
+ - 'test_*.ipynb'
948
+ kernels: # Apply to specific notebook kernels
949
+ - 'python3'
950
+ - 'ir'
951
+ directories: # Apply to specific directories
952
+ - '/projects/ml'
953
+ ---
954
+ ```
955
+
956
+ #### Configuration
957
+
958
+ **Enable/Disable Rules System:**
959
+
960
+ Edit `~/.jupyter/nbi/config.json`:
954
961
 
955
962
  ```json
956
- "participants": {
957
- "fs": {
958
- "name": "MCP - File system",
959
- "servers": ["filesystem"],
960
- "nbiTools": [
961
- "create_new_notebook",
962
- "add_markdown_cell_to_notebook",
963
- "add_code_cell_to_notebook"
964
- ]
965
- }
963
+ {
964
+ "rules_enabled": true
966
965
  }
967
966
  ```
968
967
 
969
- This chat participant will allow you to run example prompts like below.
968
+ **Auto-Reload Configuration:**
970
969
 
971
- ```
972
- @mcp-fs list the directories I have access to.
973
- ```
970
+ Rules are automatically reloaded when changed (enabled by default). This behavior is controlled by the `NBI_RULES_AUTO_RELOAD` environment variable.
974
971
 
972
+ To disable auto-reload:
973
+
974
+ ```bash
975
+ export NBI_RULES_AUTO_RELOAD=false
976
+ jupyter lab
975
977
  ```
976
- @mcp-fs add a code cell which demonstrates ipywidgets Button to this notebook.
978
+
979
+ Or to enable (default):
980
+
981
+ ```bash
982
+ export NBI_RULES_AUTO_RELOAD=true
983
+ jupyter lab
977
984
  ```
978
985
 
986
+ #### Managing Rules
987
+
988
+ Rules are automatically discovered from:
989
+
990
+ - **Global rules**: `~/.jupyter/nbi/rules/*.md`
991
+ - **Mode-specific rules**: `~/.jupyter/nbi/rules/modes/{mode}/*.md` where `{mode}` can be:
992
+ - `ask` - For question/answer interactions
993
+ - `agent` - For autonomous agent operations
994
+ - `inline-chat` - For inline code generation
995
+
996
+ Rules are applied in priority order (lower numbers first) and can be toggled on/off without deleting the files.
997
+
979
998
  ### Developer documentation
980
999
 
981
1000
  For building locally and contributing see the [developer documentatation](CONTRIBUTING.md).
@@ -94,18 +94,18 @@ jupyter lab --NotebookIntelligence.notebook_execute_tool=env_enabled
94
94
 
95
95
  ### Configuration files
96
96
 
97
- NBI saves configuration at `~/.jupyter/nbi-config.json`. It also supports environment wide base configuration at `<env-prefix>/share/jupyter/nbi-config.json`. Organizations can ship default configuration at this environment wide config path. User's changes will be stored as overrides at `~/.jupyter/nbi-config.json`.
97
+ NBI saves configuration at `~/.jupyter/nbi/config.json`. It also supports environment wide base configuration at `<env-prefix>/share/jupyter/nbi/config.json`. Organizations can ship default configuration at this environment wide config path. User's changes will be stored as overrides at `~/.jupyter/nbi/config.json`.
98
98
 
99
99
  These config files are used for saving LLM provider, model and MCP configuration. Note that API keys you enter for your custom LLM providers will also be stored in these config files.
100
100
 
101
101
  > [!IMPORTANT]
102
- > Note that updating nbi-config.json manually requires restarting JupyterLab to take effect.
102
+ > Note that updating config.json manually requires restarting JupyterLab to take effect.
103
103
 
104
104
  ### Model Context Protocol ([MCP](https://modelcontextprotocol.io)) Support
105
105
 
106
106
  NBI seamlessly integrates with MCP servers. It supports servers with both Standard Input/Output (stdio) and Server-Sent Events (SSE) transports. The MCP support is limited to server tools at the moment.
107
107
 
108
- You can easily add MCP servers to NBI by editing the configuration file [nbi-config.json](#configuration-files). Simply add a key "mcp" and "mcpServers" under it as shown below.
108
+ You can easily add MCP servers to NBI by editing the configuration file [~/.jupyter/nbi/mcp.json](#configuration-files). Environment wide base configuration is also support using the file at `<env-prefix>/share/jupyter/nbi/mcp.json`.
109
109
 
110
110
  > [!NOTE]
111
111
  > Using MCP servers requires an LLM model with tool calling capabilities. All of the GitHub Copilot models provided in NBI support this feature. If you are using other providers make sure you choose a tool calling capable model.
@@ -113,47 +113,24 @@ You can easily add MCP servers to NBI by editing the configuration file [nbi-con
113
113
  > [!CAUTION]
114
114
  > Note that most MCP servers are run on the same computer as your JupyterLab installation and they can make irreversible changes to your computer and/or access private data. Make sure that you only install MCP servers from trusted sources.
115
115
 
116
+ ### MCP Config file example
117
+
116
118
  ```json
117
119
  {
118
- "chat_model": {
119
- ...
120
- },
121
- ...<other configuration>,
122
-
123
- "mcp": {
124
- "mcpServers": {
125
- "filesystem": {
126
- "command": "npx",
127
- "args": [
128
- "-y",
129
- "@modelcontextprotocol/server-filesystem",
130
- "/Users/mbektas/mcp-test"
131
- ]
132
- },
133
- }
120
+ "mcpServers": {
121
+ "filesystem": {
122
+ "command": "npx",
123
+ "args": [
124
+ "-y",
125
+ "@modelcontextprotocol/server-filesystem",
126
+ "/Users/mbektas/mcp-test"
127
+ ]
134
128
  }
129
+ }
135
130
  }
136
131
  ```
137
132
 
138
- This will automatically create a new chat participant in NBI and you can access it by starting your prompts with `@mcp`. Use `@mcp /info` prompt to get information on the tools provided by the MCP servers you configured. This chat participant will have access all the tools provided by the servers you configure.
139
-
140
- <img src="media/mcp-prompt.png" alt="Settings dialog" width=600 />
141
-
142
- By default, each tool call to MCP servers will require approval. If you would like to auto approve tools, you can do so by using the `"alwaysAllow": []` configuration key in the nbi-config.json. Simply list the names of tools.
143
-
144
- ```json
145
- "mcpServers": {
146
- "filesystem": {
147
- "command": "npx",
148
- "args": [
149
- "-y",
150
- "@modelcontextprotocol/server-filesystem",
151
- "/Users/mbektas/mcp-test"
152
- ],
153
- "alwaysAllow": ["list_allowed_directories", "list_directory"]
154
- },
155
- }
156
- ```
133
+ You can use Agent mode to access tools provided by MCP servers you configured.
157
134
 
158
135
  For servers with stdio transport, you can also set additional environment variables by using the `env` key. Environment variables are specified as key value pairs.
159
136
 
@@ -169,12 +146,12 @@ For servers with stdio transport, you can also set additional environment variab
169
146
  }
170
147
  ```
171
148
 
172
- Below is an example of a server configuration with SSE transport. For SSE transport servers, you can also specify headers to be sent as part of the requests.
149
+ Below is an example of a server configuration with Streamable HTTP transport. For Streamable HTTP transport servers, you can also specify headers to be sent as part of the requests.
173
150
 
174
151
  ```json
175
152
  "mcpServers": {
176
153
  "remoterservername": {
177
- "url": "http://127.0.0.1:8080/sse",
154
+ "url": "http://127.0.0.1:8080/mcp",
178
155
  "headers": {
179
156
  "Authorization": "Bearer mysecrettoken"
180
157
  }
@@ -198,77 +175,119 @@ If you have multiple servers configured but you would like to disable some for a
198
175
  }
199
176
  ```
200
177
 
201
- #### Grouping MCP servers
178
+ ### Ruleset System
202
179
 
203
- When you integrate multiple MCP servers to NBI, all of their tools will be available under the same chat participant `@mcp`. However, this may not be ideal in many situations. You may want to group certain servers and their tools based on their functionality. NBI lets you do that easily by configuring MCP chat participants. You can list the servers for each custom participant. If there are any unassigned MCP servers, then they will be used the default `@mcp` chat participant.
180
+ NBI includes a powerful ruleset system that allows you to define custom guidelines and best practices that are automatically injected into AI prompts. This helps ensure consistent coding standards, project-specific conventions, and domain knowledge across all AI interactions.
204
181
 
205
- Below is an example of creating a custom MCP participant. This configuration results in two chat participants `@mcp-fs` with `filesytem` MC server tools and `@mcp` with `servername1` and `servername1` MCP server tools.
182
+ #### How It Works
206
183
 
207
- ```json
208
- {
209
- "chat_model": {
210
- ...
211
- },
212
- ...<other configuration>,
213
-
214
- "mcp": {
215
- "mcpServers": {
216
- "filesystem": {
217
- "command": "npx",
218
- "args": [
219
- "-y",
220
- "@modelcontextprotocol/server-filesystem",
221
- "/Users/mbektas/mcp-test"
222
- ]
223
- },
224
- "servername1": {
225
- "command": "",
226
- "args": [],
227
- },
228
- "servername2": {
229
- "command": "",
230
- "args": [],
231
- "disabled": true
232
- }
233
- },
234
- "participants": {
235
- "fs": {
236
- "name": "MCP - File system",
237
- "servers": ["filesystem"]
238
- }
239
- }
240
- }
241
- }
184
+ Rules are markdown files with optional YAML frontmatter stored in `~/.jupyter/nbi/rules/`. They are automatically discovered and applied based on context (file type, notebook kernel, chat mode).
185
+
186
+ #### Creating Rules
187
+
188
+ **Global Rules** - Apply to all contexts:
189
+
190
+ Create a file like `~/.jupyter/nbi/rules/01-coding-standards.md`:
191
+
192
+ ```markdown
193
+ ---
194
+ priority: 10
195
+ ---
196
+
197
+ # Coding Standards
198
+
199
+ - Always use type hints in Python functions
200
+ - Prefer list comprehensions over loops when appropriate
201
+ - Add docstrings to all public functions
242
202
  ```
243
203
 
244
- #### Using NBI tools within MCP chat participants
204
+ **Mode-Specific Rules** - Apply only to specific chat modes:
245
205
 
246
- NBI allows you to access built-in tools from an MCP participant. You can do that by adding the list of built in NBI tools to your MCP participant configuration. The built-in tools available to MCP are `create_new_notebook`, `add_markdown_cell_to_notebook`, `add_code_cell_to_notebook`. Below is an example that integrates all these tools to MCP participant `@mcp-fs`.
206
+ NBI supports mode-specific rules for three modes:
207
+
208
+ - **ask** - Question/answer mode
209
+ - **agent** - Autonomous agent mode with tool access
210
+ - **inline-chat** - Inline code generation and editing
211
+
212
+ Create a file like `~/.jupyter/nbi/rules/modes/agent/01-testing.md`:
213
+
214
+ ```markdown
215
+ ---
216
+ priority: 20
217
+ scope:
218
+ kernels: ['python3']
219
+ ---
220
+
221
+ # Testing Guidelines
222
+
223
+ When writing code in agent mode:
224
+
225
+ - Always include error handling
226
+ - Add logging for debugging
227
+ - Test edge cases
228
+ ```
229
+
230
+ #### Rule Frontmatter Options
231
+
232
+ ```yaml
233
+ ---
234
+ apply: always # 'always', 'auto', or 'manual'
235
+ active: true # Enable/disable the rule
236
+ priority: 10 # Lower numbers = higher priority
237
+ scope:
238
+ file_patterns: # Apply to specific file patterns
239
+ - '*.py'
240
+ - 'test_*.ipynb'
241
+ kernels: # Apply to specific notebook kernels
242
+ - 'python3'
243
+ - 'ir'
244
+ directories: # Apply to specific directories
245
+ - '/projects/ml'
246
+ ---
247
+ ```
248
+
249
+ #### Configuration
250
+
251
+ **Enable/Disable Rules System:**
252
+
253
+ Edit `~/.jupyter/nbi/config.json`:
247
254
 
248
255
  ```json
249
- "participants": {
250
- "fs": {
251
- "name": "MCP - File system",
252
- "servers": ["filesystem"],
253
- "nbiTools": [
254
- "create_new_notebook",
255
- "add_markdown_cell_to_notebook",
256
- "add_code_cell_to_notebook"
257
- ]
258
- }
256
+ {
257
+ "rules_enabled": true
259
258
  }
260
259
  ```
261
260
 
262
- This chat participant will allow you to run example prompts like below.
261
+ **Auto-Reload Configuration:**
263
262
 
264
- ```
265
- @mcp-fs list the directories I have access to.
266
- ```
263
+ Rules are automatically reloaded when changed (enabled by default). This behavior is controlled by the `NBI_RULES_AUTO_RELOAD` environment variable.
267
264
 
265
+ To disable auto-reload:
266
+
267
+ ```bash
268
+ export NBI_RULES_AUTO_RELOAD=false
269
+ jupyter lab
268
270
  ```
269
- @mcp-fs add a code cell which demonstrates ipywidgets Button to this notebook.
271
+
272
+ Or to enable (default):
273
+
274
+ ```bash
275
+ export NBI_RULES_AUTO_RELOAD=true
276
+ jupyter lab
270
277
  ```
271
278
 
279
+ #### Managing Rules
280
+
281
+ Rules are automatically discovered from:
282
+
283
+ - **Global rules**: `~/.jupyter/nbi/rules/*.md`
284
+ - **Mode-specific rules**: `~/.jupyter/nbi/rules/modes/{mode}/*.md` where `{mode}` can be:
285
+ - `ask` - For question/answer interactions
286
+ - `agent` - For autonomous agent operations
287
+ - `inline-chat` - For inline code generation
288
+
289
+ Rules are applied in priority order (lower numbers first) and can be toggled on/off without deleting the files.
290
+
272
291
  ### Developer documentation
273
292
 
274
293
  For building locally and contributing see the [developer documentatation](CONTRIBUTING.md).
@@ -11,7 +11,11 @@ except ImportError:
11
11
  __version__ = "dev"
12
12
 
13
13
  import logging
14
- logging.basicConfig(format='%(asctime)s - %(name)s - %(filename)s - %(levelname)s - %(message)s', level=logging.INFO)
14
+ import os
15
+
16
+ # Allow setting log level via environment variable
17
+ log_level = os.environ.get('NBI_LOG_LEVEL', 'INFO').upper()
18
+ logging.basicConfig(format='%(asctime)s - %(name)s - %(filename)s - %(levelname)s - %(message)s', level=getattr(logging, log_level, logging.INFO))
15
19
 
16
20
  from .extension import NotebookIntelligence
17
21
  from .api import *
@@ -1,4 +1,4 @@
1
1
  # This file is auto-generated by Hatchling. As such, do not:
2
2
  # - modify
3
3
  # - track in version control e.g. be sure to add to .gitignore
4
- __version__ = VERSION = '2.4.2'
4
+ __version__ = VERSION = '2.6.0'