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
38 changes: 38 additions & 0 deletions apps/vscode-e2e/src/fixtures/mcp-dynamic-load.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { LLMock } from "@copilotkit/aimock"

import {
DYNAMIC_LOAD_CALL_IDS as ids,
DYNAMIC_LOAD_MARKERS as markers,
DYNAMIC_LOAD_QUERY,
} from "../suite/tools/fixtures/mcp-catalog"
import { toolResultContains } from "./tool-result"

const complete = (id: string, result: string) => ({
toolCalls: [{ name: "attempt_completion", arguments: JSON.stringify({ result }), id }],
})

// The resumed request still holds the load result, so its fixture comes before the load-result fixture.
export function addMcpDynamicLoadFixtures(mock: InstanceType<typeof LLMock>) {
mock.addFixture({
match: { userMessage: markers.resumed },
response: complete(ids.resumedDone, "Listed the tickets again."),
})
mock.addFixture({
match: { userMessage: markers.ungated },
response: complete(ids.ungatedDone, "Listed the tickets without dynamic loading."),
})
mock.addFixture({
match: { userMessage: markers.gated },
response: {
toolCalls: [{ name: "mcp_load", arguments: JSON.stringify({ query: DYNAMIC_LOAD_QUERY }), id: ids.load }],
},
})
mock.addFixture({
match: {
predicate: (req) =>
toolResultContains(req, ids.load, []) &&
req.messages.filter((message) => message.role === "tool").at(-1)?.tool_call_id === ids.load,
},
response: complete(ids.loadDone, "Loaded the Jira search tool."),
})
}
2 changes: 2 additions & 0 deletions apps/vscode-e2e/src/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { addReadFileResultFixtures } from "./fixtures/read-file"
import { addSearchFilesResultFixtures } from "./fixtures/search-files"
import { addSubtaskFixtures } from "./fixtures/subtasks"
import { addUseMcpToolResultFixtures } from "./fixtures/use-mcp-tool"
import { addMcpDynamicLoadFixtures } from "./fixtures/mcp-dynamic-load"
import { addWriteToFileResultFixtures } from "./fixtures/write-to-file"
import {
createScenarioWorkspace,
Expand Down Expand Up @@ -155,6 +156,7 @@ async function main() {
addSearchFilesResultFixtures(mock)
addSubtaskFixtures(mock)
addUseMcpToolResultFixtures(mock)
addMcpDynamicLoadFixtures(mock)
addWriteToFileResultFixtures(mock)
addDeepSeekV4Fixtures(mock)

Expand Down
58 changes: 58 additions & 0 deletions apps/vscode-e2e/src/suite/tools/fixtures/catalog-mcp-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as fs from "fs/promises"
import * as path from "path"
import { stdin, stdout, stderr } from "process"

import { catalogTools } from "./mcp-catalog"

type JsonRpcMessage = { jsonrpc: "2.0"; id?: string | number; method?: string; params?: { name?: string } }

const readyFile = process.env.MCP_TEST_READY_FILE
let buffer = ""

stdin.setEncoding("utf8")
stdin.on("data", (chunk) => {
buffer += chunk
let newlineIndex = buffer.indexOf("\n")
while (newlineIndex !== -1) {
const line = buffer.slice(0, newlineIndex).trim()
buffer = buffer.slice(newlineIndex + 1)
if (line) handleMessage(JSON.parse(line) as JsonRpcMessage).catch((error) => stderr.write(`${error}\n`))
newlineIndex = buffer.indexOf("\n")
}
})

async function handleMessage(message: JsonRpcMessage) {
if (message.id === undefined) return
switch (message.method) {
case "initialize":
return send(message.id, {
protocolVersion: "2024-11-05",
capabilities: { tools: {} },
serverInfo: { name: "test-catalog-server", version: "1.0.0" },
})
case "tools/list":
if (readyFile) {
await fs.mkdir(path.dirname(readyFile), { recursive: true })
await fs.writeFile(readyFile, "ready")
}
return send(message.id, {
tools: catalogTools.map(({ name, description }) => ({
name,
description,
inputSchema: { type: "object", properties: {} },
})),
})
case "resources/list":
return send(message.id, { resources: [] })
case "resources/templates/list":
return send(message.id, { resourceTemplates: [] })
case "tools/call":
return send(message.id, { content: [{ type: "text", text: `called ${message.params?.name}` }] })
default:
return send(message.id, {})
}
}

function send(id: string | number, result: unknown) {
stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id, result })}\n`)
}
42 changes: 42 additions & 0 deletions apps/vscode-e2e/src/suite/tools/fixtures/mcp-catalog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export const CATALOG_SERVER_NAME = "catalog"

// Two topics. As in the production catalog, short Jira tools mention jira_search_tickets, whose own
// description is long. Without a name weight, they outrank it.
export const catalogTools = [
{
name: "jira_search_tickets",
description:
"Run a JQL query and return the matching issues with the requested fields. Page with next_page_token until is_last is true, and keep the query, the fields and max_results the same between pages. Restricted projects are left out and named in a note. An unknown project, status or issue type comes back as an error.",
},
{ name: "jira_count_tickets", description: "Count Jira tickets on a board instead of paging jira_search_tickets." },
{
name: "jira_get_board",
description: "Get a Jira board with ticket counts. To list tickets, use jira_search_tickets.",
},
{ name: "jira_find_users", description: "Find Jira users for jira_search_tickets assignee filters." },
{ name: "slack_send_message", description: "Send a Slack message to a channel." },
{ name: "slack_add_reaction", description: "Add an emoji reaction to a Slack message." },
]

export const catalogToolName = (name: string) => `mcp--${CATALOG_SERVER_NAME}--${name}`

export const DYNAMIC_LOAD_MARKERS = {
gated: "MCP_DYNAMIC_LOAD_GATED",
ungated: "MCP_DYNAMIC_LOAD_UNGATED",
resumed: "MCP_DYNAMIC_LOAD_RESUMED",
}

export const DYNAMIC_LOAD_PROMPTS = {
gated: `${DYNAMIC_LOAD_MARKERS.gated}: count the jira tickets on the board`,
ungated: `${DYNAMIC_LOAD_MARKERS.ungated}: list my jira tickets`,
resumed: `${DYNAMIC_LOAD_MARKERS.resumed}: list them again`,
}

export const DYNAMIC_LOAD_CALL_IDS = {
load: "call_mcp_dynamic_load_load_001",
loadDone: "call_mcp_dynamic_load_load_002",
ungatedDone: "call_mcp_dynamic_load_ungated_001",
resumedDone: "call_mcp_dynamic_load_resumed_001",
}

export const DYNAMIC_LOAD_QUERY = "jira_search_tickets"
195 changes: 195 additions & 0 deletions apps/vscode-e2e/src/suite/tools/mcp-dynamic-load.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading