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: expose orchestrator IPC on MCP service and config fields

dataCenter4306445b5cdd688
diff --git a/web-app/src/hooks/useMCPServers.ts b/web-app/src/hooks/useMCPServers.ts
index 9c6d197f4..54aae948b 100644
--- a/web-app/src/hooks/useMCPServers.ts
+++ b/web-app/src/hooks/useMCPServers.ts
@@ -12,6 +12,10 @@ export type MCPServerConfig = {
headers?: Record<string, string>
timeout?: number
official?: boolean
+ // Capability tags used by the orchestrator to route requests (e.g. ["web", "filesystem"])
+ capabilities?: string[]
+ // Short description of what the server provides, used by the intent classifier
+ description?: string
}
// Define the structure of all MCP servers
diff --git a/web-app/src/services/__tests__/mcp.test.ts b/web-app/src/services/__tests__/mcp.test.ts
index c294a5151..66e3148c0 100644
--- a/web-app/src/services/__tests__/mcp.test.ts
+++ b/web-app/src/services/__tests__/mcp.test.ts
@@ -3,6 +3,14 @@ import { TauriMCPService } from '../mcp/tauri'
import { MCPTool } from '@/types/completion'
import { DEFAULT_MCP_SETTINGS } from '@/hooks/useMCPServers'
+// Mock @tauri-apps/api/core so TauriMCPService.getToolsForServers and
+// getServerSummaries can be tested without a real Tauri runtime.
+vi.mock('@tauri-apps/api/core', () => ({
+ invoke: vi.fn(),
+}))
+import { invoke } from '@tauri-apps/api/core'
+const mockInvoke = invoke as ReturnType<typeof vi.fn>
+
// Mock the global window.core.api
const mockCore = {
api: {
@@ -29,6 +37,7 @@ describe('TauriMCPService', () => {
beforeEach(() => {
mcpService = new TauriMCPService()
vi.clearAllMocks()
+ mockInvoke.mockReset()
})
describe('updateMCPConfig', () => {
@@ -443,4 +452,79 @@ describe('TauriMCPService', () => {
expect(result).toEqual(toolResult)
})
})
+
+ // ─── getToolsForServers ──────────────────────────────────────────────────
+
+ describe('getToolsForServers', () => {
+ it('invokes get_tools_for_servers with the provided server names', async () => {
+ const mockTools: MCPTool[] = [
+ { name: 'read_file', description: 'Read a file', inputSchema: { type: 'object' }, server: 'filesystem' },
+ ]
+ mockInvoke.mockResolvedValue(mockTools)
+
+ const result = await mcpService.getToolsForServers(['filesystem'])
+
+ expect(mockInvoke).toHaveBeenCalledWith('get_tools_for_servers', { serverNames: ['filesystem'] })
+ expect(result).toEqual(mockTools)
+ })
+
+ it('returns empty array when no servers are specified', async () => {
+ mockInvoke.mockResolvedValue([])
+
+ const result = await mcpService.getToolsForServers([])
+
+ expect(mockInvoke).toHaveBeenCalledWith('get_tools_for_servers', { serverNames: [] })
+ expect(result).toEqual([])
+ })
+
+ it('supports multiple server names', async () => {
+ const mockTools: MCPTool[] = [
+ { name: 'read_file', description: 'Read', inputSchema: {}, server: 'fs' },
+ { name: 'browse', description: 'Browse', inputSchema: {}, server: 'web' },
+ ]
+ mockInvoke.mockResolvedValue(mockTools)
+
+ const result = await mcpService.getToolsForServers(['fs', 'web'])
+
+ expect(mockInvoke).toHaveBeenCalledWith('get_tools_for_servers', { serverNames: ['fs', 'web'] })
+ expect(result).toHaveLength(2)
+ })
+
+ it('propagates errors from invoke', async () => {
+ mockInvoke.mockRejectedValue(new Error('Tauri IPC error'))
+
+ await expect(mcpService.getToolsForServers(['fs'])).rejects.toThrow('Tauri IPC error')
+ })
+ })
+
+ // ─── getServerSummaries ──────────────────────────────────────────────────
+
+ describe('getServerSummaries', () => {
+ it('invokes get_server_summaries and returns the result', async () => {
+ const mockSummaries = [
+ { name: 'filesystem', capabilities: ['files', 'disk'], description: 'Read/write local files' },
+ { name: 'browser', capabilities: ['web', 'search'], description: 'Browse the web' },
+ ]
+ mockInvoke.mockResolvedValue(mockSummaries)
+
+ const result = await mcpService.getServerSummaries()
+
+ expect(mockInvoke).toHaveBeenCalledWith('get_server_summaries')
+ expect(result).toEqual(mockSummaries)
+ })
+
+ it('returns empty array when no servers are connected', async () => {
+ mockInvoke.mockResolvedValue([])
+
+ const result = await mcpService.getServerSummaries()
+
+ expect(result).toEqual([])
+ })
+
+ it('propagates errors from invoke', async () => {
+ mockInvoke.mockRejectedValue(new Error('no servers'))
+
+ await expect(mcpService.getServerSummaries()).rejects.toThrow('no servers')
+ })
+ })
})
diff --git a/web-app/src/services/mcp/default.ts b/web-app/src/services/mcp/default.ts
index d08f2daef..4f61c0d41 100644
--- a/web-app/src/services/mcp/default.ts
+++ b/web-app/src/services/mcp/default.ts
@@ -4,7 +4,7 @@
import { MCPTool, MCPToolCallResult } from '@janhq/core'
import type { MCPServerConfig } from '@/hooks/useMCPServers'
-import type { MCPService, MCPConfig, ToolCallWithCancellationResult } from './types'
+import type { MCPService, MCPConfig, ServerSummary, ToolCallWithCancellationResult } from './types'
export class DefaultMCPService implements MCPService {
async updateMCPConfig(configs: string): Promise<void> {
@@ -24,6 +24,14 @@ export class DefaultMCPService implements MCPService {
return []
}
+ async getToolsForServers(_serverNames: string[]): Promise<MCPTool[]> {
+ return []
+ }
+
+ async getServerSummaries(): Promise<ServerSummary[]> {
+ return []
+ }
+
async getConnectedServers(): Promise<string[]> {
return []
}
diff --git a/web-app/src/services/mcp/tauri.ts b/web-app/src/services/mcp/tauri.ts
index 6f9a31ddd..da13ea10e 100644
--- a/web-app/src/services/mcp/tauri.ts
+++ b/web-app/src/services/mcp/tauri.ts
@@ -6,7 +6,7 @@ import { invoke } from '@tauri-apps/api/core'
import { MCPTool } from '@/types/completion'
import { DEFAULT_MCP_SETTINGS } from '@/hooks/useMCPServers'
import type { MCPServerConfig, MCPServers, MCPSettings } from '@/hooks/useMCPServers'
-import type { MCPConfig } from './types'
+import type { MCPConfig, ServerSummary } from './types'
import { DefaultMCPService } from './default'
export class TauriMCPService extends DefaultMCPService {
@@ -61,6 +61,14 @@ export class TauriMCPService extends DefaultMCPService {
return window.core?.api?.getTools()
}
+ async getToolsForServers(serverNames: string[]): Promise<MCPTool[]> {
+ return invoke('get_tools_for_servers', { serverNames })
+ }
+
+ async getServerSummaries(): Promise<ServerSummary[]> {
+ return invoke('get_server_summaries')
+ }
+
async getConnectedServers(): Promise<string[]> {
return window.core?.api?.getConnectedServers()
}
diff --git a/web-app/src/services/mcp/types.ts b/web-app/src/services/mcp/types.ts
index 40dd17c36..8d4020a00 100644
--- a/web-app/src/services/mcp/types.ts
+++ b/web-app/src/services/mcp/types.ts
@@ -16,11 +16,22 @@ export interface ToolCallWithCancellationResult {
token: string
}
+/** Lightweight server metadata used by the orchestrator for tool routing. */
+export interface ServerSummary {
+ name: string
+ capabilities: string[]
+ description: string
+}
+
export interface MCPService {
updateMCPConfig(configs: string): Promise<void>
restartMCPServers(): Promise<void>
getMCPConfig(): Promise<MCPConfig>
getTools(): Promise<MCPTool[]>
+ /** Fetch tools from a specific subset of servers. */
+ getToolsForServers(serverNames: string[]): Promise<MCPTool[]>
+ /** Return name/capabilities/description for all connected servers. */
+ getServerSummaries(): Promise<ServerSummary[]>
getConnectedServers(): Promise<string[]>
callTool(args: { toolName: string; serverName?: string; arguments: object }): Promise<MCPToolCallResult>
callToolWithCancellation(args: {