Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

preview: mcp tool for marimo docs (#5745)

Myles Scolnick2aefd064bfed
diff --git a/frontend/src/components/chat/chat-panel.tsx b/frontend/src/components/chat/chat-panel.tsx
index 004bf87707..e06f06335b 100644
--- a/frontend/src/components/chat/chat-panel.tsx
+++ b/frontend/src/components/chat/chat-panel.tsx
@@ -45,6 +45,7 @@ import {
import { getCodes } from "@/core/codemirror/copilot/getCodes";
import { aiAtom, aiEnabledAtom, userConfigAtom } from "@/core/config/config";
import type { UserConfig } from "@/core/config/config-schema";
+import { FeatureFlagged } from "@/core/config/feature-flag";
import { invokeAiTool, saveUserConfig } from "@/core/network/requests";
import { useRuntimeManager } from "@/core/runtime/config";
import { ErrorBanner } from "@/plugins/impl/common/error-banner";
@@ -245,32 +246,32 @@ const ChatInputFooter: React.FC<ChatInputFooterProps> = memo(
({ input, onSendClick, isLoading, onStop }) => {
const ai = useAtomValue(aiAtom);
const [userConfig, setUserConfig] = useAtom(userConfigAtom);
- // const currentMode = ai?.mode || "manual";
+ const currentMode = ai?.mode || "manual";
const currentModel = ai?.open_ai?.model || "o4-mini";
- // const modeOptions = [
- // {
- // value: "ask",
- // label: "Ask",
- // subtitle: "Read-only tools",
- // },
- // {
- // value: "manual",
- // label: "Manual",
- // subtitle: "No tools",
- // },
- // ];
-
- // const handleModeChange = async (newMode: "ask" | "manual") => {
- // const newConfig: UserConfig = {
- // ...userConfig,
- // ai: {
- // ...userConfig.ai,
- // mode: newMode,
- // },
- // };
- // saveConfig(newConfig);
- // };
+ const modeOptions = [
+ {
+ value: "ask",
+ label: "Ask",
+ subtitle: "Read-only tools",
+ },
+ {
+ value: "manual",
+ label: "Manual",
+ subtitle: "No tools",
+ },
+ ];
+
+ const handleModeChange = async (newMode: "ask" | "manual") => {
+ const newConfig: UserConfig = {
+ ...userConfig,
+ ai: {
+ ...userConfig.ai,
+ mode: newMode,
+ },
+ };
+ saveConfig(newConfig);
+ };
const handleModelChange = async (newModel: string) => {
const newConfig: UserConfig = {
@@ -295,28 +296,29 @@ const ChatInputFooter: React.FC<ChatInputFooterProps> = memo(
return (
<div className="px-3 py-2 border-t border-border/20 flex items-center justify-between">
<div className="flex items-center gap-2">
- {/* TODO: ADD BACK ONCE THERE ARE TOOLS FOR ASK MODE */}
- {/* <Select value={currentMode} onValueChange={handleModeChange}>
- <SelectTrigger className="h-6 text-xs border-border !shadow-none !ring-0 bg-muted hover:bg-muted/30 py-0 px-2 gap-1">
- <SelectValue placeholder="manual" />
- </SelectTrigger>
- <SelectContent>
- {modeOptions.map((option) => (
- <SelectItem
- key={option.value}
- value={option.value}
- className="text-xs"
- subtitle={
- <div className="text-muted-foreground text-xs pl-2">
- {option.subtitle}
- </div>
- }
- >
- {option.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select> */}
+ <FeatureFlagged feature="mcp_docs">
+ <Select value={currentMode} onValueChange={handleModeChange}>
+ <SelectTrigger className="h-6 text-xs border-border !shadow-none !ring-0 bg-muted hover:bg-muted/30 py-0 px-2 gap-1">
+ <SelectValue placeholder="manual" />
+ </SelectTrigger>
+ <SelectContent>
+ {modeOptions.map((option) => (
+ <SelectItem
+ key={option.value}
+ value={option.value}
+ className="text-xs"
+ subtitle={
+ <div className="text-muted-foreground text-xs pl-2">
+ {option.subtitle}
+ </div>
+ }
+ >
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </FeatureFlagged>
<Select value={currentModel} onValueChange={handleModelChange}>
<SelectTrigger className="h-6 text-xs border-border !shadow-none !ring-0 bg-muted hover:bg-muted/30 py-0 px-2 gap-1">
<SelectValue placeholder="Model" />
diff --git a/frontend/src/core/config/feature-flag.tsx b/frontend/src/core/config/feature-flag.tsx
index 15c8cc6651..3e9846e894 100644
--- a/frontend/src/core/config/feature-flag.tsx
+++ b/frontend/src/core/config/feature-flag.tsx
@@ -12,6 +12,7 @@ export interface ExperimentalFeatures {
wasm_layouts: boolean; // Used in playground (community cloud)
rtc_v2: boolean;
performant_table_charts: boolean;
+ mcp_docs: boolean;
// Add new feature flags here
}
@@ -21,6 +22,7 @@ const defaultValues: ExperimentalFeatures = {
wasm_layouts: false,
rtc_v2: false,
performant_table_charts: false,
+ mcp_docs: false,
};
export function getFeatureFlag<T extends keyof ExperimentalFeatures>(
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index face4da902..960136fa59 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -485,7 +485,10 @@ class MCPConfig(TypedDict):
DEFAULT_MCP_CONFIG: MCPConfig = MCPConfig(
mcpServers={
- # TODO(bjoaquinc): add Marimo MCP server here after it is implemented
+ "marimo": MCPServerStreamableHttpConfig(
+ url="https://mcp.marimo.app/mcp"
+ ),
+ # TODO(bjoaquinc): add more Marimo MCP servers here after they are implemented
}
)
diff --git a/marimo/_server/api/lifespans.py b/marimo/_server/api/lifespans.py
index 2fa85fe9ee..48d3e01c3a 100644
--- a/marimo/_server/api/lifespans.py
+++ b/marimo/_server/api/lifespans.py
@@ -50,11 +50,30 @@ async def lsp(app: Starlette) -> AsyncIterator[None]:
async def mcp(app: Starlette) -> AsyncIterator[None]:
state = AppState.from_app(app)
session_mgr = state.session_manager
+ user_config = state.config_manager.get_config()
+ mcp_docs_enabled = user_config.get("experimental", {}).get(
+ "mcp_docs", False
+ )
# Only start MCP servers in Edit mode
- if session_mgr.mode == SessionMode.EDIT:
+ if session_mgr.mode == SessionMode.EDIT and mcp_docs_enabled:
# add MCP server here after it is implemented
- ...
+ try:
+ from marimo._server.ai.mcp import get_mcp_client
+
+ mcp_client = get_mcp_client()
+ if mcp_client and mcp_client.servers:
+ LOGGER.debug(
+ f"Starting MCP servers: {list(mcp_client.servers.keys())}"
+ )
+ await mcp_client.connect_to_all_servers()
+ LOGGER.info(
+ f"MCP servers connected: {len(mcp_client.servers)}"
+ )
+ else:
+ LOGGER.debug("No MCP servers configured")
+ except Exception as e:
+ LOGGER.warning(f"Failed to connect MCP servers: {e}")
yield
diff --git a/pyproject.toml b/pyproject.toml
index 1a5a1fefbe..820d9434f1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -529,6 +529,7 @@ format_on_save = true
[tool.marimo.experimental]
multi_column = true
performant_table_charts = true
+mcp_docs = true
[tool.marimo.display]
dataframes = "rich"