Skip to content

fix(tools/list): initialize the server mode before choosing which tools to list - #482

Merged
echarles merged 2 commits into
datalayer:mainfrom
vishalhabib99:fix/tools-list-mode-before-init
Oct 5, 2026
Merged

echarles merged 2 commits into
datalayer:mainfrom
vishalhabib99:fix/tools-list-mode-before-init

Conversation

@vishalhabib99

Copy link
Copy Markdown
Contributor

Fixes #481.

get_registered_tools() read ServerContext._mode, which stays None until initialize() runs. On a freshly started Jupyter extension, the first REST GET /mcp/tools/list therefore took the MCP_SERVER branch and listed connect_to_jupyter. That lasted until a JSON-RPC request on /mcp initialized the context. The fix reads the .mode property instead, which initializes on first use.

This is one line in server.py. The JSON-RPC handler's context.initialize(); mode = context._mode already behaves correctly, so I left it alone.

Testing

  • New tests/test_registered_tools_initializes_mode.py: starts from an uninitialized ServerContext inside a stubbed local-document extension, and checks that get_registered_tools() resolves JUPYTER_SERVER mode and leaves out connect_to_jupyter. It fails on main (assert None == ServerMode.JUPYTER_SERVER) and passes with the fix.
  • The existing test_allowed_jupyter_mcp_tools.py and test_capabilities.py still pass (42 passed with the new test).
  • Live check against a freshly started extension server (document_url=local, code_sandbox_url=local): the first GET /mcp/tools/list now returns 21 tools without connect_to_jupyter. Before the fix it returned 22.

🤖 Generated with Claude Code

…ls to list

get_registered_tools() read ServerContext._mode, which is None until
initialize() runs. On a freshly started Jupyter extension, REST
GET /mcp/tools/list was answered as if in MCP_SERVER mode and listed
connect_to_jupyter, until a JSON-RPC request initialized the context.
Read the .mode property instead, which initializes on first use.

Fixes datalayer#481

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Could a maintainer add the bug label? The enforce-label check needs one, and I don't have permission to add labels as an outside contributor. Thanks!

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echarles echarles added the bug Something isn't working label Oct 5, 2026
Comment thread docs/sourcey/mcp.json

@echarles echarles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thx @vishalhabib99

@echarles
echarles merged commit c0a49d5 into datalayer:main Oct 5, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REST /mcp/tools/list shows connect_to_jupyter in extension mode until a JSON-RPC request initializes the context

2 participants