Implement configuration function to customize MCP server#3796
Implement configuration function to customize MCP server#3796KoolADE85 wants to merge 3 commits into
Conversation
|
camdecoster
left a comment
There was a problem hiding this comment.
I left a couple of suggestions, but nothing huge. Could you add a changelog entry for this update? Specifically describing the way the user facing API changed.
| if not include_layout: | ||
| updated_resources.remove(LayoutResource) | ||
| updated_resources.remove(ComponentsResource) | ||
| if not include_clientside_callbacks: | ||
| updated_resources.remove(ClientsideCallbacksResource) | ||
| if not include_pages: | ||
| updated_resources.remove(PagesResource) | ||
| updated_resources.remove(PageLayoutResource) |
There was a problem hiding this comment.
What do you think of creating lists to keep things tidy? Something like this:
LAYOUT_RESOURCES = [ComponentsResource, LayoutResource]
if not include_layout:
updated_resources.remove(item) for item in LAYOUT_RESOURCES| updated_tools.remove(GetDashComponentTool) | ||
| MCP_TOOL_PROVIDERS[:] = updated_tools | ||
|
|
||
| get_app().mcp_callback_map = None |
There was a problem hiding this comment.
Do you need to wrap this in a try/except block too?
There was a problem hiding this comment.
Do you need to reset MCP_DECORATED_FUNCTIONS like you do in tests/unit/mcp/conftest.py?
app_context.set(app)
if MCP_DECORATED_FUNCTIONS:
app.mcp_decorated_functions = dict(MCP_DECORATED_FUNCTIONS)
MCP_DECORATED_FUNCTIONS.clear()| Any parameter that is omitted will be reset to its default value. Calling | ||
| with no args will reset all configuration to its default state. |
There was a problem hiding this comment.
IMO, it seems safer to only mutate the config values when they're specifically passed in. On first call they get set with defaults or the provided values, then subsequent calls only update the specific values passed in.
| self._callback_list: list = [] | ||
| self.callback_api_paths: dict = {} | ||
| self.mcp_decorated_functions: dict = {} | ||
| self.mcp_callback_map: Any = None |
There was a problem hiding this comment.
| self.mcp_callback_map: Any = None | |
| self.mcp_callback_map: Optional["CallbackAdapterCollection"] = None |
| if get_app().backend.has_request_context(): | ||
| raise RuntimeError("MCP server can't be configured within a callback") | ||
| except AppNotFoundError: | ||
| ... |
There was a problem hiding this comment.
| ... | |
| pass |



This PR adds a function to configure the MCP server behaviour:
Rather than add a growing list of constructor args around the MCP server, this PR implements a single
configure_mcp_server()function that allows users to toggle various parts of the server with arguments:The existing
mcp_expose_docstringsconstructor arg has been removed and replaced by this function.