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.

feat: add mcp status and refresh (#6636)

Myles Scolnick7b72430a0541
diff --git a/frontend/src/components/app-config/mcp-config.tsx b/frontend/src/components/app-config/mcp-config.tsx
index 253d3bdd59..c8c4a03eec 100644
--- a/frontend/src/components/app-config/mcp-config.tsx
+++ b/frontend/src/components/app-config/mcp-config.tsx
@@ -1,6 +1,6 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import { CheckSquareIcon } from "lucide-react";
+import { CheckSquareIcon, Loader2, RefreshCwIcon } from "lucide-react";
import React from "react";
import type { UseFormReturn } from "react-hook-form";
import {
@@ -12,6 +12,8 @@ import {
} from "@/components/ui/card";
import { FormField, FormItem } from "@/components/ui/form";
import type { UserConfig } from "@/core/config/config-schema";
+import { useMCPRefresh, useMCPStatus } from "../mcp/hooks";
+import { McpStatusText } from "../mcp/mcp-status-indicator";
import { Button } from "../ui/button";
import { Kbd } from "../ui/kbd";
import { SettingSubtitle } from "./common";
@@ -45,10 +47,48 @@ const PRESET_CONFIGS: PresetConfig[] = [
export const MCPConfig: React.FC<MCPConfigProps> = ({ form, onSubmit }) => {
const { handleClick } = useOpenSettingsToTab();
+ const { data: status, refetch, isFetching } = useMCPStatus();
+ const { refresh, isRefreshing } = useMCPRefresh();
+
+ const handleRefresh = async () => {
+ await refresh();
+ refetch();
+ };
return (
<div className="flex flex-col gap-4">
- <SettingSubtitle>MCP Servers</SettingSubtitle>
+ <div className="flex items-center justify-between">
+ <SettingSubtitle>MCP Servers</SettingSubtitle>
+ <div className="flex items-center gap-2">
+ {status && <McpStatusText status={status.status} />}
+ <Button
+ variant="outline"
+ size="xs"
+ onClick={handleRefresh}
+ disabled={isRefreshing || isFetching}
+ >
+ {isRefreshing || isFetching ? (
+ <Loader2 className="h-3 w-3 animate-spin" />
+ ) : (
+ <RefreshCwIcon className="h-3 w-3" />
+ )}
+ </Button>
+ </div>
+ </div>
+ {status?.error && (
+ <div className="text-xs text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950/20 p-2 rounded">
+ {status.error}
+ </div>
+ )}
+ {status?.servers && (
+ <div className="text-xs text-muted-foreground">
+ {Object.entries(status.servers).map(([server, status]) => (
+ <div key={server}>
+ {server}: <McpStatusText status={status} />
+ </div>
+ ))}
+ </div>
+ )}
<p className="text-sm text-muted-foreground">
Enable Model Context Protocol (MCP) servers to provide additional
capabilities and data sources for AI features.
diff --git a/frontend/src/components/chat/chat-panel.tsx b/frontend/src/components/chat/chat-panel.tsx
index ecd1f4bf97..dce1e4263b 100644
--- a/frontend/src/components/chat/chat-panel.tsx
+++ b/frontend/src/components/chat/chat-panel.tsx
@@ -63,6 +63,7 @@ import {
} from "../editor/ai/completion-utils";
import { PanelEmptyState } from "../editor/chrome/panels/empty-state";
import { CopyClipboardIcon } from "../icons/copy-icon";
+import { MCPStatusIndicator } from "../mcp/mcp-status-indicator";
import { Input } from "../ui/input";
import { Tooltip, TooltipProvider } from "../ui/tooltip";
import { toast } from "../ui/use-toast";
@@ -120,6 +121,7 @@ const ChatHeader: React.FC<ChatHeaderProps> = ({
</Button>
</Tooltip>
<div className="flex items-center gap-2">
+ <MCPStatusIndicator />
<Tooltip content="AI Settings">
<Button
variant="text"
diff --git a/frontend/src/components/editor/database/schemas.ts b/frontend/src/components/editor/database/schemas.ts
index f54b20d73e..78fca69583 100644
--- a/frontend/src/components/editor/database/schemas.ts
+++ b/frontend/src/components/editor/database/schemas.ts
@@ -18,11 +18,7 @@ function passwordField() {
function tokenField(label?: string, required?: boolean) {
let field: z.ZodString | z.ZodOptional<z.ZodString> = z.string();
- if (required) {
- field = field.nonempty();
- } else {
- field = field.optional();
- }
+ field = required ? field.nonempty() : field.optional();
field = field.describe(
FieldOptions.of({
@@ -50,11 +46,7 @@ function warehouseNameField() {
function uriField(label?: string, required?: boolean) {
let field: z.ZodString | z.ZodOptional<z.ZodString> = z.string();
- if (required) {
- field = field.nonempty();
- } else {
- field = field.optional();
- }
+ field = required ? field.nonempty() : field.optional();
return field.describe(
FieldOptions.of({ label: label || "URI", optionRegex: ".*uri.*" }),
diff --git a/frontend/src/components/forms/__tests__/form-utils.test.ts b/frontend/src/components/forms/__tests__/form-utils.test.ts
index 2d4f2efc79..2c05b01b90 100644
--- a/frontend/src/components/forms/__tests__/form-utils.test.ts
+++ b/frontend/src/components/forms/__tests__/form-utils.test.ts
@@ -191,7 +191,7 @@ describe("getDefaults", () => {
});
const result = getDefaults(schema) as { map: Map<string, number> };
expect(result.map instanceof Map).toBe(true);
- expect(Array.from(result.map.entries())).toEqual([["a", 1]]);
+ expect([...result.map.entries()]).toEqual([["a", 1]]);
});
it("should handle ZodSet with default", () => {
@@ -200,7 +200,7 @@ describe("getDefaults", () => {
});
const result = getDefaults(schema) as { set: Set<string> };
expect(result.set instanceof Set).toBe(true);
- expect(Array.from(result.set)).toEqual(["a", "b"]);
+ expect([...result.set]).toEqual(["a", "b"]);
});
it("should handle deeply nested defaults", () => {
diff --git a/frontend/src/components/mcp/hooks.ts b/frontend/src/components/mcp/hooks.ts
new file mode 100644
index 0000000000..43aa9b52dd
--- /dev/null
+++ b/frontend/src/components/mcp/hooks.ts
@@ -0,0 +1,48 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+
+import type { components } from "@marimo-team/marimo-api";
+import { useState } from "react";
+import { API } from "@/core/network/api";
+import { useAsyncData } from "@/hooks/useAsyncData";
+import { toast } from "../ui/use-toast";
+
+export type MCPStatus = components["schemas"]["MCPStatusResponse"];
+export type MCPRefreshResponse = components["schemas"]["MCPRefreshResponse"];
+
+/**
+ * Hook to fetch MCP server status
+ */
+export function useMCPStatus() {
+ return useAsyncData<MCPStatus>(async () => {
+ return API.get<MCPStatus>("/ai/mcp/status");
+ }, []);
+}
+
+/**
+ * Hook to refresh MCP server configuration
+ */
+export function useMCPRefresh() {
+ const [isRefreshing, setIsRefreshing] = useState(false);
+
+ const refresh = async () => {
+ setIsRefreshing(true);
+ try {
+ await API.post<object, MCPRefreshResponse>("/ai/mcp/refresh", {});
+ toast({
+ title: "MCP refreshed",
+ description: "MCP server configuration has been refreshed successfully",
+ });
+ } catch (error) {
+ toast({
+ title: "Refresh failed",
+ description:
+ error instanceof Error ? error.message : "Failed to refresh MCP",
+ variant: "danger",
+ });
+ } finally {
+ setIsRefreshing(false);
+ }
+ };
+
+ return { refresh, isRefreshing };
+}
diff --git a/frontend/src/components/mcp/mcp-status-indicator.tsx b/frontend/src/components/mcp/mcp-status-indicator.tsx
new file mode 100644
index 0000000000..0d973823f1
--- /dev/null
+++ b/frontend/src/components/mcp/mcp-status-indicator.tsx
@@ -0,0 +1,144 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+
+import { Loader2, PlugIcon, RefreshCwIcon } from "lucide-react";
+import { API } from "@/core/network/api";
+import { cn } from "@/utils/cn";
+import { Button } from "../ui/button";
+import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
+import { Tooltip } from "../ui/tooltip";
+import { toast } from "../ui/use-toast";
+import { useMCPStatus } from "./hooks";
+
+/**
+ * MCP Status indicator component
+ * Shows a small icon with status color and a popover with detailed information
+ */
+export const MCPStatusIndicator: React.FC = () => {
+ const { data: status, refetch, isFetching } = useMCPStatus();
+
+ const handleRefresh = async () => {
+ try {
+ await API.post<object, { success: boolean }>("/ai/mcp/refresh", {});
+ toast({
+ title: "MCP refreshed",
+ description: "MCP server configuration has been refreshed",
+ });
+ refetch();
+ } catch (error) {
+ toast({
+ title: "Refresh failed",
+ description:
+ error instanceof Error ? error.message : "Failed to refresh MCP",
+ variant: "danger",
+ });
+ }
+ };
+
+ const servers = status?.servers || {};
+ const hasServers = Object.keys(servers).length > 0;
+
+ return (
+ <Popover>
+ <Tooltip content="MCP Status">
+ <PopoverTrigger asChild={true}>
+ <Button variant="text" size="icon">
+ <PlugIcon
+ className={cn(
+ "h-4 w-4",
+ status?.status === "ok" && "text-green-500",
+ status?.status === "partial" && "text-yellow-500",
+ status?.status === "error" && hasServers && "text-red-500",
+ )}
+ />
+ </Button>
+ </PopoverTrigger>
+ </Tooltip>
+ <PopoverContent className="w-[320px]" align="start" side="right">
+ <div className="space-y-3">
+ <div className="flex items-center justify-between">
+ <h4 className="font-medium text-sm">MCP Server Status</h4>
+ <Button
+ variant="ghost"
+ size="xs"
+ onClick={handleRefresh}
+ disabled={isFetching}
+ >
+ {isFetching ? (
+ <Loader2 className="h-3 w-3 animate-spin" />
+ ) : (
+ <RefreshCwIcon className="h-3 w-3" />
+ )}
+ </Button>
+ </div>
+ {status && (
+ <div className="text-xs space-y-2">
+ {hasServers && (
+ <div className="flex justify-between items-center">
+ <span className="text-muted-foreground">Overall:</span>
+ <McpStatusText status={status.status} />
+ </div>
+ )}
+ {status.error && (
+ <div className="text-xs text-red-500 bg-red-50 dark:bg-red-950/20 p-2 rounded">
+ {status.error}
+ </div>
+ )}
+ {hasServers && (
+ <div className="space-y-1">
+ <div className="text-muted-foreground font-medium">
+ Servers:
+ </div>
+ {Object.entries(servers).map(([name, serverStatus]) => (
+ <div
+ key={name}
+ className="flex justify-between items-center pl-2"
+ >
+ <span className="text-muted-foreground truncate max-w-[180px]">
+ {name}
+ </span>
+ <McpStatusText status={serverStatus} />
+ </div>
+ ))}
+ </div>
+ )}
+ {!hasServers && (
+ <div className="text-muted-foreground text-center py-2">
+ No MCP servers configured. <br /> Configure under{" "}
+ <b>Settings &gt; AI &gt; MCP</b>
+ </div>
+ )}
+ </div>
+ )}
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+};
+
+export const McpStatusText: React.FC<{
+ status:
+ | "ok"
+ | "partial"
+ | "error"
+ | "failed"
+ | "disconnected"
+ | "pending"
+ | "connected";
+}> = ({ status }) => {
+ return (
+ <span
+ className={cn(
+ "text-xs font-medium",
+ status === "ok" && "text-green-500",
+ status === "partial" && "text-yellow-500",
+ status === "error" && "text-red-500",
+ status === "failed" && "text-red-500",
+ status === "disconnected" && "text-gray-500",
+ status === "pending" && "text-yellow-500",
+ status === "connected" && "text-green-500",
+ )}
+ >
+ {status}
+ </span>
+ );
+};
diff --git a/frontend/src/core/network/CachingRequestRegistry.ts b/frontend/src/core/network/CachingRequestRegistry.ts
index 87cce30563..549be17c44 100644
--- a/frontend/src/core/network/CachingRequestRegistry.ts
+++ b/frontend/src/core/network/CachingRequestRegistry.ts
@@ -56,9 +56,9 @@ export class CachingRequestRegistry<REQ, RES> {
const promise = this.delegate.request(req);
this.cache.set(key, promise);
- return promise.catch((err) => {
+ return promise.catch((error) => {
this.cache.delete(key);
- throw err;
+ throw error;
});
}
diff --git a/marimo/_cli/development/commands.py b/marimo/_cli/development/commands.py
index a3a71781a9..4f4231c96b 100644
--- a/marimo/_cli/development/commands.py
+++ b/marimo/_cli/development/commands.py
@@ -209,6 +209,8 @@ def _generate_server_api_schema() -> dict[str, Any]:
models.UpdateComponentValuesRequest,
models.InvokeAiToolRequest,
models.InvokeAiToolResponse,
+ models.MCPStatusResponse,
+ models.MCPRefreshResponse,
requests.CodeCompletionRequest,
requests.DeleteCellRequest,
requests.HTTPRequest,
diff --git a/marimo/_server/api/endpoints/ai.py b/marimo/_server/api/endpoints/ai.py
index 298a7a1e6e..0155646fa1 100644
--- a/marimo/_server/api/endpoints/ai.py
+++ b/marimo/_server/api/endpoints/ai.py
@@ -1,7 +1,7 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, Literal
from starlette.authentication import requires
from starlette.exceptions import HTTPException
@@ -22,6 +22,7 @@ from marimo._server.ai.config import (
get_edit_model,
get_max_tokens,
)
+from marimo._server.ai.mcp import MCPServerStatus, get_mcp_client
from marimo._server.ai.prompts import (
FIM_MIDDLE_TAG,
FIM_PREFIX_TAG,
@@ -47,6 +48,8 @@ from marimo._server.models.completion import (
from marimo._server.models.models import (
InvokeAiToolRequest,
InvokeAiToolResponse,
+ MCPRefreshResponse,
+ MCPStatusResponse,
)
from marimo._server.responses import StructResponse
from marimo._server.router import APIRouter
@@ -379,3 +382,184 @@ async def invoke_tool(
error=f"Tool invocation failed: {str(e)}",
)
)
+
+
[email protected]("/mcp/status")
+@requires("edit")
+async def mcp_status(
+ *,
+ request: Request,
+) -> Response:
+ """
+ responses:
+ 200:
+ description: Get MCP server status
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/MCPStatusResponse"
+ """
+ app_state = AppState(request)
+ app_state.require_current_session()
+
+ try:
+ # Try to get MCP client
+ mcp_client = get_mcp_client()
+
+ # Get all server statuses
+ server_statuses = mcp_client.get_all_server_statuses()
+
+ # Map internal status enum to API status strings
+ status_map: dict[
+ MCPServerStatus,
+ Literal["pending", "connected", "disconnected", "failed"],
+ ] = {
+ MCPServerStatus.CONNECTED: "connected",
+ MCPServerStatus.CONNECTING: "pending",
+ MCPServerStatus.DISCONNECTED: "disconnected",
+ MCPServerStatus.ERROR: "failed",
+ }
+
+ servers = {
+ name: status_map.get(status, "failed")
+ for name, status in server_statuses.items()
+ }
+
+ # Determine overall status
+ overall_status: Literal["ok", "partial", "error"] = "ok"
+ if not servers:
+ # No servers configured
+ overall_status = "ok"
+ error = None
+ elif all(s == "connected" for s in servers.values()):
+ # All servers connected
+ overall_status = "ok"
+ error = None
+ elif any(s == "connected" for s in servers.values()):
+ # Some servers connected
+ overall_status = "partial"
+ failed_servers = [
+ name for name, status in servers.items() if status == "failed"
+ ]
+ error = (
+ f"Some servers failed to connect: {', '.join(failed_servers)}"
+ )
+ else:
+ # No servers connected or all failed
+ overall_status = "error"
+ error = "No MCP servers connected"
+
+ return StructResponse(
+ MCPStatusResponse(
+ status=overall_status,
+ error=error,
+ servers=servers,
+ )
+ )
+
+ except ModuleNotFoundError:
+ # MCP dependencies not installed
+ return StructResponse(
+ MCPStatusResponse(
+ status="error",
+ error="Missing dependencies. Install with: pip install marimo[mcp]",
+ servers={},
+ )
+ )
+ except Exception as e:
+ LOGGER.error(f"Error getting MCP status: {e}")
+ return StructResponse(
+ MCPStatusResponse(
+ status="error",
+ error=str(e),
+ servers={},
+ )
+ )
+
+
[email protected]("/mcp/refresh")
+@requires("edit")
+async def mcp_refresh(
+ *,
+ request: Request,
+) -> Response:
+ """
+ responses:
+ 200:
+ description: Refresh MCP server configuration
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/MCPRefreshResponse"
+ """
+ app_state = AppState(request)
+ app_state.require_current_session()
+
+ try:
+ # Get the MCP client
+ mcp_client = get_mcp_client()
+
+ # Get current config
+ config = app_state.app_config_manager.get_config(hide_secrets=False)
+ mcp_config = config.get("mcp")
+
+ if mcp_config is None:
+ return StructResponse(
+ MCPRefreshResponse(
+ success=False,
+ error="MCP configuration is not set",
+ servers={},
+ )
+ )
+
+ # Reconfigure the client with the current configuration
+ # This will handle disconnecting/reconnecting as needed
+ await mcp_client.configure(mcp_config)
+
+ # Get updated server statuses
+ server_statuses = mcp_client.get_all_server_statuses()
+
+ # Map status to success boolean
+ servers = {
+ name: status == MCPServerStatus.CONNECTED
+ for name, status in server_statuses.items()
+ }
+
+ # Overall success if all servers are connected (or no servers)
+ success = len(servers) == 0 or all(servers.values())
+
+ error = None
+ if not success:
+ failed_servers = [
+ name for name, connected in servers.items() if not connected
+ ]
+ error = (
+ f"Some servers failed to connect: {', '.join(failed_servers)}"
+ )
+
+ return StructResponse(
+ MCPRefreshResponse(
+ success=success,
+ error=error,
+ servers=servers,
+ )
+ )
+
+ except ModuleNotFoundError:
+ # MCP dependencies not installed
+ return StructResponse(
+ MCPRefreshResponse(
+ success=False,
+ error="Missing dependencies. Install with: pip install marimo[mcp]",
+ servers={},
+ )
+ )
+ except Exception as e:
+ LOGGER.error(f"Error refreshing MCP: {e}")
+ return StructResponse(
+ MCPRefreshResponse(
+ success=False,
+ error=str(e),
+ servers={},
+ )
+ )
diff --git a/marimo/_server/api/endpoints/export.py b/marimo/_server/api/endpoints/export.py
index 41b4c846cf..106de58ca2 100644
--- a/marimo/_server/api/endpoints/export.py
+++ b/marimo/_server/api/endpoints/export.py
@@ -9,6 +9,7 @@ from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse, JSONResponse, PlainTextResponse
from marimo import _loggers
+from marimo._dependencies.dependencies import DependencyManager
from marimo._messaging.msgspec_encoder import asdict
from marimo._server.api.deps import AppState
from marimo._server.api.status import HTTPStatus
@@ -350,6 +351,11 @@ async def auto_export_as_ipynb(
return PlainTextResponse(status_code=HTTPStatus.NOT_MODIFIED)
async def _background_export() -> None:
+ # Check has nbformat installed
+ if not DependencyManager.nbformat.has():
+ LOGGER.error("Cannot snapshot to IPYNB: nbformat not installed")
+ return
+
# Reload the file manager to get the latest state
session.app_file_manager.reload()
diff --git a/marimo/_server/models/models.py b/marimo/_server/models/models.py
index bd0857dc8e..51a58a6aab 100644
--- a/marimo/_server/models/models.py
+++ b/marimo/_server/models/models.py
@@ -2,7 +2,7 @@
from __future__ import annotations
import os
-from typing import Any, Optional
+from typing import Any, Literal, Optional
import msgspec
@@ -161,3 +161,16 @@ class InvokeAiToolResponse(BaseResponse):
tool_name: str
result: Any
error: Optional[str] = None
+
+
+class MCPStatusResponse(msgspec.Struct, rename="camel"):
+ status: Literal["ok", "partial", "error"]
+ error: Optional[str] = None
+ servers: dict[
+ str, Literal["pending", "connected", "disconnected", "failed"]
+ ] = {} # server_name -> status
+
+
+class MCPRefreshResponse(BaseResponse):
+ error: Optional[str] = None
+ servers: dict[str, bool] = {} # server_name -> connected
diff --git a/packages/openapi/api.yaml b/packages/openapi/api.yaml
index f8fd8558d3..56f98178f3 100644
--- a/packages/openapi/api.yaml
+++ b/packages/openapi/api.yaml
@@ -2060,6 +2060,49 @@ components:
- mcpServers
title: MCPConfig
type: object
+ MCPRefreshResponse:
+ properties:
+ error:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ servers:
+ additionalProperties:
+ type: boolean
+ default: {}
+ type: object
+ success:
+ type: boolean
+ required:
+ - success
+ title: MCPRefreshResponse
+ type: object
+ MCPStatusResponse:
+ properties:
+ error:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ servers:
+ additionalProperties:
+ enum:
+ - connected
+ - disconnected
+ - failed
+ - pending
+ default: {}
+ type: object
+ status:
+ enum:
+ - error
+ - ok
+ - partial
+ required:
+ - status
+ title: MCPStatusResponse
+ type: object
MarimoAncestorPreventedError:
properties:
blamed_cell:
@@ -3690,6 +3733,24 @@ paths:
schema:
$ref: '#/components/schemas/InvokeAiToolResponse'
description: Tool invocation result
+ /api/ai/mcp/refresh:
+ post:
+ responses:
+ '200':
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/MCPRefreshResponse'
+ description: Refresh MCP server configuration
+ /api/ai/mcp/status:
+ get:
+ responses:
+ '200':
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/MCPStatusResponse'
+ description: Get MCP server status
/api/datasources/preview_column:
post:
requestBody:
diff --git a/packages/openapi/src/api.ts b/packages/openapi/src/api.ts
index 3ee67d9b42..2fc720898a 100644
--- a/packages/openapi/src/api.ts
+++ b/packages/openapi/src/api.ts
@@ -201,6 +201,76 @@ export interface paths {
patch?: never;
trace?: never;
};
+ "/api/ai/mcp/refresh": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ get?: never;
+ put?: never;
+ post: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Refresh MCP server configuration */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["MCPRefreshResponse"];
+ };
+ };
+ };
+ };
+ delete?: never;
+ options?: never;
+ head?: never;
+ patch?: never;
+ trace?: never;
+ };
+ "/api/ai/mcp/status": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ get: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Get MCP server status */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["MCPStatusResponse"];
+ };
+ };
+ };
+ };
+ put?: never;
+ post?: never;
+ delete?: never;
+ options?: never;
+ head?: never;
+ patch?: never;
+ trace?: never;
+ };
"/api/datasources/preview_column": {
parameters: {
query?: never;
@@ -3750,6 +3820,27 @@ export interface components {
};
presets?: ("context7" | "marimo")[];
};
+ /** MCPRefreshResponse */
+ MCPRefreshResponse: {
+ /** @default null */
+ error?: string | null;
+ /** @default {} */
+ servers?: {
+ [key: string]: boolean;
+ };
+ success: boolean;
+ };
+ /** MCPStatusResponse */
+ MCPStatusResponse: {
+ /** @default null */
+ error?: string | null;
+ /** @default {} */
+ servers?: {
+ [key: string]: "connected" | "disconnected" | "failed" | "pending";
+ };
+ /** @enum {unknown} */
+ status: "error" | "ok" | "partial";
+ };
/** MarimoAncestorPreventedError */
MarimoAncestorPreventedError: {
blamed_cell: string | null;
diff --git a/tests/_server/api/endpoints/test_ai.py b/tests/_server/api/endpoints/test_ai.py
index 188c2d90dd..2e6256686c 100644
--- a/tests/_server/api/endpoints/test_ai.py
+++ b/tests/_server/api/endpoints/test_ai.py
@@ -1294,6 +1294,46 @@ class TestInvokeToolEndpoint:
# Should fail without proper session
assert response.status_code in [400, 401, 403], response.text
+
+class TestMCPEndpoints:
+ """Tests for MCP status and refresh endpoints."""
+
+ @staticmethod
+ @with_session(SESSION_ID)
+ def test_mcp_status(client: TestClient) -> None:
+ """Test MCP status endpoint returns error when dependencies not installed."""
+ response = client.get(
+ "/api/ai/mcp/status",
+ headers=HEADERS,
+ )
+
+ assert response.status_code == 200, response.text
+ data = response.json()
+
+ # Should have required fields
+ assert "status" in data
+ assert "servers" in data
+ # Will likely error due to missing dependencies or no config
+ assert data["status"] in ["ok", "partial", "error"]
+
+ @staticmethod
+ @with_session(SESSION_ID)
+ def test_mcp_refresh(client: TestClient) -> None:
+ """Test MCP refresh endpoint returns error when dependencies not installed."""
+ response = client.post(
+ "/api/ai/mcp/refresh",
+ headers=HEADERS,
+ )
+
+ assert response.status_code == 200, response.text
+ data = response.json()
+
+ # Should have required fields
+ assert "success" in data
+ assert "servers" in data
+ # Will likely fail due to missing dependencies or no config
+ assert isinstance(data["success"], bool)
+
@staticmethod
@with_session(SESSION_ID)
@patch("marimo._server.api.endpoints.ai.get_tool_manager")