Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat: jan browser mcp as chat input shortcut (#7074)

Louisf51ef54cc5b6
diff --git a/web-app/src/containers/ChatInput.tsx b/web-app/src/containers/ChatInput.tsx
index 5c743fd9b..83fd6c78d 100644
--- a/web-app/src/containers/ChatInput.tsx
+++ b/web-app/src/containers/ChatInput.tsx
@@ -15,8 +15,6 @@ import {
import { ArrowRight } from 'lucide-react'
import {
IconPhoto,
- IconWorld,
- IconAtom,
IconTool,
IconCodeCircle2,
IconPlayerStopFilled,
@@ -24,6 +22,7 @@ import {
IconPaperclip,
IconLoader2,
IconCheck,
+ IconWorld,
} from '@tabler/icons-react'
import { useTranslation } from '@/i18n/react-i18next-compat'
import { useGeneralSetting } from '@/hooks/useGeneralSetting'
@@ -45,6 +44,7 @@ import { ExtensionTypeEnum, MCPExtension, fs, RAGExtension, VectorDBExtension }
import { ExtensionManager } from '@/lib/extension'
import { useAttachments } from '@/hooks/useAttachments'
import { toast } from 'sonner'
+import { useMCPServers } from '@/hooks/useMCPServers'
import { PlatformFeatures } from '@/lib/platform/const'
import { PlatformFeature } from '@/lib/platform/types'
import { isPlatformTauri } from '@/lib/platform/utils'
@@ -116,6 +116,10 @@ const ChatInput = ({
[activeModels, selectedModel?.id]
)
+ const { mcpServers, editServer, syncServers } = useMCPServers()
+ const janBrowserMCPActive = mcpServers['Jan Browser MCP']?.active || false
+ const [isJanBrowserMCPLoading, setIsJanBrowserMCPLoading] = useState(false)
+
const attachmentsEnabled = useAttachments((s) => s.enabled)
// Determine whether to show the Attach documents button (simple gating)
const showAttachmentButton =
@@ -183,10 +187,10 @@ const ChatInput = ({
prev.map((att) =>
att.name === fileName
? {
- ...att,
- processing: status === 'processing',
- processed: status === 'done' ? true : att.processed,
- }
+ ...att,
+ processing: status === 'processing',
+ processed: status === 'done' ? true : att.processed,
+ }
: att
)
)
@@ -393,12 +397,12 @@ const ChatInput = ({
prev.map((a) =>
a.path === doc.path && a.type === 'document'
? {
- ...a,
- processing: false,
- processed: true,
- id: fileInfo.id,
- chunkCount: fileInfo.chunk_count,
- }
+ ...a,
+ processing: false,
+ processed: true,
+ id: fileInfo.id,
+ chunkCount: fileInfo.chunk_count,
+ }
: a
)
)
@@ -584,11 +588,11 @@ const ChatInput = ({
prev.map((a) =>
a.name === img.name && a.type === 'image'
? {
- ...a,
- processing: false,
- processed: true,
- id: result.id,
- }
+ ...a,
+ processing: false,
+ processed: true,
+ id: result.id,
+ }
: a
)
)
@@ -784,6 +788,50 @@ const ChatInput = ({
}
}
+ const handleBrowseClick = async () => {
+ const janBrowserConfig = mcpServers['Jan Browser MCP']
+ if (!janBrowserConfig) {
+ toast.error('Jan Browser MCP not found', {
+ description: 'Please check your MCP server configuration',
+ })
+ return
+ }
+
+ const newActiveState = !janBrowserMCPActive
+
+ setIsJanBrowserMCPLoading(true)
+ try {
+ if (newActiveState) {
+ // Activate the server
+ await serviceHub
+ .mcp()
+ .activateMCPServer('Jan Browser MCP', {
+ ...janBrowserConfig,
+ active: true,
+ })
+ toast.success('Jan Browser MCP enabled')
+ } else {
+ // Deactivate the server
+ await serviceHub.mcp().deactivateMCPServer('Jan Browser MCP')
+ toast.success('Jan Browser MCP disabled')
+ }
+
+ // Update the config
+ editServer('Jan Browser MCP', {
+ ...janBrowserConfig,
+ active: newActiveState,
+ })
+ await syncServers()
+ } catch (error) {
+ toast.error('Failed to toggle Jan Browser MCP', {
+ description: error instanceof Error ? error.message : String(error),
+ })
+ console.error('Error toggling Jan Browser MCP:', error)
+ } finally {
+ setIsJanBrowserMCPLoading(false)
+ }
+ }
+
const handlePaste = async (e: React.ClipboardEvent) => {
// Only process images if model supports mmproj
if (hasMmproj) {
@@ -1071,7 +1119,7 @@ const ChatInput = ({
<div className="px-1 flex items-center gap-1 flex-1 min-w-0">
<div
className={cn(
- 'px-1 flex items-center w-full',
+ 'px-1 flex items-center w-full gap-1',
streamingContent && 'opacity-50 pointer-events-none'
)}
>
@@ -1165,7 +1213,46 @@ const ChatInput = ({
</Tooltip>
</TooltipProvider>
)}
-
+ {selectedModel?.capabilities?.includes('tools') && mcpServers['Jan Browser MCP'] && (
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <div
+ className={cn(
+ "h-7 p-1 flex items-center justify-center rounded-sm hover:bg-main-view-fg/10 transition-all duration-200 ease-in-out gap-1 cursor-pointer",
+ janBrowserMCPActive && "bg-accent/10",
+ isJanBrowserMCPLoading && "opacity-70 cursor-not-allowed"
+ )}
+ onClick={isJanBrowserMCPLoading ? undefined : handleBrowseClick}
+ >
+ {isJanBrowserMCPLoading ? (
+ <IconLoader2
+ size={18}
+ className="text-accent animate-spin"
+ />
+ ) : (
+ <IconWorld
+ size={18}
+ className={cn(
+ "text-main-view-fg/50",
+ janBrowserMCPActive && "text-accent"
+ )}
+ />
+ )}
+ </div>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>
+ {isJanBrowserMCPLoading
+ ? 'Starting...'
+ : janBrowserMCPActive
+ ? 'Browse (Active)'
+ : 'Browse'}
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ )}
{selectedModel?.capabilities?.includes('tools') &&
hasActiveMCPServers &&
(MCPToolComponent ? (
@@ -1209,21 +1296,18 @@ const ChatInput = ({
return (
<div
className={cn(
- 'h-7 p-1 flex items-center justify-center rounded-sm hover:bg-main-view-fg/10 transition-all duration-200 ease-in-out gap-1 cursor-pointer relative',
- isOpen && 'bg-main-view-fg/10'
+ 'h-7 p-1 flex items-center justify-center rounded-sm hover:bg-main-view-fg/10 transition-all duration-200 ease-in-out gap-1 cursor-pointer',
+ isOpen && 'bg-main-view-fg/10',
+ toolsCount > 0 && 'bg-accent/10'
)}
>
<IconTool
size={18}
- className="text-main-view-fg/50"
+ className={cn(
+ "text-main-view-fg/50",
+ toolsCount > 0 && "text-accent"
+ )}
/>
- {toolsCount > 0 && (
- <div className="absolute -top-2 -right-2 bg-accent text-accent-fg text-xs rounded-full size-5 flex items-center justify-center font-medium">
- <span className="leading-0 text-xs">
- {toolsCount > 99 ? '99+' : toolsCount}
- </span>
- </div>
- )}
</div>
)
}}
@@ -1236,40 +1320,6 @@ const ChatInput = ({
</Tooltip>
</TooltipProvider>
))}
- {selectedModel?.capabilities?.includes('web_search') && (
- <TooltipProvider>
- <Tooltip>
- <TooltipTrigger asChild>
- <div className="h-7 p-1 flex items-center justify-center rounded-sm hover:bg-main-view-fg/10 transition-all duration-200 ease-in-out gap-1">
- <IconWorld
- size={18}
- className="text-main-view-fg/50"
- />
- </div>
- </TooltipTrigger>
- <TooltipContent>
- <p>Web Search</p>
- </TooltipContent>
- </Tooltip>
- </TooltipProvider>
- )}
- {selectedModel?.capabilities?.includes('reasoning') && (
- <TooltipProvider>
- <Tooltip>
- <TooltipTrigger asChild>
- <div className="h-7 p-1 flex items-center justify-center rounded-sm hover:bg-main-view-fg/10 transition-all duration-200 ease-in-out gap-1">
- <IconAtom
- size={18}
- className="text-main-view-fg/50"
- />
- </div>
- </TooltipTrigger>
- <TooltipContent>
- <p>{t('reasoning')}</p>
- </TooltipContent>
- </Tooltip>
- </TooltipProvider>
- )}
</div>
</div>
diff --git a/web-app/src/containers/DropdownModelProvider.tsx b/web-app/src/containers/DropdownModelProvider.tsx
index 782706141..27092da18 100644
--- a/web-app/src/containers/DropdownModelProvider.tsx
+++ b/web-app/src/containers/DropdownModelProvider.tsx
@@ -460,7 +460,7 @@ const DropdownModelProvider = ({
return (
<Popover open={open} onOpenChange={onOpenChange}>
- <div className="bg-main-view-fg/5 hover:bg-main-view-fg/8 px-2 py-1 flex items-center gap-1.5 rounded-sm mr-2">
+ <div className="bg-main-view-fg/5 hover:bg-main-view-fg/8 px-2 py-1 flex items-center gap-1.5 rounded-sm">
<PopoverTrigger asChild>
<button
type="button"
diff --git a/web-app/src/containers/DropdownToolsAvailable.tsx b/web-app/src/containers/DropdownToolsAvailable.tsx
index 80100c15d..fc38bd667 100644
--- a/web-app/src/containers/DropdownToolsAvailable.tsx
+++ b/web-app/src/containers/DropdownToolsAvailable.tsx
@@ -34,7 +34,9 @@ export default function DropdownToolsAvailable({
initialMessage = false,
onOpenChange,
}: DropdownToolsAvailableProps) {
- const tools = useAppState((state) => state.tools)
+ const allTools = useAppState((state) => state.tools)
+ // Filter out Jan Browser MCP tools
+ const tools = allTools.filter((tool) => tool.server !== 'Jan Browser MCP')
const [isOpen, setIsOpen] = useState(false)
const { t } = useTranslation()