feat(mcp): add Model Context Protocol integration

Add  MCP integration including:
- New MCP settings tab with server configuration
- Tool invocation UI components
- API endpoints for MCP management
- Integration with chat system for tool execution
- Example configurations
This commit is contained in:
Roamin
2025-07-10 17:54:15 +00:00
parent 591c84572d
commit 5de162eec8
26 changed files with 2040 additions and 98 deletions

View File

@@ -7,6 +7,16 @@ import { WORK_DIR } from '~/utils/constants';
import WithTooltip from '~/components/ui/Tooltip';
import type { Message } from 'ai';
import type { ProviderInfo } from '~/types/model';
import type {
TextUIPart,
ReasoningUIPart,
ToolInvocationUIPart,
SourceUIPart,
FileUIPart,
StepStartUIPart,
} from '@ai-sdk/ui-utils';
import { ToolInvocations } from './ToolInvocations';
import type { ToolCallAnnotation } from '~/types/context';
interface AssistantMessageProps {
content: string;
@@ -19,6 +29,10 @@ interface AssistantMessageProps {
setChatMode?: (mode: 'discuss' | 'build') => void;
model?: string;
provider?: ProviderInfo;
parts:
| (TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart)[]
| undefined;
addToolResult: ({ toolCallId, result }: { toolCallId: string; result: any }) => void;
}
function openArtifactInWorkbench(filePath: string) {
@@ -57,6 +71,8 @@ export const AssistantMessage = memo(
setChatMode,
model,
provider,
parts,
addToolResult,
}: AssistantMessageProps) => {
const filteredAnnotations = (annotations?.filter(
(annotation: JSONValue) =>
@@ -81,6 +97,11 @@ export const AssistantMessage = memo(
totalTokens: number;
} = filteredAnnotations.find((annotation) => annotation.type === 'usage')?.value;
const toolInvocations = parts?.filter((part) => part.type === 'tool-invocation');
const toolCallAnnotations = filteredAnnotations.filter(
(annotation) => annotation.type === 'toolCall',
) as ToolCallAnnotation[];
return (
<div className="overflow-hidden w-full">
<>
@@ -155,6 +176,13 @@ export const AssistantMessage = memo(
</div>
</div>
</>
{toolInvocations && toolInvocations.length > 0 && (
<ToolInvocations
toolInvocations={toolInvocations}
toolCallAnnotations={toolCallAnnotations}
addToolResult={addToolResult}
/>
)}
<Markdown append={append} chatMode={chatMode} setChatMode={setChatMode} model={model} provider={provider} html>
{content}
</Markdown>