Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Upgraded `nodemailer` to `^9.0.1`. [#1356](https://github.com/sourcebot-dev/sourcebot/pull/1356)
- Upgraded `@opentelemetry/core` to `^2.8.0`. [#1413](https://github.com/sourcebot-dev/sourcebot/pull/1413)
- [EE] Fixed connector setup dialogs to add scrolling when connector setup content goes out of view.
- [EE] Fixed Ask connector MCP tools with provider-invalid names failing to run by sanitizing model-facing tool names while preserving raw names in the UI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Missing PR link in CHANGELOG entry.

Unlike the surrounding entries, this new line has no trailing [#<id>](url) link. As per coding guidelines, "Update CHANGELOG.md with an entry under [Unreleased] linking to the new PR" and "CHANGELOG.md entries must follow the format: single sentence description followed by a link in the format [#<id>](https://github.com/sourcebot-dev/sourcebot/pull/<id>)."

📝 Proposed fix
-- [EE] Fixed Ask connector MCP tools with provider-invalid names failing to run by sanitizing model-facing tool names while preserving raw names in the UI.
+- [EE] Fixed Ask connector MCP tools with provider-invalid names failing to run by sanitizing model-facing tool names while preserving raw names in the UI. [`#1423`](https://github.com/sourcebot-dev/sourcebot/pull/1423)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- [EE] Fixed Ask connector MCP tools with provider-invalid names failing to run by sanitizing model-facing tool names while preserving raw names in the UI.
- [EE] Fixed Ask connector MCP tools with provider-invalid names failing to run by sanitizing model-facing tool names while preserving raw names in the UI. [`#1423`](https://github.com/sourcebot-dev/sourcebot/pull/1423)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CHANGELOG.md` at line 35, The new CHANGELOG.md entry under [Unreleased] is
missing the required pull request link. Update the entry so the single-sentence
description is followed by the matching
[#<id>](https://github.com/sourcebot-dev/sourcebot/pull/<id>) link, consistent
with the surrounding CHANGELOG entries and the project’s CHANGELOG formatting
rules.

Source: Coding guidelines


## [5.0.4] - 2026-06-18

Expand Down
56 changes: 56 additions & 0 deletions packages/web/src/ee/features/chat/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,62 @@ beforeEach(() => {
});

describe('createMessageStream approval continuation', () => {
test('streams raw MCP tool names for client display', async () => {
const { getConnectedMcpClients } = await import('@/ee/features/chat/mcp/mcpClientFactory');
const { getMcpTools } = await import('@/ee/features/chat/mcp/mcpToolSets');
vi.mocked(getConnectedMcpClients).mockResolvedValueOnce([
{ serverId: 'server-backstage', serverName: 'Backstage' },
] as never);
vi.mocked(getMcpTools).mockResolvedValueOnce({
tools: {},
failedServers: [],
serverFaviconUrls: {
backstage: 'https://backstage.example.com/favicon.ico',
},
toolDisplayNames: {
'mcp_backstage__catalog_query-catalog-entities': 'catalog.query-catalog-entities',
},
cleanup: vi.fn(),
});
mockAi.streamText.mockReturnValue(createFakeStreamResult());

await createMessageStream({
chatId: 'chat-id',
messages: [createUserMessage()],
selectedRepos: [],
disabledMcpServerIds: [],
prisma: {},
model: {},
modelName: 'test-model',
promptCacheStrategy: noopStrategy,
onFinish: vi.fn(),
onError: () => 'error',
userId: 'user-id',
orgId: 1,
} as unknown as Parameters<typeof createMessageStream>[0]);

const execute = mockAi.latestCreateUIMessageStreamOptions?.execute;
if (!execute) {
throw new Error('Expected createUIMessageStream to capture execute callback.');
}

const write = vi.fn();
await execute({
writer: {
merge: vi.fn(),
write,
},
});

expect(write).toHaveBeenCalledWith({
type: 'data-mcp-tool',
data: {
modelToolName: 'mcp_backstage__catalog_query-catalog-entities',
rawToolName: 'catalog.query-catalog-entities',
},
});
});

test.each([
['dynamic', dynamicApprovalRespondedPart],
['static', staticApprovalRespondedPart],
Expand Down
13 changes: 12 additions & 1 deletion packages/web/src/ee/features/chat/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ export const createMessageStream = async ({
data: { sanitizedName, faviconUrl },
});
},
onMcpToolDiscovered: (modelToolName, rawToolName) => {
writer.write({
type: 'data-mcp-tool',
data: { modelToolName, rawToolName },
});
},
onMcpServerFailed: (serverName) => {
writer.write({
type: 'data-mcp-failed-server',
Expand Down Expand Up @@ -470,6 +476,7 @@ interface AgentOptions {
inputSources: Source[];
onWriteSource: (source: Source) => void;
onMcpServerDiscovered: (sanitizedName: string, faviconUrl: string) => void;
onMcpToolDiscovered: (modelToolName: string, rawToolName: string) => void;
onMcpServerFailed: (serverName: string) => void;
traceId: string;
chatId: string;
Expand All @@ -489,6 +496,7 @@ const createAgentStream = async ({
disabledMcpServerIds,
onWriteSource,
onMcpServerDiscovered,
onMcpToolDiscovered,
onMcpServerFailed,
traceId,
chatId,
Expand Down Expand Up @@ -525,7 +533,7 @@ const createAgentStream = async ({
}))
).filter((source) => source !== undefined);

let mcpToolSetsObj: McpToolsResult = { tools: {}, failedServers: [], serverFaviconUrls: {}, cleanup: async () => {} };
let mcpToolSetsObj: McpToolsResult = { tools: {}, failedServers: [], serverFaviconUrls: {}, toolDisplayNames: {}, cleanup: async () => {} };
if (userId && orgId && await hasEntitlement('ask') && disabledMcpServerIds !== undefined) {
try {
const allMcpClients = await getConnectedMcpClients(prisma, userId, orgId);
Expand All @@ -539,6 +547,9 @@ const createAgentStream = async ({
for (const [sanitizedName, faviconUrl] of Object.entries(mcpToolSetsObj.serverFaviconUrls)) {
onMcpServerDiscovered(sanitizedName, faviconUrl);
}
for (const [modelToolName, rawToolName] of Object.entries(mcpToolSetsObj.toolDisplayNames)) {
onMcpToolDiscovered(modelToolName, rawToolName);
}

if (mcpClients.length > 0) {
logger.info(`Connected to ${mcpClients.length} external MCP server(s): ${mcpClients.map(c => c.serverName).join(', ')}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { duplicateChat } from '@/features/chat/actions';
import { generateAndUpdateChatNameFromMessage } from '@/ee/features/chat/actions';
import { isServiceError } from '@/lib/utils';
import { NotConfiguredErrorBanner } from '@/features/chat/components/notConfiguredErrorBanner';
import { McpServerIconContext, McpServerIconMap } from '../../mcpServerIconContext';
import { McpServerIconContext, McpServerIconMap, McpToolNameContext, McpToolNameMap } from '../../mcpServerIconContext';
import { ToolApprovalProvider } from '../../toolApprovalContext';
import useCaptureEvent from '@/hooks/useCaptureEvent';
import { SignInPromptBanner } from './signInPromptBanner';
Expand Down Expand Up @@ -104,6 +104,18 @@ export const ChatThread = ({
return map;
});

const [mcpToolNameMap, setMcpToolNameMap] = useState<McpToolNameMap>(() => {
const map: McpToolNameMap = {};
initialMessages?.forEach((message) => {
message.parts
.filter((part) => part.type === 'data-mcp-tool')
.forEach((part) => {
map[part.data.modelToolName] = part.data.rawToolName;
});
});
return map;
});

const [failedMcpServers, setFailedMcpServers] = useState<string[]>(() => {
const names: string[] = [];
initialMessages?.forEach((message) => {
Expand Down Expand Up @@ -173,6 +185,12 @@ export const ChatThread = ({
[dataPart.data.sanitizedName]: dataPart.data.faviconUrl,
}));
}
if (dataPart.type === 'data-mcp-tool') {
setMcpToolNameMap((prev) => ({
...prev,
[dataPart.data.modelToolName]: dataPart.data.rawToolName,
}));
}
if (dataPart.type === 'data-mcp-failed-server') {
setFailedMcpServers((prev) => {
if (prev.includes(dataPart.data.serverName)) {
Expand Down Expand Up @@ -385,6 +403,7 @@ export const ChatThread = ({
return (
<ToolApprovalProvider value={addToolApprovalResponse}>
<McpServerIconContext.Provider value={mcpServerIconMap}>
<McpToolNameContext.Provider value={mcpToolNameMap}>
<ChatPaneDropzone
className="flex flex-col flex-1 min-h-0 w-full"
onFilesDropped={(files) => chatBoxRef.current?.addFiles(files)}
Expand Down Expand Up @@ -532,6 +551,7 @@ export const ChatThread = ({
)}
</div>
</ChatPaneDropzone>
</McpToolNameContext.Provider>
</McpServerIconContext.Provider>
</ToolApprovalProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ export const StepPartRenderer = ({ part, toolTokenUsageMap }: { part: SBChatMess
return null;
case 'data-source':
case 'data-mcp-server':
case 'data-mcp-tool':
case 'data-mcp-failed-server':
case 'data-attachment':
case 'file':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import { Button } from "@/components/ui/button";
import { McpFavicon } from "@/ee/features/chat/mcp/components/mcpFavicon";
import { useMcpServerIconMap } from "@/ee/features/chat/mcpServerIconContext";
import { McpToolNameMap, useMcpServerIconMap, useMcpToolNameMap } from "@/ee/features/chat/mcpServerIconContext";
import { useToolApproval } from "@/ee/features/chat/toolApprovalContext";
import { SBChatToolPart } from "@/features/chat/utils";
import { cn } from "@/lib/utils";
import { getToolName } from "ai";
import { ChevronRight } from "lucide-react";
import { useCallback, useState } from "react";
import { parseMcpToolName } from "./tools/mcpToolComponent";
import { getMcpToolDisplayParts } from "./tools/mcpToolComponent";
import { JsonHighlighter } from "./tools/jsonHighlighter";

export type ApprovalRequestedToolPart = SBChatToolPart & {
Expand All @@ -23,6 +23,7 @@ interface ToolApprovalBannerProps {
export const ToolApprovalBanner = ({ parts }: ToolApprovalBannerProps) => {
const addToolApprovalResponse = useToolApproval();
const iconMap = useMcpServerIconMap();
const rawToolNames = useMcpToolNameMap();

if (parts.length === 0) {
return null;
Expand All @@ -36,6 +37,7 @@ export const ToolApprovalBanner = ({ parts }: ToolApprovalBannerProps) => {
part={part}
addToolApprovalResponse={addToolApprovalResponse}
iconMap={iconMap}
rawToolNames={rawToolNames}
/>
))}
</div>
Expand All @@ -46,17 +48,17 @@ const ToolApprovalItem = ({
part,
addToolApprovalResponse,
iconMap,
rawToolNames,
}: {
part: ApprovalRequestedToolPart;
addToolApprovalResponse: ReturnType<typeof useToolApproval>;
iconMap: Record<string, string | undefined>;
rawToolNames: McpToolNameMap;
}) => {
const [isExpanded, setIsExpanded] = useState(false);
const partToolName = getToolName(part);
const parsed = parseMcpToolName(partToolName);
const serverName = parsed?.serverName ?? partToolName;
const toolName = parsed?.toolName ?? partToolName;
const faviconUrl = parsed ? iconMap[parsed.serverName] : undefined;
const display = getMcpToolDisplayParts(partToolName, rawToolNames);
const faviconUrl = display.serverName ? iconMap[display.serverName] : undefined;

const requestText = JSON.stringify(part.input, null, 2);

Expand All @@ -83,13 +85,13 @@ const ToolApprovalItem = ({
>
<McpFavicon faviconUrl={faviconUrl} className="w-4 h-4" />
<span className="text-sm text-foreground truncate">
{parsed ? (
{display.serverName ? (
<>
Agent wants to use <span className="font-medium">{toolName}</span> from <span className="font-medium">{serverName}</span>
Agent wants to use <span className="font-medium">{display.toolName}</span> from <span className="font-medium">{display.serverName}</span>
</>
) : (
<>
Agent wants to use <span className="font-medium">{toolName}</span>
Agent wants to use <span className="font-medium">{display.toolName}</span>
</>
)}
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { render, screen } from '@testing-library/react';
import type { DynamicToolUIPart } from 'ai';
import { describe, expect, test } from 'vitest';
import { McpToolNameContext } from '@/ee/features/chat/mcpServerIconContext';
import { getMcpToolDisplayParts, McpToolComponent } from './mcpToolComponent';

describe('getMcpToolDisplayParts', () => {
test('maps provider-safe MCP tool names back to raw tool names for display', () => {
expect(getMcpToolDisplayParts(
'mcp_backstage__catalog_query-catalog-entities',
{
'mcp_backstage__catalog_query-catalog-entities': 'catalog.query-catalog-entities',
},
)).toEqual({
serverName: 'backstage',
toolName: 'catalog.query-catalog-entities',
displayName: 'backstage: catalog.query-catalog-entities',
});
});

test('falls back to the provider-safe name for older messages without metadata', () => {
expect(getMcpToolDisplayParts('mcp_backstage__catalog_query-catalog-entities')).toEqual({
serverName: 'backstage',
toolName: 'catalog_query-catalog-entities',
displayName: 'backstage: catalog_query-catalog-entities',
});
});
});

describe('McpToolComponent', () => {
test('renders the raw MCP tool name when display metadata is available', () => {
const part = {
type: 'dynamic-tool',
toolName: 'mcp_backstage__catalog_query-catalog-entities',
toolCallId: 'tool-call-1',
state: 'approval-requested',
input: { filter: 'kind=component' },
} as DynamicToolUIPart;

render(
<McpToolNameContext.Provider value={{
'mcp_backstage__catalog_query-catalog-entities': 'catalog.query-catalog-entities',
}}>
<McpToolComponent part={part} />
</McpToolNameContext.Provider>
);

expect(screen.getByText('backstage: catalog.query-catalog-entities')).toBeTruthy();
expect(screen.getByText('Request (backstage: catalog.query-catalog-entities)')).toBeTruthy();
expect(screen.queryByText('backstage: catalog_query-catalog-entities')).toBeNull();
});
});
Loading
Loading