Skip to content

Commit a4eeaed

Browse files
authored
fix: mcp enable check (#2049)
* fix: mcp enable check * chore: changelog
1 parent 8302535 commit a4eeaed

File tree

8 files changed

+44
-14
lines changed

8 files changed

+44
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to Chainlit will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## [2.4.301] - 2025-03-24
8+
9+
### Fixed
10+
11+
- Mcp button should not be displayed if `@on_mcp_connect` is not defined
12+
713
## [2.4.3] - 2025-03-23
814

915
### Added

backend/chainlit/config.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@
116116
# Sample rate of the audio
117117
sample_rate = 24000
118118
119-
[features.mcp]
120-
enabled = true
121-
122119
[features.mcp.sse]
123120
enabled = true
124121
@@ -239,7 +236,7 @@ class McpStdioFeature(DataClassJsonMixin):
239236

240237
@dataclass
241238
class McpFeature(DataClassJsonMixin):
242-
enabled: bool = True
239+
enabled: bool = False
243240
sse: McpSseFeature = Field(default_factory=McpSseFeature)
244241
stdio: McpStdioFeature = Field(default_factory=McpStdioFeature)
245242

backend/chainlit/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ async def project_settings(
761761
if config.code.on_audio_chunk:
762762
config.features.audio.enabled = True
763763

764+
if config.code.on_mcp_connect:
765+
config.features.mcp.enabled = True
766+
764767
debug_url = None
765768
data_layer = get_data_layer()
766769

@@ -1091,7 +1094,7 @@ async def connect_mcp(
10911094
status_code=401,
10921095
)
10931096

1094-
mcp_enabled = config.features.mcp.enabled and config.code.on_mcp_connect is not None
1097+
mcp_enabled = config.code.on_mcp_connect is not None
10951098
if mcp_enabled:
10961099
if payload.name in session.mcp_sessions:
10971100
old_client_session, old_exit_stack = session.mcp_sessions[payload.name]

backend/chainlit/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
except metadata.PackageNotFoundError:
66
# Case where package metadata is not available, default to a 'non-outdated' version.
77
# Ref: config.py::load_settings()
8-
__version__ = "2.4.3"
8+
__version__ = "2.4.301"

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "chainlit"
3-
version = "2.4.3"
3+
version = "2.4.301"
44
keywords = [
55
'LLM',
66
'Agents',

frontend/src/components/chat/MessageComposer/Mcp/AddForm.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,24 @@ import { Translator } from 'components/i18n';
2323
interface McpAddFormProps {
2424
onSuccess: () => void;
2525
onCancel: () => void;
26+
allowStdio?: boolean;
27+
allowSse?: boolean;
2628
}
2729

28-
export const McpAddForm = ({ onSuccess, onCancel }: McpAddFormProps) => {
30+
export const McpAddForm = ({
31+
onSuccess,
32+
onCancel,
33+
allowStdio,
34+
allowSse
35+
}: McpAddFormProps) => {
2936
const apiClient = useContext(ChainlitContext);
3037
const sessionId = useRecoilValue(sessionIdState);
3138
const setMcps = useSetRecoilState(mcpState);
3239

3340
const [serverName, setServerName] = useState('');
34-
const [serverType, setServerType] = useState<'stdio' | 'sse'>('stdio');
41+
const [serverType, setServerType] = useState<'stdio' | 'sse'>(
42+
allowStdio ? 'stdio' : 'sse'
43+
);
3544
const [serverUrl, setServerUrl] = useState('');
3645
const [serverCommand, setServerCommand] = useState('');
3746
const [isLoading, setIsLoading] = useState(false);
@@ -131,8 +140,10 @@ export const McpAddForm = ({ onSuccess, onCancel }: McpAddFormProps) => {
131140
<SelectValue placeholder="Type" />
132141
</SelectTrigger>
133142
<SelectContent>
134-
<SelectItem value="sse">sse</SelectItem>
135-
<SelectItem value="stdio">stdio</SelectItem>
143+
{allowSse ? <SelectItem value="sse">sse</SelectItem> : null}
144+
{allowStdio ? (
145+
<SelectItem value="stdio">stdio</SelectItem>
146+
) : null}
136147
</SelectContent>
137148
</Select>
138149
</div>

frontend/src/components/chat/MessageComposer/Mcp/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ const McpButton = ({ disabled }: Props) => {
3232
const { config } = useConfig();
3333
const [mcps] = useRecoilState(mcpState);
3434

35-
const isEnabled = !!config?.features.mcp;
3635
const [open, setOpen] = useState(false);
3736
const [activeTab, setActiveTab] = useState('add');
3837

39-
if (!isEnabled) return null;
38+
const allowSse = !!config?.features.mcp?.sse?.enabled;
39+
const allowStdio = !!config?.features.mcp?.stdio?.enabled;
40+
const allowMcp = !!config?.features.mcp?.enabled;
41+
42+
if (!allowMcp || (!allowSse && !allowStdio)) return null;
4043

4144
const connectedMcps = mcps.filter((mcp) => mcp.status === 'connected');
4245

@@ -90,6 +93,8 @@ const McpButton = ({ disabled }: Props) => {
9093
className="flex flex-col flex-grow gap-6 p-1"
9194
>
9295
<McpAddForm
96+
allowSse={allowSse}
97+
allowStdio={allowStdio}
9398
onSuccess={() => setActiveTab('list')}
9499
onCancel={() => setOpen(false)}
95100
/>

libs/react-client/src/types/config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ export interface IChainlitConfig {
5353
user_message_autoscroll?: boolean;
5454
latex?: boolean;
5555
edit_message?: boolean;
56-
mcp?: boolean;
56+
mcp?: {
57+
enabled?: boolean;
58+
sse?: {
59+
enabled?: boolean;
60+
};
61+
stdio?: {
62+
enabled?: boolean;
63+
};
64+
};
5765
};
5866
debugUrl?: string;
5967
userEnv: string[];

0 commit comments

Comments
 (0)