@notebook-intelligence/notebook-intelligence 2.4.1 → 2.5.0

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.
package/README.md CHANGED
@@ -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,6 @@ 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
202
-
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.
204
-
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.
206
-
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
- }
242
- ```
243
-
244
- #### Using NBI tools within MCP chat participants
245
-
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`.
247
-
248
- ```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
- }
259
- }
260
- ```
261
-
262
- This chat participant will allow you to run example prompts like below.
263
-
264
- ```
265
- @mcp-fs list the directories I have access to.
266
- ```
267
-
268
- ```
269
- @mcp-fs add a code cell which demonstrates ipywidgets Button to this notebook.
270
- ```
271
-
272
178
  ### Developer documentation
273
179
 
274
180
  For building locally and contributing see the [developer documentatation](CONTRIBUTING.md).
package/lib/api.d.ts CHANGED
@@ -22,6 +22,7 @@ export declare class NBIConfig {
22
22
  get usingGitHubCopilotModel(): boolean;
23
23
  get storeGitHubAccessToken(): boolean;
24
24
  get toolConfig(): any;
25
+ get mcpServerSettings(): any;
25
26
  capabilities: any;
26
27
  chatParticipants: IChatParticipant[];
27
28
  changed: Signal<this, void>;
@@ -44,10 +45,10 @@ export declare class NBIAPI {
44
45
  static fetchCapabilities(): Promise<void>;
45
46
  static setConfig(config: any): Promise<void>;
46
47
  static updateOllamaModelList(): Promise<void>;
47
- static reloadMCPServerList(): Promise<any>;
48
48
  static getMCPConfigFile(): Promise<any>;
49
49
  static setMCPConfigFile(config: any): Promise<any>;
50
50
  static chatRequest(messageId: string, chatId: string, prompt: string, language: string, filename: string, additionalContext: IContextItem[], chatMode: string, toolSelections: IToolSelections, responseEmitter: IChatCompletionResponseEmitter): Promise<void>;
51
+ static reloadMCPServers(): Promise<any>;
51
52
  static generateCode(chatId: string, prompt: string, prefix: string, suffix: string, existingCode: string, language: string, filename: string, responseEmitter: IChatCompletionResponseEmitter): Promise<void>;
52
53
  static sendChatUserInput(messageId: string, data: any): Promise<void>;
53
54
  static sendWebSocketMessage(messageId: string, messageType: RequestDataType, data: any): Promise<void>;
package/lib/api.js CHANGED
@@ -53,6 +53,9 @@ export class NBIConfig {
53
53
  get toolConfig() {
54
54
  return this.capabilities.tool_config;
55
55
  }
56
+ get mcpServerSettings() {
57
+ return this.capabilities.mcp_server_settings;
58
+ }
56
59
  }
57
60
  class NBIAPI {
58
61
  static async initialize() {
@@ -61,7 +64,10 @@ class NBIAPI {
61
64
  NBIAPI.initializeWebsocket();
62
65
  this._messageReceived.connect((_, msg) => {
63
66
  msg = JSON.parse(msg);
64
- if (msg.type === BackendMessageType.GitHubCopilotLoginStatusChange) {
67
+ if (msg.type === BackendMessageType.MCPServerStatusChange) {
68
+ this.fetchCapabilities();
69
+ }
70
+ else if (msg.type === BackendMessageType.GitHubCopilotLoginStatusChange) {
65
71
  this.updateGitHubLoginStatus().then(() => {
66
72
  this.githubLoginStatusChanged.emit();
67
73
  });
@@ -144,9 +150,19 @@ class NBIAPI {
144
150
  return new Promise((resolve, reject) => {
145
151
  requestAPI('capabilities', { method: 'GET' })
146
152
  .then(data => {
153
+ const oldConfig = {
154
+ capabilities: structuredClone(this.config.capabilities),
155
+ chatParticipants: structuredClone(this.config.chatParticipants)
156
+ };
147
157
  this.config.capabilities = structuredClone(data);
148
158
  this.config.chatParticipants = structuredClone(data.chat_participants);
149
- this.configChanged.emit();
159
+ const newConfig = {
160
+ capabilities: structuredClone(this.config.capabilities),
161
+ chatParticipants: structuredClone(this.config.chatParticipants)
162
+ };
163
+ if (JSON.stringify(newConfig) !== JSON.stringify(oldConfig)) {
164
+ this.configChanged.emit();
165
+ }
150
166
  resolve();
151
167
  })
152
168
  .catch(reason => {
@@ -183,19 +199,6 @@ class NBIAPI {
183
199
  });
184
200
  });
185
201
  }
186
- static async reloadMCPServerList() {
187
- return new Promise((resolve, reject) => {
188
- requestAPI('reload-mcp-servers', { method: 'POST' })
189
- .then(async (data) => {
190
- await NBIAPI.fetchCapabilities();
191
- resolve(data);
192
- })
193
- .catch(reason => {
194
- console.error(`Failed to reload MCP server list.\n${reason}`);
195
- reject(reason);
196
- });
197
- });
198
- }
199
202
  static async getMCPConfigFile() {
200
203
  return new Promise((resolve, reject) => {
201
204
  requestAPI('mcp-config-file', { method: 'GET' })
@@ -244,6 +247,19 @@ class NBIAPI {
244
247
  }
245
248
  }));
246
249
  }
250
+ static async reloadMCPServers() {
251
+ return new Promise((resolve, reject) => {
252
+ requestAPI('reload-mcp-servers', { method: 'POST' })
253
+ .then(async (data) => {
254
+ await NBIAPI.fetchCapabilities();
255
+ resolve(data);
256
+ })
257
+ .catch(reason => {
258
+ console.error(`Failed to reload MCP servers.\n${reason}`);
259
+ reject(reason);
260
+ });
261
+ });
262
+ }
247
263
  static async generateCode(chatId, prompt, prefix, suffix, existingCode, language, filename, responseEmitter) {
248
264
  const messageId = UUID.uuid4();
249
265
  this._messageReceived.connect((_, msg) => {
@@ -73,12 +73,3 @@ export declare class GitHubCopilotLoginDialogBody extends ReactWidget {
73
73
  render(): JSX.Element;
74
74
  private _onLoggedIn;
75
75
  }
76
- export declare class ConfigurationDialogBody extends ReactWidget {
77
- constructor(options: {
78
- onSave: () => void;
79
- onEditMCPConfigClicked: () => void;
80
- });
81
- render(): JSX.Element;
82
- private _onEditMCPConfigClicked;
83
- private _onSave;
84
- }