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.

2.8 KB
Raw Blame
/**
 * Default MCP Service - Generic implementation with minimal returns
 */

import { MCPTool } from '@janhq/core'
import type { MCPServerConfig } from '@/hooks/useMCPServers'
import type {
  MCPService,
  MCPConfig,
  MCPAuthStatus,
  ServerSummary,
  ToolCallWithCancellationResult,
} from './types'

export class DefaultMCPService implements MCPService {
  async updateMCPConfig(configs: string): Promise<void> {
    console.log('updateMCPConfig called with configs:', configs)
    // No-op - not implemented in default service
  }

  async restartMCPServers(): Promise<void> {
    // No-op
  }

  async getMCPConfig(): Promise<MCPConfig> {
    return {}
  }

  async getTools(): Promise<MCPTool[]> {
    return []
  }

  async getToolsForServers(serverNames: string[]): Promise<MCPTool[]> {
    void serverNames
    return []
  }

  async getServerSummaries(): Promise<ServerSummary[]> {
    return []
  }

  async getConnectedServers(): Promise<string[]> {
    return []
  }

  callToolWithCancellation(args: {
    toolName: string
    arguments: object
    threadId: string
    callId: string
    cancellationToken?: string
  }): ToolCallWithCancellationResult {
    console.log('callToolWithCancellation called with args:', args)
    return {
      promise: Promise.resolve({
        error: '',
        content: []
      }),
      cancel: () => Promise.resolve(),
      token: ''
    }
  }

  async cancelToolCall(cancellationToken: string): Promise<void> {
    console.log('cancelToolCall called with token:', cancellationToken)
    // No-op - not implemented in default service
  }

  async activateMCPServer(name: string, config: MCPServerConfig): Promise<void> {
    console.log('activateMCPServer called:', { name, config })
    // No-op - not implemented in default service
  }

  async deactivateMCPServer(name: string): Promise<void> {
    console.log('deactivateMCPServer called with name:', name)
    // No-op - not implemented in default service
  }

  async checkJanBrowserExtensionConnected(): Promise<boolean> {
    return false
  }

  /**
   * Without a backend there is no token store, so every server reports
   * `notApplicable` rather than `unauthenticated`: the latter would put a
   * "sign in" button on a build that cannot run the flow.
   */
  async getMCPAuthStatus(name: string): Promise<MCPAuthStatus> {
    void name
    return {
      state: 'notApplicable',
      canAuthenticate: false,
      hasCredentials: false,
      renewable: false,
      expiresAt: null,
    }
  }

  async authorizeMCPServer(name: string): Promise<void> {
    console.log('authorizeMCPServer called with name:', name)
    // No-op - not implemented in default service
  }

  async clearMCPAuth(name: string): Promise<boolean> {
    console.log('clearMCPAuth called with name:', name)
    return false
  }
}