feat(api): integrate MCP tools support in Ollama chat route
Add support for Model Context Protocol (MCP) tools in the Ollama chat API. Detect model capabilities to use native tools or prompt engineering. Handle tool calls, execute them via MCPExecutor, and inject results back into the conversation for seamless tool-assisted responses. This enhances chat functionality by enabling external tool integration.
This commit is contained in:
1 parent
745746afa9
commit
4739a13458
18 files changed
+1782
-10
No files matched your search
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Tipos e interfaces para integração de MCPs no chat
|
||||
*/
|
||||
|
||||
/**
|
||||
* Representa um tool MCP com schema JSON
|
||||
*/
|
||||
export interface MCPTool {
|
||||
name: string;
|
||||
description: string;
|
||||
inputSchema: {
|
||||
type: "object";
|
||||
properties: Record<string, any>;
|
||||
required?: string[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Contexto de MCPs ativos para a conversa
|
||||
*/
|
||||
export interface MCPChatContext {
|
||||
mcpId: string;
|
||||
enabled: boolean;
|
||||
tools: MCPTool[];
|
||||
config: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resultado da execução de um MCP
|
||||
*/
|
||||
export interface MCPExecutionResult {
|
||||
success: boolean;
|
||||
toolName: string;
|
||||
mcpId: string;
|
||||
result?: any;
|
||||
error?: string;
|
||||
executionTime?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capabilities de function calling do modelo
|
||||
*/
|
||||
export interface ModelCapabilities {
|
||||
supportsNativeTools: boolean;
|
||||
requiresPromptEngineering: boolean;
|
||||
modelName: string;
|
||||
toolCallFormat?: "openai" | "anthropic" | "custom";
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuração de MCPs para chat
|
||||
*/
|
||||
export interface MCPChatConfig {
|
||||
alwaysActive: string[]; // MCPs sempre ativos
|
||||
neverUse: string[]; // MCPs nunca usar
|
||||
activationMode: "automatic" | "keywords" | "manual";
|
||||
}
|
||||
|
||||
/**
|
||||
* Intent detectado na mensagem do usuário
|
||||
*/
|
||||
export interface DetectedIntent {
|
||||
type:
|
||||
| "web_search"
|
||||
| "time"
|
||||
| "weather"
|
||||
| "file"
|
||||
| "code"
|
||||
| "database"
|
||||
| "other";
|
||||
confidence: number;
|
||||
keywords: string[];
|
||||
suggestedTools: string[];
|
||||
}
|
||||
Reference in new issue
Block a user